【问题标题】:JSON Schema: Definitions for array itemsJSON Schema:数组项的定义
【发布时间】:2016-04-24 01:41:37
【问题描述】:

我正在尝试在 JSON 模式中定义一个数组元素。它们的数组包含来自架构的 definitions 部分中已定义的类型的项目。

我试过了:

"properties": {
    "userId": {"$ref": "#/definitions/userId"},
    "beacons": {
        "type": "array",
        "items": { "$ref": "#/definitions/beaconSchema" }
    }
}

userId 部分用#/definitions/userId 解析。但是,列表项会忽略 #/definitions/beaconSchema 并允许其中包含任何旧垃圾。

如何使用 JSON 架构 definition 解析 JSON 数组中的所有项目?

【问题讨论】:

  • 您发布的架构片段是正确的。我建议您在 $ref 路径和 definitions 属性名称中查找拼写错误。如果您在那里没有发现问题,请尝试发布更多架构。
  • @Jason 你是对的,additionalProperties 定义中缺少键。请写下这个作为答案,我会接受。
  • 会的。很高兴你明白了。

标签: arrays definition jsonschema


【解决方案1】:

您发布的架构片段是正确的。我建议您在 $ref 路径和定义属性名称中查找拼写错误。如果您在那里没有发现问题,请尝试发布更多架构。

【讨论】:

  • 就是这样 - 定义中缺少 additionalProperties 键。谢谢(顺便说一句,你有这个问题的完美用户名)
猜你喜欢
  • 1970-01-01
  • 2016-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-22
  • 1970-01-01
相关资源
最近更新 更多