如何在 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=lower(name)cols=LOWER(name) 都可以。

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

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