【问题标题】:dependencies is not working in jsonschema validation依赖项在 jsonschema 验证中不起作用
【发布时间】:2016-01-29 07:01:08
【问题描述】:

以下是与 jsonschema 4.0 兼容的我的 json 架构。

{
"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 在那里不起作用,即每当提供信用卡详细信息时,生成的表单也应要求提供 billing_address。虽然字段显示正确,但填写 credit_card 详细信息时不会显示验证错误。

我们已在 interaction 上启用验证 我做错了还是有一些版本问题。请注意,我暂时没有指定 $schema。

有什么帮助吗?

【问题讨论】:

  • 您检查架构版本了吗?我想这应该适用于 jsonschema 4.x
  • 是的!我已经提到,虽然在我的架构中我只是没有指定架构,因此它应该占用我猜的最新架构
  • Vinay,根据依赖项tools.ietf.org/html/… 的规范,Jason 的回答是正确的

标签: json jsonschema json-schema-validator


【解决方案1】:

dependencies 不应包含在数组中。将您的 dependencies 更改为:

"dependencies": {
    "credit_card": ["billing_address"]
}

这将使您的架构有效,但这并不能保证您使用的表单生成器支持dependencies 关键字。通常它们只支持 JSON Schema 规范的一个子集。

【讨论】:

    猜你喜欢
    • 2016-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 2021-03-05
    • 1970-01-01
    相关资源
    最近更新 更多