springdoc-openapi icon indicating copy to clipboard operation
springdoc-openapi copied to clipboard

Support for tags on custom actuators

Open wolframhaussig opened this issue 2 months ago • 2 comments

Is your feature request related to a problem? Please describe.

We are implementing many management endpoints as custom actuators and we would like to group them (right now, there are > 70 actuators in the list). Currently, adding an @Tag annotation does not work, because all actuators are grouped together in a single, hardcoded group.

Describe the solution you'd like

As far as I can see it, the code in OpenApiResource has access to each method representing an actuator endpoint as part of the HandlerMethod object. So maybe the method could check for the existence of a tag like this(untested code)?

Map<Tag, List<HandlerMethod>> tagMappings = new HashMap<>();
//check for Tag annotation existance
for (HandlerMethod method : actuatorMap.values()) {
	Class<?> beanType = method.getBeanType();
	io.swagger.v3.oas.annotations.tags.Tag t = beanType.getAnnotation(io.swagger.v3.oas.annotations.tags.Tag.class);
	if(t != null) {
                //use configured tag
		Tag tag = new Tag()
						.description(t.description())
						.name(t.name());
		tagMappings.computeIfAbsent(tag, k -> new java.util.ArrayList<>()).add(method);
	}else{
                //use default tag
		tagMappings.computeIfAbsent(getTag(), k-> new java.util.ArrayList<>()).add(method);
	}
}
//add actuators by tags
tagMappings.entrySet().forEach(kvp -> {
	this.openAPIService.addTag(new HashSet<>(kvp.getValue()), kvp.getKey());
});

Describe alternatives you've considered

We considered hiding the OOTB actuators from the OpenAPI, but there seems no way to hide them without disabling them or hiding our custom actuators too.

wolframhaussig avatar Nov 03 '25 08:11 wolframhaussig

@wolframhaussig,

Not sure what you are trying to achieve. Could you provide a link to a Minimal, Reproducible Example on Github- with HelloController that explains your request.

bnasslahsen avatar Nov 11 '25 12:11 bnasslahsen

Hello @bnasslahsen,

I am sorry if my message was confusing. I have attached a sample project:

demo_actuator.zip

It contains 2 controllers (1 as a RestController, the other is an actuator). both have the same @Tag annotation, but only one is shown in this group:

Image

The Actuator is still in the actuator group:

Image

My wish would be a possibility to add the actuator into this group

wolframhaussig avatar Nov 11 '25 13:11 wolframhaussig