I have the below architecture, where I am using the spring API gateway to forward the request to the micronaut gcp function.
The product service which is a micronaut gcp function application expose the API doc in below URL
http://localhost:8081/swagger/product-0.0.yml // product micro-service
http://localhost:8082/swagger/payment-0.0.yml // order micro-service
http://localhost:8083/swagger/order-0.0.yml // payment micro-service
The api-gateway, is a spring application with the below dependency
dependencies {
implementation("org.springframework.cloud:spring-cloud-starter-gateway")
implementation("org.springdoc:springdoc-openapi-starter-webflux-ui:2.5.0")
}
I have the below configuration in the yml
spring:
application:
name: apigateway
cloud:
gateway:
routes:
- id: product-service
uri:
${PRODUCT_SERVICE_URL:http://localhost:8081}
predicates:
- Path=/product/**, /swagger/**
- id: order-service
uri:
${ORDER_SERVICE_URL:http://localhost:8082}
predicates:
- Path=/order/**, /swagger/**
And a Bean configuration as
@Configuration
public class SwaggerConfig {
@Bean
public Set<SwaggerUrl> openApiGroups(
RouteDefinitionLocator locator,
SwaggerUiConfigParameters swaggerUiParameters) {
Set<SwaggerUrl> urls = new HashSet<>();
List<RouteDefinition> definitions = locator.getRouteDefinitions().collectList().block();
Objects.requireNonNull(definitions).stream().filter(routeDefinition -> routeDefinition.getId().matches(".*-service"))
.forEach(routeDefinition -> {
String name = routeDefinition.getId().replaceAll("-service", "");
SwaggerUrl swaggerUrl = new SwaggerUrl(name, String.format("/swagger/%s-0.0.yml",name), null);
urls.add(swaggerUrl);
});
swaggerUiParameters.setUrls(urls);
return urls;
}
}
The swagger-ui in the api-gateway is loaded, but the reference API is loaded. I am not using any discovery service, since it is a serverless application. They will be hosted as GCP function.