When I hit http://localhost:8080/swagger-ui.html URL it is always redirecting to http://localhost:8080/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config.
Is there any way to stop this redirect and load swagger on http://localhost:8080/swagger-ui.html instead.
If anyone knows please let me know here or on stack overflow.
https://stackoverflow.com/q/62044228/3493829
If it is not possible currently can we have that feature?
@shilanand,
springdoc-openapi uses internal redirect to resolve the necessary swagger resources.
This the way the library is built.
You use you own version of swagger-ui, so you can add your custom Logic, without having to rely on springdoc-openapi-ui.
If you have identified any enhancements, please feel free to propose a PR.
This issue should not be closed because it's a real problem. I explain the different cases:
X-Forwarded-For HTTP header. In this case, you can get a redirect to the host where the app run (or its IP) instead of the URL behind which it is served (e.g https://gateway.corp/swagger-ui.html is redirected to https://10.21.14;18/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config which cannot be resolved, for instance in some containerized infrastructure (Docker for instance)),InternalViewResolver on SB1 to disable HTTP 1.0 redirect compatibility). It works if your app is behind a proxy, but only if it is served without a prefixed context path. In this latest case, you get a redirect that strip out the prefixed context path and a 404 error (e.g https://gateway.corp/api/swagger-ui.html is redirected to /swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config which is resolved by the client as https://gateway.corp/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config and trigger a 404 error).Redirect are not bad, but it triggers just some complexity in some cases to correctly handle them.
@stephanedaviet,
There is no problem with redirects, as long as you configure well the proxy to forward the right headers/prefixes.
Note, that your second point is not true: Even the App is behind a proxy, the prefix can also be forwareded if you configure well your front-end servers (X-Forwarded-Prefix header indeed)
It's all already explained here:
If you feel you can propose any improvements, please feel free to contribute and propose a PR.
I also encountered this issue because our app is behind a gateway/load balancer and on Docker. My goal is to really just access the Swagger UI and my workaround is to access /swagger-ui/index.html directly. It loads the "Swagger Petstore". In the "Explore" field, I type /v3/api-docs to load my application's APIs.