0

swagger 2.0 ファイルで定義された 2 つの再利用可能なパラメーターがあります。

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'  

1 つの $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

さらに、クエリ文字列と outputreq.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 に答える