JSON 用于限制数组内块出现的架构

JSON Schema for restricting block occurrences inside of an array

可能有很多关于 JSON 架构的问题,但是,我找不到我想要的答案。

我有一条 JSON 消息,其中 FlagDetails 数组中的块最多可以出现 300 次。我如何使用我在下面创建的模式来限制它,以便时间和 UID 最多可以达到 300,但每个数组块的最大出现次数为 1。

JSON正文:

{
  "SData": {
    "IData": {
      "IDatas": {
        "Flag": "Yes",
        "FlagDetails": [
          {
            "Time": "2012-07-06 09:30:00",
            "UID": 1234567
          },
          {
            "Time": "2012-07-06 09:30:00",
            "UID": 1234567
          }
        ]
      }
    }
  }
}

JSON 架构:

{
  "definitions": {},
  "type": "object",
  "required": [
    "SData"
  ],
  "properties": {
    "SData": {
      "title": "SData",
      "type": "object",
      "required": [
        "IData"
      ],
      "properties": {
        "IData": {
          "title": "IData",
          "type": "object",
          "required": [
            "IDatas"
          ],
          "properties": {
            "IDatas": {
              "title": "IDatas",
              "type": "object",
              "required": [
                "Flag"
              ],
              "properties": {
                "Flag": {
                  "title": "Flag",
                  "type": "string",
                  "default": "",
                  "examples": [
                    "Yes"
                  ],
                  "minLength": 2,
                  "maxLength": 3,
                  "minOccurs": 0,
                  "maxOccurs": 1,
                  "pattern": "^.*$"
                },
                "FlagDetails": {
                  "title": "FlagDetails",
                  "type": "array",
                  "default": [],
                  "items": {
                    "title": "Items",
                    "type": "object",
                    "properties": {
                      "Time": {
                        "title": "Time",
                        "type": "string",
                        "default": "",
                        "examples": [
                          "2012-07-06 09:30:00"
                        ],
                        "minOccurs": 0,
                        "pattern": "^.*$"
                      },
                      "UID": {
                        "title": "UId",
                        "type": "integer",
                        "default": "",
                        "examples": [
                          "12345678912"
                        ],
                        "minLength": 4,
                        "maxLength": 12,
                        "minOccurs": 0,
                        "pattern": "^.*$"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

答案是“minItems”和“maxItems”。这些我都用过,效果很好。

"FlagDetails": {
"title": "FlagDetails",
"type": "array",
**"minItems": 0,
"maxItems": 300,**
"default": []