Swagger-editor: When importing, relative $ref are not resolved

Created on 9 Jun 2016  ·  3Comments  ·  Source: swagger-api/swagger-editor

            "schema": {
              "$ref": "./mydef.json"
            }
  • Swagger Editor version(from Help > About menu): Version 2.10.1
  • My browser: Firefox

Issue
I want to import a swagger using import in URL.
This swagger has relative $ref, but are not resolved. Indeed for every $ref I have the error:
✖ Swagger Error Reference could not be resolved: ./mydef.json

Most helpful comment

This answer might be naive: it is relative to the main/default swagger.json that the editor has no problems finding (location api/swagger/swagger.json)?

E.g. both files are in the same location

api/swagger/swagger.json
api/swagger/path-pets-get.json

then this reference should work:

paths:
  /pets:
    $ref: 'path-pets-get.yaml'  # or './path-pets-get.json'

According to http://swagger.io/specification/#referenceObject

See also #639.

All 3 comments

You cannot use the relative reference syntax in the editor. Why? Because what is it relative to? You can use external references but please use the entire host/port/path to them.

This answer might be naive: it is relative to the main/default swagger.json that the editor has no problems finding (location api/swagger/swagger.json)?

E.g. both files are in the same location

api/swagger/swagger.json
api/swagger/path-pets-get.json

then this reference should work:

paths:
  /pets:
    $ref: 'path-pets-get.yaml'  # or './path-pets-get.json'

According to http://swagger.io/specification/#referenceObject

See also #639.

楼上就是坑人
in swagger.yaml, $ref for file must use full path, e.g. $ref: "api/swagger/routes/calendar.yaml"
in /calendar.yaml contains another $ref: "../model/calendar.yaml", in here it must be relative path, because model/calendar.yaml‘s parent is api/swagger/routes/calendar.yaml

in a world, use full path in swagger.yaml, in other yaml file use relative path

Was this page helpful?
0 / 5 - 0 ratings