From 5a265cc419c5ffedeabb5355873d0f3e37c88659 Mon Sep 17 00:00:00 2001 From: Aharon Hacmon Date: Sun, 27 Nov 2022 16:16:28 +0200 Subject: [PATCH 1/3] 13393: Make queryParams known to UriComponents builder so it can properly encode them --- .../libraries/resttemplate/ApiClient.mustache | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache index b5de6ce3a198..6b9ac75b9cdd 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache @@ -674,16 +674,18 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { Map uriParams = new HashMap<>(); uriParams.putAll(pathParams); - String finalUri = path; + String queryUri = null; 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); + String query = generateQueryUri(queryParams, uriParams); + queryUri = expandPath("?" + query, uriParams).substring(1); //exclude the '?' + //queryUri is the templatized query string like "?param1={param1Value}&....... + } + String expandedPath = this.expandPath(path, uriParams); + final UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(basePath) + .path(expandedPath) + .query(queryUri); URI uri; try { From d34ac8d13bd6e9c4075c1ad56d5748fc910c05f2 Mon Sep 17 00:00:00 2001 From: Aharon Hacmon Date: Sun, 18 Dec 2022 09:47:26 +0200 Subject: [PATCH 2/3] 13393: Make queryParams known to UriComponents builder so it can properly encode them --- .../java/org/openapitools/client/ApiClient.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java index b1d9b1cf1d26..e75299e540be 100644 --- a/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java @@ -629,16 +629,18 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map uriParams = new HashMap<>(); uriParams.putAll(pathParams); - String finalUri = path; + String queryUri = null; 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); + String query = generateQueryUri(queryParams, uriParams); + queryUri = expandPath("?" + query, uriParams).substring(1); //exclude the '?' + //queryUri is the templatized query string like "?param1={param1Value}&....... + } + String expandedPath = this.expandPath(path, uriParams); + final UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(basePath) + .path(expandedPath) + .query(queryUri); URI uri; try { From d6deaf8c7be1f495ae84f40e6a506b2f125db538 Mon Sep 17 00:00:00 2001 From: Aharon Hacmon Date: Sun, 18 Dec 2022 10:09:33 +0200 Subject: [PATCH 3/3] 13393: Make queryParams known to UriComponents builder so it can properly encode them --- .../java/org/openapitools/client/ApiClient.java | 16 +++++++++------- .../java/org/openapitools/client/ApiClient.java | 16 +++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/samples/client/petstore/java/resttemplate-swagger1/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resttemplate-swagger1/src/main/java/org/openapitools/client/ApiClient.java index dc250a75c79f..561e27b4db02 100644 --- a/samples/client/petstore/java/resttemplate-swagger1/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate-swagger1/src/main/java/org/openapitools/client/ApiClient.java @@ -597,16 +597,18 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map uriParams = new HashMap<>(); uriParams.putAll(pathParams); - String finalUri = path; + String queryUri = null; 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); + String query = generateQueryUri(queryParams, uriParams); + queryUri = expandPath("?" + query, uriParams).substring(1); //exclude the '?' + //queryUri is the templatized query string like "?param1={param1Value}&....... + } + String expandedPath = this.expandPath(path, uriParams); + final UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(basePath) + .path(expandedPath) + .query(queryUri); URI uri; try { diff --git a/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java index 8340b6cfa8ef..d96ed08a5cc8 100644 --- a/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java @@ -634,16 +634,18 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map uriParams = new HashMap<>(); uriParams.putAll(pathParams); - String finalUri = path; + String queryUri = null; 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); + String query = generateQueryUri(queryParams, uriParams); + queryUri = expandPath("?" + query, uriParams).substring(1); //exclude the '?' + //queryUri is the templatized query string like "?param1={param1Value}&....... + } + String expandedPath = this.expandPath(path, uriParams); + final UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(basePath) + .path(expandedPath) + .query(queryUri); URI uri; try {