I'm implementing OpenAPI documentation in a Spring Cloud Gateway service that routes to multiple microservices. I've configured the gateway to aggregate Swagger documentation from different services using GroupedOpenApi.
My configuration includes:
- Spring Cloud Gateway
- springdoc-openapi
- Multiple downstream services with their own Swagger documentation
Current Implementation :
@OpenAPIDefinition
@Configuration
public class OpenAPIConfig {
@Bean
public List<GroupedOpenApi> apis() {
List<GroupedOpenApi> groups = new ArrayList<>();
gatewayProperties.getRoutes().forEach(route -> {
String name = route.getId();
GroupedOpenApi api = GroupedOpenApi.builder()
.group(name)
.pathsToMatch("/" + name + "/**")
.build();
groups.add(api);
});
return groups;
}
}
Configuration (application.yml) :
springdoc:
api-docs:
enabled: true
path: /v3/api-docs
swagger-ui:
enabled: true
config-url: /v3/api-docs/swagger-config
urls:
- name: auth-service
url: /auth-service/v3/api-docs
- name: multi-tenant-manager-service
url: /multi-tenant-manager-service/v3/api-docs
I have the Task Manager Service which is the only service user openapi.yml in resouces/static (and it renders fine in this service)
The issue I get:
Unable to render this definition
The provided definition does not specify a valid version field.
Please indicate a valid Swagger or OpenAPI version field. Supported version fields are swagger: "2.0" and those that match openapi: 3.x.y (for example, openapi: 3.1.0).
What I've Tried :
- Added ByteArrayHttpMessageConverter with supported media types
- Configured proper CORS settings
- Ensured all services' Swagger endpoints are accessible Question : How can I properly configure the OpenAPI/Swagger UI in Spring Cloud Gateway to aggregate and display documentation from multiple microservices? Are there any specific configurations or dependencies I'm missing?
This question format provides clear context, shows what you've attempted, and asks a specific question that others can help answer.
I was expecting the swagger ui to render as it did in the task manager service.