1

我正在尝试使用https://github.com/epoberezkin/ajv库来使用switchJSON 模式 v5 的属性。

我有以下架构,但它不起作用。

{
  "type": "array",
  "id": "http://localhost/drinks.json",
  "items": {
    "type": "object",
    "properties": {
      "items": {
        "type": "array",
        "items": {
          "switch": [
            {
              "if": {
                "properties": {
                  "type": {
                    "enum": ["coffee", "tea"]
                  }
                }
              },
              "then": {
                "$ref": "http://localhost/caffeinated.json"
              }
            },
            {
              "then": {
                "$ref": "http://localhost/decaf.json"
              }
            }
          ]
        }
      }
    }
  }
}

需要明确的是,$ref没有 switch 语句, s 工作得很好。例如,这得到正确验证:

{
  "type": "array",
  "id": "http://localhost/drinks.json",
  "items": {
    "type": "object",
    "properties": {
      "items": {
        "type": "array",
        "items": {
          "oneOf": [
            {
              "$ref": "http://localhost/caffeinated.json"
            },
            {
              "$ref": "http://localhost/decaf.json"
            }
          ]
        }
      }
    }
  }
}

但是第一个模式不起作用,并且“不起作用”我的意思是它甚至不会触发有效/无效。我做错什么了吗?

4

0 回答 0