|
| 1 | +# Sample API Description |
| 2 | + |
| 3 | +Check the [Tips and Tricks](openapi.md#hide-error-responses-that-show-in-every-operation) to understand how to use this sample API description. |
| 4 | + |
| 5 | +## Overview |
| 6 | +Here you will probably give an overview of the API and add a description for it. |
| 7 | + |
| 8 | +## Authentication |
| 9 | +Since the API requires authentication, you might want to add a section to describe the authentication flow as well. |
| 10 | + |
| 11 | +## Errors |
| 12 | +Now this is the important section in this example. In this section, you can list the error responses that appear |
| 13 | +in every operation with some explanation. It can go sth like: |
| 14 | + |
| 15 | +### 401 Unauthorized |
| 16 | +These errors are returned with the status code 401 whenever the authentication fails or a request is made to an |
| 17 | +endpoint without providing the authentication information as part of the request. Here are the 2 possible errors |
| 18 | +that can be returned. |
| 19 | +```json |
| 20 | +{ |
| 21 | + "type": "client_error", |
| 22 | + "errors": [ |
| 23 | + { |
| 24 | + "code": "authentication_failed", |
| 25 | + "detail": "Incorrect authentication credentials.", |
| 26 | + "attr": null |
| 27 | + } |
| 28 | + ] |
| 29 | +} |
| 30 | +``` |
| 31 | +```json |
| 32 | +{ |
| 33 | + "type": "client_error", |
| 34 | + "errors": [ |
| 35 | + { |
| 36 | + "code": "not_authenticated", |
| 37 | + "detail": "Authentication credentials were not provided.", |
| 38 | + "attr": null |
| 39 | + } |
| 40 | + ] |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +### 405 Method Not Allowed |
| 45 | +This is returned when an endpoint is called with an unexpected http method. For example, if updating a user requires |
| 46 | +a POST request and a PATCH is issued instead, this error is returned. Here's how it looks like: |
| 47 | + |
| 48 | +```json |
| 49 | +{ |
| 50 | + "type": "client_error", |
| 51 | + "errors": [ |
| 52 | + { |
| 53 | + "code": "method_not_allowed", |
| 54 | + "detail": "Method “patch” not allowed.", |
| 55 | + "attr": null |
| 56 | + } |
| 57 | + ] |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +### 406 Not Acceptable |
| 62 | +This is returned if the `Accept` header is submitted and contains a value other than `application/json`. Here's how the response would look: |
| 63 | + |
| 64 | +```json |
| 65 | +{ |
| 66 | + "type": "client_error", |
| 67 | + "errors": [ |
| 68 | + { |
| 69 | + "code": "not_acceptable", |
| 70 | + "detail": "Could not satisfy the request Accept header.", |
| 71 | + "attr": null |
| 72 | + } |
| 73 | + ] |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +### 415 Unsupported Media Type |
| 78 | +This is returned when the request content type is not json. Here's how the response would look: |
| 79 | + |
| 80 | +```json |
| 81 | +{ |
| 82 | + "type": "client_error", |
| 83 | + "errors": [ |
| 84 | + { |
| 85 | + "code": "not_acceptable", |
| 86 | + "detail": "Unsupported media type “application/xml” in request.", |
| 87 | + "attr": null |
| 88 | + } |
| 89 | + ] |
| 90 | +} |
| 91 | +``` |
| 92 | + |
| 93 | +### 500 Internal Server Error |
| 94 | +This is returned when the API server encounters an unexpected error. Here's how the response would look: |
| 95 | + |
| 96 | +```json |
| 97 | +{ |
| 98 | + "type": "server_error", |
| 99 | + "errors": [ |
| 100 | + { |
| 101 | + "code": "error", |
| 102 | + "detail": "A server error occurred.", |
| 103 | + "attr": null |
| 104 | + } |
| 105 | + ] |
| 106 | +} |
| 107 | +``` |
0 commit comments