From ef2028e53f81702b65676e204ba66e95154a4289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20C=C3=B4t=C3=A9?= Date: Fri, 19 May 2017 10:32:19 -0400 Subject: [PATCH] [Java Play Framework] Warnings removal and default value fix (#5660) * 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 * Removal of warning (final) and fix of a missing default value for boolean query parameters --- .../newApiController.mustache | 19 ++++++------------- .../paramDefaultValue.mustache | 2 +- .../app/controllers/PetApiController.java | 12 ++++-------- .../app/controllers/StoreApiController.java | 4 ++-- .../app/controllers/UserApiController.java | 4 ++-- 5 files changed, 15 insertions(+), 26 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApiController.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApiController.mustache index 34e39b01982..8dd279077a3 100644 --- a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApiController.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApiController.mustache @@ -27,8 +27,8 @@ import swagger.SwaggerUtils.ApiAction; {{#operations}} public class {{classname}}Controller extends Controller { - private {{classname}}ControllerImp imp; - private ObjectMapper mapper; + private final {{classname}}ControllerImp imp; + private final ObjectMapper mapper; @Inject private {{classname}}Controller({{classname}}ControllerImp imp) { @@ -42,8 +42,7 @@ public class {{classname}}Controller extends Controller { public Result {{operationId}}({{#pathParams}}{{>pathParams}}{{#hasMore}},{{/hasMore}}{{/pathParams}}) {{^handleExceptions}}{{#bodyParams}}throws IOException{{/bodyParams}}{{/handleExceptions}}{{#handleExceptions}}throws Exception{{/handleExceptions}} { {{#bodyParams}} {{#collectionFormat}} - //TODO: Maybe implement this in the future if we can support collection in the body params: see bug in swagger-play: https://github.com/swagger-api/swagger-play/issues/130 - //TODO: Tt seems it is not detected that it's a list based on the collectionFormat field? + //TODO: Support this later {{/collectionFormat}} {{^collectionFormat}} JsonNode node{{paramName}} = request().body().asJson(); @@ -60,9 +59,7 @@ public class {{classname}}Controller extends Controller { {{/bodyParams}} {{#queryParams}} {{#collectionFormat}} - //TODO: Maybe implement this in the future if we can support collection in the body params: see bug in swagger-play: https://github.com/swagger-api/swagger-play/issues/130 - //TODO: Tt seems it is not detected that it's a list based on the collectionFormat field? - //WIP when both bugs will be fixed + //TODO: Support this later //List {{paramName}}Pair = SwaggerUtils.parameterToPairs("{{collectionFormat}}", "{{paramName}}", request().getQueryString("{{baseName}}")); {{{dataType}}} {{paramName}} = new Array{{{dataType}}}(); //for (Pair pair : {{paramName}}Pair) { @@ -92,9 +89,7 @@ public class {{classname}}Controller extends Controller { {{/notFile}} {{#notFile}} {{#collectionFormat}} - //TODO: Maybe implement this in the future if we can support collection in the body params: see bug in swagger-play: https://github.com/swagger-api/swagger-play/issues/130 - //TODO: Tt seems it is not detected that it's a list based on the collectionFormat field? - //WIP when both bugs will be fixed + //TODO: Support this later //List {{paramName}}Pair = SwaggerUtils.parameterToPairs("{{collectionFormat}}", "{{paramName}}", ((String[]) request().body().asMultipartFormData().asFormUrlEncoded().get("{{baseName}}"))[0]); {{{dataType}}} {{paramName}} = new Array{{{dataType}}}(); //for (Pair pair : {{paramName}}Pair) { @@ -117,9 +112,7 @@ public class {{classname}}Controller extends Controller { {{/formParams}} {{#headerParams}} {{#collectionFormat}} - //TODO: Maybe implement this in the future if we can support collection in the body params: see bug in swagger-play: https://github.com/swagger-api/swagger-play/issues/130 - //TODO: Tt seems it is not detected that it's a list based on the collectionFormat field? - //WIP when both bugs will be fixed + //TODO: Support this later //List {{paramName}}Pair = SwaggerUtils.parameterToPairs("{{collectionFormat}}", "{{paramName}}", request().getHeader("{{baseName}}")); //{{{dataType}}} {{paramName}} = new Array{{{dataType}}}(); //for (Pair pair : {{paramName}}Pair) { diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/paramDefaultValue.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/paramDefaultValue.mustache index a24853098c0..733d31a6d72 100644 --- a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/paramDefaultValue.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/paramDefaultValue.mustache @@ -1 +1 @@ -{{#isInteger}}0{{/isInteger}}{{#isDouble}}0.0{{/isDouble}}{{#isLong}}0L{{/isLong}}{{#isFloat}}0.0{{/isFloat}}{{#isString}}""{{/isString}} \ No newline at end of file +{{#isBoolean}}false{{/isBoolean}}{{#isInteger}}0{{/isInteger}}{{#isDouble}}0.0{{/isDouble}}{{#isLong}}0L{{/isLong}}{{#isFloat}}0.0{{/isFloat}}{{#isString}}""{{/isString}} \ No newline at end of file diff --git a/samples/server/petstore/java-play-framework/app/controllers/PetApiController.java b/samples/server/petstore/java-play-framework/app/controllers/PetApiController.java index 86368035356..27f3d446ff1 100644 --- a/samples/server/petstore/java-play-framework/app/controllers/PetApiController.java +++ b/samples/server/petstore/java-play-framework/app/controllers/PetApiController.java @@ -23,8 +23,8 @@ import swagger.SwaggerUtils.ApiAction; public class PetApiController extends Controller { - private PetApiControllerImp imp; - private ObjectMapper mapper; + private final PetApiControllerImp imp; + private final ObjectMapper mapper; @Inject private PetApiController(PetApiControllerImp imp) { @@ -62,9 +62,7 @@ public class PetApiController extends Controller { @ApiAction public Result findPetsByStatus() throws Exception { - //TODO: Maybe implement this in the future if we can support collection in the body params: see bug in swagger-play: https://github.com/swagger-api/swagger-play/issues/130 - //TODO: Tt seems it is not detected that it's a list based on the collectionFormat field? - //WIP when both bugs will be fixed + //TODO: Support this later //List statusPair = SwaggerUtils.parameterToPairs("csv", "status", request().getQueryString("status")); List status = new ArrayList(); //for (Pair pair : statusPair) { @@ -78,9 +76,7 @@ public class PetApiController extends Controller { @ApiAction public Result findPetsByTags() throws Exception { - //TODO: Maybe implement this in the future if we can support collection in the body params: see bug in swagger-play: https://github.com/swagger-api/swagger-play/issues/130 - //TODO: Tt seems it is not detected that it's a list based on the collectionFormat field? - //WIP when both bugs will be fixed + //TODO: Support this later //List tagsPair = SwaggerUtils.parameterToPairs("csv", "tags", request().getQueryString("tags")); List tags = new ArrayList(); //for (Pair pair : tagsPair) { diff --git a/samples/server/petstore/java-play-framework/app/controllers/StoreApiController.java b/samples/server/petstore/java-play-framework/app/controllers/StoreApiController.java index 1d0bdb3fbc6..bb8e157cf73 100644 --- a/samples/server/petstore/java-play-framework/app/controllers/StoreApiController.java +++ b/samples/server/petstore/java-play-framework/app/controllers/StoreApiController.java @@ -22,8 +22,8 @@ import swagger.SwaggerUtils.ApiAction; public class StoreApiController extends Controller { - private StoreApiControllerImp imp; - private ObjectMapper mapper; + private final StoreApiControllerImp imp; + private final ObjectMapper mapper; @Inject private StoreApiController(StoreApiControllerImp imp) { diff --git a/samples/server/petstore/java-play-framework/app/controllers/UserApiController.java b/samples/server/petstore/java-play-framework/app/controllers/UserApiController.java index bfbf7d30295..22425261cb7 100644 --- a/samples/server/petstore/java-play-framework/app/controllers/UserApiController.java +++ b/samples/server/petstore/java-play-framework/app/controllers/UserApiController.java @@ -22,8 +22,8 @@ import swagger.SwaggerUtils.ApiAction; public class UserApiController extends Controller { - private UserApiControllerImp imp; - private ObjectMapper mapper; + private final UserApiControllerImp imp; + private final ObjectMapper mapper; @Inject private UserApiController(UserApiControllerImp imp) {