【问题标题】:How to handle @Ref from XSD in JSON Schema如何在 JSON Schema 中处理来自 XSD 的 @Ref
【发布时间】:2013-09-01 02:46:05
【问题描述】:

给出以下文本元素的基本示例,它引用了一个 para 元素,并且 para 元素本身引用了 para 元素。

我想知道我在 JSON Schema 中是否正确地表示了这一点?

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <xs:element name="text">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="para"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="para">
    <xs:complexType mixed="true">
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="para"/>
      </xs:choice>
      <xs:attribute name="id" type="xs:ID"/>
    </xs:complexType>
  </xs:element>
</xs:schema>

我认为必须使用这种样式 { "$ref": "#/definitions/diskDevice" }, http://json-schema.org/example2.html

这对吗?

{
 "id": "http://some.site.somewhere/entry-schema#",
 "$schema": "http://json-schema.org/draft-04/schema#",
 "title": "text",
 "type": "object",
 "properties": {
   "$ref": "#/definitions/para"
 },
 "definitions": {"para": {
  "required": true,
  "type": "object",
  "properties": {
   "id": {
    "type": "string",
    "required": true
   },
   "$ref": "#/definitions/para"
   }
  }
 }
}

谢谢

【问题讨论】:

  • 仅供参考,在 Draft-4 JSON Schema 中使用 $ref 时,该对象中的所有其他关键字都将被忽略。

标签: jsonschema


【解决方案1】:

这种引用形式是正确的。这不是唯一组织事物的方式,但这是我推荐的方式。

不过,您的架构中确实存在错误 - 您的“属性”中直接有“$ref”。您可能没有在数据中定义一个名为“$ref”的 property,那么这是否意味着在另一个属性声明中?

【讨论】:

  • $Ref 表示引用元素 或 "definitions": {"para":
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-09-16
  • 1970-01-01
  • 2013-07-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-18
相关资源
最近更新 更多