【发布时间】:2020-09-22 11:40:17
【问题描述】:
我有以下 JSON 架构:
{
"type": "object",
"properties": {
"Ingredients": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"Description": {
"type": "string"
},
"ProductType": {
"enum": [
"Cheese",
"Salad",
"Condiment"
],
"type": "string"
}
},
"required": [
"Description",
"ProductType"
]
}
]
}
}
}
还有下面的 JSON sn-p:
{
"Ingredients": [
{
"Description": "Cheddar",
"ProductType": "Cheese"
},
{
"Description": "Rocket",
"ProductType": "Salad"
},
{
"Description": "Onion Relish",
"ProductType": "Condiment"
},
{
"Description": "Parma Ham",
"ProductType": "SlicedMeat"
}
]
}
我预计这里的验证会失败,因为“SlicedMeat”不是验证枚举。
知道我需要如何在架构中定义它吗?
我正在使用https://www.jsonschemavalidator.net/,这会有所不同。
【问题讨论】:
标签: json jsonschema json-schema-validator