swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

Feature/java play completables with play context

Open ignaciomolina opened this issue 7 years ago • 4 comments

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.sh and ./bin/security/{LANG}-petstore.sh if 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.0 branch 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

ignaciomolina avatar May 21 '18 09:05 ignaciomolina

@tzimisce012

ignaciomolina avatar May 21 '18 09:05 ignaciomolina

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.

GuillaumeMilani avatar May 24 '18 07:05 GuillaumeMilani

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());
    }

GuillaumeMilani avatar May 24 '18 07:05 GuillaumeMilani

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.

GuillaumeMilani avatar May 24 '18 07:05 GuillaumeMilani