Closed kayaelle closed 7 years ago
@kayaelle - I think something like this is what you're after...
...
"properties": {
...,
"age": {
"type": "array",
"items": {
"type": "string",
"enum": ["3-5", "6-11", "12-18", "19-40", "40-65", "65-122"]
},
"uniqueItems": true
},
...
},
...
ok - I'll look into that. Thanks! :+1:
@kayaelle - no problem. I've just confirmed that this (slightly more complex) schema
{
"type": "object",
"properties": {
"age": {
"oneOf": [
{
"type": "string",
"enum": ["3-5", "6-11", "12-18", "19-40", "40-65", "65-122"]
},
{
"type": "array",
"uniqueItems": true,
"minItems": 1,
"items": {
"$ref": "#/properties/age/oneOf/0"
}
}
]
}
}
}
will validate both
{age: "3-5"}
and
{age: ["3-5", "6-11"]}
This is great @andrewhayward & really helpful. Thank you for validating it. I think we'll find that there will be schemas that will find this useful/necessary.
@andrewhayward is a JSON-schema wizard. I'll consider making a badge for that.
:zap: wizard :
Moving to archive.
How do you define and validate against an array of values? enum seems to imply that only value can be valid at a time.
What if you want to define an array of strings and more than one can be valid. For instance if we were to define age groupings something like: "3-5", "6-11", "12-18", "19-40", "40-65", "65-122"
and want to allow multiple values, how to best define that?
@andrewhayward ? :)
Thnx