Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should Internal error (500) be part of Swagger API documentation?

As far as I checked on many swagger files of Amazon/Google and more, That error code (or generally error codes of 5xx family) is not shown as a part of the swagger files. Is their a reason for that?
I am asking because one of our microservices API returns 500 when it fails to communicate to other service (for instance) and we are wondering if that error code should be part of our swagger files.

like image 719
yoka791 Avatar asked Jan 17 '19 15:01

yoka791


People also ask

How to deal with API error 500?

IMO the correct answer is read the API documentation, try to retry on errors specificially indicated as retryable, and don't blindly retry on generic 500 until you've weighed the pros and cons. Most web services document how their API works at a more granular level than HTTP status codes.

How do I define an API in Swagger?

You can use an API design tool to define your API in the Swagger (OpenAPI) specification as follows: Notice the data types and an example described in each response item an end user can expect from a successful GET call. The successful response an end user would receive in JSON would look as follows. ….

How to integrate SwaggerHub with swagger Inspector?

The integration allows developers to automatically host and visualize their API documentation on SwaggerHub to enable API discovery and consumption by internal and external stakeholders. Head over to Swagger Inspector, and insert the end point of the resource you want to have documented.

Why am I getting an internal server error in Swagger?

Reason: Internal Server Error Hi @jessedc - per the Swagger specification, each operation must contain at least one response (either numeric or default and that response must have at least a description ). Without it, the definition you have is malformed as far as validation goes.


2 Answers

Generally clients/consumers can't do much upon getting the 5xx errors, since those are purely server side errors. So it need not to be part of your API specification.

If you think, based on the error which the API throws, client/consumer should do something (For example retry or try another site or so.), then Yes.

like image 136
Maximin Avatar answered Oct 13 '22 01:10

Maximin


I think API documentation should only contain expected errors such as 4xx ones. But 5xx are unexpected errors and should not be documented.

like image 25
numediaweb Avatar answered Oct 13 '22 00:10

numediaweb