【问题标题】:JSON schema array of repetitive object重复对象的 JSON 模式数组
【发布时间】:2019-09-19 11:58:15
【问题描述】:

我需要帮助来构建任务属性为对象类型的 JSON 模式。包含数组类型的“开发”、“审查”、“生产”和“分发”四个部门。每个部门都有重复的任务细节对象如下。

那么我该如何为这些数据定义 JSON 模式呢?

注意: 部门不应包含其他类型的数据

"taks": {
    "development":[
        {
            "description": "",
            "assigned_to":"Cortney.Brown",
            "start_date": "8-28-2019",
            "end_date": "9-15-2019",
            "status":"wip",
            "priority":"normal",
        },
        {
            "description": "",
            "assigned_to":"Renfred.Rogers",
            "start_date": "8-29-2019",
            "end_date": "9-10-2019",
            "status":"complete",
            "priority":"high",
        }
    ],
    "review": [
        {
            "description": "",
            "assigned_to":"Herring.Myers",
            "start_date": "8-30-2019",
            "end_date": "9-5-2019",
            "status":"OnHold",
            "priority":"low",
        },
        {
            "description": "",
            "assigned_to":"Dimos.Gomez",
            "start_date": "9-2-2019",
            "end_date": "9-12-2019",
            "status":"wip",
            "priority":"normal",
        }
    ],
    "production": [
        {
            "description": "",
            "assigned_to":"Ridge.Lopez",
            "start_date": "9-5-2019",
            "end_date": "9-15-2019",
            "status":"wip",
            "priority":"normal",
        },
        {
            "description": "",
            "assigned_to":"Keyon.Hill",
            "start_date": "9-7-2019",
            "end_date": "9-13-2019",
            "status":"OnHold",
            "priority":"low",
        },
        {
            "description": "",
            "assigned_to":"Bennett.Sanchez",
            "start_date": "9-10-2019",
            "end_date": "9-20-2019",
            "status":"complete",
            "priority":"low",
        }
    ],
    "distribution": [
        {
            "description": "",
            "assigned_to":"Kemen.Adams",
            "start_date": "9-12-2019",
            "end_date": "9-20-2019",
            "status":"complete",
            "priority":"high",
        }
    ]
}

【问题讨论】:

    标签: json jsonschema json-schema-validator


    【解决方案1】:

    从我可以看到这样的事情:

    {
      "type": "object",
      "$schema": "http://json-schema.org/draft-06/schema#",
      "description": "JSON schema generated with JSONBuddy https://www.json-buddy.com",
      "properties": {
        "taks": {
          "$ref": "#/definitions/taks"
        }
      },
      "definitions": {
        "an_item": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "assigned_to": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "end_date": {
              "type": "string"
            },
            "priority": {
              "type": "string"
            },
            "start_date": {
              "type": "string"
            },
            "status": {
              "type": "string"
            }
          }
        },
        "taks": {
          "type": "object",
          "properties": {
            "development": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/an_item"
              }
            },
            "distribution": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/an_item"
              }
            },
            "production": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/an_item"
              }
            },
            "review": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/an_item"
              }
            }
          }
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-03-27
      • 2020-02-09
      • 2016-08-13
      • 1970-01-01
      • 1970-01-01
      • 2013-04-27
      • 1970-01-01
      • 2020-10-31
      • 1970-01-01
      相关资源
      最近更新 更多