Gateway整合Springdoc,Springfox
简单记录一下,后续再看看有没有更好的方式
Springfox
定义Bean,没有该Bean将会出现,在通过Gateway可以访问swagger-ui,但调用时未携带router-path导致404(定义该Bean但配置中的不同,也可能出现这问题)
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.path(PathSelectors.any())
.build()
.apiInfo(new ApiInfoBuilder()
.title("My API Documentation")
.description("API documentation for my Spring Boot application")
.version("1.0")
.build());
}
}
Springdoc
这个需要在Gateway中进行配置,这种感觉有些麻烦了,不知道有没有别的好的方式,并且gateway也需要引入springdoc依赖
通过 gateway-url/webjars/swagger-ui/index.html访问,可通过definition选项切换
spring:
cloud:
gateway:
httpclient:
ssl:
# trust all downstream certificates
useInsecureTrustManager: true
handshake-timeout: 5000ms
routes:
- id: security-service
uri:
https://localhost:8081
predicates:
- Path=/security/**
filters:
- StripPrefix=1
# 注意这部分配置
- id: openapi
uri: http://localhost:${server.port}
predicates:
- Path=/v3/api-docs/**
filters:
- RewritePath=/v3/api-docs/(?<path>.*), /$\{path}/v3/api-docs
springdoc:
swagger-ui:
urls:
# 定义了definition及url,url可经过routes中 openapi部分route到实际的server
- name: security-service
display-name: unicorn-security
url: /v3/api-docs/security
- name: gateway
display-name: remote-gateway
url: /v3/api-docs