引用多个预定义的swagger 2.0参数定义抛出错误

时间:2014-12-23 19:34:36

标签: swagger swagger-2.0 apigee127

我在swagger 2.0文件中定义了两个可重复使用的参数:

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 

然后在我的路线定义中(在这种情况下为GET)我试图像这样引用两者:

parameters:
    - $ref: '#/parameters/cursorParam'
    - $ref: '#/parameters/limitParam'  

如果我使用一个$ ref,它似乎工作正常(没有编译错误),但如果我尝试使用两者,它会瞪着我:

Operation parameter already defined: undefined
at paths ▹ /users ▹ get ▹ parameters ▹ 1 ▹ name

Operation parameter already defined: undefined
at paths ▹ /authorisations ▹ get ▹ parameters ▹ 1 ▹ name

此外,如果我在查询字符串中传递这些参数并输出req.swagger.params,我会得到一个空对象。我做错了什么?

这是规范的完整SSCCE,产生相同的错误:

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         

1 个答案:

答案 0 :(得分:2)

您似乎使用的是旧版本的a127。最近修复了Swagger文档所有部分缺乏参考支持,因此更新应该解决这个问题。