I have a JSON request I'm trying to validate against a JSON schema. I'm wondering is it possible to require a field in a subschema base off the value of a field within that same subschema? I've tried anyOf, OneOf and IF, Then, Else to no avail. anyOf returns error "only 1 subschema matches out of 2" and OneOf return "2 subschemas matched instead of one".
{
"field1":"aaa",
"field2":"bbb"
"field3":{
"isTrue":true,
"inner1":"1",
"inner2":"1"
}
}
So for the above Json, can I only require fields inner1 and inner2 if field isTrue is true?
"field3": {
"type": "object",
"properties": {
"isTrue": {
"type":
"boolean"
},
"inner1": {
"type":
"integer"
},
"inner2": {
"type":
"string"
}
},
"anyOf": [
{
"properties": {
"isTrue": {
"const": "true"
}
},
"required": [
"inner1",
"inner2"
]
},
{
"properties": {
"isTrue": {
"const": "false"
}
},
"required": [
"isTrue"
]
}
]
}
The above is my offending Json schema