大幅度的错误表明需要在路径或操作级别中定义参数

时间:2019-07-10 02:54:43

标签: rest swagger swashbuckle swagger-editor

我收到以下错误:

  

声明的路径参数“ 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'

仅当我采用imageId并改成path而不是query时,我才能摆脱错误

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

对我需要更改以使其正常工作的任何想法吗?

1 个答案:

答案 0 :(得分:1)

路径字符串/api/v1/images/{unitnumber}/{type}/{imageId}表示imageId是路径参数,因此它必须为in: path

如果像imageId那样将/api/v1/images/{unitnumber}/{type}?imageId=...作为查询参数,则需要将路径字符串更改为/api/v1/images/{unitnumber}/{type}。查询参数should not be mentioned in paths,它们仅在parameters部分中定义。