I used Zuul and that solved my problem
This is how my app would be deployed

I added this in my pom.xml
<dependencies>
....
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
</dependencies>
My main class looks like this
@EnableZuulProxy
@SpringBootApplication
@EnableSwagger2
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
UiConfiguration uiConfig() {
return new UiConfiguration("validatorUrl", "list", "alpha", "schema",
UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS, false, true, 60000L);
}
}
I created the aggregator for swagger document
@Component
@Primary
@EnableAutoConfiguration
public class SwaggerAggregatorController implements SwaggerResourcesProvider {
@Override
public List<SwaggerResource> get() {
List<SwaggerResource> resources= new ArrayList<>();
SwaggerResource swaggerResource = new SwaggerResource();
swaggerResource.setName("cust-service");
swaggerResource.setLocation("/cust/v2/api-docs");
swaggerResource.setSwaggerVersion("2.0");
resources.add(swaggerResource);
return resources;
}
}
I can add more microservices in this field. (Can be improved to be read from config file)
My application.properties
looks like following
...
server.port=8001
zuul.routes.cust.path=/cust/**
zuul.routes.cust.url=http://1.1.1.2:8002/cust-service/
...
Authorizatoin: bearer: <token>
. This token will get validated on Gateway and if correct request will be passed on to particular service without auth header. How can I add this token to every request via Swagger? - Ganesh Satpute