title: How can I aggregate microservices swaggers into a single swagger
body: <p>I am trying to generate a single swagger in my microservices project, aggregating all services swaggers into a single one, in the Api Gateway. In order to achieve this, I am following the next tutorial <a href="https://objectpartners.com/2017/09/28/aggregate-services-into-a-single-swagger" rel="noreferrer">https://objectpartners.com/2017/09/28/aggregate-services-into-a-single-swagger</a></p>
  
  <p>The problem here is that, when I try to set absolute URLs, the output I am receiving is <strong><em>Failed to load API definition. undefined <a href="http://localhost:8070/apihttp://localhost:8081/api/v2/api-docs" rel="noreferrer">http://localhost:8070/apihttp://localhost:8081/api/v2/api-docs</a></em></strong> where <em>localhost:8070/api</em> is the base URL for the api gateway, and <em>localhost:8081/api/v2/api-docs</em> is the docs URL of the swagger of the microservice.</p>
  
  <p>Here is my code:</p>
  
  <p><strong>SwaggerConfiguration</strong></p>
  
  <pre><code>package com.rfd.apigateway.swagger;
  
  import org.springframework.boot.context.properties.ConfigurationProperties;
  import org.springframework.context.annotation.Configuration;
  
  import java.util.List;
  
  @Configuration
  @ConfigurationProperties(prefix = "swagger")
  public class SwaggerConfiguration {
  
      private List&lt;Resource&gt; resources;
  
      public List&lt;Resource&gt; getResources() {
          return resources;
      }
  
      public void setResources(List&lt;Resource&gt; resources) {
          this.resources = resources;
      }
  }
  </code></pre>
  
  <p><strong>Resource</strong></p>
  
  <pre><code>package com.rfd.apigateway.swagger;
  
  public class Resource {
      private String name;
      private String url;
      private String version;
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getUrl() {
          return url;
      }
  
      public void setUrl(String url) {
          this.url = url;
      }
  
      public String getVersion() {
          return version;
      }
  
      public void setVersion(String version) {
          this.version = version;
      }
  }
  </code></pre>
  
  <p><strong>DocumentationController</strong></p>
  
  <pre><code>package com.rfd.apigateway.swagger;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  import org.springframework.context.annotation.Primary;
  import org.springframework.stereotype.Component;
  import springfox.documentation.swagger.web.SwaggerResource;
  import springfox.documentation.swagger.web.SwaggerResourcesProvider;
  
  import java.util.ArrayList;
  import java.util.List;
  
  @Component
  @Primary
  @EnableAutoConfiguration
  public class DocumentationController implements SwaggerResourcesProvider {
  
      private SwaggerConfiguration swaggerConfiguration;
  
      @Autowired
      public DocumentationController(SwaggerConfiguration swaggerConfiguration){
          this.swaggerConfiguration = swaggerConfiguration;
      }
  
      @Override
      public List get() {
          List resources = new ArrayList&lt;&gt;();
          for(Resource resource : this.swaggerConfiguration.getResources()){
              resources.add(createSwaggerResource(resource));
          }
  
          return resources;
      }
  
      private SwaggerResource createSwaggerResource(Resource resource) {
          SwaggerResource swaggerResource = new SwaggerResource();
          swaggerResource.setName(resource.getName());
          swaggerResource.setUrl(resource.getUrl());
          swaggerResource.setSwaggerVersion(resource.getVersion());
          return swaggerResource;
      }
  }
  </code></pre>
  
  <p>Finally, the <strong>application.yml</strong></p>
  
  <pre><code>swagger:
    resources:
      - name: transactions
        url: http://localhost:8081/api/v2/api-docs
        version: 1.0
      - name: payments
        url: http://localhost:8083/api/v2/api-docs
        version: 1.0
  </code></pre>
  
  <p>And a couple of images that can help to understand the problem:</p>
  
  <p>Api Gateway Swagger URL
  <a href="https://i.stack.imgur.com/vvNL4.png" rel="noreferrer"><img src="https://i.stack.imgur.com/vvNL4.png" alt="Api gateway swagger URL"></a></p>
  
  <p>Microservice api-docs URL
  <a href="https://i.stack.imgur.com/7lWZ3.png" rel="noreferrer"><img src="https://i.stack.imgur.com/7lWZ3.png" alt="Microservice api-docs URL"></a></p>