Skip to content

Commit 889d8dd

Browse files
committed
Only filter out actuator endpoints with double asterisks. Fixes #2817
All endpoints that contain a double-asterisks in the path are currently being excluded from the output Swagger definition, rather than just excluding match-all actuator endpoints. The endpoint matching is therefore being altered to pre-filter the actuator endpoints to remove any that contain a double-asterisks in the path, and remove the subsequent filtering of double asterisks in the combined endpoints list so that non-actuator endpoints aren't dropped by the actuator filtering.
1 parent d9520c1 commit 889d8dd

File tree

5 files changed

+108
-2
lines changed

5 files changed

+108
-2
lines changed

Diff for: springdoc-openapi-starter-common/src/main/java/org/springdoc/api/AbstractOpenApiResource.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,7 @@ protected void calculatePath(HandlerMethod handlerMethod, RouterOperation router
661661
}
662662

663663
PathItem pathItemObject = buildPathItem(requestMethod, operation, operationPath, paths);
664-
if (!StringUtils.contains(operationPath, "**"))
665-
paths.addPathItem(operationPath, pathItemObject);
664+
paths.addPathItem(operationPath, pathItemObject);
666665
}
667666
}
668667

Diff for: springdoc-openapi-starter-webmvc-api/src/main/java/org/springdoc/webmvc/api/OpenApiResource.java

+5
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ protected void getPaths(Map<String, Object> restControllers, Locale locale, Open
167167
Optional<ActuatorProvider> actuatorProviderOptional = springDocProviders.getActuatorProvider();
168168
if (actuatorProviderOptional.isPresent() && springDocConfigProperties.isShowActuator()) {
169169
Map<RequestMappingInfo, HandlerMethod> actuatorMap = actuatorProviderOptional.get().getMethods();
170+
List<RequestMappingInfo> globMatchActuators = actuatorMap.keySet().stream()
171+
.filter(requestMappingInfo -> requestMappingInfo.getPatternValues().stream()
172+
.anyMatch(patternValues -> patternValues.contains("**")))
173+
.toList();
174+
globMatchActuators.forEach(actuatorMap::remove);
170175
this.openAPIService.addTag(new HashSet<>(actuatorMap.values()), getTag());
171176
map.putAll(actuatorMap);
172177
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
*
3+
* * Copyright 2019-2025 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.v31.app240;
20+
21+
import test.org.springdoc.api.v31.AbstractSpringDocTest;
22+
23+
import org.springframework.boot.autoconfigure.SpringBootApplication;
24+
25+
public class SpringDocApp239Test extends AbstractSpringDocTest {
26+
27+
@SpringBootApplication
28+
static class SpringDocTestApp {
29+
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
*
3+
* * Copyright 2019-2025 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.v31.app240;
20+
21+
import io.swagger.v3.oas.annotations.Operation;
22+
import jakarta.servlet.http.HttpServletRequest;
23+
24+
import org.springframework.web.bind.annotation.PostMapping;
25+
import org.springframework.web.bind.annotation.RestController;
26+
27+
@RestController
28+
public class WildcardController {
29+
@PostMapping("/**")
30+
@Operation(summary = "My Wildcard Operation")
31+
public String getItem(HttpServletRequest request) {
32+
return request.getPathInfo();
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"openapi": "3.1.0",
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+
"/**": {
15+
"post": {
16+
"tags": [
17+
"wildcard-controller"
18+
],
19+
"summary": "My Wildcard Operation",
20+
"operationId": "getItem",
21+
"responses": {
22+
"200": {
23+
"description": "OK",
24+
"content": {
25+
"*/*": {
26+
"schema": {
27+
"type": "string"
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}
34+
}
35+
},
36+
"components": {}
37+
}

0 commit comments

Comments
 (0)