【发布时间】:2019-01-09 15:02:23
【问题描述】:
我正在使用https://www.jsonschemavalidator.net/ 并尝试验证我编写的架构。
架构:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"required": [
"accounts"
],
"accounts": {
"required": "account",
"properties": {
"account": {
"type": "array",
"minItems": 1,
"maxItems": 999,
"required": [
"scheme",
"accountType",
"accountSubType"
],
"items": {
"type": "object",
"properties": {
"scheme": {
"description": "scheme",
"type": "object",
"required": [
"schemeName",
"identification"
],
"properties": {
"schemeName": {
"type": "string",
"maxLength": 40,
},
"identification": {
"type": "string",
"maxLength": 256
},
"name": {
"type": "string",
"maxLength": 70
},
"secondaryIdentification": {
"type": "string",
"maxLength": 35
}
}
},
"currency": {
"type": "string",
"format": "iso-4217",
"pattern": "^[A-Z]{3,3}$",
"maxLength": 3,
"example": "EUR"
},
"accountType": {
"type": "string"
},
"accountSubType": {
"type": "string",
"maxLength": 35
}
}
}
}
}
}
}
当我使用在线链接进行验证时
{}
我收到一个错误
Message:
Required properties are missing from object: accounts.
Schema path:
#/required
这是正确的,但当我这样做时
{
"accounts": {
}
}
我没有收到任何错误,尽管我应该收到一个错误,说“帐户”是必需的。似乎没有验证任何内部“必填”字段。
我该如何解决这个问题?
【问题讨论】:
标签: json validation