【发布时间】:2021-12-28 12:35:26
【问题描述】:
我有一个以下 JSON 模式,我正在尝试使用 JSON 模式验证器进行验证
JSON 架构:
{
"$schema": "http://json-schema.org/draft-07schema#",
"description": "Create Orders Schema",
"type": "object",
"properties": {
"street_address": {
"type": "string"
},
"country": {
"default": "United States of America",
"enum": ["United States of America", "Canada"]
}
},
"if": {
"properties": { "country": { "const": "United States of America" } }
},
"then": {
"properties": { "postal_code": { "pattern": "[0-9]{5}(-[0-9]{4})?" } }
},
"else": {
"properties": { "postal_code": { "pattern": "[A-Z][0-9][A-Z] [0-9][A-Z][0-9]" } }
}
}
当我为国家“加拿大”传递错误的 postal_code 模式时,它没有经过验证并且通过了。
无效负载:
{
"street_address": "24 Sussex Drive",
"country": "Canada",
"postal_code": "10000"
}
是我遗漏了什么还是 JSON 验证器不支持条件 if-then-else?
提前致谢
【问题讨论】: