【问题标题】:Swagger errors shows a need to define a parameter in the path or operation levelSwagger 错误表明需要在路径或操作级别定义参数
【发布时间】:2019-07-10 02:54:43
【问题描述】:

我收到以下错误:

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

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

【问题讨论】:

标签: swagger openapi swagger-editor


【解决方案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部分单独定义。

【讨论】:

    【解决方案2】:

    您必须使用问号声明查询参数,如下所示:

    /api/v1/images/{unitnumber}/{type}/{?imageId}
    

    【讨论】:

      猜你喜欢
      • 2020-09-20
      • 1970-01-01
      • 2017-07-23
      • 2021-11-14
      • 1970-01-01
      • 2020-11-07
      • 2017-08-14
      • 1970-01-01
      相关资源
      最近更新 更多