Inexperienced JSON Schema user here. I have a JSON Schema that I would like to check for the following cases. Most I've figured out, but one just isn't working out.
I could have properties A, B, C, D, E, F. Some rules:
- If E exists, it needs F, and vice versa. (Got it)
- If A, B, or C exist, they need D. (Got it)
- D or F must appear (Got it)
- If D appears, it must have either A, B, or C. (Preferably only one of A, B, or C, but I'll handle that downstream if needed.) (This one is eluding me.)
Here's the schema:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"patternProperties": {
"^*": {
"type": "object",
"properties": {
"A": {
"type": [ "string", "null" ]
},
"B": {
"type": [ "string", "null" ]
},
"C": {
"type": [ "string", "null" ]
},
"D": {
"type": [ "string", "null" ]
},
"E": {
"type": [ "string", "null" ]
},
"F": {
"type": [ "string", "null" ]
}
},
"dependentRequired": {
"E": [ "F" ],
"F": [ "E" ],
"A": [ "D" ],
"B": [ "D" ],
"C": [ "D" ]
},
"oneOf": [
{ "required": [ "D" ] },
{ "required": [ "F" ] }
]
}
}
}
The validation should fail if you only submit "D." But in this schema it will pass.
I've tried playing around with if/thens, anyOfs, ... just not able to get Rule 4 working. Some advice would be helpful!! Thank you in advance.