Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question - Swagger UI and Swagger Services on different Servers #1001

HashtagMarkus opened this issue Oct 9, 2015 · 5 comments


Copy link

I am currently setting up a small microservice architecture. I would like to run the Swagger UI in a docker container and my rest services in another.
I can't find a way to make my services known to the swagger ui. I am using the swagger-ui maven artifact which I included in a Springboot application.

Swagger UI Docker Container: http://localhost:8080
RestService1 Docker Container: http://localhost:8081
RestService2 Docker Container: http://localhost:8082

I can access the /api-docs path on both services. However I can't figure out how to configure Swagger UI accordingly.
How can I configure Swagger UI to discover the api-docs endpoints of my other docker container?
Unfortunately I can't find any resources addressing this setup. Is this even possible using the maven archetype?

Copy link

mozinrat commented Oct 9, 2015

We are looking for exact same question, and what would be best if we can use some discovery mechanism to automatically add those apidocs as dropdown, or may be some way an application can push the api-docs for registering the docs.

Copy link

I probably found a solution by reading through old issues:

I created my own ApiResourceController (Basically I copied the one from springfox and removed all the DocumentationCache stuff). I then changed the swaggerResource() method to return my services:

@RequestMapping(value = "/swagger-resources")
ResponseEntity<List<SwaggerResource>> swaggerResources() {

    List<SwaggerResource> resources = new ArrayList<SwaggerResource>();

    SwaggerResource swaggerResource = resource("myservice", "http://localhost:8081/myservice/v0");

    SwaggerResource swaggerResource2 = resource("myservice2", "http://localhost:8082/myservice2/v0");

    return new ResponseEntity<List<SwaggerResource>>(resources, HttpStatus.OK);

Obviously this is not the best solution, because I don't want to hardcode my resources. I guess I'll write some kind of registry which is called by each service on startup.

Since spring will complain about duplicated resource mappings I had to ignore the existing ApiResourceController by adding the excludeFilters to my ComponentScan annotation:
@ComponentScan(excludeFilters = @ComponentScan.Filter(value = springfox.documentation.swagger.web.ApiResourceController.class, type = FilterType.ASSIGNABLE_TYPE))

Another thing that needs to be done, is to enable CORS, which can be done by writing an own CORS Filter as described here:

This is however not working in my current application. So If someone has an idea what might go wrong here, please let me know 👍
I receive the following exception Can't read from server. It may not have the appropriate access-control-origin settings.. When I curl my resources I receive the following header:

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET, PUT, OPTIONS, DELETE
Access-Control-Max-Age: 3600
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept
X-Application-Context: application:8081
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked

which looks fine for me. I have no clue why this is not working

Copy link

@HashtagMarkus I would've suggested suggested the same thing. The CORS filter setup is pretty simple to setup. The only catch is like you said, you'll be hard coding the services without access to a registry.

Copy link

Hi @HashtagMarkus & @dilipkrish,

I am having the similar kind of requirement. I have created ApiResourceController in my local. But i am not able to exclude springfox.documentation.swagger.web.ApiResourceController.class, using the below.

@componentscan(excludeFilters = @componentscan.Filter(value = springfox.documentation.swagger.web.ApiResourceController.class, type = FilterType.ASSIGNABLE_TYPE))

ITs still failing with the below error.

Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'apiResourceController' for bean class [springfox.documentation.swagger.web.ApiResourceController] conflicts with existing, non-compatible bean definition of same name and class [************.local..ApiResourceController]

Any suggestions?

Copy link

@seshachalam Annotate yours with @Primary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

4 participants