Swagger errors shows a need to define a parameter in the path or operation level

核能气质少年 提交于 2020-07-23 09:38:05

问题


I am getting the error below:

Declared path parameter "imageId" needs to be defined as a path parameter at either the path or operation level

This is the snapshot of my swagger definition

 '/api/v1/images/{unitnumber}/{type}/{imageId}':
        delete:
          tags:
            - Images
          summary: 'Summary'
          description: "Description"
          operationId: DeleteImage
          consumes: []
          produces:
            - application/json
          parameters:
            - name: unitnumber
              in: path
              required: true
              type: string
            - name: type
              in: path
              required: true
              type: string
            - name: imageId
              in: query
              required: false
              type: string
          responses:
            '400':
              description: Bad Request
              schema:
                $ref: '#/definitions/ErrorResponse'
            '401':
              description: Unauthorized
              schema:
                type: string
            '500':
              description: Server Error
              schema:
                $ref: '#/definitions/ErrorResponse'

I only can get rid of the error if I take the imageId and changing to path instead query which is not the intention

           - name: imageId
                  in: path
                  required: true
                  type: string

Any idea of what I need to change to have this working?


回答1:


The path string /api/v1/images/{unitnumber}/{type}/{imageId} means that imageId is a path parameter so it must be in: path.

If imageId is supposed to be a query parameter, as in /api/v1/images/{unitnumber}/{type}?imageId=..., you need to change the path string to /api/v1/images/{unitnumber}/{type}. Query parameters should not be mentioned in paths, they are defined in the parameters section alone.



来源:https://stackoverflow.com/questions/56962805/swagger-errors-shows-a-need-to-define-a-parameter-in-the-path-or-operation-level

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