How can I set swagger to shown all possible responses?
Now only shows the HTTP 200, but there are more possible responses
I have a global exception handling class and I would like to a global solution.
Nothing, but now i will try some possible solutions.
If i use it:
[ProducesResponseType(200)]
[ProducesResponseType(401)]
[ProducesResponseType(404)]
at controller method it is work and swagger shows more possible responses. But i would like to a global solution
Is there a swagger settings or something else?
3
Answers
So https://stackoverflow.com/users/113116/helen find the correct and beauty solution.
Swashbuckle general response codes
Is a way to declare common response types to different actions?
What i used for general response handling: /in AddSwaggerGen
.
If you add the following attributes to the methods you can specify the output model and the error
Just an additional info, specifically for
java
andspringboot
based apps, we need use combination of@RestControllerAdvice
and@ResponseStatus
annotations.Step 1: Add
@RestControllerAdvice
onGlobalExceptionHandler
Step 2: Add
@ResponseStatus(HTTPStatus.INTERNAL_SERVICE_ERROR)
oneach method that you have handled and want to show.