首页 文章

JSON Schema:具有给定子模式的n个元素的数组

提问于
浏览
0

我完全不知道,因为这里没有一个适合的地方 . [1487417_,_1487418, oneOf ] .

让's say that I'得到 ss1ss2 子文件,分别定义 t1t2 类型的元素 . 如何编写一个接受数组_1187425_(符合 ss1 )和另一个 t2 元素(符合 ss2 )的数组的模式?

1 回答

  • 1

    items 关键字有一个特殊的格式 . 它可以是一个模式数组,而不是作为模式的值 . 当以这种方式使用 items 时,数组中的项必须符合 items 模式数组中的相应模式 . 这是一个工作示例,假设t1 = string,t2 =整数 .

    {
      "type": "array",
      "items": [
        { "$ref": "#/definitions/ss1" },
        { "$ref": "#/definitions/ss2" }
      ],
      "minItems": 2,
      "maxItems": 2,
      "definitions": {
        "ss1": { "type": "string" },
        "ss2": { "type": "integer" }
      }
    }
    

相关问题