I am trying to write a schema validating arrays with the following structural constraints:
- it can only ever contain the values 1,2,3,4,5
- if the array contains a 1, that must be the only entry
- the array can only contain either 2, 3 or 4 at the same time, so e.g. [2,3] is not allowed
- 5 can be present together with 2,3,4
so the valid arrays are
[1],
[2],
[3],
[4],
[5],
[2,5],
[3,5],
[4,5]
I started writing a schema as follows:
{
"type": "array",
"oneOf": [
{ "items": { "enum": [1] } },
{
"anyOf": [
???
]
}
]
}
I can't get the ??? part to work. Is it possible at all?
NOTE: I would like to avoid hardcoding all possible arrays, as I have to validate more complex structures - this is only an example. Also, the optimum is a solution using only anyOf, allOf, oneOf, not, avoiding keywords like minItems