Skip to content

Proxy Routing Problem When Using Swagger-UI #331

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

Closed
kjc14f opened this issue Jan 8, 2020 · 2 comments
Closed

Proxy Routing Problem When Using Swagger-UI #331

kjc14f opened this issue Jan 8, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@kjc14f
Copy link

kjc14f commented Jan 8, 2020

Hi,

Love the library! Thanks for all the work you have put in!

I've been migrating one of my applications from springfox to springdoc and I've run into a problem involving a Zuul proxy and a Spring cloud microservice using springdoc swagger-ui.

My 2 apps:

  • localhost:11111 = test-app
  • localhost:22222 = zuul proxy

When I start the test-app and go to localhost:11111/swagger-ui.html, I am routed to localhost:11111/swagger-ui/index.html?configURL=/v3/api-docs/swagger-config and everything works as expected.

Once the test-app worked I tried to get it to work through the proxy by adding
server.forward-headers-strategy: framework
to my test-app yaml as per your FAQ in order to get my reverse proxy to work. If I start both the application and the proxy and hit localhost:22222/test-app/swagger-ui.html, I am routed to the correct place and I can see the swagger-ui as expected (I can also see the forwarded prefix coming in okay).

The issue seems to arrise when using a combination of the 2 approaches. Sometimes I want to hit the swagger through the proxy, othertimes by hitting the service direct. It seems however whichever method I do first is the only one that works because it seems to cache the URL.

E.g. If the first call after startup is to the proxy (localhost:22222/test-app/swagger-ui.html) that works fine. If I then hit (localhost:11111/swagger-ui.html) afterwards it takes me to localhost:11111/swagger-ui/index.html?configURL=/test-app/v3/api-docs/swagger-config . Notice that /test-app/ is prefixed to the configURL like it is still coming from the proxy even though it isn't, this obviously gives 'Failed to load remote comfiguration'.

I stepped into the code a bit and I can see this seems to be from the method buildConfigUrl() in SwaggerWelcome.java. It has the following statement
if (StringUtils.isEmpty(swaggerUiConfig.getConfigUrl()))
This always returns false after hitting the swagger the first time but the buildConfigUrl is incorrect because it is that of the proxy.

Is there a way to stop springdoc doing this and to make it recall the buildConfigUrl() each time?

Thanks for the help! :)

@kjc14f kjc14f changed the title Proxy routing problem Proxy Routing Problem When Using Swagger-UI Jan 8, 2020
@bnasslahsen
Copy link
Collaborator

Hi @kjc14f,

The behaviour you are describing will be corrected in order to recall buildConfigUrl each time.
Also, in order to have the correct url on the servers list, you will have to set the following property:

springdoc.cache.disabled= true

All this will be available with next release: v1.2.26.

@kjc14f
Copy link
Author

kjc14f commented Jan 10, 2020

Thanks @bnasslahsen, that sounds perfect! Thanks for the quick response :)

@bnasslahsen bnasslahsen added the enhancement New feature or request label Jan 10, 2022
sonic-air-swimmer pushed a commit to sonic-air-swimmer/SpringCloudGatewaySwagger that referenced this issue Apr 23, 2022
@springdoc springdoc locked as resolved and limited conversation to collaborators Apr 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants