JSON Schema enums
JSON Schemas feature enums, which impose a constraint on the values of a string type:
{
"type": "array",
"items": [
{
"type": "number"
},
{
"type": "string"
},
{
"type": "string",
"enum": ["Street", "Avenue", "Boulevard"]
},
{
"type": "string",
"enum": ["NW", "NE", "SW", "SE"]
}
]
}
This schema validates values such as [1600, "Pennsylvania", "Avenue", "NW"]
.
The problem
Is there an elegant way to make the enum
case-insensitive, so that both Avenue
and avenue
would be accepted as the third value in the array?
Other possible solutions
I can use anyOf
on a list of values, and validate each against a case-insensitive regex - but that's cumbersome, error-prone and inelegant.