以下是我的json模式,用于"联系"实体和"详细联系"实体。它们之间的区别在于详细联系人具有与每个属性关联的元数据对象。
我想知道是否有更好的方法(但仍然易于理解),因此我不需要在两个地方定义所有联系人属性名称。
"metadata": {
"type": "object",
"properties": {
"modifiedAt": { "$ref": "#/definitions/datetime" },
"modifiedSystem": { "type": "string" },
"verifiedAt": { "$ref": "#/definitions/datetime" },
"verifiedSystem": { "type": "string" },
"lastInteractionType": { "type": "string" }
},
"required": [ "modifiedAt", "modifiedSystem" ]
},
"contact": {
"type": "object",
"properties": {
"id": { "type": "integer" },
"fullName": { "type": "string" },
"firstName": { "type": "string" },
"lastName": { "type": "string" },
"preferredName": { "type": "string" },
"gender": { "type": "string" },
"birthDate": { "type": "string" },
"nationality": { "type": "string" },
"nationality2": { "type": "string" },
"nri": { "type": "boolean" },
"optOut": { "type": "boolean" },
"maritalStatus": { "type": "string" },
"religion": { "type": "string" },
"occupation": { "type": "string" },
"prStatus": { "type": "string" },
"photoFilepath": { "type": "string" },
"phones": {
"type": "array",
"items" : { "$ref": "#/definitions/phone" }
},
"emails": {
"type": "array",
"items" : { "$ref": "#/definitions/email" }
},
"addresses": {
"type": "array",
"items" : { "$ref": "#/definitions/address" }
},
"metadata": { "$ref": "#/definitions/metadata" }
}
},
"phone": {
"type": "object",
"properties": {
"countryCode": { "type": "string" },
"number" : { "type": "string" },
"phoneType": { "type": "string" },
"type": { "type": "string" },
"status": { "type": "string" },
"metadata": { "$ref": "#/definitions/metadata" }
},
"required": [ "countryCode", "number", "phoneType", "type", "status", "metadata" ]
},
"email": {
"type": "object",
"properties": {
"address": { "type": "string" },
"type": { "type": "string" },
"status": { "type": "string" },
"metadata": { "$ref": "#/definitions/metadata" }
},
"required": [ "address", "type", "status", "metadata" ]
},
"address": {
"type": "object",
"properties": {
"addressLine1": { "type": "string" },
"townCity": { "type": "string" },
"districtCounty": { "type": "string" },
"stateProvince": { "type": "string" },
"postcode": { "type": "string" },
"country": { "type": "string" },
"type": { "type": "string" },
"status": { "type": "string" },
"metadata": { "$ref": "#/definitions/metadata" }
},
"required": [ "addressLine1", "country", "type", "status", "metadata" ]
},
"stringAttributeWithMetadata": {
"type": "object",
"properties": {
"value": { "type": "string" },
"metadata": { "$ref": "#/definitions/metadata" }
},
"dependencies": {
"value": [ "metadata" ]
}
},
"booleanAttributeWithMetadata": {
"type": "object",
"properties": {
"value": { "type": "boolean" },
"metadata": { "$ref": "#/definitions/metadata" }
},
"dependencies": {
"value": [ "metadata" ]
}
},
"virtualDetailedContact": {
"type": "object",
"properties": {
"fullName": { "$ref": "#/definitions/stringAttributeWithMetadata" },
"firstName": { "$ref": "#/definitions/stringAttributeWithMetadata" },
"lastName": { "$ref": "#/definitions/stringAttributeWithMetadata" },
"preferredName": { "$ref": "#/definitions/stringAttributeWithMetadata" },
"gender": { "$ref": "#/definitions/stringAttributeWithMetadata" },
"birthDate": {
"allOf": [
{ "$ref": "#/definitions/stringAttributeWithMetadata" },
{ "properties": {
"value": {
{ "format": "date" }
}
}
]
},
"nationality": { "$ref": "#/definitions/stringAttributeWithMetadata" },
"nationality2": { "$ref": "#/definitions/stringAttributeWithMetadata" },
"nri": { "$ref": "#/definitions/booleanAttributeWithMetadata" },
"optOut": { "$ref": "#/definitions/booleanAttributeWithMetadata" },
"maritalStatus": { "$ref": "#/definitions/stringAttributeWithMetadata" },
"religion": { "$ref": "#/definitions/stringAttributeWithMetadata" },
"occupation": { "$ref": "#/definitions/stringAttributeWithMetadata" },
"prStatus": { "$ref": "#/definitions/stringAttributeWithMetadata" },
"photoFilepath": { "$ref": "#/definitions/stringAttributeWithMetadata" },
"phones": {
"type": "array",
"items" : { "$ref": "#/definitions/phone" }
},
"emails": {
"type": "array",
"items" : { "$ref": "#/definitions/email" }
},
"addresses": {
"type": "array",
"items" : { "$ref": "#/definitions/address" }
},
"metadata": { "$ref": "#/definitions/metadata" }
}
},
"detailedContact": {
"allOf": [
{ "$ref": "#/definitions/virtualDetailedContact" },
{ "properties":
"id": { "type": "integer" },
"systems": {
"type": "array",
"items": { "type": "string" }
}
}
]
}
注意:virtualDetailedContact
与detailedContact
基本相同 - 除了没有id
和systems
属性。 (我们正在制作一个联系人合并应用程序,该应用程序将根据几个现有联系人提供的属性元数据建议新合并的联系人的定义 - 因此它不具有id
和systems
属性,因为它没有&# 39; t存在)
答案 0 :(得分:0)
我不确定我是否完全理解这个问题 - 或者您所包含的架构代码已经回答了您最初发布的问题。无论哪种方式,您的detailedContact
都有点不对,应该是:
"detailedContact": {
"type":"object",
"allOf": [
{ "$ref": "#/definitions/virtualDetailedContact" },
],
{ "properties":
"id": { "type": "integer" },
"systems": {
"type": "array",
"items": { "type": "string" }
}
}
}
您的问题是“我可以拥有一个与detailedContact
类似的对象contact
,除了detailedContact
中的每个布尔属性都是"$ref": "#/definitions/booleanAttributeWithMetadata"
,依此类推?”
如果是这样,我想不出任何办法。