Skip to content

Commit

Permalink
webclient explode query parameters support (OpenAPITools#17441)
Browse files Browse the repository at this point in the history
  • Loading branch information
dreambrother authored Dec 21, 2023
1 parent 1060479 commit 3099a2f
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ public class {{classname}} {
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();
{{#hasQueryParams}}

{{#queryParams}}
queryParams.putAll(apiClient.parameterToMultiValueMap({{#collectionFormat}}ApiClient.CollectionFormat.valueOf("{{{.}}}".toUpperCase(Locale.ROOT)){{/collectionFormat}}{{^collectionFormat}}null{{/collectionFormat}}, "{{baseName}}", {{paramName}}));
{{/queryParams}}
{{/hasQueryParams}}
{{#hasHeaderParams}}
{{#queryParams}}{{#isExplode}}{{#hasVars}}{{#vars}}queryParams.putAll(apiClient.parameterToMultiValueMap({{#collectionFormat}}ApiClient.CollectionFormat.valueOf("{{{.}}}".toUpperCase(Locale.ROOT)){{/collectionFormat}}{{^collectionFormat}}null{{/collectionFormat}}, "{{baseName}}", {{paramName}}.{{getter}}()));
{{/vars}}{{/hasVars}}{{^hasVars}}queryParams.putAll(apiClient.parameterToMultiValueMap({{#collectionFormat}}ApiClient.CollectionFormat.valueOf("{{{.}}}".toUpperCase(Locale.ROOT)){{/collectionFormat}}{{^collectionFormat}}null{{/collectionFormat}}, "{{baseName}}", {{paramName}}));
{{/hasVars}}{{/isExplode}}{{^isExplode}}queryParams.putAll(apiClient.parameterToMultiValueMap({{#collectionFormat}}ApiClient.CollectionFormat.valueOf("{{{.}}}".toUpperCase(Locale.ROOT)){{/collectionFormat}}{{^collectionFormat}}null{{/collectionFormat}}, "{{baseName}}", {{paramName}}));
{{/isExplode}}{{/queryParams}}{{/hasQueryParams}}{{#hasHeaderParams}}

{{#headerParams}}
if ({{paramName}} != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2272,6 +2272,30 @@ public void shouldProperlyExplodeRestTemplateQueryParameters_issue907() {
+ " objectParam.getSomeInteger()));");
}

@Test
public void shouldProperlyExplodeWebClientQueryParameters() {
final Map<String, File> files = generateFromContract(
"src/test/resources/3_0/java/explode-query-parameter.yaml",
JavaClientCodegen.WEBCLIENT
);

JavaFileAssert.assertThat(files.get("DefaultApi.java"))
.printFileContent()
.assertMethod("searchRequestCreation")
.bodyContainsLines(
"queryParams.putAll(apiClient.parameterToMultiValueMap(null, \"regular-param\","
+ " regularParam));")
.bodyContainsLines(
"queryParams.putAll(apiClient.parameterToMultiValueMap(null, \"someString\","
+ " objectParam.getSomeString()));")
.bodyContainsLines(
"queryParams.putAll(apiClient.parameterToMultiValueMap(null, \"someBoolean\","
+ " objectParam.getSomeBoolean()));")
.bodyContainsLines(
"queryParams.putAll(apiClient.parameterToMultiValueMap(null, \"someInteger\","
+ " objectParam.getSomeInteger()));");
}

private static Map<String, File> generateFromContract(final String pathToSpecification, final String library) {
return generateFromContract(pathToSpecification, library, new HashMap<>());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ private ResponseSpec fakeHttpSignatureTestRequestCreation(Pet pet, String query1
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

queryParams.putAll(apiClient.parameterToMultiValueMap(null, "query_1", query1));


if (header1 != null)
headerParams.add("header_1", apiClient.parameterToString(header1));
Expand Down Expand Up @@ -788,7 +789,7 @@ private ResponseSpec testBodyWithQueryParamsRequestCreation(String query, User u
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

queryParams.putAll(apiClient.parameterToMultiValueMap(null, "query", query));

final String[] localVarAccepts = { };
final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
final String[] localVarContentTypes = {
Expand Down Expand Up @@ -1111,6 +1112,7 @@ private ResponseSpec testEnumParametersRequestCreation(List<String> enumHeaderSt
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "enum_query_integer", enumQueryInteger));
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "enum_query_double", enumQueryDouble));
queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("multi".toUpperCase(Locale.ROOT)), "enum_query_model_array", enumQueryModelArray));


if (enumHeaderStringArray != null)
headerParams.add("enum_header_string_array", apiClient.parameterToString(enumHeaderStringArray));
Expand Down Expand Up @@ -1234,6 +1236,7 @@ private ResponseSpec testGroupParametersRequestCreation(Integer requiredStringGr
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "required_int64_group", requiredInt64Group));
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "string_group", stringGroup));
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "int64_group", int64Group));


if (requiredBooleanGroup != null)
headerParams.add("required_boolean_group", apiClient.parameterToString(requiredBooleanGroup));
Expand Down Expand Up @@ -1643,7 +1646,7 @@ private ResponseSpec testQueryParameterCollectionFormatRequestCreation(List<Stri
queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("multi".toUpperCase(Locale.ROOT)), "context", context));
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "language", language));
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "allowEmpty", allowEmpty));

final String[] localVarAccepts = { };
final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
final String[] localVarContentTypes = { };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ private ResponseSpec deletePetRequestCreation(Long petId, String apiKey) throws
final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();


if (apiKey != null)
headerParams.add("api_key", apiClient.parameterToString(apiKey));
final String[] localVarAccepts = { };
Expand Down Expand Up @@ -225,7 +226,7 @@ private ResponseSpec findPetsByStatusRequestCreation(List<String> status) throws
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("csv".toUpperCase(Locale.ROOT)), "status", status));

final String[] localVarAccepts = {
"application/xml", "application/json"
};
Expand Down Expand Up @@ -305,7 +306,7 @@ private ResponseSpec findPetsByTagsRequestCreation(Set<String> tags) throws WebC
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("csv".toUpperCase(Locale.ROOT)), "tags", tags));

final String[] localVarAccepts = {
"application/xml", "application/json"
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ private ResponseSpec loginUserRequestCreation(String username, String password)

queryParams.putAll(apiClient.parameterToMultiValueMap(null, "username", username));
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "password", password));

final String[] localVarAccepts = {
"application/xml", "application/json"
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ private ResponseSpec fakeHttpSignatureTestRequestCreation(Pet pet, String query1
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

queryParams.putAll(apiClient.parameterToMultiValueMap(null, "query_1", query1));


if (header1 != null)
headerParams.add("header_1", apiClient.parameterToString(header1));
Expand Down Expand Up @@ -788,7 +789,7 @@ private ResponseSpec testBodyWithQueryParamsRequestCreation(String query, User u
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

queryParams.putAll(apiClient.parameterToMultiValueMap(null, "query", query));

final String[] localVarAccepts = { };
final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
final String[] localVarContentTypes = {
Expand Down Expand Up @@ -1111,6 +1112,7 @@ private ResponseSpec testEnumParametersRequestCreation(List<String> enumHeaderSt
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "enum_query_integer", enumQueryInteger));
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "enum_query_double", enumQueryDouble));
queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("multi".toUpperCase(Locale.ROOT)), "enum_query_model_array", enumQueryModelArray));


if (enumHeaderStringArray != null)
headerParams.add("enum_header_string_array", apiClient.parameterToString(enumHeaderStringArray));
Expand Down Expand Up @@ -1234,6 +1236,7 @@ private ResponseSpec testGroupParametersRequestCreation(Integer requiredStringGr
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "required_int64_group", requiredInt64Group));
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "string_group", stringGroup));
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "int64_group", int64Group));


if (requiredBooleanGroup != null)
headerParams.add("required_boolean_group", apiClient.parameterToString(requiredBooleanGroup));
Expand Down Expand Up @@ -1643,7 +1646,7 @@ private ResponseSpec testQueryParameterCollectionFormatRequestCreation(List<Stri
queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("multi".toUpperCase(Locale.ROOT)), "context", context));
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "language", language));
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "allowEmpty", allowEmpty));

