用于验证至少一个列表的 Jsonschema 是否存在

Jsonschema to validate at least one of the lists is present

我有一个json,像这样:

{
  "listA": [
    {
      "prop1": "mine"
    },
     {
      "prop1": "mine"
    }
  ],
  "listB": [
    {
      "prop1": "mine"
    }
  ],
  "propsForAll": {
    "property1": "value",
    "property2": "value"
  }
}

我需要 json 架构来验证至少存在一种列表类型 {listA, listB, listC}

这是我试图创建的 json 模式的一部分,但是 python jsonschema 只是说“[[=22= 的内容]] 在任何给定模式下均无效":

....  
"required": [
    "propsForAll"
  ],
  "anyOf": [
    {
      "$ref": "#/properties/listA"
    },
    {
      "$ref": "#/properties/listB"
    },
    {
      "$ref": "#/properties/listC"
    }
  ],
....

如果我删除 anyOf 部分,验证会通过,但它不会检查我需要什么。 帮忙?

$ref 在这里不正确。您想改用 required

{
  "required": ["propsForAll"],
  "anyOf": [
    { "required": ["listA"] },
    { "required": ["listB"] },
    { "required": ["listC"] }
  ]
}

对于 $ref 你是说实例必须 "listA" 或 "listB" 或 "listC" 而不是它必须 包含“listA”或“listB”或“listC”。