如何在JSON模式中对数组枚举应用模式



我有一个简单的JSON模式,看起来像

{
"cols": {
"type": "array",
"items": {
"type": "string",
"enum": [
"id",
"name",
"age",
"affiliation",
""
]
},
"additionalProperties": false
}
}

我希望enum是上面规定的值+一个装饰,这样以下任何一个都可以进行

"enum" = [
"id",
"lower(name)",
"average(age)",
"distinct(affiliation)",
""
]

换句话说,对于cols

  • cols=id有效,但不允许在id周围进行进一步装饰
  • cols=namecols=lower(name)将是有效的
  • cols=agecols=average(age)将是有效的
  • cols=affiliationcols=distinct(affiliation)将有效
  • cols=''空字符串将有效

将装饰指定为模式非常好,这样它们就不区分大小写了。例如,cols=lower(name)cols=LOWER(name)都可以

您可以将enum中的枚举列表更改为模式列表:

"items": [
"type": "string",
"anyOf": [
{ "pattern": "^colsb...the rest of your pattern here...$" },
{ etc... }
]
]

最新更新