OpenAPITools / OpenAPITools/openapi-generator
Java/Resttemplate: Double URL-encoding of query parameters since 6.0.0
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated Java ApiClient path expansion and compare the RestTemplate setup between versions 5.4.0 and 6.0.0, especially the EncodingMode setting described in the report. Reproduce the $filter case and add or update a regression test so the expanded path contains %24filter rather than %2524filter.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100