[Java][Webclient] Authentication queryParams double encoded
Created by: 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
- Generate a client with authentication
- Set
1234=as auth value - Request should be sent as
apiKey=1234%3D, but instead is sent asapiKey=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.
- During
prepareRequest()all queryParams are encoded. - During
builder.build().toUri()(specifically duringtoUri()) the params are encoded once again, sincebuild()is called withoutencodedparam (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).