Skip to content

Commit 6478bf7

Browse files
committed
Tests failing after upgrading from 1.5.13 to 1.6.0. #1380.
1 parent 13b879c commit 6478bf7

File tree

4 files changed

+135
-22
lines changed

4 files changed

+135
-22
lines changed

springdoc-openapi-common/src/main/java/org/springdoc/core/customizers/ActuatorOpenApiCustomizer.java

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,29 @@ public ActuatorOpenApiCustomizer(WebEndpointProperties webEndpointProperties) {
3434

3535
@Override
3636
public void customise(OpenAPI openApi) {
37-
openApi.getPaths().entrySet().removeIf(path -> !path.getKey().startsWith(webEndpointProperties.getBasePath()));
38-
openApi.getTags().removeIf(tag -> openApi.getPaths().entrySet().stream().anyMatch(pathItemEntry -> pathItemEntry.getValue().
39-
readOperations().stream().noneMatch(operation -> operation.getTags().contains(tag.getName()))));
40-
41-
openApi.getPaths().entrySet().stream()
42-
.forEach(stringPathItemEntry -> {
43-
String path = stringPathItemEntry.getKey();
44-
Matcher matcher = pathPathern.matcher(path);
45-
while (matcher.find()) {
46-
String pathParam = matcher.group(1);
47-
PathItem pathItem = stringPathItemEntry.getValue();
48-
pathItem.readOperations().forEach(operation -> {
49-
List<Parameter> existingParameters = operation.getParameters();
50-
Optional<Parameter> existingParam = Optional.empty();
51-
if (!CollectionUtils.isEmpty(existingParameters))
52-
existingParam = existingParameters.stream().filter(p -> pathParam.equals(p.getName())).findAny();
53-
if (!existingParam.isPresent())
54-
operation.addParametersItem(new PathParameter().name(pathParam).schema(new StringSchema()));
55-
});
56-
}
57-
});
58-
37+
if (!CollectionUtils.isEmpty(openApi.getPaths())) {
38+
openApi.getPaths().entrySet().removeIf(path -> !path.getKey().startsWith(webEndpointProperties.getBasePath()));
39+
openApi.getPaths().entrySet().stream()
40+
.forEach(stringPathItemEntry -> {
41+
String path = stringPathItemEntry.getKey();
42+
Matcher matcher = pathPathern.matcher(path);
43+
while (matcher.find()) {
44+
String pathParam = matcher.group(1);
45+
PathItem pathItem = stringPathItemEntry.getValue();
46+
pathItem.readOperations().forEach(operation -> {
47+
List<Parameter> existingParameters = operation.getParameters();
48+
Optional<Parameter> existingParam = Optional.empty();
49+
if (!CollectionUtils.isEmpty(existingParameters))
50+
existingParam = existingParameters.stream().filter(p -> pathParam.equals(p.getName())).findAny();
51+
if (!existingParam.isPresent())
52+
operation.addParametersItem(new PathParameter().name(pathParam).schema(new StringSchema()));
53+
});
54+
}
55+
});
56+
}
57+
if (!CollectionUtils.isEmpty(openApi.getTags()))
58+
openApi.getTags().removeIf(tag -> openApi.getPaths().entrySet().stream().anyMatch(pathItemEntry -> pathItemEntry.getValue().
59+
readOperations().stream().noneMatch(operation -> operation.getTags().contains(tag.getName()))));
5960
super.removeBrokenReferenceDefinitions(openApi);
6061
}
6162
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.api.app172;
20+
21+
22+
import org.springframework.web.bind.annotation.GetMapping;
23+
import org.springframework.web.bind.annotation.PathVariable;
24+
import org.springframework.web.bind.annotation.RestController;
25+
26+
@RestController
27+
public class HelloController {
28+
29+
@GetMapping("/customer/{id}")
30+
public String getTenantById(@PathVariable("id") String customerId) {
31+
return "Tenant_" + customerId;
32+
}
33+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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.api.app172;
20+
21+
import org.junit.jupiter.api.Test;
22+
import org.springdoc.core.Constants;
23+
import org.springdoc.core.GroupedOpenApi;
24+
import org.springdoc.core.customizers.OpenApiCustomiser;
25+
import org.springdoc.core.customizers.OperationCustomizer;
26+
import test.org.springdoc.api.AbstractSpringDocTest;
27+
28+
import org.springframework.boot.autoconfigure.SpringBootApplication;
29+
import org.springframework.context.annotation.Bean;
30+
import org.springframework.test.context.TestPropertySource;
31+
32+
import static org.hamcrest.Matchers.is;
33+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
34+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
35+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
36+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
37+
38+
@TestPropertySource(properties = { "springdoc.show-actuator=true",
39+
"management.endpoints.web.exposure.include = tenant" })
40+
public class SpringDocApp172Test extends AbstractSpringDocTest {
41+
42+
@SpringBootApplication
43+
static class SpringDocTestApp {
44+
@Bean
45+
public GroupedOpenApi actuatorApi(OpenApiCustomiser actuatorOpenApiCustomiser, OperationCustomizer actuatorCustomizer) {
46+
return GroupedOpenApi.builder()
47+
.group("sample-group")
48+
.packagesToScan("test.org.springdoc.api.app172")
49+
.addOpenApiCustomiser(actuatorOpenApiCustomiser)
50+
.addOperationCustomizer(actuatorCustomizer)
51+
.pathsToExclude("/health/*")
52+
.build();
53+
}
54+
}
55+
56+
@Test
57+
public void testApp() throws Exception {
58+
mockMvc.perform(get(Constants.DEFAULT_API_DOCS_URL + "/sample-group"))
59+
.andExpect(jsonPath("$.openapi", is("3.0.1")))
60+
.andExpect(status().isOk())
61+
.andExpect(content().json(getContent("results/app172.json"), true));
62+
}
63+
64+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "OpenAPI definition",
5+
"version": "v0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"paths": {},
14+
"components": {}
15+
}

0 commit comments

Comments
 (0)