From d6deaf8c7be1f495ae84f40e6a506b2f125db538 Mon Sep 17 00:00:00 2001 From: Aharon Hacmon Date: Sun, 18 Dec 2022 10:09:33 +0200 Subject: [PATCH] 13393: Make queryParams known to UriComponents builder so it can properly encode them --- .../java/org/openapitools/client/ApiClient.java | 14 ++++++++------ .../java/org/openapitools/client/ApiClient.java | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 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 dc250a75c79..561e27b4db0 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 class ApiClient extends JavaTimeFormatter { 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 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(finalUri, uriParams); - final UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(basePath).path(expandedPath); + 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 8340b6cfa8e..d96ed08a5cc 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 class ApiClient extends JavaTimeFormatter { 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 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(finalUri, uriParams); - final UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(basePath).path(expandedPath); + String expandedPath = this.expandPath(path, uriParams); + final UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(basePath) + .path(expandedPath) + .query(queryUri); URI uri; try {