如果 `items` 和 `type` 被定义为数组,没有 anyOf 属性
What if `items` and `type` were defined as arrays, without anyOf property
在core/validation meta-schema中,items
和type
属性定义如下:
项
"items": {
"anyOf": [
{ "$ref": "#" },
{
"type": "array",
"minItems": 1,
"items": { "$ref": "#" }
}
],
"default": {}
},
类型
"type": {
"anyOf": [
{ "$ref": "#/definitions/simpleTypes" },
{
"type": "array",
"items": { "$ref": "#/definitions/simpleTypes" },
"minItems": 1,
"uniqueItems": true
}
]
},
据我了解:
items
可以是模式或至少一个模式的数组
type
可以是 simpleType
或至少包含一个 simpleType
的数组
除了写作的实用性和舒适性,我是否认为这些定义是等价的?
项
"items": {
"type": "array",
"items": { "$ref": "#" }
"default": [{}]
},
类型
"type": {
"type": "array",
"items": { "$ref": "#/definitions/simpleTypes" },
"uniqueItems": true
},
换句话说,以下两个模式在解释上是否存在差异:
架构 #1
{
"type": "array",
"items": {
"type": "string"
}
}
架构 #2
{
"type": ["array"],
"items": [
{
"type": "string"
}
]
}
回答 "in other words" 部分:
"type": "array"
和"type": ["array"]
之间没有语义区别
但 "items" 不同:
"items": {"type": "string"}
表示包含任意数量的字符串项的数组
"items": [{"type": "string"}]
表示任意个元素组成的数组,其中第0个必须是字符串,其余可以任意
您可以在此处找到有关列表与元组验证的更多信息:https://spacetelescope.github.io/understanding-json-schema/reference/array.html
在core/validation meta-schema中,items
和type
属性定义如下:
项
"items": {
"anyOf": [
{ "$ref": "#" },
{
"type": "array",
"minItems": 1,
"items": { "$ref": "#" }
}
],
"default": {}
},
类型
"type": {
"anyOf": [
{ "$ref": "#/definitions/simpleTypes" },
{
"type": "array",
"items": { "$ref": "#/definitions/simpleTypes" },
"minItems": 1,
"uniqueItems": true
}
]
},
据我了解:
items
可以是模式或至少一个模式的数组type
可以是simpleType
或至少包含一个simpleType
的数组
除了写作的实用性和舒适性,我是否认为这些定义是等价的?
项
"items": {
"type": "array",
"items": { "$ref": "#" }
"default": [{}]
},
类型
"type": {
"type": "array",
"items": { "$ref": "#/definitions/simpleTypes" },
"uniqueItems": true
},
换句话说,以下两个模式在解释上是否存在差异:
架构 #1
{
"type": "array",
"items": {
"type": "string"
}
}
架构 #2
{
"type": ["array"],
"items": [
{
"type": "string"
}
]
}
回答 "in other words" 部分:
"type": "array"
和"type": ["array"]
之间没有语义区别
但 "items" 不同:
"items": {"type": "string"}
表示包含任意数量的字符串项的数组"items": [{"type": "string"}]
表示任意个元素组成的数组,其中第0个必须是字符串,其余可以任意
您可以在此处找到有关列表与元组验证的更多信息:https://spacetelescope.github.io/understanding-json-schema/reference/array.html