Search code examples
javaspringspring-bootswaggerspringdoc

No API definition provided with springdoc


I am using springdoc 1.6.9 with spring boot 2.6.9

I need to load swagger-ui after the service name so i have added below,

springdoc:
  swagger-ui:
    config-url: /myservice/v3/api-docs/swagger-config
    path: /myservice/swagger-ui/index.html
    disable-swagger-default-url: true
  api-docs:
    path: /myservice/v3/api-docs

I also have below in security config,

@Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers(HttpMethod.OPTIONS, "/**").
               .antMatchers("/swagger-ui/index.html").antMatchers("/myservice/swagger-ui/**")
               .antMatchers("myservice/v3/api-docs/**");
    }

When i locally start the service and access http://localhost:8080/myservice/v3/api-docs, it successfully return api spec in json format.

But when i access swagger ui as defined in the property file as http://localhost:8080/myservice/swagger-ui/index.html it redirect to http://localhost:8080/myservice/swagger-ui/swagger-ui/index.html and shows No API definition provided.

What am i missing here?


Solution

  • On your security config you missing first (/):
    .... .antMatchers("/myservice/v3/api-docs/**")

    And for properties try to use this one:

    springdoc:
      swagger-ui:
        config-url: /myservice/v3/api-docs/swagger-config
        path: /myservice/swagger-ui.html
        url: ${springdoc.api-docs.path}
        disable-swagger-default-url: true
      api-docs:
        path: /myservice/v3/api-docs