Skip to content

Commit 2f47250

Browse files
authored
Merge pull request #1107 from d3ns0n/unify-redirect-response-code
use HTTP 302 status for UI redirect
2 parents f2abb2a + 479a41c commit 2f47250

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

springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app14/SpringDocApp14Test.java

Lines changed: 5 additions & 5 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

@@ -41,21 +41,21 @@ static class SpringDocTestApp {}
4141

4242

4343
@Test
44-
void testIndex() throws Exception {
44+
void testIndex() {
4545
EntityExchangeResult<byte[]> getResult = webTestClient.get().uri("/application/webjars/swagger-ui/index.html")
4646
.exchange()
4747
.expectStatus().isOk()
4848
.expectBody().returnResult();
49-
49+
assertThat(getResult.getResponseBody()).isNotNull();
5050
String contentAsString = new String(getResult.getResponseBody());
51-
assertTrue(contentAsString.contains("Swagger UI"));
51+
assertThat(contentAsString).contains("Swagger UI");
5252
}
5353

5454
@Test
5555
public void testIndexActuator() {
5656
HttpStatus httpStatusMono = webClient.get().uri("/application/swaggerui")
5757
.exchangeToMono( clientResponse -> Mono.just(clientResponse.statusCode())).block();
58-
assertTrue(httpStatusMono.equals(HttpStatus.TEMPORARY_REDIRECT));
58+
assertThat(httpStatusMono).isEqualTo(HttpStatus.FOUND);
5959
}
6060

6161
@Test

springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app15/SpringDocApp15Test.java

Lines changed: 4 additions & 3 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

@@ -49,15 +49,16 @@ void testIndex() {
4949
.exchange()
5050
.expectStatus().isOk()
5151
.expectBody().returnResult();
52+
assertThat(getResult.getResponseBody()).isNotNull();
5253
String contentAsString = new String(getResult.getResponseBody());
53-
assertTrue(contentAsString.contains("Swagger UI"));
54+
assertThat(contentAsString).contains("Swagger UI");
5455
}
5556

5657
@Test
5758
public void testIndexActuator() {
5859
HttpStatus httpStatusMono = webClient.get().uri("/test/application/swaggerui")
5960
.exchangeToMono( clientResponse -> Mono.just(clientResponse.statusCode())).block();
60-
assertTrue(httpStatusMono.equals(HttpStatus.TEMPORARY_REDIRECT));
61+
assertThat(httpStatusMono).isEqualTo(HttpStatus.FOUND);
6162
}
6263

6364
@Test

springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app16/SpringDocApp16Test.java

Lines changed: 5 additions & 4 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

@@ -43,20 +43,21 @@ class SpringDocApp16Test extends AbstractSpringDocActuatorTest {
4343
static class SpringDocTestApp {}
4444

4545
@Test
46-
void testIndex() throws Exception {
46+
void testIndex() {
4747
EntityExchangeResult<byte[]> getResult = webTestClient.get().uri("/application/webjars/swagger-ui/index.html")
4848
.exchange()
4949
.expectStatus().isOk()
5050
.expectBody().returnResult();
51+
assertThat(getResult.getResponseBody()).isNotNull();
5152
String contentAsString = new String(getResult.getResponseBody());
52-
assertTrue(contentAsString.contains("Swagger UI"));
53+
assertThat(contentAsString).contains("Swagger UI");
5354
}
5455

5556
@Test
5657
public void testIndexActuator() {
5758
HttpStatus httpStatusMono = webClient.get().uri("/test/application/swaggerui")
5859
.exchangeToMono( clientResponse -> Mono.just(clientResponse.statusCode())).block();
59-
assertTrue(httpStatusMono.equals(HttpStatus.TEMPORARY_REDIRECT));
60+
assertThat(httpStatusMono).isEqualTo(HttpStatus.FOUND);
6061
}
6162

6263
@Test

springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app18/SpringDocApp18Test.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import org.springframework.http.HttpStatus;
3232
import org.springframework.web.reactive.function.client.WebClient;
3333

34-
import static org.junit.jupiter.api.Assertions.assertTrue;
34+
import static org.assertj.core.api.Assertions.assertThat;
3535
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
3636

3737

@@ -62,11 +62,11 @@ void init(){
6262
public void testIndexActuator() throws Exception {
6363
HttpStatus httpStatusMono = webClient.get().uri("/test/documentation/swagger-ui.html")
6464
.exchangeToMono(clientResponse -> Mono.just(clientResponse.statusCode())).block();
65-
assertTrue(httpStatusMono.equals(HttpStatus.TEMPORARY_REDIRECT));
65+
assertThat(httpStatusMono).isEqualTo(HttpStatus.FOUND);
6666

6767
httpStatusMono = webClient.get().uri("/test/documentation/webjars-pref/swagger-ui/index.html")
6868
.exchangeToMono(clientResponse -> Mono.just(clientResponse.statusCode())).block();
69-
assertTrue(httpStatusMono.equals(HttpStatus.OK));
69+
assertThat(httpStatusMono).isEqualTo(HttpStatus.OK);
7070

7171
String contentAsString = webClient.get().uri("/test/documentation/v3/api-docs/swagger-config").retrieve()
7272
.bodyToMono(String.class).block();

springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app19/SpringDocApp19Test.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import org.springframework.http.HttpStatus;
3232
import org.springframework.web.reactive.function.client.WebClient;
3333

34-
import static org.junit.jupiter.api.Assertions.assertTrue;
34+
import static org.assertj.core.api.Assertions.assertThat;
3535
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
3636

3737

@@ -58,11 +58,11 @@ void init(){
5858
public void testIndex() throws Exception {
5959
HttpStatus httpStatusMono = webClient.get().uri("/")
6060
.exchangeToMono(clientResponse -> Mono.just(clientResponse.statusCode())).block();
61-
assertTrue(httpStatusMono.equals(HttpStatus.TEMPORARY_REDIRECT));
61+
assertThat(httpStatusMono).isEqualTo(HttpStatus.FOUND);
6262

6363
httpStatusMono = webClient.get().uri("/webjars/swagger-ui/index.html")
6464
.exchangeToMono(clientResponse -> Mono.just(clientResponse.statusCode())).block();
65-
assertTrue(httpStatusMono.equals(HttpStatus.OK));
65+
assertThat(httpStatusMono).isEqualTo(HttpStatus.OK);
6666

6767
String contentAsString = webClient.get().uri("/v3/api-docs/swagger-config").retrieve()
6868
.bodyToMono(String.class).block();

springdoc-openapi-webflux-ui/src/test/java/test/org/springdoc/ui/app20/SpringDocApp20Test.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import javax.annotation.PostConstruct;
2323

24-
import org.junit.jupiter.api.Assertions;
2524
import org.junit.jupiter.api.Test;
2625
import reactor.core.publisher.Mono;
2726
import test.org.springdoc.ui.AbstractCommonTest;
@@ -33,6 +32,7 @@
3332
import org.springframework.http.HttpStatus;
3433
import org.springframework.web.reactive.function.client.WebClient;
3534

35+
import static org.assertj.core.api.Assertions.assertThat;
3636
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
3737

3838

@@ -58,11 +58,11 @@ void init(){
5858
public void testIndex() throws Exception {
5959
HttpStatus httpStatusMono = webClient.get().uri("/test/swagger-ui.html")
6060
.exchangeToMono(clientResponse -> Mono.just(clientResponse.statusCode())).block();
61-
Assertions.assertTrue(httpStatusMono.equals(HttpStatus.TEMPORARY_REDIRECT));
61+
assertThat(httpStatusMono).isEqualTo(HttpStatus.FOUND);
6262

6363
httpStatusMono = webClient.get().uri("/webjars/swagger-ui/index.html")
6464
.exchangeToMono(clientResponse -> Mono.just(clientResponse.statusCode())).block();
65-
Assertions.assertTrue(httpStatusMono.equals(HttpStatus.OK));
65+
assertThat(httpStatusMono).isEqualTo(HttpStatus.OK);
6666

6767
String contentAsString = webClient.get().uri("/test/v3/api-docs/swagger-config").retrieve()
6868
.bodyToMono(String.class).block();

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

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

3636
@Test
37-
public void shouldRedirectWithDefaultQueryParams() throws Exception {
37+
public void shouldRedirectWithDefaultQueryParams() {
3838
WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/documentation/swagger-ui.html").exchange()
39-
.expectStatus().isTemporaryRedirect();
39+
.expectStatus().isFound();
4040
responseSpec.expectHeader()
4141
.value("Location", Matchers.is("/documentation/webjars/swagger-ui/index.html?configUrl=/documentation/v3/api-docs/swagger-config"));
4242

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

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

3636
@Test
37-
public void shouldRedirectWithPrefix() throws Exception {
37+
public void shouldRedirectWithPrefix() {
3838
WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/documentation/swagger-ui.html").exchange()
39-
.expectStatus().isTemporaryRedirect();
39+
.expectStatus().isFound();
4040
responseSpec.expectHeader()
4141
.value("Location", Matchers.is("/documentation/webjars-pref/swagger-ui/index.html?configUrl=/documentation/v3/api-docs/swagger-config"));
4242
webTestClient.get().uri("/documentation/webjars-pref/swagger-ui/index.html").exchange()

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

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

3333
@Test
34-
public void shouldDisplaySwaggerUiPage() throws Exception {
34+
public void shouldDisplaySwaggerUiPage() {
3535
webTestClient.get().uri("/documentation/swagger-ui.html").exchange()
36-
.expectStatus().isTemporaryRedirect();
36+
.expectStatus().isFound();
3737
webTestClient.get().uri("/documentation/webjars/swagger-ui/index.html").exchange()
3838
.expectStatus().isOk();
3939
}

0 commit comments

Comments
 (0)