JSON模式-如果对象*不*包含特定属性,则有效 [英] JSON schema - valid if object does *not* contain a particular property
本文介绍了JSON模式-如果对象*不*包含特定属性,则有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以设置一个仍允许additionalProperties
允许但 not 不匹配的JSON模式?换句话说,我需要知道是否有可能与required
声明完全相反.
Is it possible to set up a JSON schema that still allows for additionalProperties
but does not match if a very particular property name is present? In other words, I need to know if it's possible to have the exact opposite of the required
declaration.
模式:
{
"type": "object",
"properties": {
"x": { "type": "integer" }
},
"required": [ "x" ],
"ban": [ "z" ] // possible?
}
匹配:
{ "x": 123 }
匹配:
{ "x": 123, "y": 456 }
不匹配:
{ "x": 123, "y": 456, "z": 789 }
推荐答案
您可以使用not
关键字来完成您想做的事情.如果not
模式验证,则父模式将不验证.
What you want to do can be achieved using the not
keyword. If the not
schema validates, the parent schema will not validate.
{
"type": "object",
"properties": {
"x": { "type": "integer" }
},
"required": [ "x" ],
"not": { "required": [ "z" ] }
}
这篇关于JSON模式-如果对象*不*包含特定属性,则有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文