JSON 架构:如何在 json 中正确使用 oneOf 引用?

JSON Schema: How to correctly use oneOf reference in json?

使用以下站点:http://jeremydorn.com/json-editor/ 并在架构部分粘贴以下代码:

 {
  "type": "object",
  "Title": "Pets",

  "definitions": {
    "petType": {
      "oneOf": [
        {
          "$ref": "#definitions/cat"
        },
        {
          "$ref": "#definitions/dog"
        }
      ]
    },
    "cat": {
      "sounds": {
        "enum": [
          "meow",
          "ghh"
        ]
       }
    },
    "dog": {
      "sounds": {
        "enum": [
          "woof",
          "grr"
        ]
      }
    }
  },

   "properties": {
    "productType": {
      "type": "string",
      "enum": [
        "cats",
        "dogs"
      ]
    },

    "sounds": {
      "type": "string",
      "enum": [
        { "$ref":"#definitions/petType" }
      ] 
    }


  }
}

目标是使用匹配的宠物声音进行第二次下拉。但是如何正确引用呢?

目前这是一个open issue with the spec

一种看待它的方法是,您需要一个基于 "$data" pointer 的“$ref”指针,目前不支持该指针。

不幸的是,与此同时,像这样的安排需要用应用程序逻辑而不是直接模式 AFAIK 来处理。