How to integrate Zuul with Swagger

I faced with some issue generating swagger documentaion in my microservices project. When I add zuul custom routings swagger documentation becames inconsistent.

Examples:

  1. RestController:
    @RestController
    public class Controller {

         @PostMapping("/foo")
         public void foo() {}    
    }
  1. Zuul routings:
zuul:
  routes:
    foo:
      path: /bar/**
      url: http://localhost:8080/foo
  1. Swagger configuration
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("my.package"))
                .build();
    }
}

So, is there any solution how can I configure swagger or zuul to avoid the problem?

Upvotes: 4

Views: 2426

Answers (1)

Yan Khonski
Yan Khonski

Reputation: 13083

We had to add zuul configuration in application.yml file.

# custom configuration - used by swagger to rename endpoints in documentation
springfox:
  documentation:
    swagger:
      v2:
        path: /api/uaa/api-docs

whitelistInternal:
  - method: GET
    path: '/api/**/api-docs'
  - method: GET
    path: '/swagger-ui.html'
  - method: GET
    path: '/swagger-resources/**'

Please, check lines that suit you.

This is an example how it can be done https://dzone.com/articles/centralized-documentation-in-microservice-spring-b

Upvotes: 1

Related Questions