spring boot - springdoc open api: No api definiation provided error

Viewed 799

I need to document my spring boot application's rest apis with SpringDoc OpenApi. So, I added this dependency in my pom.xml:

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>1.6.8</version>
</dependency>

And here is my config class:

@Configuration
public class SwaggerConfig {

    @Bean
    public GroupedOpenApi apis() {
        return GroupedOpenApi.builder()
            .group("my-application")
            .packagesToScan("com.myapp.base")
            .pathsToMatch("/**")
            .build();
    }
}

When I want to use swagger-ui in /base-url/swagger-ui/index.html, the result is as below image:

enter image description here

What's wrong in my configuration?

I use spring boot 2.6.6.

Note: I don't see any problem to load swagger resources in browser console(401, 404). Also I have disabled spring security in app, there is not any problem related to security or loading swagger resources.

1 Answers

You bean looks okay to me but you're probably not hitting the right endpoint for the Swagger-UI.

The URL /base-url/swagger-ui/index.html points to the Swagger-UI provided by the Swagger Core library and there's not a lot you can do about it.

Springdoc has a transitive dependency on Swagger Core and as such the page is available. But the URL at which Springdoc exposes it's Swagger-UI is /base-url/swagger-ui.html.

Refer to the answer here for an explanation on why is it so and the ways to update it.

Related