spring-boot-starter-swagger
spring-boot-starter-swagger copied to clipboard
swagger + zuul + oauth sso集成时出现“Failed to load API definition”
根据DD的文章Spring Cloud Zuul中使用Swagger汇总API接口文档实现了在zuul的swagger-ui中查看后台服务的所有API
@Override
public List<SwaggerResource> get() {
List<String> services = discoveryClient.getServices();
List resources = new ArrayList<>();
for (String service: services
) {
resources.add(swaggerResource(service, "/" + service + "/v2/api-docs", "2.0"));
}
return resources;
}
但加入Oauth2之后,想在zuul上做单点登录,在swagger-ui中就看不到后台服务(比如user-service)的api文档了,出现了“Failed to load API definition”的问题:

思考了一下应该是/user-service/v2/api-docs这个接口需要认证,因此在SecurityConfig中添加了这个接口的过滤:
http.authorizeRequests().antMatchers(
"/v2/api-docs", "/configuration/ui", "/swagger-resources/**",
"/configuration/security", "/swagger-ui.html**", "/webjars/**",
"/user-service/v2/api-docs").permitAll()
但还是不生效,所以想知道这里应该怎么配置,zuul做SSO时,可以绕过所有服务的/v2/api-docs?