final String[] localVarAccepts = { };
final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
final String[] localVarContentTypes = { };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ private ResponseSpec deletePetRequestCreation(Long petId, String apiKey) throws
final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();


if (apiKey != null)
headerParams.add("api_key", apiClient.parameterToString(apiKey));
final String[] localVarAccepts = { };
Expand Down Expand Up @@ -225,7 +226,7 @@ private ResponseSpec findPetsByStatusRequestCreation(List<String> status) throws
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("csv".toUpperCase(Locale.ROOT)), "status", status));

final String[] localVarAccepts = {
"application/xml", "application/json"
};
Expand Down Expand Up @@ -305,7 +306,7 @@ private ResponseSpec findPetsByTagsRequestCreation(Set<String> tags) throws WebC
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("csv".toUpperCase(Locale.ROOT)), "tags", tags));

final String[] localVarAccepts = {
"application/xml", "application/json"
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ private ResponseSpec loginUserRequestCreation(String username, String password)

queryParams.putAll(apiClient.parameterToMultiValueMap(null, "username", username));
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "password", password));

final String[] localVarAccepts = {
"application/xml", "application/json"
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ private ResponseSpec fakeHttpSignatureTestRequestCreation(Pet pet, String query1
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

queryParams.putAll(apiClient.parameterToMultiValueMap(null, "query_1", query1));


if (header1 != null)
headerParams.add("header_1", apiClient.parameterToString(header1));
Expand Down Expand Up @@ -788,7 +789,7 @@ private ResponseSpec testBodyWithQueryParamsRequestCreation(String query, User u
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

queryParams.putAll(apiClient.parameterToMultiValueMap(null, "query", query));

final String[] localVarAccepts = { };
final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
final String[] localVarContentTypes = {
Expand Down Expand Up @@ -1111,6 +1112,7 @@ private ResponseSpec testEnumParametersRequestCreation(List<String> enumHeaderSt
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "enum_query_integer", enumQueryInteger));
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "enum_query_double", enumQueryDouble));
queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("multi".toUpperCase(Locale.ROOT)), "enum_query_model_array", enumQueryModelArray));


