0
votes

Cant expose spring integration flow apis, with swagger documentation

I have some apis exposed using spring integration. We tried document it, with springfox dependency (swagger2). But when access to: http://localhost:8080/myProject/swagger-ui.html, the page is empty, we cant see the services with swagger format

My example;

Class definition:

@Configuration
@EnableSwagger2
public class ConsultaBdnFlow {

          ....
}

Swagger configuration:

 @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
    }

Swagger Dependencies:

<!--  Start Swagger 2 with SpringFox -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.3.0</version>
</dependency>
<!-- End Swagger 2 with SpringFox -->

Flow to expose the service:

 @Bean
    public IntegrationFlow bdnBlacklistFlow() {
        return IntegrationFlows
                .from(Http.inboundGateway("/consultas/bdn")
                        .requestPayloadType(String.class)
                        .requestChannel(requestBlacklistChannel())
                        .replyChannel(replyBlacklistChannel())
                )
                .get();
    }

When run the project we can access to http://localhost:8080/swagger-ui.html, but dont see the service swagger document

1

1 Answers

0
votes

Maybe you are missing VendorExtension.

Change your Docket Bean to something like this and see what happens. Also include the errors it is giving you if it doesn't work. This worked on Swagger dependencies (2.9.2) and Spring-boot 2.2.0.M2.

@Bean
public Docket apiDocket() {

    Contact contact = new Contact(
            "You name",
            "Your webesite", 
            "Your email"
    );

    List<VendorExtension> vendorExtensions = new ArrayList<>();

    ApiInfo apiInfo = new ApiInfo(
   "RESTful API documentation", 
   "This pages documents Turing Ecommerce RESTful API endpoints", "1.0",
   "Website", contact, 
   "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0",vendorExtensions);

    Docket docket =  new Docket(DocumentationType.SWAGGER_2)
             .apiInfo(apiInfo)
             .select()
             .apis(RequestHandlerSelectors.basePackage("com.company.package"))
             .paths(PathSelectors.any())
             .build();

    return docket;

 }