forked from loafle/openapi-generator-original
rest-template: allow array parameters in path using collectionFormat (#2177)
* 2125: java-resttemplate: Support collection formats in pathParams * run ./bin/java-petstore-resttemplate.sh run ./bin/java-petstore-resttemplate-withxml.sh
This commit is contained in:
parent
61b6f19d74
commit
1dadd45ffe
@ -382,6 +382,28 @@ public class ApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the specified collection path parameter to a string value.
|
||||
*
|
||||
* @param collectionFormat The collection format of the parameter.
|
||||
* @param value The value of the parameter.
|
||||
* @return String representation of the parameter
|
||||
*/
|
||||
public String collectionPathParameterToString(CollectionFormat collectionFormat, Collection<? extends CharSequence> values) {
|
||||
// create the value based on the collection format
|
||||
if (CollectionFormat.MULTI.equals(collectionFormat)) {
|
||||
// not valid for path params
|
||||
return parameterToString(values);
|
||||
}
|
||||
|
||||
// collectionFormat is assumed to be "csv" by default
|
||||
if(collectionFormat == null) {
|
||||
collectionFormat = CollectionFormat.CSV;
|
||||
}
|
||||
|
||||
return collectionFormat.collectionToString(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a parameter to a {@link MultiValueMap} for use in REST requests
|
||||
* @param collectionFormat The format to convert to
|
||||
|
@ -71,7 +71,7 @@ public class {{classname}} {
|
||||
{{/required}}{{/allParams}}{{#hasPathParams}}
|
||||
// create path and map variables
|
||||
final Map<String, Object> uriVariables = new HashMap<String, Object>();{{#pathParams}}
|
||||
uriVariables.put("{{baseName}}", {{{paramName}}});{{/pathParams}}{{/hasPathParams}}
|
||||
uriVariables.put("{{baseName}}", {{#collectionFormat}}apiClient.collectionPathParameterToString(ApiClient.CollectionFormat.valueOf("{{{collectionFormat}}}".toUpperCase()), {{{paramName}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}});{{/pathParams}}{{/hasPathParams}}
|
||||
String {{localVariablePrefix}}path = UriComponentsBuilder.fromPath("{{{path}}}"){{#hasPathParams}}.buildAndExpand(uriVariables){{/hasPathParams}}{{^hasPathParams}}.build(){{/hasPathParams}}.toUriString();
|
||||
|
||||
final MultiValueMap<String, String> {{localVariablePrefix}}queryParams = new LinkedMultiValueMap<String, String>();
|
||||
|
@ -371,6 +371,28 @@ public class ApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the specified collection path parameter to a string value.
|
||||
*
|
||||
* @param collectionFormat The collection format of the parameter.
|
||||
* @param value The value of the parameter.
|
||||
* @return String representation of the parameter
|
||||
*/
|
||||
public String collectionPathParameterToString(CollectionFormat collectionFormat, Collection<? extends CharSequence> values) {
|
||||
// create the value based on the collection format
|
||||
if (CollectionFormat.MULTI.equals(collectionFormat)) {
|
||||
// not valid for path params
|
||||
return parameterToString(values);
|
||||
}
|
||||
|
||||
// collectionFormat is assumed to be "csv" by default
|
||||
if(collectionFormat == null) {
|
||||
collectionFormat = CollectionFormat.CSV;
|
||||
}
|
||||
|
||||
return collectionFormat.collectionToString(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a parameter to a {@link MultiValueMap} for use in REST requests
|
||||
* @param collectionFormat The format to convert to
|
||||
|
@ -366,6 +366,28 @@ public class ApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the specified collection path parameter to a string value.
|
||||
*
|
||||
* @param collectionFormat The collection format of the parameter.
|
||||
* @param value The value of the parameter.
|
||||
* @return String representation of the parameter
|
||||
*/
|
||||
public String collectionPathParameterToString(CollectionFormat collectionFormat, Collection<? extends CharSequence> values) {
|
||||
// create the value based on the collection format
|
||||
if (CollectionFormat.MULTI.equals(collectionFormat)) {
|
||||
// not valid for path params
|
||||
return parameterToString(values);
|
||||
}
|
||||
|
||||
// collectionFormat is assumed to be "csv" by default
|
||||
if(collectionFormat == null) {
|
||||
collectionFormat = CollectionFormat.CSV;
|
||||
}
|
||||
|
||||
return collectionFormat.collectionToString(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a parameter to a {@link MultiValueMap} for use in REST requests
|
||||
* @param collectionFormat The format to convert to
|
||||
|
Loading…
x
Reference in New Issue
Block a user