Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JSON架构未验证所需的属性_Json_Jsonschema_Json Schema Validator - Fatal编程技术网

JSON架构未验证所需的属性

JSON架构未验证所需的属性,json,jsonschema,json-schema-validator,Json,Jsonschema,Json Schema Validator,这里是标准:单个区域对象可以与数组共存,并且只能与亚洲/欧洲/澳大利亚(亚洲/欧洲/澳大利亚的一次一个区域)共存 除此之外,每个区域对象都可以有一些必需的属性和嵌套的属性 问题在于模式验证器没有抱怨所需的属性(即维度对象的宽度属性) 下面是JSON模式 { "type": "object", "$schema": "http://json-schema.org/draft-07/schema#", "properties": { "stat_data": { "t

这里是标准:单个区域对象可以与数组共存,并且只能与亚洲/欧洲/澳大利亚(亚洲/欧洲/澳大利亚的一次一个区域)共存

除此之外,每个区域对象都可以有一些必需的属性和嵌套的属性

问题在于模式验证器没有抱怨所需的属性(即维度对象的宽度属性)

下面是JSON模式

{
  "type": "object",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "properties": {
    "stat_data": {
      "type": "array",
      "if": {
        "contains": {
          "type": "object",
          "properties": {
            "region": {
              "type": "string",
              "enum": [
                "europe"
              ]
            }
          }
        }
      },
      "then": {
        "not": {
          "contains": {
            "type": "object",
            "properties": {
              "region": {
                "type": "string",
                "enum": [
                  "asia",
                  "australia"
                ]
              }
            }
          }
        }
      },
      "else": {
        "if": {
          "contains": {
            "type": "object",
            "properties": {
              "region": {
                "type": "string",
                "enum": [
                  "asia"
                ]
              }
            }
          }
        },
        "then": {
          "not": {
            "contains": {
              "type": "object",
              "properties": {
                "region": {
                  "type": "string",
                  "enum": [
                    "europe",
                    "australia"
                  ]
                }
              }
            }
          }
        },
        "else": {
          "if": {
            "contains": {
              "type": "object",
              "properties": {
                "region": {
                  "type": "string",
                  "enum": [
                    "australia"
                  ]
                }
              }
            }
          },
          "then": {
            "not": {
              "contains": {
                "type": "object",
                "properties": {
                  "region": {
                    "type": "string",
                    "enum": [
                      "europe",
                      "asia"
                    ]
                  }
                }
              }
            }
          },
          "else": {}
        }
      },
      "items": {
        "type": "object",
        "properties": {
          "details": {
            "$ref": "#/definitions/dimension"
          },
          "population": {
            "$ref": "#/definitions/details"
          },
          "dimension": {
            "$ref": "#/definitions/population"
          },
          "region": {
            "enum": [
              "asia",
              "europe",
              "australia",
              "some-pencil-region",
              "some-oil-pastels-region"
            ]
          }
        }
      }
    }
  },
  "definitions": {
    "dimension": {
      "type": "object",
      "required": [
        "width"
      ],
      "properties": {
        "height": {
          "type": "integer"
        },
        "width": {
          "type": "integer"
        }
      }
    },
    "details": {
      "type": "object",
      "properties": {
        "brand": {
          "type": "string"
        },
        "year": {
          "type": "integer"
        }
      }
    },
    "population": {
      "type": "object",
      "properties": {
        "change": {
          "type": "integer"
        },
        "year": {
          "type": "integer"
        }
      }
    }
  }
}
还有JSON

{
  "stat_data": [
    {
      "region": "some-pencil-region",
      "details": {
        "brand": "Camlin",
        "year": 2019
      }
    },
    {
      "region": "some-oil-pastels-region",
      "height": 30
    },
    {
      "region": "asia",
      "population": {
        "year": 2018,
        "change": 2
      }
    }
  ]
}

你可以在_https://jsonschema.dev/ 通过在编辑器中复制模式和json,您的json验证器可能没有发现问题?显示有关缺少“宽度”属性的消息: