I have an array that contains strings, such as:
[ 'foo', 'bar' ]
The possible values are limited. For example, valid values are foo
, bar
, and baz
.
Now the array shall be valid when it contains only values that are valid, no value more than once, but it can have an arbitrary number of values.
Examples for valid arrays would be [ 'foo' ]
, [ 'foo', 'bar' ]
, and [ 'bar', 'baz' ]
. Examples for invalid arrays would be []
, [ 'foo', 'foo' ]
, and [ 'bar', 'something-else' ]
.
How can I do this validation using JSON schema? So far, I have figured out the array
type which provides the minItems
and the uniqueItems
properties. What I could not yet figure out is: How to allow multiple (but only valid) values? I know that there is enum
, but this only allows a single value, not multiple ones.
Can anybody help?
PS: Just in case it matters, I'm using the ajv module with Node.js to run the validation.