I'm trying to use JSON Schema validation to ensure that my array favoriteVegetables
includes at least one value from my vegetables enum (carrot
, lettuce
, cucumber
).
The array can have any and all of these values, but it must have at least one value.
Here's my schema:
{
"$id": "https://www.example.com/vegetables.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Vegetables",
"required": [ "favoriteVegetables" ],
"type": "object",
"properties": {
"favoriteVegetables": {
"type": "array",
"items": {
"type": "string",
"enum": ["carrot", "lettuce", "cucumber"]
}
},
},
"additionalProperties": false
}
The problem is that this validates for an object where favoriteVegetables
is []
. How do I add the requirement "must have at least one value" (cannot be a null array)?