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

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

本文介绍了Swagger 错误显示需要在路径或操作级别定义参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误:

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

这是我的swagger定义的快照

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'

如果我使用 imageId 并更改为 path 而不是 query,我只能摆脱错误>

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?

推荐答案

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

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

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

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.

这篇关于Swagger 错误显示需要在路径或操作级别定义参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 11:33