{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Product set",
"type": "array",
"items": {
"title": "Product",
"type": "object",
"properties": {
"id": {
"description": "The unique identifier for a product",
"type": "number"
},
"name": {
"type": "string"
},
"price": {
"type": "number",
"minimum": 0,
"exclusiveMinimum": true
},
"tags": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true
},
"dimensions": {
"type": "object",
"properties": {
"length": {"type": "number"},
"width": {"type": "number"},
"height": {"type": "number"}
},
"required": ["length", "width", "height"]
},
"warehouseLocation": {
"description": "Coordinates of the warehouse with the product",
"$ref": "http://json-schema.org/geo"
}
},
"required": ["id", "name", "price"]
}
}
在上面的Json架构"维度"是"类型":"对象" ,是类型可选的,如果"类型"如果我认为它是对象,则不指定。找不到与可选元素相关的规格中的任何内容。
答案 0 :(得分:1)
http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.1
If the property is not defined or is not in this list, then any
type of value is acceptable.
type是可选的,如果省略type,则可以接受任何值。
答案 1 :(得分:-1)
我认为不是可选的。正如您在下面的元架构中所看到的,属性" type"没有默认值:
同样在我的JSON模式库NJsonSchema中,我将类型设置为None
而不是Object
。查看TypeRaw
属性:
https://github.com/rsuter/NJsonSchema/blob/master/NJsonSchema/JsonSchema4.Serialization.cs
当默认值设置为Object
时,JSON Schema测试套件中的更多测试失败。也许你可以在这个JSON Schema测试套件中找到一个明确的答案: