JSON formatting “$ref” error

陌路散爱 提交于 2020-01-17 05:59:38

问题


I am trying to find what is making the following JSON invalid. The strange thing is that it passes off as valid JSON in this website but is invalid in this one

Here's the schema:

http://pastebin.com/QPxEPjMT

The error logged on the second schema validation website is as follows:

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

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

Can someone clarify whether my schema is incorrect or this is about some ambiguous rule in the JSON Schema itself?


回答1:


You do not have the schema defined for the object of type 'identifiable' on the root definitions level:

 {
    ...
    "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
        ...
  }
...
}

But you have it defined inside your definition of the object of type 'subscriptions'. So, the reference you have in the scheme is pointing to:

[root]/definitions/identifiable

but you have it on:

[root]/definitions/subscriptions/definitions/identifiable

Please, fix your reference. BTW, both of sites are marking your schema invalid.



来源:https://stackoverflow.com/questions/38034478/json-formatting-ref-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!