Skip to content

Commit 97f7e82

Browse files
committed
Missing paths after upgrading from Spring Docs 1.5.13 to 1.6.0. Fixes #1381
1 parent 6478bf7 commit 97f7e82

File tree

5 files changed

+50
-13
lines changed

5 files changed

+50
-13
lines changed

springdoc-openapi-common/src/main/java/org/springdoc/core/SpringDocConfiguration.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ static BeanFactoryPostProcessor springdocBeanFactoryPostProcessor3(List<GroupedO
400400
*/
401401
@Bean
402402
@Lazy(false)
403+
@ConditionalOnMissingBean
404+
@ConditionalOnManagementPort(ManagementPortType.SAME)
403405
OperationCustomizer actuatorCustomizer() {
404406
return new ActuatorOperationCustomizer();
405407
}
@@ -412,6 +414,8 @@ OperationCustomizer actuatorCustomizer() {
412414
*/
413415
@Bean
414416
@Lazy(false)
417+
@ConditionalOnMissingBean
418+
@ConditionalOnManagementPort(ManagementPortType.SAME)
415419
OpenApiCustomiser actuatorOpenApiCustomiser(WebEndpointProperties webEndpointProperties) {
416420
return new ActuatorOpenApiCustomizer(webEndpointProperties);
417421
}

springdoc-openapi-common/src/main/java/org/springdoc/core/SpringdocActuatorBeanFactoryConfigurer.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,17 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
6969
WebEndpointProperties webEndpointProperties = result.get();
7070

7171
List<GroupedOpenApi> newGroups = new ArrayList<>();
72+
73+
ActuatorOpenApiCustomizer actuatorOpenApiCustomiser = new ActuatorOpenApiCustomizer(webEndpointProperties);
74+
beanFactory.registerSingleton("actuatorOpenApiCustomiser", actuatorOpenApiCustomiser);
75+
ActuatorOperationCustomizer actuatorCustomizer = new ActuatorOperationCustomizer();
76+
beanFactory.registerSingleton("actuatorCustomizer", actuatorCustomizer);
77+
7278
GroupedOpenApi actuatorGroup = GroupedOpenApi.builder().group(ACTUATOR_DEFAULT_GROUP)
7379
.pathsToMatch(webEndpointProperties.getBasePath() + ALL_PATTERN)
7480
.pathsToExclude(webEndpointProperties.getBasePath() + HEALTH_PATTERN)
75-
.addOperationCustomizer(new ActuatorOperationCustomizer())
76-
.addOpenApiCustomiser(new ActuatorOpenApiCustomizer(webEndpointProperties))
81+
.addOperationCustomizer(actuatorCustomizer)
82+
.addOpenApiCustomiser(actuatorOpenApiCustomiser)
7783
.build();
7884
// Add the actuator group
7985
newGroups.add(actuatorGroup);

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.util.regex.Matcher;
66
import java.util.regex.Pattern;
77

8-
import io.swagger.v3.core.filter.SpecFilter;
98
import io.swagger.v3.oas.models.OpenAPI;
109
import io.swagger.v3.oas.models.PathItem;
1110
import io.swagger.v3.oas.models.media.StringSchema;
@@ -15,11 +14,13 @@
1514
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
1615
import org.springframework.util.CollectionUtils;
1716

17+
import static org.springframework.util.AntPathMatcher.DEFAULT_PATH_SEPARATOR;
18+
1819
/**
1920
* The type Actuator open api customiser.
2021
* @author bnasslahsen
2122
*/
22-
public class ActuatorOpenApiCustomizer extends SpecFilter implements OpenApiCustomiser {
23+
public class ActuatorOpenApiCustomizer implements OpenApiCustomiser {
2324

2425
/**
2526
* The Path pathern.
@@ -34,9 +35,9 @@ public ActuatorOpenApiCustomizer(WebEndpointProperties webEndpointProperties) {
3435

3536
@Override
3637
public void customise(OpenAPI openApi) {
37-
if (!CollectionUtils.isEmpty(openApi.getPaths())) {
38-
openApi.getPaths().entrySet().removeIf(path -> !path.getKey().startsWith(webEndpointProperties.getBasePath()));
38+
if (!CollectionUtils.isEmpty(openApi.getPaths()))
3939
openApi.getPaths().entrySet().stream()
40+
.filter(stringPathItemEntry -> stringPathItemEntry.getKey().startsWith(webEndpointProperties.getBasePath() + DEFAULT_PATH_SEPARATOR))
4041
.forEach(stringPathItemEntry -> {
4142
String path = stringPathItemEntry.getKey();
4243
Matcher matcher = pathPathern.matcher(path);
@@ -53,10 +54,5 @@ public void customise(OpenAPI openApi) {
5354
});
5455
}
5556
});
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()))));
60-
super.removeBrokenReferenceDefinitions(openApi);
6157
}
6258
}

springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app68/SpringDocApp68Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void testActuator() throws Exception {
8383
public void testActuatorDescription() throws Exception {
8484
mockMvc.perform(get(Constants.DEFAULT_API_DOCS_URL)).andExpect(status().isOk())
8585
.andExpect(jsonPath("$.openapi", is("3.0.1")))
86-
.andExpect(jsonPath("$.tags", hasSize(1)))
86+
.andExpect(jsonPath("$.tags", hasSize(4)))
8787
.andExpect(jsonPath("$.tags[?(@.name == '" + Constants.SPRINGDOC_ACTUATOR_TAG + "')].name", contains(Constants.SPRINGDOC_ACTUATOR_TAG)))
8888
.andExpect(jsonPath("$.tags[?(@.name == '" + Constants.SPRINGDOC_ACTUATOR_TAG + "')].description", contains(Constants.SPRINGDOC_ACTUATOR_DESCRIPTION)))
8989
.andExpect(jsonPath("$.tags[?(@.name == '" + Constants.SPRINGDOC_ACTUATOR_TAG + "')].externalDocs.description", contains(Constants.SPRINGDOC_ACTUATOR_DOC_DESCRIPTION)))

springdoc-openapi-webmvc-core/src/test/resources/results/app172.json

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,37 @@
1010
"description": "Generated server url"
1111
}
1212
],
13-
"paths": {},
13+
"paths": {
14+
"/customer/{id}": {
15+
"get": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "getTenantById",
20+
"parameters": [
21+
{
22+
"name": "id",
23+
"in": "path",
24+
"required": true,
25+
"schema": {
26+
"type": "string"
27+
}
28+
}
29+
],
30+
"responses": {
31+
"200": {
32+
"description": "OK",
33+
"content": {
34+
"*/*": {
35+
"schema": {
36+
"type": "string"
37+
}
38+
}
39+
}
40+
}
41+
}
42+
}
43+
}
44+
},
1445
"components": {}
1546
}

0 commit comments

Comments
 (0)