2

Could we add Actuator endpoints as a groupedOpenApi that will be gourped separately ?

ex :

@bean
public GroupedOpenApi actuatorApi() {
return GroupedOpenApi.builder().setGroup("Actuator")
.packagesToScan("org.springframework.boot.actuate")
.pathsToMatch("/actuator/**")
.build();
}

Thanks

Yawyaw1
  • 83
  • 1
  • 8
  • The solution was by adding the value below **springdoc.api-docs.groups.enabled=true** **springdoc.show-actuator=true** to the application.properties and then you create your bean as above without packageToScan – Yawyaw1 Apr 23 '20 at 13:56

2 Answers2

4

First you need to enable actuator on the swagger-ui:

springdoc.show-actuator=true

You just need to declare GroupedOpenApi bean:

@Bean
 public GroupedOpenApi actuatorApi(){
     String[] paths = {"/actuator/**"};
     return GroupedOpenApi.builder()
             .setGroup("groups")
             .pathsToMatch(paths)
             .build();
 } 

Here are the steps to add actuator:

https://github.com/springdoc/springdoc-openapi-demos/commit/aa6bcf1f0312c8fc36f94aeb4653718b36c308f6

brianbro
  • 4,141
  • 2
  • 24
  • 37
  • Is there a way to add enable actuator property to OpenApi bean instead of application properties? –  Jul 30 '20 at 08:35
  • In my case (Spring Boot v2.4) it was not even necessary to add the `GroupedOpenApi` bean. Setting the `springdoc.show-actuator` property to `true` seemed sufficient. – jeroen_de_schutter Feb 25 '21 at 09:22
0

The solution provided by @brianbro mostly works but there is an issue where some endpoints that use parameters in URL, e.g. /actuator/metrics/{requiredMetricName} due to way spring boot handles the actuator endpoints (single handler method, no @PathParam) the PathParam fields don't show in Swagger. See Spring boot actuator endpoint parameters issue.

Example of what shows in Swagger without resolving the issue: enter image description here Example of what shows in Swagger after resolving the issue: enter image description here How to fix this is discussed in Adding Actuator as a groupedOpenApi but some of the links are broken. The key issue is there is an ActuatorOpenApiCustomiser class that is used to fix the PathParams for Actuator, and that class is not being called when Actuator resides within a GroupedOpenApi.

Full solution (working with springdoc:1.6.9)...

First you need to enable actuator on the swagger-ui:

springdoc.show-actuator=true

Declare GroupedOpenApi bean using code (you can't use the springdoc.group-configs[0] properties because you need to add a OpenApiCustomiser to the group):

@Bean
 public GroupedOpenApi actuatorApi(OpenApiCustomiser actuatorOpenApiCustomiser){
     String[] paths = {"/actuator/**"};
     return GroupedOpenApi.builder()
             .setGroup("Actuator")
             .pathsToMatch(paths)
             .addOpenApiCustomiser(actuatorOpenApiCustomiser)
             .build();
 }

Addtional Sample from SpringDoc

Tony Falabella
  • 335
  • 1
  • 6
  • 17