There is a Spring Boot application where exceptions are handled within a general @ControllerAdvice and several @ExceptionHandler. For example:
@ControllerAdvice
public class CustomExceptionHandler extends ResponseEntityExceptionHandler {
@ResponseStatus(HttpStatus.FORBIDDEN) // 403
@ExceptionHandler(AccessDeniedCustomException.class)
public ResponseEntity<Object> handleAccessDeniedException(Exception ex, WebRequest request) {
...
}
@ResponseStatus(HttpStatus.NOT_FOUND) // 404
@ExceptionHandler(NotFoundCustomException.class)
public ResponseEntity<Object> handleNotFoundException(Exception ex, WebRequest request) {
...
}
}
And with this configuration I get generated OpenAPI yaml file with the responses 403 and 404 for every endpoint.
I want to hide 403 for some specific endpoints, how can I do that?
I know about @Hidden annotation for handler method, but it removes response code from every endpoint. It isn't a desired behavior.