From fd85359548dbc147c11417785acec68c21e7b985 Mon Sep 17 00:00:00 2001 From: Rasmus Zweidorff Iversen Date: Tue, 17 Sep 2024 11:57:35 +0200 Subject: [PATCH] [Java] [apache-httpclient] Fix issue with toString causing wrong value with collections (#19576) * Fix issue with toString causing wrong value with collections With collections, calling toString will result in the value becoming [a,b] instead of just a,b. Using the existing apiClient::parameterToString method ensures it gets parsed correctly if it is a collection * Updated samples --------- Co-authored-by: Rasmus Zweidorff Iversen --- .../Java/libraries/apache-httpclient/api.mustache | 2 +- .../main/java/org/openapitools/client/api/PathApi.java | 8 ++++---- .../main/java/org/openapitools/client/api/PetApi.java | 10 +++++----- .../java/org/openapitools/client/api/StoreApi.java | 4 ++-- .../main/java/org/openapitools/client/api/UserApi.java | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/api.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/api.mustache index eecc6da74b20..cfcd9f04ce6b 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/api.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/api.mustache @@ -99,7 +99,7 @@ public class {{classname}} extends BaseApi { {{/required}}{{/allParams}} // create path and map variables String localVarPath = "{{{path}}}"{{#pathParams}} - .replaceAll("\\{" + "{{baseName}}" + "\\}", apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}}; + .replaceAll("\\{" + "{{baseName}}" + "\\}", apiClient.escapeString(apiClient.parameterToString({{{paramName}}}))){{/pathParams}}; StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); String localVarQueryParameterBaseName; diff --git a/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/api/PathApi.java b/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/api/PathApi.java index 7eee07ae3e02..63748db9f33f 100644 --- a/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/api/PathApi.java +++ b/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/api/PathApi.java @@ -92,10 +92,10 @@ public String testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnu // create path and map variables String localVarPath = "/path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path}" - .replaceAll("\\{" + "path_string" + "\\}", apiClient.escapeString(pathString.toString())) - .replaceAll("\\{" + "path_integer" + "\\}", apiClient.escapeString(pathInteger.toString())) - .replaceAll("\\{" + "enum_nonref_string_path" + "\\}", apiClient.escapeString(enumNonrefStringPath.toString())) - .replaceAll("\\{" + "enum_ref_string_path" + "\\}", apiClient.escapeString(enumRefStringPath.toString())); + .replaceAll("\\{" + "path_string" + "\\}", apiClient.escapeString(apiClient.parameterToString(pathString))) + .replaceAll("\\{" + "path_integer" + "\\}", apiClient.escapeString(apiClient.parameterToString(pathInteger))) + .replaceAll("\\{" + "enum_nonref_string_path" + "\\}", apiClient.escapeString(apiClient.parameterToString(enumNonrefStringPath))) + .replaceAll("\\{" + "enum_ref_string_path" + "\\}", apiClient.escapeString(apiClient.parameterToString(enumRefStringPath))); StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); String localVarQueryParameterBaseName; diff --git a/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/api/PetApi.java b/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/api/PetApi.java index 9523dca1711d..27ae144592a4 100644 --- a/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/api/PetApi.java +++ b/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/api/PetApi.java @@ -145,7 +145,7 @@ public void deletePet(Long petId, String apiKey, Map additionalH // create path and map variables String localVarPath = "/pet/{petId}" - .replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString())); + .replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(apiClient.parameterToString(petId))); StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); String localVarQueryParameterBaseName; @@ -375,7 +375,7 @@ public Pet getPetById(Long petId, Map additionalHeaders) throws // create path and map variables String localVarPath = "/pet/{petId}" - .replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString())); + .replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(apiClient.parameterToString(petId))); StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); String localVarQueryParameterBaseName; @@ -523,7 +523,7 @@ public void updatePetWithForm(Long petId, String name, String status, Map additionalHeaders) t // create path and map variables String localVarPath = "/store/order/{order_id}" - .replaceAll("\\{" + "order_id" + "\\}", apiClient.escapeString(orderId.toString())); + .replaceAll("\\{" + "order_id" + "\\}", apiClient.escapeString(apiClient.parameterToString(orderId))); StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); String localVarQueryParameterBaseName; @@ -210,7 +210,7 @@ public Order getOrderById(Long orderId, Map additionalHeaders) t // create path and map variables String localVarPath = "/store/order/{order_id}" - .replaceAll("\\{" + "order_id" + "\\}", apiClient.escapeString(orderId.toString())); + .replaceAll("\\{" + "order_id" + "\\}", apiClient.escapeString(apiClient.parameterToString(orderId))); StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); String localVarQueryParameterBaseName; diff --git a/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/api/UserApi.java b/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/api/UserApi.java index 73e32f24338e..eaa5ed28aa73 100644 --- a/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/api/UserApi.java +++ b/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/api/UserApi.java @@ -283,7 +283,7 @@ public void deleteUser(String username, Map additionalHeaders) t // create path and map variables String localVarPath = "/user/{username}" - .replaceAll("\\{" + "username" + "\\}", apiClient.escapeString(username.toString())); + .replaceAll("\\{" + "username" + "\\}", apiClient.escapeString(apiClient.parameterToString(username))); StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); String localVarQueryParameterBaseName; @@ -357,7 +357,7 @@ public User getUserByName(String username, Map additionalHeaders // create path and map variables String localVarPath = "/user/{username}" - .replaceAll("\\{" + "username" + "\\}", apiClient.escapeString(username.toString())); + .replaceAll("\\{" + "username" + "\\}", apiClient.escapeString(apiClient.parameterToString(username))); StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); String localVarQueryParameterBaseName; @@ -584,7 +584,7 @@ public void updateUser(String username, User user, Map additiona // create path and map variables String localVarPath = "/user/{username}" - .replaceAll("\\{" + "username" + "\\}", apiClient.escapeString(username.toString())); + .replaceAll("\\{" + "username" + "\\}", apiClient.escapeString(apiClient.parameterToString(username))); StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); String localVarQueryParameterBaseName;