0

I have a requirement that microservice should have for swagger-ui, and Swagger UI documentation is independent of the code/server because there are many microservices and I would like to have all them documented in the same place and should run in a different server. Any one tried this, please help me on this.

  • Possibly related: [Swagger UI with Multiple Urls](https://stackoverflow.com/q/44816594/113116), [How to organise/build a Swagger UI interface for a directory which contains many Swagger definition .json/.yml files](https://stackoverflow.com/q/39521627/113116) – Helen Nov 15 '18 at 16:16

1 Answers1

0

You can aggregating multiple service’s API documentation by implementing SwaggerResourcesProvider and then override public List get() method. If you're using zuul, below should work:

@Component
@Primary
@EnableAutoConfiguration
public class DocumentationController implements SwaggerResourcesProvider {

    @Override
    public List get() {
        List resources = new ArrayList<>();
        resources.add(swaggerResource("sample-service", "/api/sample/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;
    }

}

Gateway route configuration will look like:

zuul:
  prefix: /api
  routes:
    account:
      path: /sample/**
      serviceId: sample-service

Original Post: Microservices API Documentation with Swagger2

Sukhpal Singh
  • 2,130
  • 9
  • 20
  • thank you for you reply. I wonder , is there any chance to segregate the swagger code from the micro services. In this code snippet swagger code is also integrated with the micro service. Is this achievable by writing swagger json/yml file . If you please please let me know – Asha Sivasubramanian Nov 20 '18 at 07:29
  • You can write your custom spring-boot-starter module and define this bean there. Then you just need to add that dependency in your microservice. – Sukhpal Singh Nov 20 '18 at 08:03
  • As i am new to swagger, Could you please give me the sample to do it with yml file – Asha Sivasubramanian Nov 20 '18 at 09:06