问题
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