2626import org .springframework .web .servlet .mvc .method .RequestMappingInfoHandlerMapping ;
2727
2828import javax .servlet .http .HttpServletRequest ;
29- import java .util .*;
30-
31- import static org .springdoc .core .Constants .*;
29+ import java .util .HashSet ;
30+ import java .util .LinkedHashMap ;
31+ import java .util .List ;
32+ import java .util .Map ;
33+ import java .util .Optional ;
34+ import java .util .Set ;
35+
36+ import static org .springdoc .core .Constants .API_DOCS_URL ;
37+ import static org .springdoc .core .Constants .APPLICATION_OPENAPI_YAML ;
38+ import static org .springdoc .core .Constants .DEFAULT_API_DOCS_URL_YAML ;
3239import static org .springframework .util .AntPathMatcher .DEFAULT_PATH_SEPARATOR ;
3340
3441@ RestController
@@ -38,9 +45,6 @@ public class OpenApiResource extends AbstractOpenApiResource {
3845
3946 private final Optional <ActuatorProvider > servletContextProvider ;
4047
41- @ Value (SPRINGDOC_SHOW_ACTUATOR_VALUE )
42- private boolean showActuator ;
43-
4448 public OpenApiResource (OpenAPIBuilder openAPIBuilder , AbstractRequestBuilder requestBuilder ,
4549 AbstractResponseBuilder responseBuilder , OperationBuilder operationParser ,
4650 RequestMappingInfoHandlerMapping requestMappingHandlerMapping , Optional <ActuatorProvider > servletContextProvider ,
@@ -53,12 +57,10 @@ public OpenApiResource(OpenAPIBuilder openAPIBuilder, AbstractRequestBuilder req
5357 public OpenApiResource (OpenAPIBuilder openAPIBuilder , AbstractRequestBuilder requestBuilder ,
5458 AbstractResponseBuilder responseBuilder , OperationBuilder operationParser ,
5559 RequestMappingInfoHandlerMapping requestMappingHandlerMapping , Optional <ActuatorProvider > servletContextProvider ,
56- Optional <List <OpenApiCustomiser >> openApiCustomisers , List <String > pathsToMatch , List <String > packagesToScan ,
57- boolean showActuator ) {
60+ Optional <List <OpenApiCustomiser >> openApiCustomisers , List <String > pathsToMatch , List <String > packagesToScan ) {
5861 super (openAPIBuilder , requestBuilder , responseBuilder , operationParser , openApiCustomisers , pathsToMatch , packagesToScan );
5962 this .requestMappingHandlerMapping = requestMappingHandlerMapping ;
6063 this .servletContextProvider = servletContextProvider ;
61- this .showActuator = showActuator ;
6264 }
6365
6466 @ Operation (hidden = true )
@@ -82,16 +84,16 @@ public String openapiYaml(HttpServletRequest request, @Value(DEFAULT_API_DOCS_UR
8284 @ Override
8385 protected void getPaths (Map <String , Object > restControllers ) {
8486 Map <RequestMappingInfo , HandlerMethod > map = requestMappingHandlerMapping .getHandlerMethods ();
85- calculatePath (restControllers , map );
86- if ( showActuator && servletContextProvider . isPresent ()) {
87- map = servletContextProvider .get (). getWebMvcHandlerMapping (). getHandlerMethods ();
88- Set < HandlerMethod > handlerMethods = new HashSet <>( map . values () );
89- this .openAPIBuilder .addTag (handlerMethods , SPRINGDOC_ACTUATOR_TAG );
90- calculatePath (restControllers , map );
87+ calculatePath (restControllers , map , Optional . empty () );
88+
89+ if ( servletContextProvider .isPresent ()){
90+ map = servletContextProvider . get (). getMethods ( );
91+ this .openAPIBuilder .addTag (new HashSet <>( map . values ()), servletContextProvider . get (). getTag () );
92+ calculatePath (restControllers , map , servletContextProvider );
9193 }
9294 }
9395
94- private void calculatePath (Map <String , Object > restControllers , Map <RequestMappingInfo , HandlerMethod > map ) {
96+ private void calculatePath (Map <String , Object > restControllers , Map <RequestMappingInfo , HandlerMethod > map , Optional < ActuatorProvider > actuatorProvider ) {
9597 for (Map .Entry <RequestMappingInfo , HandlerMethod > entry : map .entrySet ()) {
9698 RequestMappingInfo requestMappingInfo = entry .getKey ();
9799 HandlerMethod handlerMethod = entry .getValue ();
@@ -100,7 +102,10 @@ private void calculatePath(Map<String, Object> restControllers, Map<RequestMappi
100102 Map <String , String > regexMap = new LinkedHashMap <>();
101103 for (String pattern : patterns ) {
102104 String operationPath = PathUtils .parsePath (pattern , regexMap );
103- if (isRestController (restControllers , handlerMethod , operationPath ) && isPackageToScan (handlerMethod .getBeanType ().getPackage ().getName ()) && isPathToMatch (operationPath )) {
105+ if ( ((actuatorProvider .isPresent () && actuatorProvider .get ().isRestController (restControllers , handlerMethod , operationPath ))
106+ || isRestController (restControllers , handlerMethod , operationPath ))
107+ && isPackageToScan (handlerMethod .getBeanType ().getPackage ().getName ())
108+ && isPathToMatch (operationPath )) {
104109 Set <RequestMethod > requestMethods = requestMappingInfo .getMethodsCondition ().getMethods ();
105110 calculatePath (openAPIBuilder , handlerMethod , operationPath , requestMethods );
106111 }
@@ -110,21 +115,13 @@ private void calculatePath(Map<String, Object> restControllers, Map<RequestMappi
110115
111116 private boolean isRestController (Map <String , Object > restControllers , HandlerMethod handlerMethod ,
112117 String operationPath ) {
113- boolean result ;
114- if (showActuator )
115- result = operationPath .startsWith (DEFAULT_PATH_SEPARATOR );
116- else {
117- ResponseBody responseBodyAnnotation = ReflectionUtils .getAnnotation (handlerMethod .getBeanType (),
118- ResponseBody .class );
119-
120- if (responseBodyAnnotation == null )
121- responseBodyAnnotation = ReflectionUtils .getAnnotation (handlerMethod .getMethod (), ResponseBody .class );
122- result = operationPath .startsWith (DEFAULT_PATH_SEPARATOR )
123- && (restControllers .containsKey (handlerMethod .getBean ().toString ())
124- || (responseBodyAnnotation != null && AnnotationUtils .findAnnotation (handlerMethod .getBeanType (), Hidden .class ) == null ));
125- }
118+ ResponseBody responseBodyAnnotation = ReflectionUtils .getAnnotation (handlerMethod .getBeanType (), ResponseBody .class );
126119
127- return result ;
120+ if (responseBodyAnnotation == null )
121+ responseBodyAnnotation = ReflectionUtils .getAnnotation (handlerMethod .getMethod (), ResponseBody .class );
122+ return operationPath .startsWith (DEFAULT_PATH_SEPARATOR )
123+ && (restControllers .containsKey (handlerMethod .getBean ().toString ())
124+ || (responseBodyAnnotation != null && AnnotationUtils .findAnnotation (handlerMethod .getBeanType (), Hidden .class ) == null ));
128125 }
129126
130127 private void calculateServerUrl (HttpServletRequest request , String apiDocsUrl ) {
0 commit comments