依赖项在 jsonschema 验证中不起作用
dependencies is not working in jsonschema validation
下面是我的 json 模式与 json 模式 4.0 兼容。
{
"type": "object",
"properties": {
"name": { "type": "string" },
"credit_card": {
"type": "number" ,
"id":"credit_card"
},
"billing_address": {
"type": "string" ,
"id":"billing_address"
}
},
"required": ["name"],
"dependencies": [{
"credit_card": ["billing_address"]
}]
}
dependencies
在那里不起作用,即每当给出 credit_card 详细信息时,生成的表格也应该要求 billing_address。虽然字段显示正确,但在填写 credit_card 详细信息时未显示验证错误。
我们已在 interaction
上启用验证
我做错了吗还是有一些版本问题。请注意,我暂时没有指定 $schema。
有帮助吗?
dependencies
不应包含在数组中。将您的 dependencies
更改为:
"dependencies": {
"credit_card": ["billing_address"]
}
这将使您的架构有效,但这并不能保证您使用的表单生成器支持 dependencies
关键字。他们通常只支持 JSON 模式规范的一个子集。
下面是我的 json 模式与 json 模式 4.0 兼容。
{
"type": "object",
"properties": {
"name": { "type": "string" },
"credit_card": {
"type": "number" ,
"id":"credit_card"
},
"billing_address": {
"type": "string" ,
"id":"billing_address"
}
},
"required": ["name"],
"dependencies": [{
"credit_card": ["billing_address"]
}]
}
dependencies
在那里不起作用,即每当给出 credit_card 详细信息时,生成的表格也应该要求 billing_address。虽然字段显示正确,但在填写 credit_card 详细信息时未显示验证错误。
我们已在 interaction
上启用验证
我做错了吗还是有一些版本问题。请注意,我暂时没有指定 $schema。
有帮助吗?
dependencies
不应包含在数组中。将您的 dependencies
更改为:
"dependencies": {
"credit_card": ["billing_address"]
}
这将使您的架构有效,但这并不能保证您使用的表单生成器支持 dependencies
关键字。他们通常只支持 JSON 模式规范的一个子集。