swagger-api / swagger-node

Swagger module for node.js
http://swagger.io
Apache License 2.0
3.97k stars 584 forks source link

External definition of the path to the endpoints raises swagger error #505

Open cortezthekiller opened 7 years ago

cortezthekiller commented 7 years ago

Using node v7.10.0 and npm 4.2.0. I have created a nodejs 'Hello World' project and I was trying to reorganize the main swagger.yaml taking the paths out to a sepparate paths.yaml file. I get a swagger error:

Relative paths to the individual endpoints. They must be relative to the 'basePath'.

This is how I reference the paths object in my api/swagger/swagger.yaml file¨:

paths:
  $ref: './paths.yaml'
  /swagger:
    x-swagger-pipe: swagger_raw

and this is the referenced file (api/swagger/paths.yaml) :

/hello:
  # binds a127 app logic to a route
  x-swagger-router-controller: hello_world
  get:
    description: Returns 'Hello' to the caller
    # used as the method name of the controller
    operationId: hello
    parameters:
      - name: name
        in: query
        description: The name of the person to whom to say hello
        required: false
        type: string
    responses:
      "200":
        description: Success
        schema:
          # a pointer to a definition
          $ref: "#/definitions/HelloWorldResponse"
      # responses may fall through to errors
      default:
        description: Error
        schema:
          $ref: "#/definitions/ErrorResponse"

Is it possible to reference the paths to the endpoints in a sepparate yaml file as I'm trying to do? In that case, is the swagger error pointing to the $ref object in the swagger.yaml file or is it pointing to the /hello endpoint inpaths.yaml ?

basask commented 7 years ago

I have hit the same issue. Same node and npm version also. There is a PR https://github.com/swagger-api/swagger-node/pull/496 to fix it. Works just fine.