Skip to content

Commit 570e367

Browse files
dgswanDmitry Lebedko
authored and
Dmitry Lebedko
committed
Avoid mutation of org.springdoc.core.properties.AbstractSwaggerUiConfigProperties.urls and replace it with mutation of org.springdoc.core.properties.AbstractSwaggerUiConfigProperties.SwaggerUrl.url when necessary. Enhance SpringDocApp8MultipleUrlsSeveralParallelRequestsTest by specifying custom servlet path to check no exception is thrown.
1 parent da0eb3e commit 570e367

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,10 @@ else if (swaggerUiConfigParameters.isValidUrl(swaggerUiUrl))
142142
.forEach(swaggerUrl -> {
143143
final var url = buildUrlWithContextPath(swaggerUrl.getUrl());
144144
if (!Objects.equals(url, swaggerUrl.getUrl())) {
145-
swaggerUiConfigParameters.getUrls().remove(swaggerUrl);
146-
swaggerUrl.setUrl(url);
147-
swaggerUiConfigParameters.getUrls().add(swaggerUrl);
145+
swaggerUiConfigParameters.getUrls()
146+
.stream()
147+
.filter(swaggerUrl::equals)
148+
.forEach(subUrl -> subUrl.setUrl(url));
148149
}
149150
});
150151
}

springdoc-openapi-starter-webmvc-ui/src/test/java/test/org/springdoc/ui/app8/SpringDocApp8MultipleUrlsSeveralParallelRequestsTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
* @author Dmitry Lebedko (lebedko.dmitrii@gmail.com)
4242
*/
4343
@TestPropertySource(properties = {
44+
"spring.mvc.servlet.path=/servlet-path",
4445
"springdoc.swagger-ui.urls[0].name=first-user-list",
4546
"springdoc.swagger-ui.urls[0].url=/api-docs.yaml",
4647
"springdoc.swagger-ui.urls[1].name=second-user-list",
@@ -63,14 +64,14 @@ public void swagger_config_for_multiple_groups_and_many_parallel_requests() {
6364
try {
6465
mockMvc.perform(get("/v3/api-docs/swagger-config"))
6566
.andExpect(status().isOk())
66-
.andExpect(jsonPath("configUrl", equalTo("/v3/api-docs/swagger-config")))
67+
.andExpect(jsonPath("configUrl", equalTo("/servlet-path/v3/api-docs/swagger-config")))
6768
.andExpect(jsonPath("url").doesNotExist())
6869
.andExpect(jsonPath("urls.length()", equalTo(3)))
69-
.andExpect(jsonPath("urls[0].url", equalTo("/api-docs.yaml")))
70+
.andExpect(jsonPath("urls[0].url", equalTo("/servlet-path/api-docs.yaml")))
7071
.andExpect(jsonPath("urls[0].name", equalTo("first-user-list")))
71-
.andExpect(jsonPath("urls[1].url", equalTo("/api-docs.yaml")))
72+
.andExpect(jsonPath("urls[1].url", equalTo("/servlet-path/api-docs.yaml")))
7273
.andExpect(jsonPath("urls[1].name", equalTo("second-user-list")))
73-
.andExpect(jsonPath("urls[2].url", equalTo("/api-docs.yaml")))
74+
.andExpect(jsonPath("urls[2].url", equalTo("/servlet-path/api-docs.yaml")))
7475
.andExpect(jsonPath("urls[2].name", equalTo("third-user-list")));
7576
} catch (Exception e) {
7677
throw new RuntimeException(e);

0 commit comments

Comments
 (0)