我有一个 Json 模式模板,其中包含对象数组。我需要使用该模板验证 Json 输入。但我希望这不应该依赖于数组中对象的顺序。
下面我们在模板中有 3 个不同对象的数组,即 abs、endpoint 和 dispatch。我想从这里删除订单的依赖。我可以在 Json 输入模式中提供项目的蚂蚁顺序。它不应该依赖于模板。我正在使用“ajv”节点 js 模板来验证带有模板数据的 Json 输入。任何帮助,将不胜感激。谢谢。
Attached template and input json.
Json Template
var schema1 = {
"additionalProperties" : {
"type" : "integer"
},
"properties": {
"name": { "type": "string" },
"description": { "type": "string" },
"services": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"type": { "type": "string", "const" :"abs" },
"id": { "type": "string" },
"name": { "type": "string" },
"appId": { "type": "string" },
"endpoint": { "type": "string" }
},
//"additionalProperties": false
"required": [ "type","id", "name","appId", "endpoint"]
},
{
"type": "object",
"properties": {
"type": { "type": "string", "const" :"endpoint" },
"id": { "type": "string" },
"name": { "type": "string" },
"appPassword": { "type": "string" },
"appId": { "type": "string" },
"endpoint": { "type": "string" }
},
//"additionalProperties": false,
"required": [ "type","id", "name","appPassword","appId", "endpoint"]
}
,
{
"type": "object",
"properties": {
"type": { "type": "string", "const" :"dispatch" },
"serviceIds" : {"type":"array", "items": [{ "type": "string" }]},
"name": { "type": "string" },
"appId": { "type": "string" },
"authoringKey": { "type": "string" },
"version": { "type": "string" },
"region": { "type": "string" },
"id": { "type": "string" }
},
//"additionalProperties": false
"required": [ "type","serviceIds", "name","appId","authoringKey","version","region", "id"]
}
]
}
}
};
Input Json :
{
"name": "ScorpioBot-development",
"description": "",
"services": [
{
"type": "endpoint",
"id": "1",
"name": "development",
"appId": "test",
"appPassword": "test",
"endpoint": "http://localhost:3978"
},
{
"type": "abs",
"id": "49",
"name": "test-development",
"appId": "12323",
"endpoint": "http://localhost:3978/"
},
{
"type": "endpoint",
"id": "11",
"name": "development",
"appId": "test1",
"appPassword": "test1",
"endpoint": "http://localhost:3978"
},
{
"type": "dispatch",
"serviceIds": [
"general"
],
"name": "test_Dispatch",
"appId": "test",
"authoringKey": "1234,
"version": "Dispatch",
"region": "test",
"id": "dispatch"
}
]
}` {
"name": "ScorpioBot-development",
"description": "",
"services": [
{
"type": "endpoint",
"id": "1",
"name": "development",
"appId": "test",
"appPassword": "test",
"endpoint": "http://localhost:3978"
},
{
"type": "abs",
"id": "49",
"name": "test-development",
"appId": "12323",
"endpoint": "http://localhost:3978/"
},
{
"type": "endpoint",
"id": "11",
"name": "development",
"appId": "test1",
"appPassword": "test1",
"endpoint": "http://localhost:3978"
},
{
"type": "dispatch",
"serviceIds": [
"general"
],
"name": "test_Dispatch",
"appId": "test",
"authoringKey": "1234,
"version": "Dispatch",
"region": "test",
"id": "dispatch"
}
]
}`