问题是“非”语义。“不需要”不表示“禁止包含”。这只是意味着您不必添加它即可验证该架构。
但是,您可以使用“ oneOf”以更简单的方式满足您的规范。请记住,这意味着“只有这些模式之一可以验证”。以下架构实现了您要解决的属性切换:
{ "$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" ] }, { "required": [ "fileNames" ] }, { "anyOf": [ { "required": [ "matchesFiles" ] }, { "required": [ "doesntMatchFiles" ] } ] } ]}


