Remove `-controller` prefix from spring-doc generated tags``

Viewed 21

Given a controller named MyController, spring doc generates the tag my-controller which in turn will generate a client MyControllerApi.

I'd like to remove this -controller suffix; is this possible with Spring-Doc?

1 Answers

This component will automatically remove any -controller suffix on tags

@Component
public class RemoveControllerTagSuffix implements OpenApiCustomiser {
    @Override
    public void customise(OpenAPI openApi) {
        openApi.getPaths()
               .forEach((s, pathItem) ->
                       pathItem.readOperations()
                               .forEach(operation ->
                                       operation.setTags(operation.getTags()
                                                                  .stream()
                                                                  .map(t -> t.replace("-controller", ""))
                                                                  .toList())));
    }
}
Related