[英]JSON Schema: Using anyOf, oneOf, allOf within additionalProperties
我试图验证一个对象可以有任意键,其值是一个看起来像这样的对象: { "href": "some string" }
或者包含与上述内容匹配的对象的数组。
这是我目前拥有的并且不起作用:
{
"$schema": "http://json-schema.org/schema#",
"id": "https://turnstyle.io/schema/links.json",
"type": "object",
"additionalProperties": {
"oneOf": [
{
"type": "object",
"required": "href"
},
{
"type": "array",
"items": {
"type": "object",
"required": "href"
}
}
]
}
}
Passing example:
{
"customer": { "href": "/customer/1" },
"products": [
{ "href": "/product/1" },
{ "href": "/product/2" }
]
}
Failing example:
{
"customer": { "wrongKey": "/customer/1" },
"products": "aString"
}
是否可能,如果是,那么正确的语法是什么?
我的假设是,这是行不通的,因为在传球模式(S) oneOf|anyOf|allOf
的additionalProperties
必须适用于所有按键下下降additionalProperties
。
“required”应该是v4中必需的属性数组。
或“required”:true(或false)作为v3中属性的一部分。
尝试这个:
{
"$schema": "http://json-schema.org/schema#",
"id": "https://turnstyle.io/schema/links.json",
"type": "object",
"additionalProperties": {
"oneOf": [
{
"type": "object",
"properties": {
"href": {"type": "string"}
},
"required": ["href"]
},
{
"type": "array",
"items": {
"type": "object",
"properties": {
"href": {"type": "string"}
},
"required": ["href"]
}
}
]
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.