Json 当布尔属性a为真时,如何要求属性B
使用JSON模式,当属性Json 当布尔属性a为真时,如何要求属性B,json,jsonschema,Json,Jsonschema,使用JSON模式,当属性foo(aboolean)设置为true时,如何指定属性bar是必需的 我尝试了以下方法: { "type": "object", "properties": { "foo": { "type": "boolean" }, "bar": { "type": "string" } }, "if": { "properties": { "foo": { "boolean": true } }, "requir
foo
(aboolean
)设置为true
时,如何指定属性bar
是必需的
我尝试了以下方法:
{
"type": "object",
"properties": {
"foo": { "type": "boolean" },
"bar": { "type": "string" }
},
"if": {
"properties": {
"foo": { "boolean": true }
},
"required": ["foo"]
},
"then": { "required": ["bar"] }
}
但是,这无法验证:
{
"foo": false
}
因为尽管foo
为false
,但似乎仍然需要bar
:
Message:
Required properties are missing from object: bar.
Schema path:
#/then/required
我也试过:
{
"type": "object",
"properties": {
"foo": { "type": "boolean" },
"bar": { "type": "string" }
},
"if": {
"properties": {
"foo": { "const": "true" }
},
"required": ["foo"]
},
"then": { "required": ["bar"] }
}
但它接受以下JSON,这应被视为无效:
{
"foo": true
}
我已经看到了,但是它使用类型string
表示foo
,这很好。我需要foo
成为boolean
当
foo
为true
时,我如何规定需要bar
您使用的const
是正确的,但是该值是一个字符串,而不是布尔值。你想要
“foo”:{“const”:true}
我投票决定结束,因为这是一个简单的打字错误。