0

I have tried doing some poc on springfox swagger with spring boot. It does generate swagger ui on the same host and port as my application is running.

http://localhost:8080/swagger-ui.html

My application is composed of multiple microservices deployed on a cloud infrastructure. This way i may end up having multiple swagger hub ui as

http://microservice1:8080/swagger-ui.html
http://microservice2:8081/swagger-ui.html
http://microservice3:8082/swagger-ui.html

How i can host all of my springfox swagger hub application on same host. So that i can have a consolidate webpage to have all my api documentation at single place.

For spring rest doc, i could generate a single html document using asciidoctor for my microservice. Again i had different html docs for different microservices.

Is this feature available with spring rest doc? or in spring cloud where consolidate all my documents in one single web application.

vashishth
  • 2,751
  • 4
  • 38
  • 68
  • It's not clear to me if you're asking a question about consolidating Swagger's web UI in a single place or something about Spring REST Docs. Can you please clarify? – Andy Wilkinson Nov 27 '17 at 11:49
  • @AndyWilkinson I am looking for such feature. Where i can consolidate all my rest docs from different microservices at one server, I have done a poc on spring-rest where i can generate a single html document for all my api from one springboot application. My application is composed of 6 spring boot application. Please suggest if this is doable using spring rest doc. – vashishth Nov 28 '17 at 05:31
  • 1
    That's really an Asciidoctor question, rather than a Spring REST Docs question. Once REST Docs has created the snippets you can include those snippets in Asciidoctor, generate HTML, and host that HTML in pretty much any way you want. – Andy Wilkinson Nov 28 '17 at 08:32

1 Answers1

0

Create a Zuul filter concept. Create a Zuul filter service and add swagger2 dependency in your pom.xml and create a configuration class in this service as mentioned below

@EnableSwagger2
@Configuration
@Component
@Primary
public class SwaggerConfig implements SwaggerResourcesProvider {
    @Override
    public List<SwaggerResource> get() {
        List resources = new ArrayList<>();
        resources.add(swaggerResource("microservice1", "/microservice1/v2/api-docs", "2.0"));
        resources.add(swaggerResource("microservice2", "/microservice2/v2/api-docs", "2.0"));
       resources.add(swaggerResource("microservice3", "/microservice3/v2/api-docs", "2.0"));
        return resources;
    }

    private SwaggerResource swaggerResource(String name, String location, String version) {
        SwaggerResource swaggerResource = new SwaggerResource();
        swaggerResource.setName(name);
        swaggerResource.setLocation(location);
        swaggerResource.setSwaggerVersion(version);
        return swaggerResource;
    }
}

Add below mentioned configuration in the other three microservices(microservice1,microservice2,microservice3..)

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2).select()
                .apis(RequestHandlerSelectors.basePackage("com.stackoverflow.login.controller"))
                .paths(PathSelectors.regex("/.*")).build().apiInfo(apiEndPointsInfo());
    }

    private ApiInfo apiEndPointsInfo() {
        return new ApiInfoBuilder().title("Spring Boot REST API").description("Employee Management REST API")
                .contact(new Contact("stackoverflow", "www.stackoverflow.com", ""))
                .license("Apache 2.0").licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html").version("1.0.0")
                .build();
    }
}
Noyal
  • 223
  • 2
  • 7