【问题标题】:JSON Validator not validating the schema in MuleJSON Validator 未验证 Mule 中的模式
【发布时间】:2021-12-28 12:35:26
【问题描述】:

我有一个以下 JSON 模式,我正在尝试使用 JSON 模式验证器进行验证

JSON 架构:

{
    "$schema": "http://json-schema.org/draft-07schema#",
    "description": "Create Orders Schema",
    "type": "object",
    "properties": {
    "street_address": {
      "type": "string"
    },
    "country": {
      "default": "United States of America",
      "enum": ["United States of America", "Canada"]
    }
  },
  "if": {
    "properties": { "country": { "const": "United States of America" } }
  },
  "then": {
    "properties": { "postal_code": { "pattern": "[0-9]{5}(-[0-9]{4})?" } }
  },
  "else": {
    "properties": { "postal_code": { "pattern": "[A-Z][0-9][A-Z] [0-9][A-Z][0-9]" } }
  }
}

当我为国家“加拿大”传递错误的 postal_code 模式时,它没有经过验证并且通过了。

无效负载:

{
  "street_address": "24 Sussex Drive",
  "country": "Canada",
  "postal_code": "10000"
}

是我遗漏了什么还是 JSON 验证器不支持条件 if-then-else?

提前致谢

【问题讨论】:

    标签: mulesoft mule4


    【解决方案1】:

    问题可能是架构使用了 Draft 7 JSON 架构规范。连接器的文档说validate schema operation 只支持草案 3 或 4:

    此连接器仅支持 JSON Schema Validation Drafts 3 和 4。

    【讨论】:

    • 感谢您的回复。草案 7 中提供了 if-then-else 条件。if-then-else 是否有其他替代方法来检查值并相应地设置其他字段的属性?
    • if-then-else 已在草案 7 中添加。您可以尝试替换为如下所述的含义:json-schema.org/understanding-json-schema/reference/…
    • 尝试了暗示中给出的相同示例,但看起来 JSON Validator 没有按预期工作(如链接中所述,即使在有效场景中它也会失败)
    • 您是否声明该示例使用的是 Draft 04? http://json-schema.org/draft-04/schema#
    • 是的,尝试使用 Draft 04,但在有效场景中仍然失败。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多