The following json schema works the following way (DEMO):
- If
switchis true,objectDependingOnSwitchwill have a string property calledswitchIsTrue. - If
switchis false,objectDependingOnSwitchwill have a string property calledswitchIsFalse.
{
"type": "object",
"properties": {
"switch": {
"type": "boolean"
},
"objectDependingOnSwitch": {
"type": "object"
}
},
"allOf": [
{
"if": {
"properties": {
"switch": {
"const": true
}
}
},
"then": {
"properties": {
"objectDependingOnSwitch": {
"type": "object",
"properties": {
"switchIsTrue": {
"type": "string"
}
}
}
}
}
},
{
"if": {
"properties": {
"switch": {
"const": false
}
}
},
"then": {
"properties": {
"objectDependingOnSwitch": {
"type": "object",
"properties": {
"switchIsFalse": {
"type": "string"
}
}
}
}
}
}
]
}
Is there any way to remove the allOf property based on a given json value?
For example, for following json value:
{
switch: true
}
I want the discriminatory json schema:
{
"type": "object",
"properties": {
"switch": {
"type": "boolean"
},
"objectDependingOnSwitch": {
"type": "object",
"properties": {
"switchIsTrue": {
"type": "string"
}
}
}
}
}