Skip to content

Commit ef2028e

Browse files
JFCotewing328
authored andcommitted
[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
1 parent ad0838f commit ef2028e

File tree

5 files changed

+15
-26
lines changed

5 files changed

+15
-26
lines changed

modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApiController.mustache

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import swagger.SwaggerUtils.ApiAction;
2727
{{#operations}}
2828
public class {{classname}}Controller extends Controller {
2929
30-
private {{classname}}ControllerImp imp;
31-
private ObjectMapper mapper;
30+
private final {{classname}}ControllerImp imp;
31+
private final ObjectMapper mapper;
3232

3333
@Inject
3434
private {{classname}}Controller({{classname}}ControllerImp imp) {
@@ -42,8 +42,7 @@ public class {{classname}}Controller extends Controller {
4242
public Result {{operationId}}({{#pathParams}}{{>pathParams}}{{#hasMore}},{{/hasMore}}{{/pathParams}}) {{^handleExceptions}}{{#bodyParams}}throws IOException{{/bodyParams}}{{/handleExceptions}}{{#handleExceptions}}throws Exception{{/handleExceptions}} {
4343
{{#bodyParams}}
4444
{{#collectionFormat}}
45-
//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
46-
//TODO: Tt seems it is not detected that it's a list based on the collectionFormat field?
45+
//TODO: Support this later
4746
{{/collectionFormat}}
4847
{{^collectionFormat}}
4948
JsonNode node{{paramName}} = request().body().asJson();
@@ -60,9 +59,7 @@ public class {{classname}}Controller extends Controller {
6059
{{/bodyParams}}
6160
{{#queryParams}}
6261
{{#collectionFormat}}
63-
//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
64-
//TODO: Tt seems it is not detected that it's a list based on the collectionFormat field?
65-
//WIP when both bugs will be fixed
62+
//TODO: Support this later
6663
//List<Pair> {{paramName}}Pair = SwaggerUtils.parameterToPairs("{{collectionFormat}}", "{{paramName}}", request().getQueryString("{{baseName}}"));
6764
{{{dataType}}} {{paramName}} = new Array{{{dataType}}}();
6865
//for (Pair pair : {{paramName}}Pair) {
@@ -92,9 +89,7 @@ public class {{classname}}Controller extends Controller {
9289
{{/notFile}}
9390
{{#notFile}}
9491
{{#collectionFormat}}
95-
//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
96-
//TODO: Tt seems it is not detected that it's a list based on the collectionFormat field?
97-
//WIP when both bugs will be fixed
92+
//TODO: Support this later
9893
//List<Pair> {{paramName}}Pair = SwaggerUtils.parameterToPairs("{{collectionFormat}}", "{{paramName}}", ((String[]) request().body().asMultipartFormData().asFormUrlEncoded().get("{{baseName}}"))[0]);
9994
{{{dataType}}} {{paramName}} = new Array{{{dataType}}}();
10095
//for (Pair pair : {{paramName}}Pair) {
@@ -117,9 +112,7 @@ public class {{classname}}Controller extends Controller {
117112
{{/formParams}}
118113
{{#headerParams}}
119114
{{#collectionFormat}}
120-
//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
121-
//TODO: Tt seems it is not detected that it's a list based on the collectionFormat field?
122-
//WIP when both bugs will be fixed
115+
//TODO: Support this later
123116
//List<Pair> {{paramName}}Pair = SwaggerUtils.parameterToPairs("{{collectionFormat}}", "{{paramName}}", request().getHeader("{{baseName}}"));
124117
//{{{dataType}}} {{paramName}} = new Array{{{dataType}}}();
125118
//for (Pair pair : {{paramName}}Pair) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{#isInteger}}0{{/isInteger}}{{#isDouble}}0.0{{/isDouble}}{{#isLong}}0L{{/isLong}}{{#isFloat}}0.0{{/isFloat}}{{#isString}}""{{/isString}}
1+
{{#isBoolean}}false{{/isBoolean}}{{#isInteger}}0{{/isInteger}}{{#isDouble}}0.0{{/isDouble}}{{#isLong}}0L{{/isLong}}{{#isFloat}}0.0{{/isFloat}}{{#isString}}""{{/isString}}

samples/server/petstore/java-play-framework/app/controllers/PetApiController.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
public class PetApiController extends Controller {
2525

26-
private PetApiControllerImp imp;
27-
private ObjectMapper mapper;
26+
private final PetApiControllerImp imp;
27+
private final ObjectMapper mapper;
2828

2929
@Inject
3030
private PetApiController(PetApiControllerImp imp) {
@@ -62,9 +62,7 @@ public Result deletePet(Long petId) throws Exception {
6262

6363
@ApiAction
6464
public Result findPetsByStatus() throws Exception {
65-
//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
66-
//TODO: Tt seems it is not detected that it's a list based on the collectionFormat field?
67-
//WIP when both bugs will be fixed
65+
//TODO: Support this later
6866
//List<Pair> statusPair = SwaggerUtils.parameterToPairs("csv", "status", request().getQueryString("status"));
6967
List<String> status = new ArrayList<String>();
7068
//for (Pair pair : statusPair) {
@@ -78,9 +76,7 @@ public Result findPetsByStatus() throws Exception {
7876

7977
@ApiAction
8078
public Result findPetsByTags() throws Exception {
81-
//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
82-
//TODO: Tt seems it is not detected that it's a list based on the collectionFormat field?
83-
//WIP when both bugs will be fixed
79+
//TODO: Support this later
8480
//List<Pair> tagsPair = SwaggerUtils.parameterToPairs("csv", "tags", request().getQueryString("tags"));
8581
List<String> tags = new ArrayList<String>();
8682
//for (Pair pair : tagsPair) {

samples/server/petstore/java-play-framework/app/controllers/StoreApiController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
public class StoreApiController extends Controller {
2424

25-
private StoreApiControllerImp imp;
26-
private ObjectMapper mapper;
25+
private final StoreApiControllerImp imp;
26+
private final ObjectMapper mapper;
2727

2828
@Inject
2929
private StoreApiController(StoreApiControllerImp imp) {

samples/server/petstore/java-play-framework/app/controllers/UserApiController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
public class UserApiController extends Controller {
2424

25-
private UserApiControllerImp imp;
26-
private ObjectMapper mapper;
25+
private final UserApiControllerImp imp;
26+
private final ObjectMapper mapper;
2727

2828
@Inject
2929
private UserApiController(UserApiControllerImp imp) {

0 commit comments

Comments
 (0)