swagger-editor icon indicating copy to clipboard operation
swagger-editor copied to clipboard

When importing, relative $ref are not resolved

Open marcopiraccini opened this issue 10 years ago • 3 comments

            "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

marcopiraccini avatar Jun 09 '16 16:06 marcopiraccini

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.

fehguy avatar Jun 09 '16 19:06 fehguy

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.

nuarhu avatar Jun 23 '16 17:06 nuarhu

楼上就是坑人 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

zeng-ge avatar Oct 13 '17 09:10 zeng-ge