forked from loafle/openapi-generator-original
okhttp-gson: allow array parameters in path using collectionFormat (#2137)
* okhttp-gson: allow array parameters in path using collectionFormat * run bin/java-petstore-okhttp-gson-parcelable.sh
This commit is contained in:
committed by
William Cheng
parent
8d6278bd4c
commit
534ff3607f
@@ -671,6 +671,40 @@ public class ApiClient {
|
|||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(String collectionFormat, Collection value) {
|
||||||
|
// create the value based on the collection format
|
||||||
|
if ("multi".equals(collectionFormat)) {
|
||||||
|
// not valid for path params
|
||||||
|
return parameterToString(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// collectionFormat is assumed to be "csv" by default
|
||||||
|
String delimiter = ",";
|
||||||
|
|
||||||
|
if ("ssv".equals(collectionFormat)) {
|
||||||
|
delimiter = " ";
|
||||||
|
} else if ("tsv".equals(collectionFormat)) {
|
||||||
|
delimiter = "\t";
|
||||||
|
} else if ("pipes".equals(collectionFormat)) {
|
||||||
|
delimiter = "|";
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder() ;
|
||||||
|
for (Object item : value) {
|
||||||
|
sb.append(delimiter);
|
||||||
|
sb.append(parameterToString(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.substring(delimiter.length());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sanitize filename by removing path.
|
* Sanitize filename by removing path.
|
||||||
* e.g. ../../sun.gif becomes sun.gif
|
* e.g. ../../sun.gif becomes sun.gif
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class {{classname}} {
|
|||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
String localVarPath = "{{{path}}}"{{#pathParams}}
|
String localVarPath = "{{{path}}}"{{#pathParams}}
|
||||||
.replaceAll("\\{" + "{{baseName}}" + "\\}", localVarApiClient.escapeString({{{paramName}}}.toString())){{/pathParams}};
|
.replaceAll("\\{" + "{{baseName}}" + "\\}", localVarApiClient.escapeString({{#collectionFormat}}localVarApiClient.collectionPathParameterToString("{{{collectionFormat}}}", {{{paramName}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}.toString(){{/collectionFormat}})){{/pathParams}};
|
||||||
|
|
||||||
{{javaUtilPrefix}}List<Pair> localVarQueryParams = new {{javaUtilPrefix}}ArrayList<Pair>();
|
{{javaUtilPrefix}}List<Pair> localVarQueryParams = new {{javaUtilPrefix}}ArrayList<Pair>();
|
||||||
{{javaUtilPrefix}}List<Pair> localVarCollectionQueryParams = new {{javaUtilPrefix}}ArrayList<Pair>();
|
{{javaUtilPrefix}}List<Pair> localVarCollectionQueryParams = new {{javaUtilPrefix}}ArrayList<Pair>();
|
||||||
|
|||||||
@@ -637,6 +637,40 @@ public class ApiClient {
|
|||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(String collectionFormat, Collection value) {
|
||||||
|
// create the value based on the collection format
|
||||||
|
if ("multi".equals(collectionFormat)) {
|
||||||
|
// not valid for path params
|
||||||
|
return parameterToString(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// collectionFormat is assumed to be "csv" by default
|
||||||
|
String delimiter = ",";
|
||||||
|
|
||||||
|
if ("ssv".equals(collectionFormat)) {
|
||||||
|
delimiter = " ";
|
||||||
|
} else if ("tsv".equals(collectionFormat)) {
|
||||||
|
delimiter = "\t";
|
||||||
|
} else if ("pipes".equals(collectionFormat)) {
|
||||||
|
delimiter = "|";
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder() ;
|
||||||
|
for (Object item : value) {
|
||||||
|
sb.append(delimiter);
|
||||||
|
sb.append(parameterToString(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.substring(delimiter.length());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sanitize filename by removing path.
|
* Sanitize filename by removing path.
|
||||||
* e.g. ../../sun.gif becomes sun.gif
|
* e.g. ../../sun.gif becomes sun.gif
|
||||||
|
|||||||
@@ -637,6 +637,40 @@ public class ApiClient {
|
|||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(String collectionFormat, Collection value) {
|
||||||
|
// create the value based on the collection format
|
||||||
|
if ("multi".equals(collectionFormat)) {
|
||||||
|
// not valid for path params
|
||||||
|
return parameterToString(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// collectionFormat is assumed to be "csv" by default
|
||||||
|
String delimiter = ",";
|
||||||
|
|
||||||
|
if ("ssv".equals(collectionFormat)) {
|
||||||
|
delimiter = " ";
|
||||||
|
} else if ("tsv".equals(collectionFormat)) {
|
||||||
|
delimiter = "\t";
|
||||||
|
} else if ("pipes".equals(collectionFormat)) {
|
||||||
|
delimiter = "|";
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder() ;
|
||||||
|
for (Object item : value) {
|
||||||
|
sb.append(delimiter);
|
||||||
|
sb.append(parameterToString(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.substring(delimiter.length());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sanitize filename by removing path.
|
* Sanitize filename by removing path.
|
||||||
* e.g. ../../sun.gif becomes sun.gif
|
* e.g. ../../sun.gif becomes sun.gif
|
||||||
|
|||||||
Reference in New Issue
Block a user