想知道模式草案 03 是否可以做到这一点。我已经让依赖项在其他地方工作,我认为可能只是需要对它们进行一些创造性的使用,以便使用它们来指定required
某些字段的属性。
我目前的最佳尝试(不起作用)应该让您对我所追求的有所了解。我想要一个默认需要的值,当另一个字段具有特定值时是可选的。
{
"description" : "An address...",
"type" : "object",
"properties" : {
"postcode": {
"type" : "string",
// postcode should be required by default
"required" : true,
// postcode shouldn't be required if the country is new zealand
"dependencies" : {
"country" : {
"enum" : ["NZ", "NZL", "NEW ZEALAND"]
},
"postcode" : {
"required" : false
}
}
},
"country": {
"type" : "string",
"enum" : [
// various country codes and names...
],
"default" : "AUS"
}
}
}