我有这样的家长模式:JSON模式 - 如何使anyOf两个或多个属性所需
{
"definitions": {
"parcel": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"accountNumber": {
"type": "string"
},
"parcelNumber": {
"type": "string"
},
"propertyType": {
"type": "string"
},
"address": {
"$ref": "address.json#/definitions/address"
},
"coordinates": {
"$ref": "coordinates.json#/definitions/coordinates"
}
},
"required": ["accountNumber", "parcelNumber"]
}
}
}
以下是引用的子模式:
{
"definitions": {
"address": {
"type": "object",
"properties": {
"addressString": {
"type": "string",
"addressType": {
"enum": ["residential", "business"]
}
},
"required": ["addressString"]
}
}
}
}
{
"definitions": {
"coordinates": {
"type": "object",
"properties": {
"latitude": {
"type": "number"
},
"longitude": {
"type": "number"
},
"projection": {
"type": "string"
}
},
"required": ["latitude ", "longitude", " projection"]
}
}
}
我想申请以下条件到父架构。
- 提供地址或坐标或两者都提供。
- 如果既没有提供地址也没有提供坐标,它将无法通过验证。
小评:你可以在模式中使用单个定义对象,其中包含全部三个子模式。他们不需要分开的对象。 –
另一个问题:我认为你的“ID”属性属于“属性” –