Springdoc-openapi: How to stop redirection to /swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config

Created on 22 Jun 2020  路  4Comments  路  Source: springdoc/springdoc-openapi

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?

All 4 comments

@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:

  1. Either you get absolute URL redirect. It's the default with Spring. But when you are behind a kind of proxy (gateway or other), this redirect can be broken if one of the intermediate proxy doesn't provision 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)),
  2. Either you configure Spring to perform relative redirect (either a prop in Spring Boot 2 or a conf of 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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bfs-natewallman picture bfs-natewallman  路  4Comments

Orxcle-xx picture Orxcle-xx  路  4Comments

hectoryo picture hectoryo  路  5Comments

chaki13 picture chaki13  路  4Comments

urswiss picture urswiss  路  5Comments