如何将Zuul与Swagger集成

时间:2020-03-12 14:12:52

标签: spring swagger netflix-zuul

我遇到了一些在微服务项目中生成草率文档的问题。当我添加zuul自定义路由时,草率的文档变得不一致。

示例:

  1. RestController:
    @RestController
    public class Controller {

         @PostMapping("/foo")
         public void foo() {}    
    }
  1. Zuul路由:
zuul:
  routes:
    foo:
      path: /bar/**
      url: http://localhost:8080/foo
  1. 昂扬的配置
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("my.package"))
                .build();
    }
}
  • 我需要什么:Swagger UI显示/ bar端点
  • 我得到的是:Swagger UI显示/ foo端点(这对前端开发人员来说是无用的,因为他们在运行时使用swagger生成了组件)

那么,有什么解决方案可以配置swagger或zuul来避免此问题吗?

1 个答案:

答案 0 :(得分:1)

我们必须在 application.yml 文件中添加zuul配置。

# 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/**'

请检查适合您的行。

这是一个如何完成此操作的示例 https://dzone.com/articles/centralized-documentation-in-microservice-spring-b