I have an outdated API that I am trying to define in a JSON schema, and the object has a strange structure where there is a set of 4 properties, any of them are necessary, and 3 of them are mutually exclusive. After that there are more than 30 common additional properties, I will mark them as ...
eg.
{ "foo": "bar", "baz": 1234, ... } // OK { "foo": "bar", "buzz": 1234, ... } // OK { "foo": "bar", "fizz": 1234, ... } // OK { "foo": 1234, ... } // OK { "baz": 1234, ... } // OK { ... } // NOT OK { "baz": 1234, "buzz": 1234, ... } // NOT OK
I could make oneOf , but not allowing foo be present along with others, anyOf allows baz , buzz and fizz to be present with each other, it is impossible.
I tried to define something like the following:
{ "type": "object", "properties": { "foo": {"type": "string"}, "baz": {"type": "number"}, "buzz": {"type": "number"}, "fizz": {"type": "number"} }, "anyOf": [ {"required": ["foo"]}, {"required": [{"oneOf": [ {"required": ["baz"]}, {"required": ["buzz"]}, {"required": ["fizz"]} ]} ]} ] }
and
{ "type": "object", "properties": { "foo": {"type": "string"}, "baz": {"type": "number"}, "buzz": {"type": "number"}, "fizz": {"type": "number"} }, "anyOf": [ {"required": ["foo"]}, {"oneOf": [ {"required": ["baz"]}, {"required": ["buzz"]}, {"required": ["fizz"]} ] } ] }
But this does not work, and I just don’t know enough about the json scheme, but I know if this is possible.