if (enumHeaderStringArray != null)
headerParams.add("enum_header_string_array", apiClient.parameterToString(enumHeaderStringArray));
Expand Down Expand Up @@ -1234,6 +1236,7 @@ private ResponseSpec testGroupParametersRequestCreation(Integer requiredStringGr
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "required_int64_group", requiredInt64Group));
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "string_group", stringGroup));
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "int64_group", int64Group));


if (requiredBooleanGroup != null)
headerParams.add("required_boolean_group", apiClient.parameterToString(requiredBooleanGroup));
Expand Down Expand Up @@ -1643,7 +1646,7 @@ private ResponseSpec testQueryParameterCollectionFormatRequestCreation(List<Stri
queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("multi".toUpperCase(Locale.ROOT)), "context", context));
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "language", language));
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "allowEmpty", allowEmpty));

final String[] localVarAccepts = { };
final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
final String[] localVarContentTypes = { };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ private ResponseSpec deletePetRequestCreation(Long petId, String apiKey) throws
final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();


if (apiKey != null)
headerParams.add("api_key", apiClient.parameterToString(apiKey));
final String[] localVarAccepts = { };
Expand Down Expand Up @@ -225,7 +226,7 @@ private ResponseSpec findPetsByStatusRequestCreation(List<String> status) throws
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("csv".toUpperCase(Locale.ROOT)), "status", status));

final String[] localVarAccepts = {
"application/xml", "application/json"
};
Expand Down Expand Up @@ -305,7 +306,7 @@ private ResponseSpec findPetsByTagsRequestCreation(Set<String> tags) throws WebC
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("csv".toUpperCase(Locale.ROOT)), "tags", tags));

final String[] localVarAccepts = {
"application/xml", "application/json"
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ private ResponseSpec loginUserRequestCreation(String username, String password)

queryParams.putAll(apiClient.parameterToMultiValueMap(null, "username", username));
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "password", password));

final String[] localVarAccepts = {
"application/xml", "application/json"
};
Expand Down

0 comments on commit 3099a2f

Please sign in to comment.