Is there any possible way to define same path multiple times with change in parameters?

送分小仙女□ 提交于 2020-02-24 14:40:57

问题


I need to define a service that is used multiple times with change in parameters.I need to define this multiple times but whenever I define it second time it automatically overwrites the previous one. Following is how I defined it.This is first definition:

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

This is the second definition:

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

Is it possible to have same path appear more than once in one API spec?


回答1:


No, it is not possible. I tried to do that but it gives a duplication error when checking with Swagger Editor, as my API is built on the Swagger definition. My suggestion is to append the path with a name for the purpose of that service, e.g. for definitions one /service/get or /service/delete.

Also, I see that your second definition is designed to delete a resource and your first is to obtain a resource. You can the second one a DELETE HTTP method and the first one a GET HTTP method and combine the two definitions together. This way, your path is the same and can execute different HTTP functions. This link is a list of all HTTP method options you can use. POST is usually used in creating a brand new resource.

This problem is an open issue (marked 182) on the OpenAPI's Github.

I hope this helps!



来源:https://stackoverflow.com/questions/36262804/is-there-any-possible-way-to-define-same-path-multiple-times-with-change-in-para

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!