-
-
Notifications
You must be signed in to change notification settings - Fork 557
Description
Describe the bug
Issue #2969 and pull #2970 attempt to apply the same SpringDoc transformations to the SpringDoc resources under /webjars/**.
In addition, commit e3b4311 modifies the mappings for SpringDoc resources in WebFlux if the springdoc.webjars.prefix property is altered.
However, these changes have multiple issues:
-
The
uiRootPathis erroneously added to the front of the pattern. E.g. if the Swagger path is/documentation/spring-doc.html, then the WebJar resources will be at/documentation/webjars/**instead of/webjars/**.Line 119 in 4b95d0e
registry.addResourceHandler(uiRootPath + swaggerUiWebjarsPrefix + ALL_PATTERN) -
The
swaggerUiPrefixvalue is set to the same asswaggerUiWebjarsPrefixwhenspringdoc.webjars.prefixis not/webjars. TheswaggerUiPrefixpattern should not be affected by the WebJars prefix value.Lines 114 to 116 in 4b95d0e
swaggerUiPrefix = webjarsPrefix; resourcePath = DEFAULT_WEB_JARS_PREFIX_URL + DEFAULT_PATH_SEPARATOR; swaggerUiWebjarsPrefix = swaggerUiPrefix; -
The
springdoc.webjars.prefixproperty is unnecessary and confusing. It is only currently used for WebFlux and not WebMvc, when the behaviour of WebJars is the same for both.It also doesn't make sense to have, as the mappings for WebJar resources on the classpath are already configured using Spring config properties:
spring.web.resources.add-mappingscontrol whether the WebJar resources are actually exposed.spring.mvc.webjars-path-patternandspring.webflux.webjars-path-patternset the pattern to expose WebJar resources (the default is/webjars/**) - hence another property for the same value is not needed.
-
The
uiRootPathfor the resource handler patterns is computed incorrectly. For the resource mappings the actuator base path is added last, instead of first. For the consumers (i.e. the subclasses ofAbstractSwaggerWelcome), the actuator base path is added first.E.g. if the Swagger path is
/documentation/spring-doc.html, and the actuator base path is/actuator, thenSwaggerWelcomeCommonwill redirect to/actuator/documentation/swagger-ui/index.htmlas expected, but the index resource will be actually be exposed at/documentation/actuator/swagger-ui/index.html.Lines 98 to 103 in 4b95d0e
StringBuilder uiRootPath = new StringBuilder(); String swaggerPath = swaggerUiConfigProperties.getPath(); if (swaggerPath.contains(DEFAULT_PATH_SEPARATOR)) uiRootPath.append(swaggerPath, 0, swaggerPath.lastIndexOf(DEFAULT_PATH_SEPARATOR)); if (actuatorProvider.isPresent() && actuatorProvider.get().isUseManagementPort()) uiRootPath.append(actuatorProvider.get().getBasePath()); Lines 193 to 198 in 4b95d0e
if (ArrayUtils.isNotEmpty(sbUrls)) sbUrl = sbUrls[0]; String swaggerPath = swaggerUiConfigParameters.getPath(); if (swaggerPath.contains(DEFAULT_PATH_SEPARATOR)) sbUrl.append(swaggerPath, 0, swaggerPath.lastIndexOf(DEFAULT_PATH_SEPARATOR)); swaggerUiConfigParameters.setUiRootPath(sbUrl.toString());
To Reproduce
Steps to reproduce the behavior:
-
Clone the latest version (i.e. 3.0.0-RC1).
-
Add the property
"springdoc.swagger-ui.path=/documentation/swagger-ui.html"to thespringdoc-openapi-starter-webflux-uitestapp34(from pull ISSUE-2969 fix path to register resource handler to work SwaggerIndexPageTransformer considering /webjar path prefix #2970), and it will fail.Line 36 in 4b95d0e
@TestPropertySource(properties = "springdoc.swagger-ui.disable-swagger-default-url=true")
Expected behavior
-
The
springdoc.webjars.prefixshould not affect the normal (non-WebJar) mappings to the Swagger UI resources. -
The behaviour of the WebJars prefix should be the same for WebFlux and WebMvc, as both map WebJar resources to
/webjars/**by default (i.e. it's not specific to WebFlux only). -
The properties
spring.mvc.webjars-path-patternandspring.webflux.webjars-path-patternshould be used instead ofspringdoc.webjars.prefix. -
The
/webjars/swagger-ui/**mapping should not be added if resource mappings at/webjars/**have been disabled (i.e. ifspring.web.resources.add-mappingsis set tofalse).