Flowable and Swagger

Hi,
How come I can’t see Swagger’s controllers in swagger UI ?
I’ve created a simple spring-boot 2.0.2 app. These are the relevant parts in my pom.xml :

<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>2.0.2.RELEASE</version>
	<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
	<java.version>1.8</java.version>
	<flowable.version>6.3.1</flowable.version>		
</properties>


<dependencies>
	<!-- Spring Boot -->
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter</artifactId>
	</dependency>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-test</artifactId>
		<scope>test</scope>
	</dependency>	

           <!-- Flowable -->
	<dependency>
		<groupId>org.flowable</groupId>
		<artifactId>flowable-spring-boot-starter-rest</artifactId>					
		<version>${flowable.version}</version>
	</dependency>		

	<!-- Swagger -->		
	<dependency>
	    <groupId>io.springfox</groupId>
	    <artifactId>springfox-swagger-ui</artifactId>
	    <version>2.9.2</version>
	</dependency>
	<dependency>
	    <groupId>io.springfox</groupId>
	    <artifactId>springfox-swagger2</artifactId>
	    <version>2.9.2</version>
	</dependency>		 
</dependencies>

And I have the following class:
@EnableSwagger2
@Configuration
public class SwaggerConfig {

}

Hey,

Sorry for the late reply.

The Flowable REST API is not registered as part of the root context. Each engine registers a custom servlet with a custom configuration. Have a look at RestApiAutoConfiguration. I suppose that you somehow need to extend those configurations and hook in the swagger config.

Have you had a look at the flowable-rest application? We also have a static swagger documentation that can be used.

Cheers,
Filip

Hi,

As I know springfox will only pick the controllers that are registered components.
So you have to add
@ComponentScan(basePackages = “org.flowable.rest.service.api”)

and sample code:

@Configuration
@EnableSwagger2
@ComponentScan(basePackages = "org.flowable.rest.service.api")
public class SwaggerConfig extends WebMvcConfigurationSupport {

///process-api
@Bean
public Docket processApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .groupName("processAPI”)
            .select()
            .apis(RequestHandlerSelectors.basePackage("org.flowable.rest.service.api”))
            .paths(PathSelectors.any())
            .build()
            .pathMapping("/process-api");
}

@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("swagger-ui.html”)
            .addResourceLocations("classpath:/META-INF/resources/”);

    registry.addResourceHandler("/webjars/**")
            .addResourceLocations("classpath:/META-INF/resources/webjars/”);
}

}

The only drawback I see is that it will register Flowable REST APIs as part of the root context and also under /process-api, /app-api, etc. (all from RestApiAutoConfiguration)
But you can also exclude this autoconfiguration:
@SpringBootApplication(exclude = { RestApiAutoConfiguration.class })

I try something similar like @eran. But I use spring-boot-starter-parent in version 2.0.0.M3 and flowable 6.4.0 but I think its no difference to your configuration. I use nearly the same swagger configuration of @rgorzkowski post. But if I start my application I run into following error.
Description:
Field restResponseFactory in org.flowable.rest.service.api.history.HistoricActivityInstanceBaseResource required a bean of type ‘org.flowable.rest.service.api.RestResponseFactory’ that could not be found.
Action:
Consider defining a bean of type ‘org.flowable.rest.service.api.RestResponseFactory’ in your configuration.
For me it sounds like a problem in flowable-rest package. Or do you have a special hint for me.

Another question to @rgorzkowski. Is the extends of WebMvcConfigurationSupport necessary and what should it do.

@tanzmann - did you manage to get past this?

I’m getting the same error after configuring Swagger to scan for APIs in flowable code…
Same Spring boot with flowable-rest spring starter.

Thanks

No, but I haven’t try it again.

Thanks for the reply.
Eventually we decided to run Flowable separate from the Spring Boot, and use the REST Api to control it.

Have a great day! :slight_smile:

Here is what I did to get the swagger ui working:

package io.avalia.experiments.flowable.simpleapp.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.flowable.rest.service.api.RestResponseFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@Configuration
@EnableSwagger2
@ComponentScan(basePackages = "org.flowable.rest.service.api")

public class SwaggerDocumentationConfig {

    @Autowired
    protected ObjectMapper objectMapper;
    
    @Bean()
    public RestResponseFactory restResponseFactory() {
        RestResponseFactory restResponseFactory = new RestResponseFactory(objectMapper);
        return restResponseFactory;
    }

    ApiInfo apiInfo() {
        return new ApiInfoBuilder()
            .title("Flowable APIs")
            .build();
    }

}
3 Likes

refer to this code, it work.
think you!