【发布时间】:2021-09-02 16:38:00
【问题描述】:
我想为不同的场景创建几个 json 模式。
对于场景 1,我想说明:
a) 属性“draftenabled”的值必须为 true。
b) 属性“draftenabled”确实存在。
我已经查看了这篇文章 Validating Mandatory String values in JSON Schema 并尝试了以下
我试图验证这个 json
{
"$schema": "./test-schema.json",
"draftenabled": false,
"prefix": "hugo"
}
使用我在 Visual Studio Code 中创建的这个架构 test-schema.json。
{
"$schema": "http://json-schema.org/draft-04/schema#",
"properties": {
"$schema": {
"type": "string"
},
"draftenabled": {
"type": "boolean"
},
"prefix": {
"type": "string"
}
},
"additionalItems": false,
"contains": {
"properties": {
"draftenabled": {
"const": true
}
},
"required": [
"draftenabled"
]
}
}
我预计会出现错误,因为 draftenabled 的值是 false 而不是 true。
【问题讨论】:
标签: json jsonschema