update: added requirements
I am trying to implement a JSON schema that works like so…
given the following params: foo
, bar
, baz
, one
, and two
One of the following should apply
- either no param exists
- if one or more params exist then
- if
foo
exists - thenone
andtwo
are not required - else if any param(s) other than
foo
exist(s) - thenone
andtwo
are required
- if
of course, if any params are provided that are not in the schema then an appropriate error should be raised.
After a lot of finagling, and inspiration, here is my attempt which doesn't really work
{
"type": "object",
"properties": {
"foo": { "type": "string" },
"bar": { "type": "string" },
"baz": { "type": "string" }
},
"oneOf": [
{
"not": {
"properties": { "foo": { "const": "" } },
"required": []
}
},
{ "required": [ "one", "two" ] }
]
}
I also tried the following but was not successful
{
"type": "object",
"properties": {
"foo": { "type": "string" },
"bar": { "type": "string" },
"baz": { "type": "string" }
},
"dependencies": {
"not": {
"foo": { "required": ["one", "two"] }
}
}
}