我一直在閱讀如何定義json架構以容納不同形狀對象的列表:人,地址,車輛。部分研究使我找到了有用的補充建議。例如添加「uniqueitems」:true,以便列表不包含重複項。http://www.jsonschemavalidator.net/不會出現要兌現「uniqueitems」:true或「additionalProperties」:false
我發現該網站http://www.jsonschemavalidator.net/非常有用的驗證我的架構和JSON數據,但我不能找出我在做什麼毛病都
"additionalProperties": false
和
"uniqueitems": true
這裏是我的示例架構和數據:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "an array of Insurable Items",
"type": "array",
"items": {
"type": "object",
"OneOf": [
{
"type": "object",
"description": "A Person",
"properties": {
"person": {
"type": "object",
"$ref": "#/definitions/person"
}
},
"required": [
"person"
],
"additionalProperties": false
},
{
"type": "object",
"description": "An Address",
"properties": {
"address": {
"type": "object",
"$ref": "#/definitions/address"
}
},
"required": [
"address"
],
"additionalProperties": false
},
{
"type": "object",
"description": "A Vehicle",
"properties": {
"vehicle": {
"type": "object",
"$ref": "#/definitions/vehicle"
}
},
"required": [
"vehicle"
],
"additionalProperties": false
}
],
"uniqueitems": true
},
"definitions": {
"person": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"title": {
"type": "string"
},
"firstname": {
"type": "string"
},
"lastname": {
"type": "string"
},
"dateofbirth": {
"type": "string"
},
"employmentstatus": {
"type": "string"
},
"occupation": {
"type": "string"
}
},
"additionalProperties": false
},
"address": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"line1": {
"type": "string"
},
"line2": {
"type": "string"
},
"line3": {
"type": "string"
},
"line4": {
"type": "string"
},
"line5": {
"type": "string"
},
"postcode": {
"type": "string"
}
},
"additionalProperties": false
},
"vehicle": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"vehiclecode": {
"type": "string"
},
"registrationyear": {
"type": "string"
},
"registrationletter": {
"type": "string"
},
"registrationnumber": {
"type": "string"
},
"description": {
"type": "string"
}
},
"additionalProperties": false
}
}
}
數據:
[
{
"person": {
"id": "123456789-01",
"title": "Mr",
"firstname": "Joe",
"lastname": "blogs"
},
"badadditional": "thing"
},
{
"address": {
"id": "123456789-A",
"line1": "1 The Mall",
"line2": "Westminster",
"line3": "London",
"postcode": "SW1A 1AA"
}
},
{
"address": {
"id": "123456789-A",
"line1": "1 The Mall",
"line2": "Westminster",
"line3": "London",
"postcode": "SW1A 1AA"
}
},
{
"vehicle": {
"id": "123456789-01-01",
"vehiclecode": "string",
"registrationyear": "string",
"registrationletter": "string",
"registrationnumber": "string",
"description": "string",
"badadditional": "other thing"
}
}
]
如果您複製這些到http://www.jsonschemavalidator.net/架構驗證,它儘管
"badadditional": "thing"
和
"badadditional": "other thing"
存在和重複地址對象報告沒有問題。
我一直在尋找stackoverflow [標籤爲json.net],閱讀(其中),http://grokbase.com,http://json-schema.org,我正在努力草案-04。
我也試過https://jsonschemalint.com/#/version/draft-04/markup/json但也沒有抱怨。
任何人都可以指向其他驗證器,json架構文檔和示例,或者讓我知道我做錯了什麼,如果它很明顯?
謝謝傑森。我希望這是我做的一些愚蠢的事情。現在我再看資源,他們顯然是區分大小寫的! –
這是一種享受 - 謝謝 –