json 架构验证模式属性和属性冲突

json schema validation patternProperties and properties conflict

我有这个 JSON 架构

{
  "title": "JSON Schema for revues subscribtion",
  "type": "object",
  "properties": {
    "lab": {
      "type": "string"
    }
  },
  "patternProperties": {
    "[A-Za-z][A-Za-z_]*[A-Za-z]": {
      "type": "boolean"
    }
  },
  "required": [
    "lab"
  ]
}

我想匹配 json 数据,例如

{
 "SP": false,
 "lab": "labri"
}

但它失败了,因为 "lab" 值预期为 boolean。这意味着 "lab"patternProperties.

匹配

有人对此有解决方案吗?

PS : 抱歉我英语不好

一种方法是使用匹配您需要但不匹配 'lab' 的正则表达式。充其量这不是微不足道的。

另一个是这个架构:

{
    "title" : "JSON Schema for revues subscribtion",
    "type" : "object",
    "properties" : {
        "lab" : { "type" : "string" }
    },
    "additionalProperties" : { "type": "boolean" },
    "required" : [ "lab" ]
}

它将要求除 lab 之外的所有属性都是布尔值。我不认为你能做得更好。