【问题标题】:JSON validation giving success even when required field is missing即使缺少必填字段,JSON 验证也会成功
【发布时间】:2020-10-20 11:29:46
【问题描述】:

请解释为什么这个 json 没有针对架构给出验证错误:

架构

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properites": {
    "address": {
      "type": "array",
      "items":{
          "type": "object",
          "properties": {
            "ip": {
              "type": "string"
            },
            "port": {
              "type": "integer"
            },
            "interface": {
              "type": "string"
            },
            "maskLength": {
              "type": "integer"
            }
          },
          "required": [
            "ip",
            "port",
            "interface",
            "maskLength"
          ]
        }
    }
  },
      "required": [
        "address"
  ]
}

JSON

{
        "address": [
            {
                "ip": 1,
                "port": 8305
            },
            {
                "ip": "2405:200:1413:100::5:cc",
                "port": "8205",
                "interface": "eno1",
                "maskLength": 112
            },
            {
                "ip": 2,
                "port": 8105,
            }
        ]
}

我正在https://www.jsonschemavalidator.net/ 上对此进行测试,它使验证成功,我不明白。 interfacema​​skLength 根据架构是必需的字段,并且在某些数组元素中缺少这些字段。此外,“ip”的类型在模式中是字符串,但在 json 中,整数类型也被接受。为什么这个json没有被拒绝?

【问题讨论】:

    标签: json jsonschema json-schema-validator


    【解决方案1】:

    捂脸

    我把属性拼错了!该死!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-24
      • 1970-01-01
      • 2014-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-05
      相关资源
      最近更新 更多