How not to copy-paste 3 common error answers on almost all paths?

I want almost all of my paths to have the following 3 generic error responses. How to describe this in Swagger without copying these lines everywhere?

401: description: The requester is unauthorized. schema: $ref: '#/definitions/Error' 500: description: "Something went wrong. It server fault." schema: $ref: '#/definitions/Error' 503: description: Server is unavailable. Maybe there is maintenance? schema: $ref: '#/definitions/Error' 

An example of how I use this in a query:

 paths: /roles: get: summary: Roles description: | Returns all roles available for users. responses: 200: description: An array with all roles. schema: type: array items: $ref: '#/definitions/Role' 401: description: The requester is unauthorized. schema: $ref: '#/definitions/Error' 500: description: "Something went wrong. It server fault." schema: $ref: '#/definitions/Error' 503: description: Server is unavailable. Maybe there is maintenance? schema: $ref: '#/definitions/Error' 
+6
source share
2 answers

It looks like I can add the following global response definition:

 # An object to hold responses that can be used across operations. # This property does not define global responses for all operations. responses: NotAuthorized: description: The requester is unauthorized. schema: $ref: '#/definitions/Error' 

However, I still have to refer to it like this:

 401: $ref: "#/responses/NotAuthorized" 
+4
source

The Open API specification does not seem to support this.

0
source

All Articles