我在设置JSON模式时遇到问题,该模式将验证JSON是否包含:
但是当它们的倍数存在时不匹配.
在我的具体情况下,我想要一个
copyAllfileNamesmatchesFiles 和/或 doesntMatchFiles验证,但我不想接受超过那个.
这是我到目前为止所得到的:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"required": [ "unrelatedA" ],
"properties": {
"unrelatedA": {
"type": "string"
},
"fileNames": {
"type": "array"
},
"copyAll": {
"type": "boolean"
},
"matchesFiles": {
"type": "array"
},
"doesntMatchFiles": {
"type": "array"
}
},
"oneOf": [
{"required": ["copyAll"], "not":{"required":["matchesFiles"]}, "not":{"required":["doesntMatchFiles"]}, "not":{"required":["fileNames"]}},
{"required": ["fileNames"], "not":{"required":["matchesFiles"]}, "not":{"required":["doesntMatchFiles"]}, "not":{"required":["copyAll"]}},
{"anyOf": [
{"required": ["matchesFiles"], "not":{"required":["copyAll"]}, "not":{"required":["fileNames"]}},
{"required": ["doesntMatchFiles"], "not":{"required":["copyAll"]}, "not":{"required":["fileNames"]}}]}
]
} ;
Run Code Online (Sandbox Code Playgroud)
这比我想要的更多.我希望这匹配以下所有内容:
{"copyAll": true, "unrelatedA":"xxx"}
{"fileNames": …Run Code Online (Sandbox Code Playgroud) 是否有可能建立一个JSON模式,它仍然允许additionalProperties但不若一个非常特别的属性名存在匹配吗?换句话说,我需要知道是否可能与required声明完全相反.
架构:
{
"type": "object",
"properties": {
"x": { "type": "integer" }
},
"required": [ "x" ],
"ban": [ "z" ] // possible?
}
Run Code Online (Sandbox Code Playgroud)
比赛:
{ "x": 123 }
Run Code Online (Sandbox Code Playgroud)
比赛:
{ "x": 123, "y": 456 }
Run Code Online (Sandbox Code Playgroud)
难道不匹配:
{ "x": 123, "y": 456, "z": 789 }
Run Code Online (Sandbox Code Playgroud)