Skip to content

Swagger UI shows petstore swagger by default in webflux #2969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lagoshny opened this issue Apr 16, 2025 · 2 comments
Open

Swagger UI shows petstore swagger by default in webflux #2969

lagoshny opened this issue Apr 16, 2025 · 2 comments

Comments

@lagoshny
Copy link

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

@lagoshny
Copy link
Author

I have opened the PR how to fix it #2970

@lagoshny
Copy link
Author

This is a simple project how to reproduce this bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant