如何在 JSON 模式中对数组枚举应用模式
how to apply patterns on array enums in JSON schema
我有一个简单的 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=name
和 cols=lower(name)
有效
cols=age
和 cols=average(age)
是有效的
cols=affiliation
和 cols=distinct(affiliation)
是有效的
cols=''
空字符串有效
将装饰指定为模式会很好,这样它们就会不区分大小写。例如,cols=lower(name)
和 cols=LOWER(name)
都可以。
您可以将 enum
中的枚举列表更改为模式列表:
"items": [
"type": "string",
"anyOf": [
{ "pattern": "^cols\b...the rest of your pattern here...$" },
{ etc... }
]
]
我有一个简单的 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=name
和cols=lower(name)
有效cols=age
和cols=average(age)
是有效的cols=affiliation
和cols=distinct(affiliation)
是有效的cols=''
空字符串有效
将装饰指定为模式会很好,这样它们就会不区分大小写。例如,cols=lower(name)
和 cols=LOWER(name)
都可以。
您可以将 enum
中的枚举列表更改为模式列表:
"items": [
"type": "string",
"anyOf": [
{ "pattern": "^cols\b...the rest of your pattern here...$" },
{ etc... }
]
]