我在项目中有以上架构。产品、订单、支付微服务是Rest API,目前已经集成了Swagger,但是现在流程发生了变化,我不能暴露微服务的Rest API,现在所有的REST API调用都是从API网关进行的。
有没有办法通过API网关在swagger中文档化API,或者这种情况下的最佳实践是什么。
这是API Gateway Spring Boot 的路由配置。
在订单微服务项目中的Swagger配置
有没有办法通过API网关在swagger中文档化API,或者这种情况下的最佳实践是什么。
这是API Gateway Spring Boot 的路由配置。
@Bean
public RouteLocator gatewayRoutes(RouteLocatorBuilder builder) {
return builder.routes()
.route(r -> r.path("/order/**")
.filters(f -> f.hystrix(option -> option.setName("order-service").
setFallbackUri("forward:/orderFallBack")))
.uri("lb://ORDER-SERVICE")
.id("order-service"))
.route(r -> r.path("/payment/**")
.filters(f -> f.hystrix(option -> option.setName("payment-service")
.setFallbackUri("forward:/paymentFallBack")))
.uri("lb://PAYMENT-SERVICE")
.id("payment-service"))
.route(r -> r.path("/product/**")
.filters(f -> f.hystrix(option -> option.setName("product-service")
.setFallbackUri("forward:/productFallBack")))
.uri("lb://PRODUCT-SERVICE")
.id("product-service"))
.build();
}
在订单微服务项目中的Swagger配置
@Configuration
public class SwaggerConfiguration {
@Bean
public Docket orderApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
.paths(PathSelectors.any())
.build()
.apiInfo(getApiInfo());
}
//create api metadata that goes at the top of the generated page
private ApiInfo getApiInfo() {
return new ApiInfoBuilder()
.title("Fete Bird Order Microservice")
.version("1.0")
.description("API for managing Fete Bird Order Microservice.")
.license("Fete Bird License Version 1.0")
.build();
}
}