3

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.

hamed
  • 7,939
  • 15
  • 60
  • 114
  • are you able to get some content when you got to /base-url/v3/api-docs/my-application this is URL where your definition should be generated based on your config? – vzhemevko May 12 '22 at 18:25
  • Does the package named `com.myapp.base` supplied to `packagesToScan()` actually exist in your application and contain at least one `@RestController` ? – dekkard May 12 '22 at 21:28
  • @vzhemevko The `.../v3/api-docs/...` returns json object that contains valid controllers data. – hamed May 13 '22 at 03:28
  • @dekkard Yes, the package exists and I have a `@RestController` inside the package. Also `.../v3/api-docs` returns valid json value contains that controller data. – hamed May 13 '22 at 03:30
  • @hamed as a suggestion try to remove the bean and just add the following props to your application props springdoc.packagesToScan=com.myapp.base springdoc.api-docs.path=/api/api-docs springdoc.swagger-ui.path=/api/swagger-ui then go to /base-url/api/swagger-ui in browser – vzhemevko May 13 '22 at 12:14

1 Answers1

0

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.

Debargha Roy
  • 2,320
  • 1
  • 15
  • 34