Skip to content

Commit 3237787

Browse files
committed
code review
1 parent ad86c0a commit 3237787

File tree

3 files changed

+96
-1
lines changed

3 files changed

+96
-1
lines changed

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/AbstractRequestService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ private boolean isRequestBodyWithMapType(MethodParameter parameter) {
483483
return false;
484484
}
485485
Class<?> parameterType = parameter.getParameterType();
486-
return parameterType == java.util.Map.class;
486+
return Map.class.isAssignableFrom(parameterType);
487487
}
488488

489489
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.ui.app32;
20+
21+
import jakarta.annotation.PostConstruct;
22+
import org.junit.jupiter.api.Test;
23+
import reactor.core.publisher.Mono;
24+
import test.org.springdoc.ui.AbstractCommonTest;
25+
import test.org.springdoc.ui.AbstractSpringDocTest;
26+
27+
import org.springframework.boot.autoconfigure.SpringBootApplication;
28+
import org.springframework.boot.test.context.SpringBootTest;
29+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
30+
import org.springframework.boot.test.web.server.LocalServerPort;
31+
import org.springframework.context.annotation.Import;
32+
import org.springframework.http.HttpStatus;
33+
import org.springframework.http.HttpStatusCode;
34+
import org.springframework.test.context.TestPropertySource;
35+
import org.springframework.web.reactive.function.client.WebClient;
36+
37+
import static org.assertj.core.api.Assertions.assertThat;
38+
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
39+
40+
41+
@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT,
42+
properties = { "spring.webflux.base-path=/test",
43+
"server.forward-headers-strategy=framework",
44+
"server.port=9318",
45+
"springdoc.swagger-ui.path=/documentation/swagger-ui.html",
46+
"springdoc.api-docs.path=/documentation/v3/api-docs",
47+
"springdoc.webjars.prefix= /webjars-pref" })
48+
49+
@Import(SpringDocConfig.class)
50+
public class SpringDocBehindProxyBasePathTest extends AbstractCommonTest {
51+
52+
private static final String X_FORWARD_PREFIX = "/path/prefix";
53+
54+
@LocalServerPort
55+
private int port;
56+
57+
private WebClient webClient;
58+
59+
@PostConstruct
60+
void init() {
61+
webClient = WebClient.builder().baseUrl("http://localhost:" + port)
62+
.build();
63+
}
64+
65+
@Test
66+
public void testIndex() throws Exception {
67+
HttpStatusCode httpStatusMono = webClient.get().uri("/test/documentation/swagger-ui.html")
68+
.header("X-Forwarded-Prefix", X_FORWARD_PREFIX)
69+
.exchangeToMono(clientResponse -> Mono.just(clientResponse.statusCode())).block();
70+
assertThat(httpStatusMono).isEqualTo(HttpStatus.FOUND);
71+
72+
httpStatusMono = webClient.get().uri("/test/documentation/webjars-pref/swagger-ui/index.html")
73+
.header("X-Forwarded-Prefix", X_FORWARD_PREFIX)
74+
.exchangeToMono(clientResponse -> Mono.just(clientResponse.statusCode())).block();
75+
assertThat(httpStatusMono).isEqualTo(HttpStatus.OK);
76+
77+
String contentAsString = webClient.get().uri("/test/documentation/v3/api-docs/swagger-config")
78+
.header("X-Forwarded-Prefix", X_FORWARD_PREFIX)
79+
.retrieve()
80+
.bodyToMono(String.class).block();
81+
String expected = getContent("results/app32-1.json");
82+
assertEquals(expected, contentAsString, true);
83+
}
84+
85+
86+
87+
@SpringBootApplication
88+
static class SpringDocTestApp {}
89+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"configUrl": "/path/prefix/documentation/v3/api-docs/swagger-config",
3+
"oauth2RedirectUrl": "http://localhost:9318/path/prefix/documentation/webjars-pref/swagger-ui/oauth2-redirect.html",
4+
"url": "/path/prefix/documentation/v3/api-docs",
5+
"validatorUrl": ""
6+
}

0 commit comments

Comments
 (0)