Skip to content

[Java][Spring] Fix template for reactive implementation with interfaceOnly parameter #2437

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

Merged
merged 1 commit into from
Apr 23, 2019
Merged

[Java][Spring] Fix template for reactive implementation with interfaceOnly parameter #2437

merged 1 commit into from
Apr 23, 2019

Conversation

logarithm
Copy link
Contributor

@logarithm logarithm commented Mar 18, 2019

PR checklist

  • Read the contribution guidelines.
  • 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, ./bin/openapi3/{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\.
  • Filed the PR against the correct branch: master, 3.4.x, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language (Java technical committee: @bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger).

Description of the PR

If for java spring-boot template generator we combine reactive and interfaceOnly properties then openapi generator generates incorrect code.

Example without fix:

default Mono<ResponseEntity<ResponseWrapper>> _methodName(@ApiParam(value = ""  )  @Valid @RequestBody Mono<RequestWrapper> requestWrapper, ServerWebExchange exchange) {
    return methodName(requestWrapper);
}

// Override this method
default Mono<ResponseEntity<ResponseWrapper>> methodName(RequestWrapper requestWrapper, ServerWebExchange exchange) {
    Mono<Void> result = Mono.empty();
    exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
    for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) {
        if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
            result = ApiUtil.getExampleResponse(exchange, "");
            break;
        }
    }
    return result.then(Mono.empty());
}

There are multiple problems:

  1. Interface method passes incorrect parameter list to delegate.
  2. First parameter type of delegate method is incorrect.

After template fix applied:

default Mono<ResponseEntity<ResponseWrapper>> _methodName(@ApiParam(value = ""  )  @Valid @RequestBody Mono<RequestWrapper> requestWrapper, ServerWebExchange exchange) {
    return methodName(requestWrapper, exchange);
}

// Override this method
default Mono<ResponseEntity<ResponseWrapper>> methodName(Mono<RequestWrapper> requestWrapper, ServerWebExchange exchange) {
    Mono<Void> result = Mono.empty();
    exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
    for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) {
        if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
            result = ApiUtil.getExampleResponse(exchange, "");
            break;
        }
    }
    return result.then(Mono.empty());
}

@logarithm
Copy link
Contributor Author

AppVeyor integration fails because it couldn't clone repo. Unfortunately, I don't have restart button. Could anyone please with permissions re-run AppVeyor build?

@wing328
Copy link
Member

wing328 commented Apr 22, 2019

@logarithm thanks for the PR. I've restarted the job. (AppVeyor CI covers C# related code)

If no one has further question/feedback on this PR, I'll merge it tomorrow (Tue)

@logarithm
Copy link
Contributor Author

@wing328 thanks a lot!

@wing328 wing328 merged commit 34e2a0b into OpenAPITools:master Apr 23, 2019
@logarithm logarithm deleted the fix-spring-reactive branch April 23, 2019 10:06
jimschubert added a commit that referenced this pull request Apr 25, 2019
* master: (40 commits)
  Remove quotation marks around {{paramName}} for header params in api-body.mustache (#2727)
  Add FiNC Technologies (#2728)
  fix missing parenthesis for http bearer auth (#2723)
  Add missing closing parenthesis (#2720)
  update perl test with correct body parameter (#2717)
  [Java][Spring] Fix template for reactive implementation with `interfaceOnly` parameter (#2437)
  Bugfix(Perl): Support nested primitive types in ARRARY or HASH for basic object (#2713)
  Remove `-XX:MaxPermSize` (#2712)
  Remove setting generateAliasAsModel in rust server generator (#2714)
  update rust server samples
  Revert "update rust samples"
  update rust samples
  update samples
  [Rust Server] Improve XML support (#2504)
  Improve CONTRIBUTING.md (#2699)
  [PHP][Lumen] Rename template folder (#2707)
  [aspnetcore] Support async tasks and some code cleanups (#2629)
  [C++][Pistache] Fixed #2643 (#2653)
  update petstore samples (#2697)
  [JAVA][Webclient]fix select body for url encoded media type. (#2686)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants