有没有可能通过参数更改多次定义相同路径的方法?

时间:2016-03-28 12:55:01

标签: swagger swagger-2.0 swagger-editor

我需要定义一个多次使用并且参数更改的服务。我需要多次定义它,但每当我第二次定义它时它会自动覆盖前一个。 以下是我如何定义它。这是第一个定义:

  /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'

这是第二个定义:

  /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'

是否可以在一个API规范中多次出现相同的路径?

1 个答案:

答案 0 :(得分:2)

不,这是不可能的。我尝试这样做但是在使用Swagger Editor进行检查时出现重复错误,因为我的API是基于Swagger定义构建的。我的建议是在路径上添加一个名称以用于该服务,例如:对于定义one / service / get或/ service / delete。

此外,我发现您的第二个定义旨在删除资源,而您的第一个定义是获取资源。第二个是DELETE HTTP方法,第一个是GET HTTP方法,可以将两个定义组合在一起。这样,您的路径是相同的,可以执行不同的HTTP功能。 This link是您可以使用的所有HTTP方法选项的列表。 POST通常用于创建全新的资源。

这个问题是OpenAPI的Github上的一个未解决的问题(标记为182)。

我希望这有帮助!

相关问题