Skip to content

Commit 5367f71

Browse files
committed
report changes: #2213
1 parent bb6baa4 commit 5367f71

File tree

4 files changed

+74
-3
lines changed

4 files changed

+74
-3
lines changed

springdoc-openapi-starter-common/src/main/java/org/springdoc/ui/AbstractSwaggerWelcome.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,11 @@ else if (swaggerUiConfigParameters.isValidUrl(swaggerUiUrl))
134134
else
135135
swaggerUiConfigParameters.addUrl(apiDocsUrl);
136136
if (!CollectionUtils.isEmpty(swaggerUiConfig.getUrls())) {
137-
swaggerUiConfigParameters.setUrls(swaggerUiConfig.cloneUrls());
138-
swaggerUiConfigParameters.getUrls().forEach(swaggerUrl -> {
137+
swaggerUiConfig.cloneUrls().forEach(swaggerUrl -> {
138+
swaggerUiConfigParameters.getUrls().remove(swaggerUrl);
139139
if (!swaggerUiConfigParameters.isValidUrl(swaggerUrl.getUrl()))
140140
swaggerUrl.setUrl(buildUrlWithContextPath(swaggerUrl.getUrl()));
141+
swaggerUiConfigParameters.getUrls().add(swaggerUrl);
141142
});
142143
}
143144
}

springdoc-openapi-starter-webmvc-ui/src/test/java/test/org/springdoc/ui/app1/SpringDocSwaggerConfigTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@
2323

2424
import org.springframework.boot.autoconfigure.SpringBootApplication;
2525
import org.springframework.boot.test.context.SpringBootTest;
26+
import org.springframework.test.annotation.DirtiesContext;
2627

2728
import static org.hamcrest.CoreMatchers.equalTo;
2829
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
2930
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
3031
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
3132

3233

34+
@DirtiesContext
3335
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
3436
properties = { "spring.jackson.property-naming-strategy=UPPER_CAMEL_CASE", "springdoc.show-actuator=true",
3537
"management.endpoints.web.base-path=/management",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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.app1;
20+
21+
import org.junit.jupiter.api.Test;
22+
import test.org.springdoc.ui.AbstractSpringDocActuatorTest;
23+
24+
import org.springframework.boot.autoconfigure.SpringBootApplication;
25+
import org.springframework.boot.test.context.SpringBootTest;
26+
import org.springframework.test.annotation.DirtiesContext;
27+
28+
import static org.hamcrest.CoreMatchers.equalTo;
29+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
30+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
31+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
32+
33+
/*
34+
Test showing how specs generated at runtime and specs configured in can work at the same time.
35+
36+
The expectation is that the openapi.yml file will be shown together with the generated ones.
37+
*/
38+
@DirtiesContext
39+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
40+
properties = { "spring.jackson.property-naming-strategy=UPPER_CAMEL_CASE", "springdoc.show-actuator=true",
41+
"management.endpoints.web.base-path=/management",
42+
"server.servlet.context-path=/demo/api", "management.server.port=9002", "management.server.base-path=/demo/api",
43+
"springdoc.swagger-ui.urls[0].url=/api-docs/xxx/v1/openapi.yml",
44+
"springdoc.swagger-ui.urls[0].name=toto",
45+
})
46+
public class SpringDocSwaggerConfigWithBothFileGeneratedSpecsTest extends AbstractSpringDocActuatorTest {
47+
48+
@Test
49+
public void testIndexSwaggerConfig() throws Exception {
50+
mockMvc.perform(get("/demo/api/v3/api-docs/swagger-config").contextPath("/demo/api"))
51+
.andExpect(status().isOk())
52+
.andExpect(jsonPath("validatorUrl", equalTo("")))
53+
.andExpect(jsonPath("oauth2RedirectUrl", equalTo("http://localhost/demo/api/swagger-ui/oauth2-redirect.html")))
54+
.andExpect(jsonPath("url").doesNotExist())
55+
.andExpect(jsonPath("urls[0].url", equalTo("/demo/api/v3/api-docs/springdocDefault")))
56+
.andExpect(jsonPath("urls[0].name", equalTo("springdocDefault")))
57+
.andExpect(jsonPath("urls[1].url", equalTo("/demo/api/api-docs/xxx/v1/openapi.yml")))
58+
.andExpect(jsonPath("urls[1].name", equalTo("toto")))
59+
.andExpect(jsonPath("urls[2].url", equalTo("/demo/api/v3/api-docs/x-actuator")))
60+
.andExpect(jsonPath("urls[2].name", equalTo("x-actuator")));
61+
}
62+
63+
64+
@SpringBootApplication
65+
static class SpringDocTestApp {}
66+
67+
}

springdoc-openapi-tests/springdoc-openapi-actuator-webflux-tests/src/test/java/test/org/springdoc/api/app145/SpringDocApp1451Test.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@
2525
import org.springframework.boot.test.context.SpringBootTest;
2626
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
2727
import org.springframework.http.HttpStatus;
28+
import org.springframework.test.annotation.DirtiesContext;
2829
import org.springframework.web.reactive.function.client.WebClientResponseException;
2930

3031
import static org.junit.jupiter.api.Assertions.assertTrue;
3132
import static org.junit.jupiter.api.Assertions.fail;
3233
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
3334

34-
35+
@DirtiesContext
3536
@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT,
3637
properties = { "management.endpoints.web.exposure.include=*",
3738
"server.port=52594",

0 commit comments

Comments
 (0)