[BUG] openapi-generator-maven-plugin version 5.2.1 not encoded comma
Created by: laidani
Hello, after upgrading openapi-generator-maven-plugin from 5.1.1 to 5.2.1, we notice that comma is not encoded in urls
https://localhost/v1/pets/v1.0/infos?code=1234&languages=fr%2Cen
https://localhost/v1/pets/v1.0/infos?code=1234&languages=fr,en
The first url work very well because the comma is encoded to %2C
, but the second is not working because the comma is not encoded.
The question now: is this a bug, or we should to add some configuration to encode commas ?
More details
If we look at the class ApiClient
we can easily notice that the encoded part is removed from the new version
Version 5.1.1
public <T> ResponseEntity<T> invokeAPI(String path, HttpMethod method, MultiValueMap<String, String> queryParams, Object body, HttpHeaders headerParams, MultiValueMap<String, String> cookieParams, MultiValueMap<String, Object> formParams, List<MediaType> accept, MediaType contentType, String[] authNames, ParameterizedTypeReference<T> returnType) throws RestClientException {
updateParamsForAuth(authNames, queryParams, headerParams, cookieParams);
final UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(basePath).path(path);
if (queryParams != null) {
//encode the query parameters in case they contain unsafe characters
for (List<String> values : queryParams.values()) {
if (values != null) {
for (int i = 0; i < values.size(); i++) {
try {
values.set(i, URLEncoder.encode(values.get(i), "utf8"));
} catch (UnsupportedEncodingException e) {
}
}
}
}
builder.queryParams(queryParams);
}
URI uri;
try {
uri = new URI(builder.build().toUriString());
} catch(URISyntaxException ex) {
throw new RestClientException("Could not build URL: " + builder.toUriString(), ex);
}
final BodyBuilder requestBuilder = RequestEntity.method(method, uri);
if(accept != null) {
requestBuilder.accept(accept.toArray(new MediaType[accept.size()]));
}
if(contentType != null) {
requestBuilder.contentType(contentType);
}
Version 5.2.1
public <T> ResponseEntity<T> invokeAPI(String path, HttpMethod method, Map<String, Object> pathParams, MultiValueMap<String, String> queryParams, Object body, HttpHeaders headerParams, MultiValueMap<String, String> cookieParams, MultiValueMap<String, Object> formParams, List<MediaType> accept, MediaType contentType, String[] authNames, ParameterizedTypeReference<T> returnType) throws RestClientException {
updateParamsForAuth(authNames, queryParams, headerParams, cookieParams);
Map<String,Object> uriParams = new HashMap();
uriParams.putAll(pathParams);
String finalUri = path;
if (queryParams != null && !queryParams.isEmpty()) {
//Include queryParams in uriParams taking into account the paramName
String queryUri = generateQueryUri(queryParams, uriParams);
//Append to finalUri the templatized query string like "?param1={param1Value}&.......
finalUri += "?" + queryUri;
}
String expandedPath = this.expandPath(finalUri, uriParams);
final UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(basePath).path(expandedPath);
URI uri;
try {
uri = new URI(builder.build().toUriString());
} catch (URISyntaxException ex) {
throw new RestClientException("Could not build URL: " + builder.toUriString(), ex);
}
final BodyBuilder requestBuilder = RequestEntity.method(method, uri);
if (accept != null) {
requestBuilder.accept(accept.toArray(new MediaType[accept.size()]));
}
if (contentType != null) {
requestBuilder.contentType(contentType);
}