Spring Boot OpenAPI 3.0 Error Handling on Specific Endpoints

434 views Asked by At

I have a little question for you. I have a spring boot app that has some authorization mechanism, meaning that some endpoints under /private path requires some priviliges.

I've already written this feature, if there is an authorization problem my controller advice returns appropriate 403 forbidden message to client.

My question starts here,

If I put the @ApiResponse annotation at the controller advice, the generated OpenAPI spec contains 403 error for every endpoint. Naturally, I don't want to see message 'This endpoint could give 403 error' on my public endpoints and also I don't want to add @ApiResponse annotation to all of my private endpoints as you can guess.

Is there any way to, tell OpenAPI spec generator to;

"I have a exception (for this example 403) I define the exception handler at in controller advice with appropriate @ApiResponse but include that error on endpoint's spec if an only if that endpoint will throws this exception."

Thanks in advance.

0

There are 0 answers