forked from loafle/openapi-generator-original
Add basic support for collection. (#5776)
This commit is contained in:
parent
6a986975e4
commit
ccf2f2ff07
@ -41,9 +41,6 @@ public class {{classname}}Controller extends Controller {
|
||||
{{#wrapCalls}}@ApiAction{{/wrapCalls}}
|
||||
public Result {{operationId}}({{#pathParams}}{{>pathParams}}{{#hasMore}},{{/hasMore}}{{/pathParams}}) {{^handleExceptions}}{{#bodyParams}}throws IOException{{/bodyParams}}{{/handleExceptions}}{{#handleExceptions}}throws Exception{{/handleExceptions}} {
|
||||
{{#bodyParams}}
|
||||
{{#collectionFormat}}
|
||||
//TODO: Support this later
|
||||
{{/collectionFormat}}
|
||||
{{^collectionFormat}}
|
||||
JsonNode node{{paramName}} = request().body().asJson();
|
||||
{{{dataType}}} {{paramName}};
|
||||
@ -59,12 +56,12 @@ public class {{classname}}Controller extends Controller {
|
||||
{{/bodyParams}}
|
||||
{{#queryParams}}
|
||||
{{#collectionFormat}}
|
||||
//TODO: Support this later
|
||||
//List<Pair> {{paramName}}Pair = SwaggerUtils.parameterToPairs("{{collectionFormat}}", "{{paramName}}", request().getQueryString("{{baseName}}"));
|
||||
List<String> {{paramName}}List = SwaggerUtils.parametersToList("{{collectionFormat}}", "{{paramName}}", request().getQueryString("{{baseName}}"));
|
||||
{{{dataType}}} {{paramName}} = new Array{{{dataType}}}();
|
||||
//for (Pair pair : {{paramName}}Pair) {
|
||||
// {{paramName}}.add({{>conversionBegin}}pair.getValue(){{>conversionEnd}});
|
||||
//}
|
||||
for (String curParam : {{paramName}}List) {
|
||||
//noinspection UseBulkOperation
|
||||
{{paramName}}.add({{>conversionBegin}}curParam{{>conversionEnd}});
|
||||
}
|
||||
{{/collectionFormat}}
|
||||
{{^collectionFormat}}
|
||||
String value{{paramName}} = request().getQueryString("{{paramName}}");
|
||||
@ -89,15 +86,15 @@ public class {{classname}}Controller extends Controller {
|
||||
{{/notFile}}
|
||||
{{#notFile}}
|
||||
{{#collectionFormat}}
|
||||
//TODO: Support this later
|
||||
//List<Pair> {{paramName}}Pair = SwaggerUtils.parameterToPairs("{{collectionFormat}}", "{{paramName}}", ((String[]) request().body().asMultipartFormData().asFormUrlEncoded().get("{{baseName}}"))[0]);
|
||||
List<String> {{paramName}}List = SwaggerUtils.parametersToList("{{collectionFormat}}", "{{paramName}}", (request().body().asMultipartFormData().asFormUrlEncoded().get("{{baseName}}"))[0]);
|
||||
{{{dataType}}} {{paramName}} = new Array{{{dataType}}}();
|
||||
//for (Pair pair : {{paramName}}Pair) {
|
||||
// {{paramName}}.add({{>conversionBegin}}pair.getValue(){{>conversionEnd}});
|
||||
//}
|
||||
for (String curParam : {{paramName}}List) {
|
||||
//noinspection UseBulkOperation
|
||||
{{paramName}}.add({{>conversionBegin}}curParam{{>conversionEnd}});
|
||||
}
|
||||
{{/collectionFormat}}
|
||||
{{^collectionFormat}}
|
||||
String value{{paramName}} = ((String[]) request().body().asMultipartFormData().asFormUrlEncoded().get("{{baseName}}"))[0];
|
||||
String value{{paramName}} = (request().body().asMultipartFormData().asFormUrlEncoded().get("{{baseName}}"))[0];
|
||||
{{{dataType}}} {{paramName}};
|
||||
{{^required}}
|
||||
if (value{{paramName}} != null) {
|
||||
@ -112,12 +109,12 @@ public class {{classname}}Controller extends Controller {
|
||||
{{/formParams}}
|
||||
{{#headerParams}}
|
||||
{{#collectionFormat}}
|
||||
//TODO: Support this later
|
||||
//List<Pair> {{paramName}}Pair = SwaggerUtils.parameterToPairs("{{collectionFormat}}", "{{paramName}}", request().getHeader("{{baseName}}"));
|
||||
//{{{dataType}}} {{paramName}} = new Array{{{dataType}}}();
|
||||
//for (Pair pair : {{paramName}}Pair) {
|
||||
// {{paramName}}.add({{>conversionBegin}}pair.getValue(){{>conversionEnd}});
|
||||
//}
|
||||
List<String> {{paramName}}List = SwaggerUtils.parametersToList("{{collectionFormat}}", "{{paramName}}", request().getHeader("{{baseName}}"));
|
||||
{{{dataType}}} {{paramName}} = new Array{{{dataType}}}();
|
||||
for (String curParam : {{paramName}}List) {
|
||||
//noinspection UseBulkOperation
|
||||
{{paramName}}.add({{>conversionBegin}}curParam{{>conversionEnd}});
|
||||
}
|
||||
{{/collectionFormat}}
|
||||
{{^collectionFormat}}
|
||||
String value{{paramName}} = request().getHeader("{{baseName}}");
|
||||
|
@ -7,10 +7,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class SwaggerUtils {
|
||||
|
||||
@ -22,8 +19,8 @@ public class SwaggerUtils {
|
||||
}
|
||||
{{/handleExceptions}}
|
||||
|
||||
public static Map<String, String> parameterToPairs(String collectionFormat, String name, Object value){
|
||||
Map<String, String> params = new HashMap<>();
|
||||
public static List<String> parametersToList(String collectionFormat, String name, Object value){
|
||||
List<String> params = new ArrayList<>();
|
||||
|
||||
// preconditions
|
||||
if (name == null || name.isEmpty() || value == null) return params;
|
||||
@ -32,7 +29,7 @@ public class SwaggerUtils {
|
||||
if (value instanceof Collection) {
|
||||
valueCollection = (Collection) value;
|
||||
} else {
|
||||
params.put(name, parameterToString(value));
|
||||
params.add(parameterToString(value));
|
||||
return params;
|
||||
}
|
||||
|
||||
@ -46,7 +43,7 @@ public class SwaggerUtils {
|
||||
// create the params based on the collection format
|
||||
if (collectionFormat.equals("multi")) {
|
||||
for (Object item : valueCollection) {
|
||||
params.put(name, parameterToString(item));
|
||||
params.add(parameterToString(item));
|
||||
}
|
||||
|
||||
return params;
|
||||
@ -70,7 +67,7 @@ public class SwaggerUtils {
|
||||
sb.append(parameterToString(item));
|
||||
}
|
||||
|
||||
params.put(name, sb.substring(1));
|
||||
params.add(sb.substring(1));
|
||||
|
||||
return params;
|
||||
}
|
||||
|
@ -62,12 +62,12 @@ public class PetApiController extends Controller {
|
||||
|
||||
@ApiAction
|
||||
public Result findPetsByStatus() throws Exception {
|
||||
//TODO: Support this later
|
||||
//List<Pair> statusPair = SwaggerUtils.parameterToPairs("csv", "status", request().getQueryString("status"));
|
||||
List<String> statusList = SwaggerUtils.parametersToList("csv", "status", request().getQueryString("status"));
|
||||
List<String> status = new ArrayList<String>();
|
||||
//for (Pair pair : statusPair) {
|
||||
// status.add(pair.getValue());
|
||||
//}
|
||||
for (String curParam : statusList) {
|
||||
//noinspection UseBulkOperation
|
||||
status.add(curParam);
|
||||
}
|
||||
List<Pet> obj = imp.findPetsByStatus(status);
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
@ -76,12 +76,12 @@ public class PetApiController extends Controller {
|
||||
|
||||
@ApiAction
|
||||
public Result findPetsByTags() throws Exception {
|
||||
//TODO: Support this later
|
||||
//List<Pair> tagsPair = SwaggerUtils.parameterToPairs("csv", "tags", request().getQueryString("tags"));
|
||||
List<String> tagsList = SwaggerUtils.parametersToList("csv", "tags", request().getQueryString("tags"));
|
||||
List<String> tags = new ArrayList<String>();
|
||||
//for (Pair pair : tagsPair) {
|
||||
// tags.add(pair.getValue());
|
||||
//}
|
||||
for (String curParam : tagsList) {
|
||||
//noinspection UseBulkOperation
|
||||
tags.add(curParam);
|
||||
}
|
||||
List<Pet> obj = imp.findPetsByTags(tags);
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
@ -110,7 +110,7 @@ public class PetApiController extends Controller {
|
||||
|
||||
@ApiAction
|
||||
public Result updatePetWithForm(Long petId) throws Exception {
|
||||
String valuename = ((String[]) request().body().asMultipartFormData().asFormUrlEncoded().get("name"))[0];
|
||||
String valuename = (request().body().asMultipartFormData().asFormUrlEncoded().get("name"))[0];
|
||||
String name;
|
||||
if (valuename != null) {
|
||||
name = (String)valuename;
|
||||
@ -118,7 +118,7 @@ public class PetApiController extends Controller {
|
||||
} else {
|
||||
name = "";
|
||||
}
|
||||
String valuestatus = ((String[]) request().body().asMultipartFormData().asFormUrlEncoded().get("status"))[0];
|
||||
String valuestatus = (request().body().asMultipartFormData().asFormUrlEncoded().get("status"))[0];
|
||||
String status;
|
||||
if (valuestatus != null) {
|
||||
status = (String)valuestatus;
|
||||
@ -133,7 +133,7 @@ public class PetApiController extends Controller {
|
||||
|
||||
@ApiAction
|
||||
public Result uploadFile(Long petId) throws Exception {
|
||||
String valueadditionalMetadata = ((String[]) request().body().asMultipartFormData().asFormUrlEncoded().get("additionalMetadata"))[0];
|
||||
String valueadditionalMetadata = (request().body().asMultipartFormData().asFormUrlEncoded().get("additionalMetadata"))[0];
|
||||
String additionalMetadata;
|
||||
if (valueadditionalMetadata != null) {
|
||||
additionalMetadata = (String)valueadditionalMetadata;
|
||||
|
@ -7,10 +7,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class SwaggerUtils {
|
||||
|
||||
@ -20,8 +17,8 @@ public class SwaggerUtils {
|
||||
public @interface ApiAction {
|
||||
}
|
||||
|
||||
public static Map<String, String> parameterToPairs(String collectionFormat, String name, Object value){
|
||||
Map<String, String> params = new HashMap<>();
|
||||
public static List<String> parametersToList(String collectionFormat, String name, Object value){
|
||||
List<String> params = new ArrayList<>();
|
||||
|
||||
// preconditions
|
||||
if (name == null || name.isEmpty() || value == null) return params;
|
||||
@ -30,7 +27,7 @@ public class SwaggerUtils {
|
||||
if (value instanceof Collection) {
|
||||
valueCollection = (Collection) value;
|
||||
} else {
|
||||
params.put(name, parameterToString(value));
|
||||
params.add(parameterToString(value));
|
||||
return params;
|
||||
}
|
||||
|
||||
@ -44,7 +41,7 @@ public class SwaggerUtils {
|
||||
// create the params based on the collection format
|
||||
if (collectionFormat.equals("multi")) {
|
||||
for (Object item : valueCollection) {
|
||||
params.put(name, parameterToString(item));
|
||||
params.add(parameterToString(item));
|
||||
}
|
||||
|
||||
return params;
|
||||
@ -68,7 +65,7 @@ public class SwaggerUtils {
|
||||
sb.append(parameterToString(item));
|
||||
}
|
||||
|
||||
params.put(name, sb.substring(1));
|
||||
params.add(sb.substring(1));
|
||||
|
||||
return params;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user