0

我在我的 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         
4

1 回答 1

2

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

于 2014-12-23T20:32:58.003 回答