【发布时间】:2017-06-24 16:59:46
【问题描述】:
我有一个 API 路由在处理逻辑之前验证 json 架构。
此路由可以根据发送的 JSON 创建 2 种类型的“文章”。我使用 OneOf 检查架构是否对应于这两种类型之一。
{
"type": "object",
"oneOf": [{
"properties": {
"name": {
"type": "string",
},
"description": {
"type": "string"
}
}
}, {
"properties": {
"author": {
"type": "string",
},
"editor": {
"type": "string"
}
},
"required":["author", "editor"]
}]
}
所以第一个类型可以有名称和描述,但是这个字段不是必需的。
第二种类型需要有作者和编辑。
如果发送的 JSON 架构仅包含 author 字段会怎样? (编辑器为空)
感谢您的回复。
【问题讨论】:
标签: javascript json api validation schema