Json-schema - 如何验证特定元素不在数组中?
Json-schema - How to verify that a specific element is not in an array?
我有一个帐户列表(accountId、货币、accountType)
Id1,美元,账户/
Id2, GBP, 账户 /
Id3,欧元,帐户/
Id4,挪威克朗,账户
当我调用 api 获取帐户列表时,我想确保 accountid = 3 不在结果中。我怎样才能做到这一点?这是我的模式:
{
"title": "Acc schema",
"type": "object",
"definitions": {
"account": {
"properties": {
"accountId": {
"type": "string",
"minLength": 1,
"maxLength": 15
},
"currency": {
"type": "string",
"minLength": 3,
"maxLength": 3
},
"accountType": {
"type": "string",
"enum": [
”Account”
]
}
},
"required": ["accountId"],
"additionalProperties": false
},
"data": {
"type": "object",
"properties": {
"accounts": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/definitions/account"
}
],
"additionalItems": false
}
},
"additionalProperties": false
}
}
},
"properties": {
"data": {
"$ref": "#/definitions/data"
},
"headers": {
"type": "object"
},
"config": {
"type": "object"
},
"request": {
"type": "object"
},
"status": {
"type": "number"
},
"statusText": {
"type": "string"
}
},
"additionalProperties": false
}
主要关键字是 not
和 contains
。
您在 definitions
中的 data
条目可能如下所示(也没有不必要的 anyOf
):
"data": {
"type": "object",
"properties": {
"accounts": {
"type": "array",
"items": {
"$ref": "#/definitions/account"
},
“not”: {
“contains”: {
“type”: “object”,
“properties”: {
“accountId”: {
“const”: “3”
}
}
}
}
}
}
"additionalProperties": false
}
我有一个帐户列表(accountId、货币、accountType)
Id1,美元,账户/ Id2, GBP, 账户 / Id3,欧元,帐户/ Id4,挪威克朗,账户
当我调用 api 获取帐户列表时,我想确保 accountid = 3 不在结果中。我怎样才能做到这一点?这是我的模式:
{
"title": "Acc schema",
"type": "object",
"definitions": {
"account": {
"properties": {
"accountId": {
"type": "string",
"minLength": 1,
"maxLength": 15
},
"currency": {
"type": "string",
"minLength": 3,
"maxLength": 3
},
"accountType": {
"type": "string",
"enum": [
”Account”
]
}
},
"required": ["accountId"],
"additionalProperties": false
},
"data": {
"type": "object",
"properties": {
"accounts": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/definitions/account"
}
],
"additionalItems": false
}
},
"additionalProperties": false
}
}
},
"properties": {
"data": {
"$ref": "#/definitions/data"
},
"headers": {
"type": "object"
},
"config": {
"type": "object"
},
"request": {
"type": "object"
},
"status": {
"type": "number"
},
"statusText": {
"type": "string"
}
},
"additionalProperties": false
}
主要关键字是 not
和 contains
。
您在 definitions
中的 data
条目可能如下所示(也没有不必要的 anyOf
):
"data": {
"type": "object",
"properties": {
"accounts": {
"type": "array",
"items": {
"$ref": "#/definitions/account"
},
“not”: {
“contains”: {
“type”: “object”,
“properties”: {
“accountId”: {
“const”: “3”
}
}
}
}
}
}
"additionalProperties": false
}