swagger-editor: Editor not able to resolve external reference with $ref

Hi, I am trying to refer to an external definition file with $ref. The editor is failing to compile. I am using editor.swagger.io

Here is how I am setting the reference in my swagger definition file:

    '500':
      description: Unexpected error
      schema:
        $ref: 'Response-status.yaml#/Response-status'

I have a file called “Response-status.yaml”, stored locally, that is defined as follows:

 Response-status:
   type: object
   required:
       - status
       - http-code
  properties:
      status:
      type: string
      description: Status of the request.
      ........
      .......

Please advise.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 3
  • Comments: 19 (8 by maintainers)

Most upvoted comments

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

I found this issue too. When i inspect the network logs on the browser i can see that the editor is resolving relative references relative to the editor URL instead of relative to the document URL.

@pgtelus yes it does. You need to use absolute paths:

$ref: http://petstore.swagger.io/v2/swagger.json#/definitions/Pet

Works just fine as a schema item. The only issue here was about the paths being relative which doesn’t make sense for the editor.