Feature/java play completables with play context
PR checklist
- [x] Read the contribution guidelines.
- [x] Ran the shell script under
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.shand./bin/security/{LANG}-petstore.shif updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\. - [x] Filed the PR against the correct branch:
3.0.0branch for changes related to OpenAPI spec 3.0. Default:master. - [x] Copied the technical committee to review the pull request if your PR is targeting a particular programming language.
@bbdouglas @JFCote @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @wing328
Description of the PR
- Fix missing semicolon in some controllers with async support
- Add usage of play framework HttpExecutionContext to avoid the creation of new threads from java ForkJoin
@tzimisce012
Hi @ignaciomolina and thanks for you contribution, I need this feature for my project !
I tried to generate PetShop's API code using you template, but Import for CompletionStage and CompletableFuture are missing in ControllerImp.
A return statement is also missing in some controllers :
@ApiAction
public CompletionStage<Result> uploadFile(Long petId) throws Exception {
String valueadditionalMetadata = (request().body().asMultipartFormData().asFormUrlEncoded().get("additionalMetadata"))[0];
String additionalMetadata;
if (valueadditionalMetadata != null) {
additionalMetadata = valueadditionalMetadata;
} else {
additionalMetadata = null;
}
Http.MultipartFormData.FilePart file = request().body().asMultipartFormData().getFile("file");
CompletionStage<ModelApiResponse> stage = imp.uploadFile(petId, additionalMetadata, file).thenApplyAsync(obj -> {
if (configuration.getBoolean("useOutputBeanValidation")) {
SwaggerUtils.validate(obj);
}
return obj;
}, executionContext.current());
stage.thenApplyAsync(obj -> {
JsonNode result = mapper.valueToTree(obj);
return ok(result);
}, executionContext.current());
}
Finally, ControllerImp methods are potentially throwing exception whose are not catched when calling the methods from Controller.
Sorry for spamming your PR. I'll try to find solutions as I need this feature but I'm not used to Mustache and Swagger codegen.