'Swagger UI redirecting to /swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config
I am using springdoc-openapi-ui, 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.
Solution 1:[1]
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.
Solution 2:[2]
this is not about the redirect, as it works to just open to http://localhost:8080/swagger-ui/index.html. But some answers are about disabling the petshop and configUrl. Supplying configUrl is not working anymore for a autoconfigured springdoc. Overwriting the url, config-url (if needed) and default url works with the following application.yml:
springdoc:
swagger-ui:
url: "/v3/api-docs"
disable-swagger-default-url: true
or you can use the topics plugin:
springdoc:
swagger-ui:
disable-swagger-default-url: true
urls:
- url: "/v3/api-docs"
name: "myService"
Solution 3:[3]
I found a post to workaround for this. Scan and modify the index.html to replace petStore URL for apiDoc URL
@Configuration
public class DocOpenApiConfiguration implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**/*.html")
.addResourceLocations("classpath:/META-INF/resources/webjars/")
.resourceChain(false)
.addResolver(new WebJarsResourceResolver())
.addResolver(new PathResourceResolver())
.addTransformer(new IndexPageTransformer());
}
public static class IndexPageTransformer implements ResourceTransformer {
private String overwriteDefaultUrl(String html) {
return html.replace("https://petstore.swagger.io/v2/swagger.json",
"/v3/api-docs");
}
@Override
public Resource transform(HttpServletRequest httpServletRequest, Resource resource, ResourceTransformerChain resourceTransformerChain) throws IOException {
if (resource.getURL().toString().endsWith("/index.html")) {
String html = IOUtils.toString(resource.getInputStream(), StandardCharsets.UTF_8);
html = overwriteDefaultUrl(html);
return new TransformedResource(resource, html.getBytes());
} else {
return resource;
}
}
}
}
Solution 4:[4]
When I ran your code the legend was there, but it was behind and slightly above the plot, and then cut off when plt.savefig() is called. I was able to get it to work with the bbox_inches='tight' argument of plt.savefig() and the following to move the legend.
fig.legend(handles=[l1, l2], bbox_to_anchor=(0.7, 1.1), ncol=2)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Milo Felipe |
| Solution 2 | |
| Solution 3 | SSK |
| Solution 4 |

