Reputation: 876
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?
Upvotes: 4
Views: 11790
Reputation: 75
(The question is not clear in the context of the question so:)
If you are using OpenAPI and in a C# context:
[OpenApiParameter("imageId", In = ParameterLocation.Path, Required = true, Type = typeof(string), Description = "The image identifier")]
The error occurs in some pipelines that use OpenAPI. Place the code snippet above your Azure Function/ Endpoint / Controller and the error should be fixed.
Upvotes: 0
Reputation: 329
You have to declare a query parameter using a question mark as follows:
/api/v1/images/{unitnumber}/{type}/{?imageId}
Upvotes: 2
Reputation: 97540
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.
Upvotes: 10