The default server response of a SpringBoot app in case of unhandled errors is
{
"timestamp": 1594232435849,
"path": "/my/path",
"status": 500,
"error": "Internal Server Error",
"message": "this request is failed because of ...",
"requestId": "ba5058f3-4"
}
I want to describe it in a Springdoc annotation for routes of an application.
Assuming that there is a standard class DefaultErrorResponse
(just a mock name), it could look like the following:
@Operation(
// ... other details
responses = {
// ... other possible responses
@ApiResponse(
responseCode = "500",
content = @Content(schema = @Schema(implementation = DefaultErrorResponse.class)))
}
)
In a worse case scenario such class does not exists and Spring uses just a Map
under the hood for this response creation. Then this annotation will be more verbose, including explicit mention of every field contained in the response.
Obviously for most of the routes this part @ApiResponse(responseCode="500",...
is the same, and it would be good to reduce duplication.
What is the proper way to introduce description of the default error response in the documentation?