I have a rest api that I want to document in Swagger. On all requests the API can respond with a 401.
So instead of defining the 401 again again and again for each path (not so DRY). I want to define that all paths can return a 401.
Is this possible?
As far as i know, this is not possible. You will need to annotate each API endpoint with @ApiResponse. The only annotations available at the class level are @Api and @ApiModel . For details, please refer to this link -
http://docs.swagger.io/swagger-core/v1.5.0/apidocs/io/swagger/annotations/ApiModel.html
I don't think this is a perfect solution but I've done this in an attempt to DRY it up a bit.
In the root swagger schema you can define a
responses
object which, as defined by the Swagger Spec:Once you've done that you can reference the shared responses in the path.
At a minimum this gets you consistency with regards to the
response
description and any schema defined for that response type. I was really hoping for a way to group all of the common error responses and just reference the group but I haven't found any way to do that.