88import io .swagger .v3 .oas .annotations .Hidden ;
99import io .swagger .v3 .oas .annotations .Operation ;
1010import io .swagger .v3 .oas .models .OpenAPI ;
11- import org .springdoc .core .*;
11+ import org .springdoc .core .AbstractRequestBuilder ;
12+ import org .springdoc .core .AbstractResponseBuilder ;
13+ import org .springdoc .core .OpenAPIBuilder ;
14+ import org .springdoc .core .OperationBuilder ;
15+ import org .springdoc .core .SecurityOAuth2Provider ;
1216import org .springdoc .core .customizers .OpenApiCustomiser ;
1317import org .springframework .beans .factory .annotation .Value ;
1418import org .springframework .core .annotation .AnnotationUtils ;
2327import org .springframework .web .servlet .mvc .method .RequestMappingInfoHandlerMapping ;
2428
2529import javax .servlet .http .HttpServletRequest ;
26- import java .util .*;
27-
28- import static org .springdoc .core .Constants .*;
30+ import java .util .HashSet ;
31+ import java .util .LinkedHashMap ;
32+ import java .util .List ;
33+ import java .util .Map ;
34+ import java .util .Optional ;
35+ import java .util .Set ;
36+
37+ import static org .springdoc .core .Constants .API_DOCS_URL ;
38+ import static org .springdoc .core .Constants .APPLICATION_OPENAPI_YAML ;
39+ import static org .springdoc .core .Constants .DEFAULT_API_DOCS_URL_YAML ;
2940import static org .springframework .util .AntPathMatcher .DEFAULT_PATH_SEPARATOR ;
3041
3142@ RestController
@@ -35,9 +46,6 @@ public class OpenApiResource extends AbstractOpenApiResource {
3546
3647 private final Optional <ActuatorProvider > servletContextProvider ;
3748
38- @ Value (SPRINGDOC_SHOW_ACTUATOR_VALUE )
39- private boolean showActuator ;
40-
4149 public OpenApiResource (OpenAPIBuilder openAPIBuilder , AbstractRequestBuilder requestBuilder ,
4250 AbstractResponseBuilder responseBuilder , OperationBuilder operationParser ,
4351 RequestMappingInfoHandlerMapping requestMappingHandlerMapping , Optional <ActuatorProvider > servletContextProvider ,
@@ -51,11 +59,10 @@ public OpenApiResource(OpenAPIBuilder openAPIBuilder, AbstractRequestBuilder req
5159 AbstractResponseBuilder responseBuilder , OperationBuilder operationParser ,
5260 RequestMappingInfoHandlerMapping requestMappingHandlerMapping , Optional <ActuatorProvider > servletContextProvider ,
5361 Optional <List <OpenApiCustomiser >> openApiCustomisers , List <String > pathsToMatch , List <String > packagesToScan ,
54- boolean showActuator , boolean cacheDisabled ) {
55- super (openAPIBuilder , requestBuilder , responseBuilder , operationParser , openApiCustomisers , pathsToMatch , packagesToScan ,cacheDisabled );
62+ boolean cacheDisabled ) {
63+ super (openAPIBuilder , requestBuilder , responseBuilder , operationParser , openApiCustomisers , pathsToMatch , packagesToScan , cacheDisabled );
5664 this .requestMappingHandlerMapping = requestMappingHandlerMapping ;
5765 this .servletContextProvider = servletContextProvider ;
58- this .showActuator = showActuator ;
5966 }
6067
6168 @ Operation (hidden = true )
@@ -79,23 +86,23 @@ public String openapiYaml(HttpServletRequest request, @Value(DEFAULT_API_DOCS_UR
7986 @ Override
8087 protected void getPaths (Map <String , Object > restControllers ) {
8188 Map <RequestMappingInfo , HandlerMethod > map = requestMappingHandlerMapping .getHandlerMethods ();
82- calculatePath (restControllers , map );
83- if ( showActuator && servletContextProvider . isPresent ()) {
84- map = servletContextProvider .get (). getWebMvcHandlerMapping (). getHandlerMethods ();
85- Set < HandlerMethod > handlerMethods = new HashSet <>( map . values () );
86- this .openAPIBuilder .addTag (handlerMethods , SPRINGDOC_ACTUATOR_TAG );
87- calculatePath (restControllers , map );
89+ calculatePath (restControllers , map , Optional . empty () );
90+
91+ if ( servletContextProvider .isPresent ()){
92+ map = servletContextProvider . get (). getMethods ( );
93+ this .openAPIBuilder .addTag (new HashSet <>( map . values ()), servletContextProvider . get (). getTag () );
94+ calculatePath (restControllers , map , servletContextProvider );
8895 }
8996 Optional <SecurityOAuth2Provider > securityOAuth2ProviderOptional = openAPIBuilder .getSpringSecurityOAuth2Provider ();
9097 if (securityOAuth2ProviderOptional .isPresent ()) {
9198 SecurityOAuth2Provider securityOAuth2Provider = securityOAuth2ProviderOptional .get ();
9299 Map <RequestMappingInfo , HandlerMethod > mapOauth = securityOAuth2Provider .getHandlerMethods ();
93100 Map <String , Object > requestMappingMapSec = securityOAuth2Provider .getFrameworkEndpoints ();
94- calculatePath (requestMappingMapSec , mapOauth );
101+ calculatePath (requestMappingMapSec , mapOauth , Optional . empty () );
95102 }
96103 }
97104
98- private void calculatePath (Map <String , Object > restControllers , Map <RequestMappingInfo , HandlerMethod > map ) {
105+ private void calculatePath (Map <String , Object > restControllers , Map <RequestMappingInfo , HandlerMethod > map , Optional < ActuatorProvider > actuatorProvider ) {
99106 for (Map .Entry <RequestMappingInfo , HandlerMethod > entry : map .entrySet ()) {
100107 RequestMappingInfo requestMappingInfo = entry .getKey ();
101108 HandlerMethod handlerMethod = entry .getValue ();
@@ -104,7 +111,10 @@ private void calculatePath(Map<String, Object> restControllers, Map<RequestMappi
104111 Map <String , String > regexMap = new LinkedHashMap <>();
105112 for (String pattern : patterns ) {
106113 String operationPath = PathUtils .parsePath (pattern , regexMap );
107- if (isRestController (restControllers , handlerMethod , operationPath ) && isPackageToScan (handlerMethod .getBeanType ().getPackage ().getName ()) && isPathToMatch (operationPath )) {
114+ if ( ((actuatorProvider .isPresent () && actuatorProvider .get ().isRestController (restControllers , handlerMethod , operationPath ))
115+ || isRestController (restControllers , handlerMethod , operationPath ))
116+ && isPackageToScan (handlerMethod .getBeanType ().getPackage ().getName ())
117+ && isPathToMatch (operationPath )) {
108118 Set <RequestMethod > requestMethods = requestMappingInfo .getMethodsCondition ().getMethods ();
109119 calculatePath (openAPIBuilder , handlerMethod , operationPath , requestMethods );
110120 }
@@ -114,21 +124,13 @@ private void calculatePath(Map<String, Object> restControllers, Map<RequestMappi
114124
115125 private boolean isRestController (Map <String , Object > restControllers , HandlerMethod handlerMethod ,
116126 String operationPath ) {
117- boolean result ;
118- if (showActuator )
119- result = operationPath .startsWith (DEFAULT_PATH_SEPARATOR );
120- else {
121- ResponseBody responseBodyAnnotation = ReflectionUtils .getAnnotation (handlerMethod .getBeanType (),
122- ResponseBody .class );
123-
124- if (responseBodyAnnotation == null )
125- responseBodyAnnotation = ReflectionUtils .getAnnotation (handlerMethod .getMethod (), ResponseBody .class );
126- result = operationPath .startsWith (DEFAULT_PATH_SEPARATOR )
127- && (restControllers .containsKey (handlerMethod .getBean ().toString ())
128- || (responseBodyAnnotation != null && AnnotationUtils .findAnnotation (handlerMethod .getBeanType (), Hidden .class ) == null ));
129- }
127+ ResponseBody responseBodyAnnotation = ReflectionUtils .getAnnotation (handlerMethod .getBeanType (), ResponseBody .class );
130128
131- return result ;
129+ if (responseBodyAnnotation == null )
130+ responseBodyAnnotation = ReflectionUtils .getAnnotation (handlerMethod .getMethod (), ResponseBody .class );
131+ return operationPath .startsWith (DEFAULT_PATH_SEPARATOR )
132+ && (restControllers .containsKey (handlerMethod .getBean ().toString ())
133+ || (responseBodyAnnotation != null && AnnotationUtils .findAnnotation (handlerMethod .getBeanType (), Hidden .class ) == null ));
132134 }
133135
134136 private void calculateServerUrl (HttpServletRequest request , String apiDocsUrl ) {
0 commit comments