Skip to content

[Java][Webclient] Authentication queryParams double encoded #909

Closed
@marcoreni

Description

@marcoreni
Description

A querystring authentication param is double encoded during request.

openapi-generator version

3.2.3-SNAPSHOT

OpenAPI declaration file content or url
security:
  - apiKey: []
components:
  securitySchemes:
    apiKey:
      type: apiKey
      in: query
      name: apiKey
[...]
Steps to reproduce
  1. Generate a client with authentication
  2. Set 1234= as auth value
  3. Request should be sent as apiKey=1234%3D, but instead is sent as apiKey=1234%253D
Suggest a fix/enhancement

I'm assuming that this behavior happens for all query params, since there is no special handling for authentication query params once these are added to the list in https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache#L529 .

I checked the generated code and debugged a request.

  1. During prepareRequest() all queryParams are encoded.
  2. During builder.build().toUri() (specifically during toUri()) the params are encoded once again, since build() is called without encoded param (see https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/util/UriComponentsBuilder.html#build-- / https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/util/UriComponentsBuilder.html#build-boolean- ).

I think the best solution would be to leave the encoding to toUri(), thus removing the loop in prepareRequest() (https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache#L534).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions