'How to use OpenApi annotations in spring-webflux RouterFunction endpoints?

I am currently working on a project where I use spring functional web programming. I usually use annotations of swagger 2 in restController but with functional web programming I can not find where ! The place to tell the app to do a search for endpoints (like basepackage in Docket) and load swagger in an html page. Here is my code:

@Configuration
public class RouterClient{

@Bean
public RouterFunction<ServerResponse> routes(ClientHandler client){
  return route(GET("/api/client"), client::findAll)
      .andRoute(POST("/api/client"),client::add);
  }
}

Config Class:

@Configuration
public class OpenApiConfiguration{

  @Bean
    public GroupedOpenApi groupOpenApi() {
        String paths[] = {"/api/**"};
        String packagesToscan[] = {"com.demo.client"};
        return GroupedOpenApi.builder().setGroup("groups").pathsToMatch(paths).packagesToScan(packagesToscan)
                .build();
    }

}

The dependencies:

    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-webflux-core</artifactId>
        <version>1.2.32</version>
    </dependency>
    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-webflux-ui</artifactId>
        <version>1.2.32</version>
    </dependency>

The result :

enter image description here



Solution 1:[1]

set

springdoc.api-docs.enabled=false

This will skip classpath scanning (springfox) for the API annotations. (OAS3 replaced these in v3) and replace them with reading in the spec file (json/yaml).

Put the documentation in the Spec files, as one can generate any number of clients from these. Easiest way to start with legacy code is to copy the /api-docs/ files generated by springfox.

You can go to editor.swagger.io, load in the version 2 yaml and convert it to version 3 if springfox still doesn't do that. Then work with yaml files. (it's a contract UP-Front specification for a reason)

Solution 2:[2]

https://springdoc.org/ You need springdoc-openapi-webflux-ui and @RouterOperation.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tyler2P
Solution 2 Artur