SpringDoc allows you to customize the generated OpenAPI specification by implementing your own Customizer bean.
There are plenty of Customizer interfaces that you can use for customization, but the most usable are OperationCustomizer
, ParameterCustomizer
, and PropertyCustomizer
.
Below is an example of Operation Customizer for your use case.
@Component
public class OperationCustomizer implements org.springdoc.core.customizers.OperationCustomizer {
@Override
public Operation customize(Operation operation, HandlerMethod handlerMethod) {
CustomAnnotation annotation = handlerMethod.getMethodAnnotation(CustomAnnotation.class);
if (annotation != null) {
operation.description(annotation.value());
}
return operation;
}
}
Here you can find an example of the project that uses custom annotations and Customizers for them.
And here an example of the project that modifies the generated specification based on the @NonNull annotation.