2

パラメータを変更して複数回使用されるサービスを定義する必要があります。これを複数回定義する必要がありますが、2 回目に定義するたびに、前のサービスが自動的に上書きされます。以下は私が定義した方法です。これは最初の定義です:

  /sevice :
    post:
      summary: Service ABC
      description: |
        This service is used to get ABC.
      parameters:
        - name: XYZ
          in: query
          description: '8'
          required: true
          type: number
          format: integer
        - name: LMN
          in: query
          description: '2'
          required: true
          type: number
          format: integer
      tags:
        - ABC
      responses:
        '200':
          description: An array of products
          schema:
            type: array
            items:
              $ref: '#/definitions/ABC'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'

これは 2 番目の定義です。

  /sevice :
    post:
      summary: Service ABC
      description: |
        This service is used to remove ABC.
      parameters:
        - in: body
          name: jsonData
          description: Object that needs to be sended to the store.
          required: true
          schema:
            $ref: '#/definitions/PQR'
      tags:
        - ABC
      responses:
        '200':
          description: An array of products
          schema:
            type: array
            items:
              $ref: '#/definitions/LMN'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'

1 つの API 仕様で同じパスを複数回使用することはできますか?

4

1 に答える 1

2

いいえ、できません。私はそれをやろうとしましたが、私の API は Swagger 定義に基づいて構築されているため、Swagger Editorでチェックすると重複エラーが発生します。私の提案は、そのサービスの目的でパスに名前を追加することです。たとえば、定義の場合は /service/get または /service/delete です。

また、2 番目の定義はリソースを削除するように設計されており、最初の定義はリソースを取得するように設計されているようです。2 番目は DELETE HTTP メソッドで、最初は GET HTTP メソッドで、2 つの定義を組み合わせることができます。このように、パスは同じで、異なる HTTP 関数を実行できます。このリンクは、使用できるすべての HTTP メソッド オプションのリストです。POST は通常、新しいリソースの作成に使用されます。

この問題は、OpenAPI の Github で未解決の問題 (182 とマーク) です。

これが役立つことを願っています!

于 2016-07-15T18:39:51.123 に答える