Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JAVA][RestTemplate]Query parameter is not URL encoded #249

Closed
simingweng opened this issue Jun 7, 2018 · 4 comments
Closed

[JAVA][RestTemplate]Query parameter is not URL encoded #249

simingweng opened this issue Jun 7, 2018 · 4 comments

Comments

@simingweng
Copy link
Contributor

Description

If an API accept query parameter and parameter contains unsafe symbol, such as "&" sign, in the RestTemplate-based Java client, it is not encoded. When the request is sent as it is to the server side, it prevents the server from parsing the parameter properly.

openapi-generator version

3.0.0

OpenAPI declaration file content or url

https://github.com/OpenAPITools/openapi-generator/blob/v3.0.0/modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml

Command line used for generation

https://github.com/OpenAPITools/openapi-generator/blob/v3.0.0/bin/java-petstore-resttemplate.sh

Steps to reproduce

the line of code in question is at

the parameter string are put into UriComponentsBuilder as it is

Suggest a fix/enhancement

It seems other flavour of Java clients, such as "okhttp-gson", is doing "escaping" while building the request, at

url.append(escapeString(param.getName())).append("=").append(escapeString(value));

we need to introduce this sanitisation in RestTemplate-based client

@wing328
Copy link
Member

wing328 commented Jun 7, 2018

@simingweng thanks for reporting the issue with the details. May I know if you've time to contribute a fix?

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache#L530 is a good starting point and I agree with you we should reuse similar technique in other Java clients.

@wing328 wing328 added this to the 3.0.1 milestone Jun 7, 2018
@simingweng
Copy link
Contributor Author

sure, I can work on this.

@wing328 wing328 modified the milestones: 3.0.1, 3.0.2 Jun 11, 2018
@jmini jmini modified the milestones: 3.0.2, 3.0.3 Jun 18, 2018
@ackintosh
Copy link
Contributor

Could this issue be closed?

@simingweng
Copy link
Contributor Author

Yes, I think so, the fix is already in 3.0.1 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants