You'll need to use the if
/then
keywords to describe this. The hard part is the if
schema.
You need to define an if
schema that will validate to true when given an instance where your conditions are met. It can help to develop this schema separately and then add it to your full schema.
{
"type": "object",
"properties": {
"FlatNo": { "const": "Excalibur" },
"LandMarks": {
"type": "object",
"properties": {
"LandMark1": { "const": "USA" }
},
"required": ["LandMark1"]
}
},
"required": ["LandMarks", "FlatNo"]
}
The following instance would pass validation against that schema. It would fail if FlatNo != Excalibur or LandMark1 != USA.
{
"FlatNo":"Excalibur",
"Sector":"07",
"LandMarks":{
"LandMark1":"USA",
"LandMark2":"UK"
}
}
Now it should be trivial to apply if
/then
to your address schema.
"if": { ... schema from above ... },
"then": { "required": ["Sector"] }
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…