I have a simple JSON schema that looks like so (and works)
{
"cols": {
"type": "array",
"items": {
"type": "string",
"enum": [
"id",
"name",
"age",
"affiliation",
""
]
},
"additionalProperties": false
}
}
I would like the enum
to be the values prescribed above a decoration so that any of the following would be allowed
"enum" = [
"id",
"lower(name)",
"average(age)",
"distinct(affiliation)",
""
]
In other words, for cols
cols=id
would be valid but no further decoration would be allowed aroundid
cols=name
andcols=lower(name)
would be validcols=age
andcols=average(age)
would be validcols=affiliation
andcols=distinct(affiliation)
would be validcols=''
empty string would be valid
Specifying the decorations as patterns would be great so that they would be case-insensitive. For example, cols=lower(name)
and cols=LOWER(name)
would both be ok.
CodePudding user response:
You can change your enumerated list in enum
to a list of patterns:
"items": [
"type": "string",
"anyOf": [
{ "pattern": "^cols\b...the rest of your pattern here...$" },
{ etc... }
]
]