Replies: 2 comments 2 replies
-
Since this is for a config file, I assume the intended validator is your editor/IDE of choice. Unfortunately, a lot of editors/IDEs haven't implemented some of the newer JSON Schema features (specifically, {
"anyOf": [
{
"type": "object",
"properties": {
"type": { "enum": ["CPU", "GPU"] },
"temp": { "type": "boolean" }
},
"required": ["type"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": { "const": "LocalIp" },
"showIpv6": { "type": "boolean" },
"namePrefix": { "type": "string" }
},
"required": ["type"],
"additionalProperties": false
}
]
} In most validators, you won't get very good error messages with this pattern in some cases, but editors/IDEs tend to handle this kind of thing pretty well, so I think this will be a good approach for you. |
Beta Was this translation helpful? Give feedback.
-
Another question Can I make enums / constants case insensitive? |
Beta Was this translation helpful? Give feedback.
-
I'm creating JSON schema for the JSON configuration file of my project
This is the WIP schema: https://github.com/fastfetch-cli/fastfetch/blob/dev/src/data/json_schema.jsonc
The question:
My program have many modules. Each module have its own type. eg
"type"
specifies the module type. This is the only required property.Only if the module type is either
"CPU"
or"GPU"
, a user can specify another property"temp"
. Only if the module type is"LocalIp"
, a user can specify another two properties"showIpv6"
and"namePrefix"
. ModuleCPU
andGPU
cannot have propertyshowIpv6
andnamePrefix
. ModuleLocalIp
cannot have propertytemp
.What's the best way to do that?
Beta Was this translation helpful? Give feedback.
All reactions