4

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

3 Answers 3

10

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.

Sign up to request clarification or add additional context in comments.

Comments

2

You have to declare a query parameter using a question mark as follows:

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

Comments

0

(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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.