I have two properties (propOne and propTwo).
If one of the properties values is true the other must be set to false.
How do I describe this in jsonschema?
I can say if propOne is true require propTwo, but this isn’t enough:
"anyOf": [
{
"not": {
"properties": {
"propOne": {
"const": true
}
},
"required": [
"propOne"
]
}
},
{
"required": [
"propTwo"
]
}
],
What is the most concise way to describe my requirements?
Edit:
Per the answer this does what I want. I know there is a handful of ways to describe this. It seems like oneOf is the most concise? I think if conditions would require more lines?
"oneOf": [
{
"type": "object",
"properties": {
"propOne": {
"const": true
},
"propTwo": {
"const": false
}
}
},
{
"type": "object",
"properties": {
"propOne": {
"const": true
},
"propTwo": {
"const": false
}
}
}
],
>Solution :
There are the if/then/else keywords, and also oneOf (see https://json-schema.org/understanding-json-schema/reference/conditionals.html)
So, in pseudocode:
- must be an object.
- require propOne and propTwo.
- propOne is a boolean.
- propTwo is a boolean.
and either of these are equivalent (when combined with the above restrictions):
- if propOne is true, then propTwo is false, else propTrue is true.
- oneOf:
- propOne is true and propTwo is false.
- propOne is false and propTwo is true.