I've got two re-usable parameters defined in my swagger 2.0 file:
parameters:
cursorParam:
name: cursor
in: query
description: Pagination cursor.
required: false
type: string
limitParam:
name: limit
in: query
description: Result limiter.
required: false
type: integer
And then in my route definitions (a GET in this case) I'm trying to reference both like this:
parameters:
- $ref: '#/parameters/cursorParam'
- $ref: '#/parameters/limitParam'
If I use one $ref, it seems to work OK (no compile errors), but if I try using both, it gawks at me:
Operation parameter already defined: undefined
at paths ▹ /users ▹ get ▹ parameters ▹ 1 ▹ name
Operation parameter already defined: undefined
at paths ▹ /authorisations ▹ get ▹ parameters ▹ 1 ▹ name
Moreover, if I pass these parameters in the query string and output req.swagger.params
, I get an empty object. What am I doing wrong?
Here's a full SSCCE of the spec, generating the same error:
swagger: "2.0"
info:
version: "0.0.1"
title: Test
# during dev, should point to your local machine
host: localhost
# basePath prefixes all resource paths
basePath: /
#
schemes:
# tip: remove http to make production-grade
- http
- https
# format of bodies a client can send (Content-Type)
consumes:
- application/json
# format of the responses to the client (Accepts)
produces:
- application/json
x-a127-config: {}
x-volos-resources: {}
paths:
/authorisations:
x-swagger-router-controller: authorizations
x-volos-authorizations: {}
x-volos-apply: {}
get:
description: Returns all authorizations. Requires administrator rights to view unfiltered results, or if authenticated, returns the authorization entity belonging to the OAuth token.
operationId: authorizationsGetAll #controller method name
parameters:
- $ref: '#/parameters/cursorParam'
- $ref: '#/parameters/limitParam'
responses:
200:
description: OK
# reusable parameters have parameter definitions
parameters:
cursorParam:
name: cursor
in: query
description: Pagination cursor passed to a BaaS collection. Note that if this parameter is present, lastAccessedTimestamp.{channelType} should not be updated.
required: false
type: string
limitParam:
name: limit
in: query
description: Result limiter to be passed to a BaaS collection.
required: false
type: integer
It appears you are using an old version of a127. The lack of reference support in all parts of the Swagger document were fixed recently so updating should fix this.