【问题标题】:Json Schema, Properties as Property not workingJson Schema,属性作为属性不起作用
【发布时间】:2016-02-06 17:53:39
【问题描述】:

也许听起来令人困惑,我想验证这个模型架构(应该有 $schema、title、properties 和必填字段):

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "My Schema",
  "type": "object",
  "properties": {
    "myData": {
      "type": "object",
      "properties": {
        "name_1": {
          "type": "string"
        },
        "name_2": {
          "type": "string"
        },
        "name_3": {
          "type": "string"
        }
      }
    }
  },
  "required": [
    "myData"
  ]
}

我已经这样做了:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "$schema": {
      "type": "string"
    },
    "title": {
      "type": "string"
    },
    "properties": {
      "type": "object",
      "enum": "myData"
    },
    "required": {
      "type": "array",
      "items": {
        "myData": "string"
      }
    }
  }
}

但这部分效果不好:

"properties": {
      "type": "object",
      "enum": "myData"
 },

可以这样做吗?还是禁止使用那些构建的模式词,例如:“required”、“enum”、“properties”作为“properties”中的属性? 提前感谢您帮助我理解这部分:)

【问题讨论】:

    标签: json jsonschema json-schema-validator


    【解决方案1】:

    我的错,对不起。我创建了错误的 json 架构,应该是这样的:

    {
      "$schema": "http://json-schema.org/draft-04/schema#",
      "id": "http://jsonschema.net",
      "type": "object",
      "properties": {
        "title": {
          "type": "string"
        },
        "type": {
          "type": "string"
        },
        "properties": {
          "type": "object",
          "properties": {
            "myData": {
              "type": "object"
            }
          }
        },
        "required": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    }
    

    而且工作正常:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-28
      • 2010-11-16
      • 2021-12-01
      • 1970-01-01
      • 2011-03-31
      • 2018-11-19
      • 2012-07-23
      • 2016-07-16
      相关资源
      最近更新 更多