json 数组中对象的架构
json schema of object inside array
我正在尝试编写一个 json
模式,以便我可以使用它来验证 Postman 中的响应。
我感觉我快到了,但缺少一些明显的东西。
我已经在 Whosebug
、this page 上检查了 Q&A
以及搜索 [=47= 时出现在 google 上的所有其他内容] 数组中的架构对象
我link 2段代码:
- 我的模式需要修复吗
- 是我正在尝试使用架构验证的响应。
Note: Postman does accept the schema, but when I intentionally make an error ("type": "number" when it is a string in the response) the test in Postman just passes as if everything is allright. I expect the test to fail.
架构:
const resultaatSchema = {
"type": "object",
"properties": {
"InputParameters": {"type": "object"},
"Resultaat": {"type": "array",
"items": {
"Bedrijfsnaam": {"type": "number"},
"Winkel": {"type": "string"},
"Kvknummer": {"type": "string"},
"Accountmanager": {"type": "object"},
"Eigenaar": {"type": "object",
"properties": {
"Naam": {"type": "string"},
"EmailAdres": {"type": "string"},
"RegionaleUnive": {"type": "object",
"properties": {
"Naam": {"type": "string"},
"Nummer": {"type": "number"}
}
}
}
}
}
}
}
};
响应验证
{
"InputParameters": {
"ZoekWaardes": [
"Z-000168378"
]
},
"Resultaat": [
{
"Bedrijfsnaam": "Companyname",
"Winkel": "City",
"Kvknummer": "08129882",
"AccountManager": {
"Gebruikersnaam": "Somename",
"EmailAdres": "some.mail@address.nl"
},
"Eigenaar": {
"Naam": "aName",
"EmailAdres": null,
"RegionaleUnive": {
"Naam": "anotherName",
"Nummer": 1111
}
},
"Website": null,
"EmailAdressen": [
{
"TypeId": 1,
"Type": "Primair",
"Adres": "mail@address.nl"
},
{
"TypeId": 2,
"Type": "Secundair",
"Adres": "mail@addres2.nl"
}
],
"Telefoonnummers": [
{
"TypeId": 2,
"Type": "Vast",
"Nummer": "+31623568744",
"Geheim": false
},
{
"TypeId": 3,
"Type": "Mobiel",
"Nummer": "+31623568744",
"Geheim": false
}
],
"Addressen": [
{
"TypeId": 2,
"Type": "Bezoek",
"Straat": "Streetname",
"Huisnummer": "1",
"HuisnummerToevoeging": null,
"Postcode": "postalcode",
"Woonplaats": "City",
"Provincie": "province",
"LandCode": "NL",
"Geheim": false
},
{
"TypeId": 3,
"Type": "Post",
"Straat": "addresline1",
"Huisnummer": "addresline2",
"HuisnummerToevoeging": null,
"Postcode": "postalcode",
"Woonplaats": "City",
"Provincie": "Province",
"LandCode": "XX",
"Geheim": false
}
],
"Id": "9bba2277-8536-e911-8109-0050568803e2",
"CrmRelatieNummer": "Z-000168378",
"URN": null
}
]
}
您的 "items" 架构关键字不是有效架构。 items 的值必须是模式或模式数组。在单个模式的情况下,数组的所有项目都根据该模式进行验证。在数组的情况下,项目根据它们的位置进行验证。
刚刚添加评论也作为答案,以便其他人可以快速看到。
我正在尝试编写一个 json
模式,以便我可以使用它来验证 Postman 中的响应。
我感觉我快到了,但缺少一些明显的东西。
我已经在 Whosebug
、this page 上检查了 Q&A
以及搜索 [=47= 时出现在 google 上的所有其他内容] 数组中的架构对象
我link 2段代码:
- 我的模式需要修复吗
- 是我正在尝试使用架构验证的响应。
Note: Postman does accept the schema, but when I intentionally make an error ("type": "number" when it is a string in the response) the test in Postman just passes as if everything is allright. I expect the test to fail.
架构:
const resultaatSchema = {
"type": "object",
"properties": {
"InputParameters": {"type": "object"},
"Resultaat": {"type": "array",
"items": {
"Bedrijfsnaam": {"type": "number"},
"Winkel": {"type": "string"},
"Kvknummer": {"type": "string"},
"Accountmanager": {"type": "object"},
"Eigenaar": {"type": "object",
"properties": {
"Naam": {"type": "string"},
"EmailAdres": {"type": "string"},
"RegionaleUnive": {"type": "object",
"properties": {
"Naam": {"type": "string"},
"Nummer": {"type": "number"}
}
}
}
}
}
}
}
};
响应验证
{
"InputParameters": {
"ZoekWaardes": [
"Z-000168378"
]
},
"Resultaat": [
{
"Bedrijfsnaam": "Companyname",
"Winkel": "City",
"Kvknummer": "08129882",
"AccountManager": {
"Gebruikersnaam": "Somename",
"EmailAdres": "some.mail@address.nl"
},
"Eigenaar": {
"Naam": "aName",
"EmailAdres": null,
"RegionaleUnive": {
"Naam": "anotherName",
"Nummer": 1111
}
},
"Website": null,
"EmailAdressen": [
{
"TypeId": 1,
"Type": "Primair",
"Adres": "mail@address.nl"
},
{
"TypeId": 2,
"Type": "Secundair",
"Adres": "mail@addres2.nl"
}
],
"Telefoonnummers": [
{
"TypeId": 2,
"Type": "Vast",
"Nummer": "+31623568744",
"Geheim": false
},
{
"TypeId": 3,
"Type": "Mobiel",
"Nummer": "+31623568744",
"Geheim": false
}
],
"Addressen": [
{
"TypeId": 2,
"Type": "Bezoek",
"Straat": "Streetname",
"Huisnummer": "1",
"HuisnummerToevoeging": null,
"Postcode": "postalcode",
"Woonplaats": "City",
"Provincie": "province",
"LandCode": "NL",
"Geheim": false
},
{
"TypeId": 3,
"Type": "Post",
"Straat": "addresline1",
"Huisnummer": "addresline2",
"HuisnummerToevoeging": null,
"Postcode": "postalcode",
"Woonplaats": "City",
"Provincie": "Province",
"LandCode": "XX",
"Geheim": false
}
],
"Id": "9bba2277-8536-e911-8109-0050568803e2",
"CrmRelatieNummer": "Z-000168378",
"URN": null
}
]
}
您的 "items" 架构关键字不是有效架构。 items 的值必须是模式或模式数组。在单个模式的情况下,数组的所有项目都根据该模式进行验证。在数组的情况下,项目根据它们的位置进行验证。
刚刚添加评论也作为答案,以便其他人可以快速看到。