【问题标题】:JSON Schema: How to correctly use oneOf reference in json?JSON Schema:如何在 json 中正确使用 oneOf 引用?
【发布时间】:2017-10-17 13:03:42
【问题描述】:

使用以下站点: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" }
      ] 
    }


  }
}

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

【问题讨论】:

    标签: json enums jsonschema


    【解决方案1】:

    目前这是open issue with the spec

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

    不幸的是,与此同时,此类安排需要使用应用程序逻辑而不是直接架构 AFAIK 来处理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-09
      • 2017-06-24
      • 2014-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多