From 5220195d33e4bd9f6e7706d2ea063e3866bd9fde Mon Sep 17 00:00:00 2001 From: Ilya Lagoshny Date: Wed, 16 Apr 2025 23:10:47 +0300 Subject: [PATCH 1/3] ISSUE-2969 fix path to register resource handler to work SwaggerIndexPageTransformer considering /webjar path prefix --- .../java/org/springdoc/webflux/ui/SwaggerWebFluxConfigurer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/springdoc-openapi-starter-webflux-ui/src/main/java/org/springdoc/webflux/ui/SwaggerWebFluxConfigurer.java b/springdoc-openapi-starter-webflux-ui/src/main/java/org/springdoc/webflux/ui/SwaggerWebFluxConfigurer.java index 482d9fe64..51ba5d0cf 100644 --- a/springdoc-openapi-starter-webflux-ui/src/main/java/org/springdoc/webflux/ui/SwaggerWebFluxConfigurer.java +++ b/springdoc-openapi-starter-webflux-ui/src/main/java/org/springdoc/webflux/ui/SwaggerWebFluxConfigurer.java @@ -106,7 +106,7 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) { String resourcePath,swaggerUiPrefix; if (DEFAULT_WEB_JARS_PREFIX_URL.equals(webjarsPrefix)) { - swaggerUiPrefix = SWAGGER_UI_PREFIX; + swaggerUiPrefix = webjarsPrefix + SWAGGER_UI_PREFIX; resourcePath = webjarsPrefix + SWAGGER_UI_PREFIX + DEFAULT_PATH_SEPARATOR + swaggerUiConfigProperties.getVersion() + DEFAULT_PATH_SEPARATOR; } else { swaggerUiPrefix = webjarsPrefix; From a39ce4f8449ff1de9f99e0f496b3bb7ed8f75c88 Mon Sep 17 00:00:00 2001 From: Ilya Lagoshny Date: Thu, 17 Apr 2025 00:09:12 +0300 Subject: [PATCH 2/3] ISSUE-2969 fix path to register resource handler to work SwaggerIndexPageTransformer considering /webjar path prefix --- .../webflux/ui/SwaggerWebFluxConfigurer.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/springdoc-openapi-starter-webflux-ui/src/main/java/org/springdoc/webflux/ui/SwaggerWebFluxConfigurer.java b/springdoc-openapi-starter-webflux-ui/src/main/java/org/springdoc/webflux/ui/SwaggerWebFluxConfigurer.java index 51ba5d0cf..b1f31746b 100644 --- a/springdoc-openapi-starter-webflux-ui/src/main/java/org/springdoc/webflux/ui/SwaggerWebFluxConfigurer.java +++ b/springdoc-openapi-starter-webflux-ui/src/main/java/org/springdoc/webflux/ui/SwaggerWebFluxConfigurer.java @@ -103,16 +103,24 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) { uiRootPath.append(actuatorProvider.get().getBasePath()); String webjarsPrefix = springDocConfigProperties.getWebjars().getPrefix(); - String resourcePath,swaggerUiPrefix; + String resourcePath,swaggerUiPrefix,swaggerUiWebjarsPrefix; if (DEFAULT_WEB_JARS_PREFIX_URL.equals(webjarsPrefix)) { - swaggerUiPrefix = webjarsPrefix + SWAGGER_UI_PREFIX; - resourcePath = webjarsPrefix + SWAGGER_UI_PREFIX + DEFAULT_PATH_SEPARATOR + swaggerUiConfigProperties.getVersion() + DEFAULT_PATH_SEPARATOR; + swaggerUiPrefix = SWAGGER_UI_PREFIX; + resourcePath = webjarsPrefix + SWAGGER_UI_PREFIX + DEFAULT_PATH_SEPARATOR + swaggerUiConfigProperties.getVersion() + DEFAULT_PATH_SEPARATOR; + swaggerUiWebjarsPrefix = webjarsPrefix + swaggerUiPrefix; } else { swaggerUiPrefix = webjarsPrefix; resourcePath = DEFAULT_WEB_JARS_PREFIX_URL + DEFAULT_PATH_SEPARATOR; + swaggerUiWebjarsPrefix = swaggerUiPrefix; } + registry.addResourceHandler(uiRootPath + swaggerUiWebjarsPrefix + ALL_PATTERN) + .addResourceLocations(CLASSPATH_RESOURCE_LOCATION + resourcePath) + .resourceChain(false) + .addResolver(swaggerResourceResolver) + .addTransformer(swaggerIndexTransformer); + registry.addResourceHandler(uiRootPath + swaggerUiPrefix + ALL_PATTERN) .addResourceLocations(CLASSPATH_RESOURCE_LOCATION + resourcePath) .resourceChain(false) From 6c3ac257a006e9626248a77b6aa50942be01e845 Mon Sep 17 00:00:00 2001 From: Ilya Lagoshny Date: Thu, 17 Apr 2025 14:37:53 +0300 Subject: [PATCH 3/3] ISSUE-2969 fix path to register resource handler to work SwaggerIndexPageTransformer considering /webjar path prefix - add test --- .../springdoc/ui/app34/HelloController.java | 40 ++++++++++++++ .../ui/app34/SpringDocApp34Test.java | 53 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/app34/HelloController.java create mode 100644 springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/app34/SpringDocApp34Test.java diff --git a/springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/app34/HelloController.java b/springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/app34/HelloController.java new file mode 100644 index 000000000..1439f5b2e --- /dev/null +++ b/springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/app34/HelloController.java @@ -0,0 +1,40 @@ +/* + * + * * + * * * + * * * * Copyright 2019-2020 the original author or authors. + * * * * + * * * * Licensed under the Apache License, Version 2.0 (the "License"); + * * * * you may not use this file except in compliance with the License. + * * * * You may obtain a copy of the License at + * * * * + * * * * https://www.apache.org/licenses/LICENSE-2.0 + * * * * + * * * * Unless required by applicable law or agreed to in writing, software + * * * * distributed under the License is distributed on an "AS IS" BASIS, + * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * * * See the License for the specific language governing permissions and + * * * * limitations under the License. + * * * + * * + * + * + */ + +package test.org.springdoc.ui.app34; + +import jakarta.validation.Valid; +import jakarta.validation.constraints.Size; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HelloController { + + @GetMapping(value = "/persons") + public void persons(@Valid @RequestParam @Size(min = 4, max = 6) String name) { + + } + +} diff --git a/springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/app34/SpringDocApp34Test.java b/springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/app34/SpringDocApp34Test.java new file mode 100644 index 000000000..5ef84394e --- /dev/null +++ b/springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/app34/SpringDocApp34Test.java @@ -0,0 +1,53 @@ +/* + * + * * + * * * + * * * * Copyright 2019-2020 the original author or authors. + * * * * + * * * * Licensed under the Apache License, Version 2.0 (the "License"); + * * * * you may not use this file except in compliance with the License. + * * * * You may obtain a copy of the License at + * * * * + * * * * https://www.apache.org/licenses/LICENSE-2.0 + * * * * + * * * * Unless required by applicable law or agreed to in writing, software + * * * * distributed under the License is distributed on an "AS IS" BASIS, + * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * * * See the License for the specific language governing permissions and + * * * * limitations under the License. + * * * + * * + * + * + */ + +package test.org.springdoc.ui.app34; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.web.reactive.server.EntityExchangeResult; +import test.org.springdoc.ui.AbstractSpringDocTest; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@TestPropertySource(properties = "springdoc.swagger-ui.disable-swagger-default-url=true") +public class SpringDocApp34Test extends AbstractSpringDocTest { + + @Test + void transformed_index_with_oauth() throws Exception { + EntityExchangeResult getResult = webTestClient.get().uri("/webjars/swagger-ui/swagger-initializer.js") + .exchange() + .expectStatus().isOk() + .expectBody().returnResult(); + + var responseContent = new String(getResult.getResponseBody()); + assertFalse(responseContent.contains("https://petstore.swagger.io/v2/swagger.json")); + assertTrue(responseContent.contains("/v3/api-docs")); + } + + @SpringBootApplication + static class SpringDocTestApp {} + +} \ No newline at end of file