JSON 架构:恰好包含给定子架构的 n 个元素的数组

JSON Schema: array with exactly n elements of given sub-schemas

我想弄清楚如何为必须恰好包含 2 个元素的数组编写 JSON 架构,其中每个元素都符合其自己的子架构。我完全不知道,因为 anyOfallOfoneOf 中的 none 不适合这里。

假设我有 ss1ss2 子模式,它们分别定义了 t1t2 类型的元素。我如何编写一个模式来接受一个 t1 类型的元素(符合 ss1)和另一个 t2 类型的元素(符合 ss2)的数组?

items 关键字具有特殊的格式。值不是模式,而是模式数组。当以这种方式使用 items 时,数组中的项目必须符合 items 架构数组中的相应架构。这是一个工作示例,假设 t1 = 字符串和 t2 = 整数。

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