【发布时间】: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