JSON数据
{
"alert_details": {
"event_date": "2021-04-26T12:30:80Z",
"camount": "789",
"profile": {
"name": {
"first_name": "xxxx",
"last_name": "xxxx",
"middle_name": "xxx"
}
},
"check_cash_date": "2021-04-26",
"profile_address": {
"name": "xxxxx",
"street_address": "xxxxxx",
"city": "xxxx",
"state": "CA",
"zip_code": "90021"
},
"alert_id": {
"id": "abc123",
"subject": "abc123",
"abc_id": "abc123"
}
},
"alert_sub_type": "check change",
"alert_type": "change",
"provider": "ABCD",
"view_date": "2020-11-03T10:15:30Z",
"status": "Read"
}
和
{
"alert_details": {
"event_date": "2020-11-03T10:15:30Z",
"account_number": "*********xxx",
"check_start_number": "2",
"myprofile": {
"name": {
"first_name": "xxxx",
"last_name": "xxxx",
"middle_name": "M"
}
},
"order_shipped_date": "2021-04-23",
"myprofile_address": {
"name": "xxxxx",
"street_address": "xxxxx",
"city": "xxxx",
"state": "xxxx",
"zip_code": "90021"
},
"quantity_ordered": "12",
"alert_id": {
"id": "abc123",
"subject": "abc123",
"abc_id": "abc123"
}
},
"alert_sub_type": "review Check",
"alert_type": "review",
"provider": "abcd",
"view_date": "2020-11-03T10:15:30Z",
"status": "Read"
}
不了解如何使用oneof并使用此有效负载创建架构,我是使用oneof编写架构的新手,我使用oneof:编写了此架构
{
"description" : "schema validating people and vehicles",
"type" : "object",
"oneOf": [
{ "$ref":"#/definitions/checkchange" },
{ "$ref":"#/definitions/reviewcheck" }
],
"definitions": {
"checkchange":{
"type": "object",
"properties": {
"alert_details": {
"$ref": "#/definitions/AlertDetails"
},
"alert_sub_type": {
"type": "string"
},
"alert_type": {
"type": "string"
},
"provider": {
"type": "string"
},
"view_date": {
"type": "string",
"format": "date-time"
},
"status": {
"type": "string"
}
},
"required": [
"alert_details",
"alert_sub_type",
"alert_type",
"provider",
"status",
"view_date"
],
"title": "Welcome4"
},
"AlertDetails": {
"type": "object",
"properties": {
"event_date": {
"type": "string"
},
"camount": {
"type": "string",
"format": "integer"
},
"profile": {
"$ref": "#/definitions/Profile"
},
"check_cash_date": {
"type": "string",
"format": "date"
},
"profile_address": {
"$ref": "#/definitions/ProfileAddress"
},
"alert_id": {
"$ref": "#/definitions/AlertID"
}
},
"required": [
"alert_id",
"camount",
"check_cash_date",
"event_date",
"profile",
"profile_address"
],
"title": "AlertDetails"
},
"AlertID": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"subject": {
"type": "string"
},
"abc_id": {
"type": "string"
}
},
"required": [
"abc_id",
"id",
"subject"
],
"title": "AlertID"
},
"Profile": {
"type": "object",
"properties": {
"name": {
"$ref": "#/definitions/Name"
}
},
"required": [
"name"
],
"title": "Profile"
},
"Name": {
"type": "object",
"properties": {
"first_name": {
"type": "string"
},
"last_name": {
"type": "string"
},
"middle_name": {
"type": "string"
}
},
"required": [
"first_name",
"last_name",
"middle_name"
],
"title": "Name"
},
"ProfileAddress": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"street_address": {
"type": "string"
},
"city": {
"type": "string"
},
"state": {
"type": "string"
},
"zip_code": {
"type": "string",
"format": "integer"
}
},
"required": [
"city",
"name",
"state",
"street_address",
"zip_code"
],
"title": "ProfileAddress"
},
"reviewcheck":{
"type": "object",
"properties": {
"alert_details": {
"$ref": "#/definitions/AlertDetails"
},
"alert_sub_type": {
"type": "string"
},
"alert_type": {
"type": "string"
},
"provider": {
"type": "string"
},
"view_date": {
"type": "string",
"format": "date-time"
},
"status": {
"type": "string"
}
},
"required": [
"alert_details",
"alert_sub_type",
"alert_type",
"provider",
"status",
"view_date"
]
},
"AlertDetails": {
"type": "object",
"properties": {
"event_date": {
"type": "string",
"format": "date-time"
},
"account_number": {
"type": "string"
},
"check_start_number": {
"type": "string",
"format": "integer"
},
"myprofile": {
"$ref": "#/definitions/Myprofile"
},
"order_shipped_date": {
"type": "string",
"format": "date"
},
"myprofile_address": {
"$ref": "#/definitions/MyprofileAddress"
},
"quantity_ordered": {
"type": "string",
"format": "integer"
},
"alert_id": {
"$ref": "#/definitions/AlertID"
}
},
"required": [
"account_number",
"alert_id",
"check_start_number",
"event_date",
"myprofile",
"myprofile_address",
"order_shipped_date",
"quantity_ordered"
],
"title": "AlertDetails"
},
"AlertID": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"subject": {
"type": "string"
},
"abc_id": {
"type": "string"
}
},
"required": [
"abc_id",
"id",
"subject"
],
"title": "AlertID"
},
"Myprofile": {
"type": "object",
"properties": {
"name": {
"$ref": "#/definitions/Name"
}
},
"required": [
"name"
],
"title": "Myprofile"
},
"Name": {
"type": "object",
"additionalProperties": false,
"properties": {
"first_name": {
"type": "string"
},
"last_name": {
"type": "string"
},
"middle_name": {
"type": "string"
}
},
"required": [
"first_name",
"last_name",
"middle_name"
],
"title": "Name"
},
"MyprofileAddress": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"street_address": {
"type": "string"
},
"city": {
"type": "string"
},
"state": {
"type": "string"
},
"zip_code": {
"type": "string",
"format": "integer"
}
},
"required": [
"city",
"name",
"state",
"street_address",
"zip_code"
],
"title": "MyprofileAddress"
}
}}
验证对我不起作用,例如,在这个模式中,我提供了所需的字段";alert_id";,如果我在JSON数据中删除该字段,验证仍然会成功,而不是失败,并出现一些错误
https://www.jsonschemavalidator.net/s/Tqh2XRMI.--->在这种情况下,我保留
aaaparofile而不是配置文件aaalert_id而不是alert_id
它应该抛出一个验证错误,但我没有得到任何验证错误
第4行有一个拼写错误。它应该是oneOf
,而不是其中之一:
"oneOf": [
{ "$ref":"#/definitions/checkchange" },
{ "$ref":"#/definitions/reviewcheck" }
]
验证抛出一个关于此更改后缺少必需属性的错误。