Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Play Framework] Update Play Framework Generator to latest version #7860

Merged
merged 6 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,13 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o

for (CodegenParameter param : operation.allParams) {
if (param.isFormParam && param.isFile) {
param.dataType = "Http.MultipartFormData.FilePart";
param.dataType = "Http.MultipartFormData.FilePart<TemporaryFile>";
}
}

for (CodegenParameter param : operation.formParams) {
if (param.isFile) {
param.dataType = "Http.MultipartFormData.FilePart";
param.dataType = "Http.MultipartFormData.FilePart<TemporaryFile>";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public class ApiCall extends Action<OpenAPIUtils.ApiAction> {
@Inject
private ApiCall() {}

public CompletionStage<Result> call(Http.Context ctx) {
public CompletionStage<Result> call(Http.Request request) {
try {
//TODO: Do stuff you want to handle with each API call (metrics, logging, etc..)
return delegate.call(ctx);
return delegate.call(request);
} catch (Throwable t) {
//TODO: log the error in your metric

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.io.FileInputStream;
import play.api.libs.Files.TemporaryFile;
{{#supportAsync}}
import java.util.concurrent.CompletionStage;
import java.util.concurrent.CompletableFuture;
Expand All @@ -18,7 +19,7 @@ import javax.validation.constraints.*;
{{/useBeanValidation}}
{{>generatedAnnotation}}
{{#operations}}
public class {{classname}}ControllerImp {{#useInterfaces}}implements {{classname}}ControllerImpInterface{{/useInterfaces}} {
public class {{classname}}ControllerImp {{#useInterfaces}}extends {{classname}}ControllerImpInterface{{/useInterfaces}} {
{{#operation}}
{{#useInterfaces}}@Override{{/useInterfaces}}
public {{^returnType}}void{{/returnType}}{{#returnType}}{{#supportAsync}}CompletionStage<{{/supportAsync}}{{>returnTypesNoVoid}}{{#supportAsync}}>{{/supportAsync}}{{/returnType}} {{operationId}}(Http.Request request{{#hasParams}}, {{/hasParams}}{{#allParams}}{{>pathParams}}{{>queryParams}}{{>bodyParams}}{{>formParams}}{{>headerParams}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {{#handleExceptions}}throws Exception{{/handleExceptions}} {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.inject.Inject;
import java.io.File;
import play.api.libs.Files.TemporaryFile;
{{^handleExceptions}}
import java.io.IOException;
{{/handleExceptions}}
Expand All @@ -38,7 +39,6 @@ import openapitools.OpenAPIUtils.ApiAction;
{{>generatedAnnotation}}
{{#operations}}
public class {{classname}}Controller extends Controller {

{{^controllerOnly}}
private final {{classname}}ControllerImp{{#useInterfaces}}Interface{{/useInterfaces}} imp;
{{/controllerOnly}}
Expand All @@ -59,7 +59,6 @@ public class {{classname}}Controller extends Controller {
}

{{#operation}}

{{#wrapCalls}}@ApiAction{{/wrapCalls}}
public {{#supportAsync}}CompletionStage<{{/supportAsync}}Result{{#supportAsync}}>{{/supportAsync}} {{operationId}}(Http.Request request{{#hasPathParams}}, {{/hasPathParams}}{{#pathParams}}{{>pathParams}}{{#hasMore}},{{/hasMore}}{{/pathParams}}) {{^handleExceptions}}{{#bodyParams}}throws IOException{{/bodyParams}}{{/handleExceptions}}{{#handleExceptions}}throws Exception{{/handleExceptions}} {
{{#bodyParams}}
Expand Down Expand Up @@ -129,9 +128,10 @@ public class {{classname}}Controller extends Controller {
{{/queryParams}}
{{#formParams}}
{{#isFile}}
{{{dataType}}} {{paramName}} = request.body().asMultipartFormData().getFile("{{baseName}}");
Http.MultipartFormData<TemporaryFile> body{{paramName}} = request.body().asMultipartFormData();
{{{dataType}}} {{paramName}} = body{{paramName}}.getFile("{{baseName}}");
{{#required}}
if (({{paramName}} == null || ((File) {{paramName}}.getFile()).length() == 0)) {
if (({{paramName}} == null || {{paramName}}.getFileSize() == 0)) {
throw new IllegalArgumentException("'{{baseName}}' file cannot be empty");
}
{{/required}}
Expand Down Expand Up @@ -201,82 +201,24 @@ public class {{classname}}Controller extends Controller {
}
{{/collectionFormat}}
{{/headerParams}}
{{#useInterfaces}}
{{#controllerOnly}}
return ok();
{{/controllerOnly}}
{{^controllerOnly}}
{{^returnType}}
{{#supportAsync}}
return CompletableFuture.supplyAsync(() -> {
return imp.{{operationId}}Http(request{{#hasParams}}, {{/hasParams}}{{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
{{/supportAsync}}
{{/returnType}}
{{#returnType}}{{#supportAsync}}CompletionStage<{{>returnTypesNoVoid}}> stage = {{/supportAsync}}{{^supportAsync}}{{>returnTypesNoVoid}} obj = {{/supportAsync}}{{/returnType}}{{^returnType}}{{#supportAsync}} {{/supportAsync}}{{/returnType}}imp.{{operationId}}(request{{#hasParams}}, {{/hasParams}}{{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}){{#returnType}}{{#supportAsync}}.thenApply(obj -> { {{/supportAsync}}{{/returnType}}{{^supportAsync}};{{/supportAsync}}{{#supportAsync}}{{^returnType}};{{/returnType}}{{/supportAsync}}
{{#returnType}}
{{^isResponseFile}}
{{^returnTypeIsPrimitive}}
{{#useBeanValidation}}
{{^supportAsync}}
if (configuration.getBoolean("useOutputBeanValidation")) {
{{#isArray}}
for ({{{returnType}}} curItem : obj) {
OpenAPIUtils.validate(curItem);
}
{{/isArray}}
{{#isMap}}
for (Map.Entry<String, {{{returnType}}}> entry : obj.entrySet()) {
OpenAPIUtils.validate(entry.getValue());
}
{{/isMap}}
{{^returnContainer}}
OpenAPIUtils.validate(obj);
{{/returnContainer}}
}
{{/supportAsync}}
{{#supportAsync}}
if (configuration.getBoolean("useOutputBeanValidation")) {
{{#isArray}}
for ({{{returnType}}} curItem : obj) {
OpenAPIUtils.validate(curItem);
}
{{/isArray}}
{{#isMap}}
for (Map.Entry<String, {{{returnType}}}> entry : obj.entrySet()) {
OpenAPIUtils.validate(entry.getValue());
}
{{/isMap}}
{{^returnContainer}}
OpenAPIUtils.validate(obj);
{{/returnContainer}}
}
{{/supportAsync}}
{{/useBeanValidation}}
{{/returnTypeIsPrimitive}}
{{/isResponseFile}}
{{#supportAsync}}
return obj;
});
{{/supportAsync}}
{{/returnType}}
{{#returnType}}
{{#supportAsync}}
stage.thenApply(obj -> {
{{/supportAsync}}
{{^isResponseFile}}
{{#supportAsync}} {{/supportAsync}}JsonNode result = mapper.valueToTree(obj);
{{#supportAsync}} {{/supportAsync}}return ok(result);
{{/isResponseFile}}
{{#isResponseFile}}
{{#supportAsync}} {{/supportAsync}}return ok(obj);
{{/isResponseFile}}
{{/returnType}}
{{^returnType}}
{{#supportAsync}} {{/supportAsync}}return ok();
{{/returnType}}
{{#supportAsync}}
});
return imp.{{operationId}}Http(request{{#hasParams}}, {{/hasParams}}{{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
{{/supportAsync}}
{{/controllerOnly}}
{{#controllerOnly}}
return ok();
{{/controllerOnly}}
{{/useInterfaces}}
{{^useInterfaces}}
{{>responseToResult}}
{{/useInterfaces}}
}

{{/operation}}
}
{{/operations}}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@ package {{package}};
{{#imports}}import {{import}};
{{/imports}}

import com.google.inject.Inject;
import com.typesafe.config.Config;
import play.mvc.Controller;
import play.mvc.Http;
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import play.mvc.Result;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.JsonNode;
import openapitools.OpenAPIUtils;
import static play.mvc.Results.ok;
import play.api.libs.Files.TemporaryFile;
{{#supportAsync}}
import java.util.concurrent.CompletionStage;
import java.util.concurrent.CompletableFuture;
Expand All @@ -18,9 +27,18 @@ import javax.validation.constraints.*;

{{#operations}}
@SuppressWarnings("RedundantThrows")
public interface {{classname}}ControllerImpInterface {
public abstract class {{classname}}ControllerImpInterface {
{{#useBeanValidation}}
@Inject private Config configuration;
{{/useBeanValidation}}
private ObjectMapper mapper = new ObjectMapper();

{{#operation}}
{{^returnType}}void{{/returnType}}{{#returnType}}{{#supportAsync}}CompletionStage<{{/supportAsync}}{{>returnTypesNoVoid}}{{#supportAsync}}>{{/supportAsync}}{{/returnType}} {{operationId}}(Http.Request request{{#hasParams}}, {{/hasParams}}{{#allParams}}{{>pathParams}}{{>queryParams}}{{>bodyParams}}{{>formParams}}{{>headerParams}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {{#handleExceptions}}throws Exception{{/handleExceptions}};
public {{#supportAsync}}CompletionStage<{{/supportAsync}}Result{{#supportAsync}}>{{/supportAsync}} {{operationId}}Http(Http.Request request{{#hasParams}}, {{/hasParams}}{{#allParams}}{{>pathParams}}{{>queryParams}}{{>bodyParams}}{{>formParams}}{{>headerParams}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {{#handleExceptions}}throws Exception{{/handleExceptions}} {
{{>responseToResult}}
}

public abstract {{^returnType}}void{{/returnType}}{{#returnType}}{{#supportAsync}}CompletionStage<{{/supportAsync}}{{>returnTypesNoVoid}}{{#supportAsync}}>{{/supportAsync}}{{/returnType}} {{operationId}}(Http.Request request{{#hasParams}}, {{/hasParams}}{{#allParams}}{{>pathParams}}{{>queryParams}}{{>bodyParams}}{{>formParams}}{{>headerParams}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {{#handleExceptions}}throws Exception{{/handleExceptions}};

{{/operation}}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.7.5")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.3")
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{{^controllerOnly}}
{{^returnType}}
{{#supportAsync}}
return CompletableFuture.supplyAsync(() -> {
{{/supportAsync}}
{{/returnType}}
{{#returnType}}{{#supportAsync}}CompletionStage<{{>returnTypesNoVoid}}> stage = {{/supportAsync}}{{^supportAsync}}{{>returnTypesNoVoid}} obj = {{/supportAsync}}{{/returnType}}{{^returnType}}{{#supportAsync}} {{/supportAsync}}{{/returnType}}{{^useInterfaces}}imp.{{/useInterfaces}}{{operationId}}(request{{#hasParams}}, {{/hasParams}}{{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}){{#returnType}}{{#supportAsync}}.thenApply(obj -> { {{/supportAsync}}{{/returnType}}{{^supportAsync}};{{/supportAsync}}{{#supportAsync}}{{^returnType}};{{/returnType}}{{/supportAsync}}
{{#returnType}}
{{^isResponseFile}}
{{^returnTypeIsPrimitive}}
{{#useBeanValidation}}
{{^supportAsync}}
if (configuration.getBoolean("useOutputBeanValidation")) {
{{#isArray}}
for ({{{returnType}}} curItem : obj) {
OpenAPIUtils.validate(curItem);
}
{{/isArray}}
{{#isMap}}
for (Map.Entry<String, {{{returnType}}}> entry : obj.entrySet()) {
OpenAPIUtils.validate(entry.getValue());
}
{{/isMap}}
{{^returnContainer}}
OpenAPIUtils.validate(obj);
{{/returnContainer}}
}
{{/supportAsync}}
{{#supportAsync}}
if (configuration.getBoolean("useOutputBeanValidation")) {
{{#isArray}}
for ({{{returnType}}} curItem : obj) {
OpenAPIUtils.validate(curItem);
}
{{/isArray}}
{{#isMap}}
for (Map.Entry<String, {{{returnType}}}> entry : obj.entrySet()) {
OpenAPIUtils.validate(entry.getValue());
}
{{/isMap}}
{{^returnContainer}}
OpenAPIUtils.validate(obj);
{{/returnContainer}}
}
{{/supportAsync}}
{{/useBeanValidation}}
{{/returnTypeIsPrimitive}}
{{/isResponseFile}}
{{#supportAsync}}
return obj;
});
{{/supportAsync}}
{{/returnType}}
{{#returnType}}
{{#supportAsync}}
stage.thenApply(obj -> {
{{/supportAsync}}
{{^isResponseFile}}
{{#supportAsync}} {{/supportAsync}}JsonNode result = mapper.valueToTree(obj);
{{#supportAsync}} {{/supportAsync}}return ok(result);
{{/isResponseFile}}
{{#isResponseFile}}
{{#supportAsync}} {{/supportAsync}}return ok(obj);
{{/isResponseFile}}
{{/returnType}}
{{^returnType}}
{{#supportAsync}} {{/supportAsync}}return ok();
{{/returnType}}
{{#supportAsync}}
});
{{/supportAsync}}
{{/controllerOnly}}
{{#controllerOnly}}
return ok();
{{/controllerOnly}}
Loading