openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

Java/Resttemplate: Double URL-encoding of query parameters since 6.0.0

Open christian-stahl-hochbahn opened this issue 3 years ago • 0 comments

Hi, since version 6.0.0 (and also in the latest 7.0.0-SNAPSHOT version) of the java/resttemplate client generator, there is an issue related to URL encoding, if there are query parameters with special characters in their names.

The special character in the query parameter name gets URL-encoded, and afterwards the whole request path gets URL-encoded again, leading to a double URL-encoding of the query parameter names.

Example for reproducing the issue:

  • Some API with an endpoint "/resource" with one query parameter with name "$filter"
  • Use Java/resttemplate client generator
  • Call the endpoint using the generated client, with query parameter value "filterValue"
  • When debugging in the generated ApiClient class, the "expandedPath" has a value of "/resource?%2524filter=filterValue"

With version 5.4.0, this can not be observed:

  • Same steps as above
  • When debugging in the generated ApiClient class, the "expandedPath" has a value of "/resource?%24filter=filterValue"

Some analysis from my side: In version 5.4.0, the resttemplate instance, which is used for expanding the path, is set up with "DefaultUriBuilderFactory.EncodingMode.NONE". In version 6.0.0, this is no longer the case. Maybe this is the reason for the changed behavior?