Skip to content

Commit 1733bf9

Browse files
author
bnasslahsen
committed
code review
1 parent 17de960 commit 1733bf9

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

springdoc-openapi-webflux-ui/src/main/java/org/springdoc/webflux/ui/SwaggerWelcome.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public class SwaggerWelcome extends AbstractSwaggerWelcome {
5353

5454
private String webJarsPrefixUrl;
5555

56+
private UriComponentsBuilder oauthPrefix;
57+
5658
public SwaggerWelcome(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties) {
5759
super(swaggerUiConfig, springDocConfigProperties);
5860
this.webJarsPrefixUrl = springDocConfigProperties.getWebjars().getPrefix();
@@ -91,8 +93,9 @@ protected void calculateUiRootPath(StringBuilder... sbUrls) {
9193

9294
@Override
9395
protected void calculateOauth2RedirectUrl(UriComponentsBuilder uriComponentsBuilder) {
94-
if (!swaggerUiConfig.isValidUrl(swaggerUiConfig.getOauth2RedirectUrl())) {
95-
swaggerUiConfig.setOauth2RedirectUrl(uriComponentsBuilder.path(this.uiRootPath).path(webJarsPrefixUrl).path(swaggerUiConfig.getOauth2RedirectUrl()).build().toString());
96+
if (oauthPrefix == null && !swaggerUiConfig.isValidUrl(swaggerUiConfig.getOauth2RedirectUrl())) {
97+
this.oauthPrefix = uriComponentsBuilder.path(this.uiRootPath).path(webJarsPrefixUrl);
98+
swaggerUiConfig.setOauth2RedirectUrl(this.oauthPrefix.path(swaggerUiConfig.getOauth2RedirectUrl()).build().toString());
9699
}
97100
}
98101

springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app3/SpringDocApp3RedirectDefaultTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818

1919
package test.org.springdoc.ui.app3;
2020

21+
import org.hamcrest.Matchers;
2122
import org.junit.jupiter.api.Test;
2223
import test.org.springdoc.ui.AbstractSpringDocTest;
2324

2425
import org.springframework.boot.autoconfigure.SpringBootApplication;
2526
import org.springframework.test.context.TestPropertySource;
27+
import org.springframework.test.web.reactive.server.WebTestClient;
2628

2729

2830
@TestPropertySource(properties = {
@@ -33,6 +35,11 @@ public class SpringDocApp3RedirectDefaultTest extends AbstractSpringDocTest {
3335

3436
@Test
3537
public void shouldRedirectWithDefaultQueryParams() throws Exception {
38+
WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/documentation/swagger-ui.html").exchange()
39+
.expectStatus().isTemporaryRedirect();
40+
responseSpec.expectHeader()
41+
.value("Location", Matchers.is("/documentation/webjars/swagger-ui/index.html?configUrl=/documentation/v3/api-docs/swagger-config"));
42+
3643
webTestClient.get().uri("/documentation/v3/api-docs/swagger-config").exchange()
3744
.expectStatus().isOk().expectBody()
3845
.jsonPath("$.validatorUrl").isEqualTo("")

0 commit comments

Comments
 (0)