【发布时间】:2021-11-01 18:17:46
【问题描述】:
参考:https://json-schema.org/understanding-json-schema/reference/conditionals.html
- 架构 sn-p
"properties": {
"country": {
"default": "United States of America",
"enum": [
"United States of America",
"Canada"
]
},
"address": {
"properties": {
"AddressLine1": {
"type": "string"
},
"if": {
"properties": {
"country": {
"const": "United States of America"
}
}
},
"then": {
"postal_code": {
"type": "integer"
}
},
"else": {
"postal_code": {
"type": "string"
}
}
},
"required": [
"AddressLine1",
"postal_code"
]
示例数据 1 - 预期通过
{ “地址”: { "AddressLine1": "美国地址线 1", “邮政编码”:11779 } }
示例数据 2 - 预期失败
{ “地址”: { "AddressLine1": "加拿大地址线 1", “邮政编码”:“RA90 188” } }
我预计第二个样本会失败,但它通过了,没有任何问题。我正在使用 PowerShell Test-JSON 进行验证
【问题讨论】:
标签: powershell jsonschema json-schema-validator