springdoc / springdoc-openapi

Library for OpenAPI 3 with spring-boot
https://springdoc.org
Apache License 2.0
3.28k stars 495 forks source link

Unable to infer base url problem. #137

Closed ucraida closed 4 years ago

ucraida commented 4 years ago

Using springdoc-openapi-ui:1.2.0. Adding this to a project which previously had springfox/annotations 1.5.x. Springboot is 2.1.x. The swagger-ui webjars loaded is 3.24.

When attempting to load http://localhost:8080//swagger-ui.html get the common failure seen with swagger-ui: "Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base url is the root of where all the swagger resources are served. For e.g. if the api is available at http://example.org/api/v2/api-docs then the base url is http://example.org/api/. Please enter the location manually: "

I already have resource handlers in place for webjars:

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("swagger-ui.html")
        .addResourceLocations("classpath:/META-INF/resources/");

    registry.addResourceHandler("/webjars/**")
        .addResourceLocations("classpath:/META-INF/resources/webjars/");
}

however - messing with changing the root path & stepping through SwaggerWelcome code I found /swagger-ui/index.htmI. That loaded and eventually I got to this url, which loads fine. http://localhost:8080//swagger-ui/index.html?url=//v3/api-docs&validatorUrl=

springdoc commented 4 years ago

Hi,

By default, you don't need to define the resource handlers, if you want to use springdoc-openapi-ui. There is no relation between springdoc-openapi and springfox.

If you want to migrate to OpenAPI 3:

Please note, that by default you just need to add the right dependency to your project, according to the documentation:

ucraida commented 4 years ago

I understand they are different projects, I mentioned springfox because it was working there. However that was my downfall. I just determined that the issue is that swagger-ui.html was an old version cached in chrome from springfox. I plan on opening an issue with springfox, since the way that error is presented prevents the page from being inspected.

Thanks for the quick response and keep up the good work.