2017-01-13 15 views
0

配列パラメータに列挙型の文字列型の参照を使用する方法を取得できません。 アイテムキーの参照を作成できますが、動作していますが、スワッガーはエラーを生成します:有効なパラメータ定義ではありません。Swagger 2:配列型のクエリパラメータにenum参照を使用

Web UIはインターフェイスを生成しますが、

これを行う適切な方法は何ですか?

マイコード:

swagger: '2.0': 
    paths: 
     /test: 
     get: 
      parameters: 
      - in: origin 
      name: status 
      description: Origin 
      required: false 
      schema: 
       type: array 
       items: 
       $ref: '#/definitions/Origin' 
      collectionFormat: pipes' 
    definitions: 
     Origin: 
     type: string 
     description: Campaign origin 
     enum: 
      - one 
      - two 
    externalDocs: 
     description: Find out more about Swagger 
     url: http://swagger.io 
    host: virtserver.swaggerhub.com 
    basePath:/

答えて

1
$refを含む items

配列パラメータは、OpenAPIの/闊歩2.0でnotsupportedあります。しかし、次のバージョン3.0ではthis will be possibleのように見えます。今のところ、いくつかの回避策があります。以下を参照してください。

あなたのスペックにもいくつかの他の問題があります。

  • in: originは有効ではありません。 inキーワードは、パラメータの場所(パス、クエリ、ヘッダーなど)を指定し、OpenAPI/Swagger仕様に従って特定の値のみを受け入れます。私はあなたがin: queryまたはin: headerを意味したと思います。

  • タイプミス(またはコピー&ペーストの誤り?):swagger: '2.0':は、最後に余分な:を持っており、collectionFormat: pipes'は、最後に余分な'を持っています。

     parameters: 
         - in: query 
          name: status 
          description: Origin 
          required: false 
          type: array 
          collectionFormat: pipes 
          items: 
          type: string 
          enum: 
           - one 
           - two 
    

    別の溶液(hereを発見)YAMLが列挙を参照するアンカーを使用することである:enum値を含む配列パラメータを持つため


一つの解決策は、列挙インラインで定義することです。これはYAMLの機能で、キーに&anchor-nameとマークし、さらにそのキーの値を参照するために*anchor-nameを使用します。

definitions: 
    Origin: 
    type: string 
    description: Campaign origin 
    enum: &origin 
     - one 
     - two 

paths: 
    /test: 
    get: 
     parameters: 
     - in: query 
      name: status 
      description: Origin 
      required: false 
      type: array 
      collectionFormat: pipes 
      items: 
      type: string 
      enum: *origin 
関連する問題