GarlicBread
3 years agoNew Member
Add multiple Swagger definitions To Spring Cloud Gateway
I'm trying to add definitions from multiple microservices into my gateway.
This is what I've done:
public class SwaggerResourcesProviderImpl implements SwaggerResourcesProvider {
@Override
public List<SwaggerResource> get() {
List<SwaggerResource> resources = new ArrayList<>();
resources.add(swaggerResource("server-one", "/server-one/v2/api-docs", "0.0.1"));
resources.add(swaggerResource("server-two", "/server-two/v2/api-docs", "0.0.1"));
}
private SwaggerResource swaggerResource(String name, String location, String version) {
SwaggerResource swaggerResource = new SwaggerResource();
swaggerResource.setName(name);
swaggerResource.setLocation(location);
swaggerResource.setSwaggerVersion(version);
return swaggerResource;
}
}
Note:
- Server-one and Server-two is registered with Eureka, the routes above points to their respective servers.
- I can access the api-docs of the microservices directly (eg: http://{microservice-one-url}/v2/api-docs)
- I can access other apis of the microservices through the gateway but not the api-docs
Swagger version:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
Thanks in advance for any help.