【问题标题】:JSON formatting "$ref" errorJSON 格式“$ref”错误
【发布时间】:2016-10-28 07:37:26
【问题描述】:

我正在尝试找出导致以下 JSON 无效的原因。奇怪的是它在this 网站中作为有效JSON 传递,但在this 中无效

这是架构:

http://pastebin.com/QPxEPjMT

第二个schema验证网站记录的错误如下:

Error when resolving schema reference '#/definitions/identifiable'. 

Path 'definitions.subscription.allOf[0]', line 19, position 17.

有人可以澄清我的架构是否不正确,或者这是关于 JSON 架构本身的一些模棱两可的规则吗?

【问题讨论】:

  • 在您提供的jsonschemavalidator.net 网站中,如果您选择“schema Draft v3”或“schema Draft v4”并且 json 被验证为良好。此外,在 jslint.com(这是我使用的)中,您的 json 是有效的。
  • @AshwinKrishnamurthy 感谢您的响应,但是当您从下拉列表中选择 v4 时,网站会加载一些默认架构。
  • 我很抱歉。我相信我错过了:)

标签: json json-schema-validator


【解决方案1】:

您没有在根定义级别为“可识别”类型的对象定义架构:

 {
    ...
    "definitions": {
         ...
        "identifiable": {
                "$schema": "http://json-schema.org/draft-04/schema#",
                "id": "http://api.sprint.com/schema/identifiable#",
                "title": "Identifiable Schema",
                "type": "object",
                "properties": {
                    "id": {
                        "type": "string",
                        "description": "READ ONLY. The id of the resource."
                    }
                },
                "required": [
                    "id"
                ],
                "additionalProperties": true
        ...
  }
...
}

但是您已经在“订阅”类型的对象的定义中定义了它。因此,您在方案中的参考指向:

[root]/definitions/identifiable

但你有它:

[root]/definitions/subscriptions/definitions/identifiable

请修正您的参考。 顺便说一句,这两个网站都将您的架构标记为无效。

【讨论】:

    猜你喜欢
    • 2019-05-07
    • 2016-11-18
    • 2018-11-09
    • 2018-02-10
    • 2021-09-04
    • 2019-04-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多