Skip to content

Swagger UI shows petstore swagger by default in webflux #2969

Closed
@lagoshny

Description

@lagoshny

Describe the bug
After update to Spring Boot to 3.4.4 version and springdoc webflux ui starter to 2.8.6 the main page Swagger UI
shows by default petstore swagger Open API.
I know that we can use to disable this behavior additional configuration:

springdoc:
  swagger-ui:
    disable-swagger-default-url: true

But it doesn't work because SwaggerIndexPageTransformer ignored when I open default swagger path for webflux /webjars/swagger-ui/index.html

After some research, I found that Spring added resource handler with org.springframework.web.reactive.resource.CachingResourceTransformer for path /webjars/** in org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration.WebFluxConfig#addResourceHandlers and this is used to process when I open /webjars/swagger-ui/index.html instead SwaggerIndexPageTransformer.

The problem in org.springdoc.webflux.ui.SwaggerWebFluxConfigurer#addResourceHandlers it adds SwaggerIndexPageTransformer for path /swagger-ui and it is not used when we open /webjars/swagger-ui/index.html URL.

if (DEFAULT_WEB_JARS_PREFIX_URL.equals(webjarsPrefix)) {
      swaggerUiPrefix = SWAGGER_UI_PREFIX;
      resourcePath = webjarsPrefix + SWAGGER_UI_PREFIX + DEFAULT_PATH_SEPARATOR + swaggerUiConfigProperties.getVersion();
    } else {
      swaggerUiPrefix = webjarsPrefix;
      resourcePath = DEFAULT_WEB_JARS_PREFIX_URL + DEFAULT_PATH_SEPARATOR;
    }

    registry.addResourceHandler(uiRootPath + swaggerUiPrefix + ALL_PATTERN)
        .addResourceLocations(CLASSPATH_RESOURCE_LOCATION + resourcePath)
        .resourceChain(false)
        .addResolver(swaggerResourceResolver)
        .addTransformer(swaggerIndexTransformer);

We need to add webjarsPrefix to swaggerUiPrefix and then SwaggerIndexPageTransformer will be used for path /webjars/swagger-ui that overrides default Spring CachingResourceTransformer.

To Reproduce
Steps to reproduce the behavior:

  • Create Spring boot 3.4.4 project and add org.springdoc:springdoc-openapi-starter-webflux-ui:2.8.6 deps.
  • Create some RestController with Dto's that used OpenAPI.
  • Open swagger UI for your service, and you will see default petstroe swagger instead of your project /v3/api-docs

Expected behavior

I expected that when I set up

springdoc:
  swagger-ui:
    disable-swagger-default-url: true

then springdoc will be transforming the index page and use /v3/api-docs by default instead petstore swagger

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions