swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.9k stars 6.03k forks source link

[Spring] support generating Spring WebFlux-based server stub #7217

Open simingweng opened 6 years ago

simingweng commented 6 years ago
Description

The feature request is to support generating a spring boot server stub based on the non-blocking Spring WebFlux framework.

Command line used for generation

add a new sub-template via -l spring --library spring-webflux

Suggest a fix/enhancement

The straightforward approach would be following the annotated controller pattern, it would mean using Mono as type of @RequestBody annotated controller method argument, as well as Mono<ResponseEntity> as return type.

The functional endpoints flavour appears to require much more effort to implement, and it could be another sub template if it really makes sense to support it.

simingweng commented 6 years ago

The feature shall have dependency on Spring Boot 2.0.0 release, which is work-in-progress, but is soon due for first release. It is needed for the WebFlux auto configuration in the generated Spring Boot project.

cbornet commented 6 years ago

Yes. A simple option should be enough, no need to pull a full library

tylerpashigian commented 6 years ago

Has there been any update on adding this option to generate a SpringBoot Reactive Server Stub using WebFlux? I saw the dependency is added to the pom.xml on the spring-boot library generation for SpringBoot 2.0.0, but I don't believe it was auto configured for WebFlux.

ikv163 commented 5 years ago

+1

naturallight commented 5 years ago

+1

batousik commented 5 years ago

Is there any progress? @simingweng

AdamPapros commented 5 years ago

+1 Is there any progress?

HugoMario commented 5 years ago

going to assign this to myself to work on it.

sbilello commented 5 years ago

@HugoMario is not it possible to generate from an api

  @ApiOperation(value = "Get Test Mono Api", nickname = "getTestData")
  @ResponseBody
  public Mono<UserTestDataResponse> getTestData(
      @RequestParam(required = false, defaultValue = "0") final Integer userId,
      @RequestParam(required = false) final Guid guidObjectJson,
      @RequestHeader HttpHeaders httpHeaders) {

    return testDataService.getData(userId, guidObjectJson);
  }

The corresponding client with mvn generate-sources?

HugoMario commented 4 years ago

@sbilello , no sure about it, i think that is something that can be customized in an own project.

btw, sorry for so late reply :/

davide1995 commented 4 years ago

Any update?

lvohra commented 3 years ago

any update on this?

davide1995 commented 3 years ago

any update on this?

Well, I don't use swagger but I changed to the openapi code gen library to do that

Macadoshis commented 2 years ago

@HugoMario is not it possible to generate from an api

  @ApiOperation(value = "Get Test Mono Api", nickname = "getTestData")
  @ResponseBody
  public Mono<UserTestDataResponse> getTestData(
      @RequestParam(required = false, defaultValue = "0") final Integer userId,
      @RequestParam(required = false) final Guid guidObjectJson,
      @RequestHeader HttpHeaders httpHeaders) {

    return testDataService.getData(userId, guidObjectJson);
  }

The corresponding client with mvn generate-sources?

I tried something like this and it did the work, but it's clumsy.

<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.29</version>
<configuration>
    <language>spring</language>
    <library>spring-mvc</library>
    <generateSupportingFiles>false</generateSupportingFiles>
    <generateApis>false</generateApis>
    <generateApiTests>false</generateApiTests>
    <generateModelTests>false</generateModelTests>
    <generateModels>true</generateModels>
    <generateModelDocumentation>true</generateModelDocumentation>
    <generateApiDocumentation>true</generateApiDocumentation>
    <detail>true</detail>
    <additionalProperties>
        <skipDefaultInterface>true</skipDefaultInterface>
    </additionalProperties>
    <configOptions>
        <dateLibrary>java8</dateLibrary>
        <interfaceOnly>true</interfaceOnly>
        <defaultInterfaces>false</defaultInterfaces>
        <reactive>true</reactive>
        <delegatePattern>true</delegatePattern>
        <responseWrapper>reactor.core.publisher.Mono</responseWrapper>
    </configOptions>
</configuration>
Latsode commented 2 years ago

any update on this?

Well, I don't use swagger but I changed to the openapi code gen library to do that

Hey , I am trying to generate spring-webflux server stub , could you explain how you did that using openapi code gen library. Thank you !

Latsode commented 2 years ago

@HugoMario is not it possible to generate from an api

  @ApiOperation(value = "Get Test Mono Api", nickname = "getTestData")
  @ResponseBody
  public Mono<UserTestDataResponse> getTestData(
      @RequestParam(required = false, defaultValue = "0") final Integer userId,
      @RequestParam(required = false) final Guid guidObjectJson,
      @RequestHeader HttpHeaders httpHeaders) {

    return testDataService.getData(userId, guidObjectJson);
  }

The corresponding client with mvn generate-sources?

I tried something like this and it did the work, but it's clumsy.

<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.29</version>
<configuration>
    <language>spring</language>
    <library>spring-mvc</library>
    <generateSupportingFiles>false</generateSupportingFiles>
    <generateApis>false</generateApis>
    <generateApiTests>false</generateApiTests>
    <generateModelTests>false</generateModelTests>
    <generateModels>true</generateModels>
    <generateModelDocumentation>true</generateModelDocumentation>
    <generateApiDocumentation>true</generateApiDocumentation>
    <detail>true</detail>
    <additionalProperties>
        <skipDefaultInterface>true</skipDefaultInterface>
    </additionalProperties>
    <configOptions>
        <dateLibrary>java8</dateLibrary>
        <interfaceOnly>true</interfaceOnly>
        <defaultInterfaces>false</defaultInterfaces>
        <reactive>true</reactive>
        <delegatePattern>true</delegatePattern>
        <responseWrapper>reactor.core.publisher.Mono</responseWrapper>
    </configOptions>
</configuration>

Hello, do you mind sharing the steps to make this work , I cant even figure out where to put that code . Thank you !

Macadoshis commented 2 years ago

@Latsode my snippet was for maven generation. Normally everything supported by the command line is supported by maven (the opposite is not guaranteed).

For command line client, there should be an equivalent like : --responseWrapper reactor.core.publisher.Mono.

See https://openapi-generator.tech/docs/generators/spring/#config-options for complete list