Springdoc (Swagger) grouping configuration after proxy

9/23/2020

I'm using newest springdoc library to create one common endpoint with all Swagger configurations in one place. There're a bunch of microservices deployed in Kubernetes, so having documentation in one place would be convenient. The easiest way to do that is by using sth like this (https://springdoc.org/faq.html#how-can-i-define-groups-using-applicationyml):

springdoc:
  api-docs:
    enabled: true
  swagger-ui:
    disable-swagger-default-url: true
    urls:
      - name: one-service
        url: 'http://one.server/v3/api-docs'
      - name: second-service
        url: 'http://second.server/v3/api-docs'

and it works great, I can choose from list in upper right corner. The problem is that it doesn't work through proxy. According to documentation I need to set some headers (https://springdoc.org/faq.html#how-can-i-deploy-springdoc-openapi-ui-behind-a-reverse-proxy) and it works for single service called directly. But when i try grouping described above, headers are not passed to one-service or second-service, and they generates documentation pointing to localhost.

I suspect I need to use grouping (https://springdoc.org/faq.html#how-can-i-define-multiple-openapi-definitions-in-one-spring-boot-project) but I miss good example, how to achive similar effect (grouping documentation from different microservices). Examples shows only one external address, or grouping local endpoints. I hope, that using this approach, I'll be able to pass headers.

-- Marx
kubernetes
springdoc
swagger

1 Answer

5/23/2021

The properties springdoc.swagger-ui.urls.*, are suitable to configure external (/v3/api-docs url), for example if you want to agreagte all the endpoints of other services, inside one single application.

It will not inherit the proxy configuration, but it will use servers urls defined in your: servers http://one.server/v3/api-docs and http://second.server/v3/api-docs.

You want to have a proxy in front of your service, it's up to your service to handle the correct server urls you want to expose.

If you want it work out of the box, you can use a solution that handles proxying and routing like spring-cloud-gateway

-- brianbro
Source: StackOverflow