Swagger 错误显示需要在路径或操作级别定义参数

Hei*_*ich 1 rest swagger swagger-editor swashbuckle

我收到以下错误:

声明的路径参数“imageId”需要在路径或操作级别定义为路径参数

这是我的招摇定义的快照

 '/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'
Run Code Online (Sandbox Code Playgroud)

我只可以摆脱错误的,如果我走了imageId,改变以path代替query其意向不大

           - name: imageId
                  in: path
                  required: true
                  type: string
Run Code Online (Sandbox Code Playgroud)

知道我需要改变什么才能让它工作吗?

Hel*_*len 5

路径字符串/api/v1/images/{unitnumber}/{type}/{imageId}意味着这imageId是一个路径参数,所以它必须是in: path.

如果imageId应该是查询参数,如/api/v1/images/{unitnumber}/{type}?imageId=...,则需要将路径字符串更改为/api/v1/images/{unitnumber}/{type}。查询参数不应在路径中提及,它们parameters单独在该部分中定义。