5757import java .util .List ;
5858import java .util .Locale ;
5959import java .util .Map ;
60+ import java .util .Map .Entry ;
6061import java .util .Optional ;
6162import java .util .Properties ;
6263
8586import static io .micronaut .openapi .visitor .FileUtils .resolve ;
8687import static io .micronaut .openapi .visitor .OpenApiConfigProperty .ALL ;
8788import static io .micronaut .openapi .visitor .OpenApiConfigProperty .ENDPOINTS_EXTENSIONS ;
89+ import static io .micronaut .openapi .visitor .OpenApiConfigProperty .ENDPOINTS_GROUPS ;
90+ import static io .micronaut .openapi .visitor .OpenApiConfigProperty .ENDPOINTS_GROUPS_EXCLUDED ;
8891import static io .micronaut .openapi .visitor .OpenApiConfigProperty .ENDPOINTS_PATH ;
8992import static io .micronaut .openapi .visitor .OpenApiConfigProperty .ENDPOINTS_SECURITY_REQUIREMENTS ;
9093import static io .micronaut .openapi .visitor .OpenApiConfigProperty .ENDPOINTS_SERVERS ;
147150import static io .micronaut .openapi .visitor .UrlUtils .parsePath ;
148151import static io .micronaut .openapi .visitor .group .RouterVersioningProperties .DEFAULT_HEADER_NAME ;
149152import static io .micronaut .openapi .visitor .group .RouterVersioningProperties .DEFAULT_PARAMETER_NAME ;
153+ import static io .micronaut .openapi .visitor .management .EndpointUtils .ALL_MICRONAUT_MANAGEMENT_ENDPOINTS ;
154+ import static io .micronaut .openapi .visitor .management .SpringActuatorConfigUtils .mergeWithActuatorProperties ;
150155
151156/**
152157 * Configuration utilities methods.
157162public final class ConfigUtils {
158163
159164 public static final String ALL_ENDPOINTS_NAME = "all" ;
165+ public static final String ALL_SPRING_ACTUATOR_ENDPOINTS_NAME = "*" ;
160166
161167 private static final String LOADED_POSTFIX = ".loaded" ;
162168 private static final String VALUE_POSTFIX = ".value" ;
163169
164- public static final String ALL_ENDPOINTS_NAME = "all" ;
165-
166170 private static final List <String > DEFAULT_PREFIXES = List .of ("" );
167171 private static final List <String > DEFAULT_POSTFIXES = List .of ("controller" , "api" , "endpoints" , "endpoint" );
168172
@@ -200,22 +204,22 @@ public static SchemaDecorator getSchemaDecoration(String packageName, VisitorCon
200204 // third read environments properties
201205 Environment environment = getEnv (context );
202206 if (environment != null ) {
203- for (Map . Entry <String , Object > entry : environment .getProperties (MICRONAUT_OPENAPI_SCHEMA_PREFIX , StringConvention .RAW ).entrySet ()) {
207+ for (Entry <String , Object > entry : environment .getProperties (MICRONAUT_OPENAPI_SCHEMA_PREFIX , StringConvention .RAW ).entrySet ()) {
204208 SchemaDecorator decorator = schemaDecorators .computeIfAbsent (entry .getKey (), k -> new SchemaDecorator ());
205209 decorator .setPrefix ((String ) entry .getValue ());
206210 }
207211
208- for (Map . Entry <String , Object > entry : environment .getProperties (MICRONAUT_OPENAPI_SCHEMA_POSTFIX , StringConvention .RAW ).entrySet ()) {
212+ for (Entry <String , Object > entry : environment .getProperties (MICRONAUT_OPENAPI_SCHEMA_POSTFIX , StringConvention .RAW ).entrySet ()) {
209213 SchemaDecorator decorator = schemaDecorators .computeIfAbsent (entry .getKey (), k -> new SchemaDecorator ());
210214 decorator .setPostfix ((String ) entry .getValue ());
211215 }
212216
213- for (Map . Entry <String , Object > entry : environment .getProperties (MICRONAUT_OPENAPI_SCHEMA_DECORATOR_PREFIX , StringConvention .RAW ).entrySet ()) {
217+ for (Entry <String , Object > entry : environment .getProperties (MICRONAUT_OPENAPI_SCHEMA_DECORATOR_PREFIX , StringConvention .RAW ).entrySet ()) {
214218 SchemaDecorator decorator = schemaDecorators .computeIfAbsent (entry .getKey (), k -> new SchemaDecorator ());
215219 decorator .setPrefix ((String ) entry .getValue ());
216220 }
217221
218- for (Map . Entry <String , Object > entry : environment .getProperties (MICRONAUT_OPENAPI_SCHEMA_DECORATOR_POSTFIX , StringConvention .RAW ).entrySet ()) {
222+ for (Entry <String , Object > entry : environment .getProperties (MICRONAUT_OPENAPI_SCHEMA_DECORATOR_POSTFIX , StringConvention .RAW ).entrySet ()) {
219223 SchemaDecorator decorator = schemaDecorators .computeIfAbsent (entry .getKey (), k -> new SchemaDecorator ());
220224 decorator .setPostfix ((String ) entry .getValue ());
221225 }
@@ -254,7 +258,7 @@ public static ClassElement getCustomSchema(String className, Map<String, ClassEl
254258 // third read environments properties
255259 Environment environment = getEnv (context );
256260 if (environment != null ) {
257- for (Map . Entry <String , Object > entry : environment .getProperties (MICRONAUT_OPENAPI_SCHEMA , StringConvention .RAW ).entrySet ()) {
261+ for (Entry <String , Object > entry : environment .getProperties (MICRONAUT_OPENAPI_SCHEMA , StringConvention .RAW ).entrySet ()) {
258262
259263 String configuredClassName = entry .getKey ();
260264 // Remove this check, after we remove MICRONAUT_OPENAPI_SCHEMA property
@@ -266,7 +270,7 @@ public static ClassElement getCustomSchema(String className, Map<String, ClassEl
266270 String targetClassName = (String ) entry .getValue ();
267271 readCustomSchema (configuredClassName , targetClassName , customSchemas , context );
268272 }
269- for (Map . Entry <String , Object > entry : environment .getProperties (MICRONAUT_OPENAPI_SCHEMA_MAPPING , StringConvention .RAW ).entrySet ()) {
273+ for (Entry <String , Object > entry : environment .getProperties (MICRONAUT_OPENAPI_SCHEMA_MAPPING , StringConvention .RAW ).entrySet ()) {
270274 String configuredClassName = entry .getKey ();
271275
272276 // Remove this check, after we remove MICRONAUT_OPENAPI_SCHEMA property
@@ -512,14 +516,14 @@ public static List<Pair<String, String>> getExpandableProperties(VisitorContext
512516
513517 var expandedPropsMap = new HashMap <String , String >();
514518 if (CollectionUtils .isNotEmpty (propertiesFromEnv )) {
515- for (Map . Entry <String , Object > entry : propertiesFromEnv .entrySet ()) {
519+ for (Entry <String , Object > entry : propertiesFromEnv .entrySet ()) {
516520 expandedPropsMap .put (entry .getKey (), entry .getValue ().toString ());
517521 }
518522 }
519523
520524 // next, read openapi.properties file
521525 Properties openapiProps = readOpenApiConfigFile (context );
522- for (Map . Entry <Object , Object > entry : openapiProps .entrySet ()) {
526+ for (Entry <Object , Object > entry : openapiProps .entrySet ()) {
523527 String key = entry .getKey ().toString ();
524528 if (!key .startsWith (expandPrefix )) {
525529 continue ;
@@ -529,7 +533,7 @@ public static List<Pair<String, String>> getExpandableProperties(VisitorContext
529533
530534 // next, read system properties
531535 if (CollectionUtils .isNotEmpty (System .getProperties ())) {
532- for (Map . Entry <Object , Object > entry : System .getProperties ().entrySet ()) {
536+ for (Entry <Object , Object > entry : System .getProperties ().entrySet ()) {
533537 String key = entry .getKey ().toString ();
534538 if (!key .startsWith (expandPrefix )) {
535539 continue ;
@@ -538,7 +542,7 @@ public static List<Pair<String, String>> getExpandableProperties(VisitorContext
538542 }
539543 }
540544
541- for (Map . Entry <String , String > entry : expandedPropsMap .entrySet ()) {
545+ for (Entry <String , String > entry : expandedPropsMap .entrySet ()) {
542546 String key = entry .getKey ();
543547 if (key .startsWith (expandPrefix )) {
544548 key = key .substring (expandPrefix .length ());
@@ -585,7 +589,7 @@ public static Map<String, String> getAdocProperties(OpenApiInfo openApiInfo, boo
585589
586590 // next, read openapi.properties file
587591 Properties openapiProps = readOpenApiConfigFile (context );
588- for (Map . Entry <Object , Object > entry : openapiProps .entrySet ()) {
592+ for (Entry <Object , Object > entry : openapiProps .entrySet ()) {
589593 String key = entry .getKey ().toString ();
590594 if (!key .startsWith (expandPrefix )) {
591595 continue ;
@@ -595,7 +599,7 @@ public static Map<String, String> getAdocProperties(OpenApiInfo openApiInfo, boo
595599
596600 // next, read system properties
597601 if (CollectionUtils .isNotEmpty (System .getProperties ())) {
598- for (Map . Entry <Object , Object > entry : System .getProperties ().entrySet ()) {
602+ for (Entry <Object , Object > entry : System .getProperties ().entrySet ()) {
599603 String key = entry .getKey ().toString ();
600604 if (!key .startsWith (expandPrefix )) {
601605 continue ;
@@ -723,7 +727,7 @@ public static Map<String, GroupProperties> getGroupsPropertiesMap(VisitorContext
723727 // third read environments properties
724728 Environment environment = getEnv (context );
725729 if (environment != null ) {
726- for (Map . Entry <String , Object > entry : environment .getProperties (MICRONAUT_OPENAPI_GROUPS , StringConvention .RAW ).entrySet ()) {
730+ for (Entry <String , Object > entry : environment .getProperties (MICRONAUT_OPENAPI_GROUPS , StringConvention .RAW ).entrySet ()) {
727731 String entryKey = entry .getKey ();
728732 String [] propParts = entryKey .split ("\\ ." );
729733 String propName = propParts [propParts .length - 1 ];
@@ -823,21 +827,25 @@ private static void setGroupProperty(String groupName, String propertyName, Obje
823827 * @return The EndpointsConfiguration.
824828 */
825829 public static EndpointsConfig getEndpointsConfig (VisitorContext context ) {
826- var cfg = ContextUtils .get (MICRONAUT_INTERNAL_OPENAPI_ENDPOINTS , EndpointsConfig .class , context );
827- if (cfg != null ) {
828- return cfg ;
830+ var endpointsConfig = ContextUtils .get (MICRONAUT_INTERNAL_OPENAPI_ENDPOINTS , EndpointsConfig .class , context );
831+ if (endpointsConfig != null ) {
832+ return endpointsConfig ;
829833 }
830834
831- cfg = new EndpointsConfig (isEndpointsEnabled (context ));
832- cfg .setPath (parsePath (getConfigProperty (ENDPOINTS_PATH , context )));
833- cfg .setTags (parseTags (getConfigProperty (ENDPOINTS_TAGS , context )));
834- cfg .setServers (parseServers (getConfigProperty (ENDPOINTS_SERVERS , context ), context ));
835- cfg .setSecurityRequirements (parseSecurityRequirements (getConfigProperty (ENDPOINTS_SECURITY_REQUIREMENTS , context ), context ));
836- cfg .setExtensions (parseExtensions (getConfigProperty (ENDPOINTS_EXTENSIONS , context ), context ));
837- cfg .setEndpoints (endpointsProperties (context ));
835+ endpointsConfig = new EndpointsConfig (isEndpointsEnabled (context ));
836+ endpointsConfig .setPath (parsePath (getConfigProperty (ENDPOINTS_PATH , context )));
837+ endpointsConfig .setTags (parseTags (getConfigProperty (ENDPOINTS_TAGS , context )));
838+ endpointsConfig .setServers (parseServers (getConfigProperty (ENDPOINTS_SERVERS , context ), context ));
839+ endpointsConfig .setSecurityRequirements (parseSecurityRequirements (getConfigProperty (ENDPOINTS_SECURITY_REQUIREMENTS , context ), context ));
840+ endpointsConfig .setExtensions (parseExtensions (getConfigProperty (ENDPOINTS_EXTENSIONS , context ), context ));
841+ endpointsConfig .setGroups (getListStringsProperty (ENDPOINTS_GROUPS , Collections .emptyList (), context ));
842+ endpointsConfig .setGroupsExcluded (getListStringsProperty (ENDPOINTS_GROUPS_EXCLUDED , Collections .emptyList (), context ));
843+ endpointsConfig .setEndpoints (endpointsProperties (context ));
844+
845+ mergeWithActuatorProperties (endpointsConfig , context );
838846
839- ContextUtils .put (MICRONAUT_INTERNAL_OPENAPI_ENDPOINTS , cfg , context );
840- return cfg ;
847+ ContextUtils .put (MICRONAUT_INTERNAL_OPENAPI_ENDPOINTS , endpointsConfig , context );
848+ return endpointsConfig ;
841849 }
842850
843851 public static Map <String , EndpointProperties > endpointsProperties (VisitorContext context ) {
@@ -855,14 +863,33 @@ public static Map<String, EndpointProperties> endpointsProperties(VisitorContext
855863 // third read environments properties
856864 Environment environment = getEnv (context );
857865 if (environment != null ) {
858- for (Map . Entry <String , Object > entry : environment .getProperties (MICRONAUT_ENDPOINTS_PREFIX , StringConvention .RAW ).entrySet ()) {
866+ for (Entry <String , Object > entry : environment .getProperties (MICRONAUT_ENDPOINTS_PREFIX , StringConvention .RAW ).entrySet ()) {
859867 String entryKey = entry .getKey ();
860868 String endpointName = entryKey .substring (0 , entryKey .indexOf ('.' ));
861869 String propName = entryKey .substring (endpointName .length () + 1 );
862870 setEndpointProperty (endpointName , propName , entry .getValue (), endpointPropertiesMap , context );
863871 }
864872 }
865873
874+ // set standard endpoints implementations, if not set in config
875+ for (var entry : ALL_MICRONAUT_MANAGEMENT_ENDPOINTS .entrySet ()) {
876+ var endpointName = entry .getKey ();
877+ var endpointProperties = endpointPropertiesMap .get (endpointName );
878+ if (endpointProperties == null ) {
879+ endpointProperties = new EndpointProperties (endpointName );
880+ endpointPropertiesMap .put (endpointName , endpointProperties );
881+ }
882+ if (endpointProperties .getElement () != null ) {
883+ continue ;
884+ }
885+ var className = entry .getValue ();
886+ if (className == null ) {
887+ continue ;
888+ }
889+ var classEl = ContextUtils .getClassElement (className , context );
890+ endpointProperties .setElement (classEl );
891+ }
892+
866893 return endpointPropertiesMap ;
867894 }
868895
0 commit comments