forked from loafle/openapi-generator-original
Add File support + some fixes to Play generator (#5263)
* First commit of the Java Play Framework server generator. It is highly based on Spring so there might me a couple of things that don't make sense (like options or parameters) for the Play Framework. * Fix suggestions in the PR discussion + add .bat and .sh file as requested. * Updated Readme.md file * Remove unused mustache file + fix baseName vs paramName in all the mustache files. * Fix the compilation error when we have a body which is a list or map. Doesn't fix the problem with the annotation itself. * Fix the problem with the Http.MultipartFormData.FilePart * Return a FileInputStream when the returnType is "file" + Fix a couple of other bugs with boolean + updated sample * Return an InputStream instead of FileInputStream (except in the instantiation) * A little cleanup for the form param of type file.
This commit is contained in:
committed by
wing328
parent
aef98f464e
commit
2e46bb9b9f
@@ -1 +1 @@
|
||||
{{#isInteger}}Integer.parseInt({{/isInteger}}{{#isDouble}}Double.parseDouble({{/isDouble}}{{#isLong}}Long.parseLong({{/isLong}}{{#isFloat}}Float.parseFloat({{/isFloat}}{{#isString}}(String){{/isString}}
|
||||
{{#isBoolean}}Boolean.getBoolean({{/isBoolean}}{{#isInteger}}Integer.parseInt({{/isInteger}}{{#isDouble}}Double.parseDouble({{/isDouble}}{{#isLong}}Long.parseLong({{/isLong}}{{#isFloat}}Float.parseFloat({{/isFloat}}{{#isString}}(String){{/isString}}
|
||||
@@ -1 +1 @@
|
||||
{{#isInteger}}){{/isInteger}}{{#isDouble}}){{/isDouble}}{{#isLong}}){{/isLong}}{{#isFloat}}){{/isFloat}}{{#isString}}{{/isString}}
|
||||
{{#isBoolean}}){{/isBoolean}}{{#isInteger}}){{/isInteger}}{{#isDouble}}){{/isDouble}}{{#isLong}}){{/isLong}}{{#isFloat}}){{/isFloat}}{{#isString}}{{/isString}}
|
||||
@@ -1 +1 @@
|
||||
{{#isFormParam}}{{#notFile}}{{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}}Http.MultipartFormData.FilePart {{paramName}}{{/isFile}}{{/isFormParam}}
|
||||
{{#isFormParam}}{{{dataType}}} {{paramName}}{{/isFormParam}}
|
||||
@@ -7,6 +7,7 @@ import play.mvc.Http;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.io.FileInputStream;
|
||||
{{#useBeanValidation}}
|
||||
import javax.validation.constraints.*;
|
||||
{{/useBeanValidation}}
|
||||
@@ -14,9 +15,10 @@ import javax.validation.constraints.*;
|
||||
{{#operations}}
|
||||
public class {{classname}}ControllerImp {{#useInterfaces}}implements {{classname}}ControllerImpInterface{{/useInterfaces}} {
|
||||
{{#operation}}
|
||||
{{#useInterfaces}}@Override{{/useInterfaces}}
|
||||
public {{>returnTypes}} {{operationId}}({{#allParams}}{{>pathParams}}{{>queryParams}}{{>bodyParams}}{{>formParams}}{{>headerParams}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {{#handleExceptions}}throws Exception{{/handleExceptions}} {
|
||||
//Do your magic!!!
|
||||
{{#returnType}}return new {{>returnTypesNoVoidNoAbstract}}();{{/returnType}}
|
||||
{{#returnType}}{{#isResponseFile}}return new FileInputStream("replace this");{{/isResponseFile}}{{^isResponseFile}}return new {{>returnTypesNoVoidNoAbstract}}();{{/isResponseFile}}{{/returnType}}
|
||||
}
|
||||
|
||||
{{/operation}}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class {{classname}}Controller extends Controller {
|
||||
{{/queryParams}}
|
||||
{{#formParams}}
|
||||
{{^notFile}}
|
||||
Http.MultipartFormData.FilePart {{paramName}} = request().body().asMultipartFormData().getFile("{{baseName}}");
|
||||
{{{dataType}}} {{paramName}} = request().body().asMultipartFormData().getFile("{{baseName}}");
|
||||
{{#required}}if (({{paramName}} == null || ((File) {{paramName}}.getFile()).length() == 0)) {
|
||||
throw new RuntimeException("File cannot be empty");
|
||||
}
|
||||
@@ -140,8 +140,8 @@ public class {{classname}}Controller extends Controller {
|
||||
{{/collectionFormat}}
|
||||
{{/headerParams}}
|
||||
{{#returnType}}{{>returnTypesNoVoid}} obj = {{/returnType}}imp.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
||||
{{#returnType}}JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);{{/returnType}}
|
||||
{{#returnType}}{{^isResponseFile}}JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);{{/isResponseFile}}{{#isResponseFile}}return ok(obj);{{/isResponseFile}}{{/returnType}}
|
||||
{{^returnType}}return ok();{{/returnType}}
|
||||
}
|
||||
{{/operation}}
|
||||
|
||||
Reference in New Issue
Block a user