我遇到了一些在微服务项目中生成草率文档的问题。当我添加zuul自定义路由时,草率的文档变得不一致。
示例:
@RestController public class Controller { @PostMapping("/foo") public void foo() {} }
zuul: routes: foo: path: /bar/** url: http://localhost:8080/foo
@Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage("my.package")) .build(); } }
那么,有什么解决方案可以配置swagger或zuul来避免此问题吗?
答案 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