【发布时间】:2016-12-15 19:49:59
【问题描述】:
我有这个父架构:
{
"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”属性属于“properties”
标签: json jsonschema