Skip to content

Commit 479a41c

Browse files
committed
use HTTP 302 status for UI redirect
1 parent a7a3adf commit 479a41c

19 files changed

+51
-50
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected Mono<Void> redirectToUi(ServerHttpRequest request, ServerHttpResponse
7575
String contextPath = this.fromCurrentContextPath(request);
7676
String sbUrl = this.buildUrl(contextPath, swaggerUiConfigParameters.getUiRootPath() + springDocConfigProperties.getWebjars().getPrefix() + SWAGGER_UI_URL);
7777
UriComponentsBuilder uriBuilder = getUriComponentsBuilder(sbUrl);
78-
response.setStatusCode(HttpStatus.TEMPORARY_REDIRECT);
78+
response.setStatusCode(HttpStatus.FOUND);
7979
response.getHeaders().setLocation(URI.create(uriBuilder.build().encode().toString()));
8080
return response.setComplete();
8181
}

springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app1/SpringDocApp1RedirecFilterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
public class SpringDocApp1RedirecFilterTest extends AbstractSpringDocTest {
3232

3333
@Test
34-
public void shouldRedirectWithConfigUrlIgnoringQueryParams() throws Exception {
34+
public void shouldRedirectWithConfigUrlIgnoringQueryParams() {
3535

3636
WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/swagger-ui.html").exchange()
37-
.expectStatus().isTemporaryRedirect();
37+
.expectStatus().isFound();
3838
responseSpec.expectHeader()
3939
.value("Location", Matchers.is("/webjars/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config&filter=false"));
4040

springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app1/SpringDocApp1RedirectConfigUrlTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
public class SpringDocApp1RedirectConfigUrlTest extends AbstractSpringDocTest {
3535

3636
@Test
37-
public void shouldRedirectWithConfigUrlIgnoringQueryParams() throws Exception {
37+
public void shouldRedirectWithConfigUrlIgnoringQueryParams() {
3838

3939
WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/swagger-ui.html").exchange()
40-
.expectStatus().isTemporaryRedirect();
40+
.expectStatus().isFound();
4141
responseSpec.expectHeader()
4242
.value("Location", Matchers.is("/webjars/swagger-ui/index.html?configUrl=/foo/bar"));
4343

springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app1/SpringDocApp1RedirectDefaultTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
public class SpringDocApp1RedirectDefaultTest extends AbstractSpringDocTest {
3030

3131
@Test
32-
public void shouldRedirectWithDefaultQueryParams() throws Exception {
32+
public void shouldRedirectWithDefaultQueryParams() {
3333
WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/swagger-ui.html").exchange()
34-
.expectStatus().isTemporaryRedirect();
34+
.expectStatus().isFound();
3535
responseSpec.expectHeader()
3636
.value("Location", Matchers.is("/webjars/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config"));
3737

springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app1/SpringDocApp1RedirectLayoutTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
public class SpringDocApp1RedirectLayoutTest extends AbstractSpringDocTest {
3232

3333
@Test
34-
public void shouldRedirectWithConfigUrlIgnoringQueryParams() throws Exception {
34+
public void shouldRedirectWithConfigUrlIgnoringQueryParams() {
3535

3636
WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/swagger-ui.html").exchange()
37-
.expectStatus().isTemporaryRedirect();
37+
.expectStatus().isFound();
3838
responseSpec.expectHeader()
3939
.value("Location", Matchers.is("/webjars/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config&layout=BaseLayout"));
4040

springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app1/SpringDocApp1RedirectQueryParams1Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
public class SpringDocApp1RedirectQueryParams1Test extends AbstractSpringDocTest {
3232

3333
@Test
34-
public void shouldRedirectWithQueryParamsWithoutOauth2() throws Exception {
34+
public void shouldRedirectWithQueryParamsWithoutOauth2() {
3535

3636
WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/swagger-ui.html").exchange()
37-
.expectStatus().isTemporaryRedirect();
37+
.expectStatus().isFound();
3838
responseSpec.expectHeader()
3939
.value("Location", Matchers.is("/webjars/swagger-ui/index.html?url=/v3/api-docs"));
4040

springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app1/SpringDocApp1RedirectQueryParams2Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
public class SpringDocApp1RedirectQueryParams2Test extends AbstractSpringDocTest {
3232

3333
@Test
34-
public void shouldRedirectWithQueryParams() throws Exception {
34+
public void shouldRedirectWithQueryParams() {
3535

3636
WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/swagger-ui.html").exchange()
37-
.expectStatus().isTemporaryRedirect();
37+
.expectStatus().isFound();
3838
responseSpec.expectHeader()
3939
.value("Location", Matchers.is("/webjars/swagger-ui/index.html?oauth2RedirectUrl=/webjars/swagger-ui/oauth2-redirect.html&url=/v3/api-docs"));
4040

springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app1/SpringDocApp1RedirectWithConfigTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
public class SpringDocApp1RedirectWithConfigTest extends AbstractSpringDocTest {
3434

3535
@Test
36-
public void shouldRedirectWithConfiguredParams() throws Exception {
36+
public void shouldRedirectWithConfiguredParams() {
3737
WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/swagger-ui.html").exchange()
38-
.expectStatus().isTemporaryRedirect();
38+
.expectStatus().isFound();
3939

4040
responseSpec.expectHeader()
4141
.value("Location", Matchers.is("/webjars/swagger-ui/index.html?configUrl=/baf/batz/swagger-config"));

springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app1/SpringDocApp1Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
public class SpringDocApp1Test extends AbstractSpringDocTest {
2828

2929
@Test
30-
public void shouldDisplaySwaggerUiPage() throws Exception {
30+
public void shouldDisplaySwaggerUiPage() {
3131
webTestClient.get().uri("/swagger-ui.html").exchange()
32-
.expectStatus().isTemporaryRedirect();
32+
.expectStatus().isFound();
3333
}
3434

3535
@SpringBootApplication

springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app13/SpringDocApp13Test.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.springframework.http.HttpStatus;
2828
import org.springframework.test.web.reactive.server.EntityExchangeResult;
2929

30-
import static org.junit.jupiter.api.Assertions.assertTrue;
30+
import static org.assertj.core.api.Assertions.assertThat;
3131
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
3232

3333

@@ -42,22 +42,21 @@ class SpringDocApp13Test extends AbstractSpringDocActuatorTest {
4242
static class SpringDocTestApp {}
4343

4444
@Test
45-
void testIndex() throws Exception {
46-
45+
void testIndex() {
4746
EntityExchangeResult<byte[]> getResult = webTestClient.get().uri("/application/webjars/swagger-ui/index.html")
4847
.exchange()
4948
.expectStatus().isOk()
5049
.expectBody().returnResult();
51-
50+
assertThat(getResult.getResponseBody()).isNotNull();
5251
String result = new String(getResult.getResponseBody());
53-
assertTrue(result.contains("Swagger UI"));
52+
assertThat(result).contains("Swagger UI");
5453
}
5554

5655
@Test
5756
public void testIndexActuator() {
5857
HttpStatus httpStatusMono = webClient.get().uri("/application/swaggerui")
5958
.exchangeToMono( clientResponse -> Mono.just(clientResponse.statusCode())).block();
60-
assertTrue(httpStatusMono.equals(HttpStatus.TEMPORARY_REDIRECT));
59+
assertThat(httpStatusMono).isEqualTo(HttpStatus.FOUND);
6160
}
6261

6362
@Test

0 commit comments

Comments
 (0)