summaryrefslogtreecommitdiff
path: root/doc/spec.md
blob: 8f0f87f6b8608589303b79c88c7eb86614eaee75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
## Minimal Document Structure

* openapi: version of the OAS. e.g. "3.1.0"
* info: provides metadata about the API
* paths: describes each of the endpoints in the API

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "The API",
    "version": "0.1.0"
  },
  "paths": {
  }
}
```

## API Endpoints (paths)

* "paths": is an object with the route path as the key.
  * http method: the http method for each path that the path responds to
  * "responses" is an object with http status codes for each key.

```json
{
  "paths": {
    "/users" {
      "get": {
        "summary": "List all the users",
        "description": "List all the users",
        "parameters": [
          {
            "in": "query",
            "name": "q",
            "schema": {
              "type": "string",
              "minimum": 2,
              "maximum": 256
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
            }
          }
        }
      },
      "post": {
        "summary": "create a user",
        "description": "create a user",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": "string",
                  "email": "string"
                }
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "No Content",
          },
        }
      }
    }
  }
}
```

## Content

The `content` field in each response is an object with keys for each media type
that the endpoint can be returned as.

* "content": object with keys for each media type
  * media type: the shape of each response for the media type

```json
{
  "content": {
    "application/json": {
      "schema": {
        "type": "array",
        "minItems": 0,
        "maxItems": 12,
        "items": {
          "type": "object",
          "properties": {
            "id": "integer",
            "username": "string",
            "email": "string"
          }
        }
      }
    },
    "text/html": {
      "schema": {
      }
    }
  }
}
```

## Schema

The schema object defines the shape of the response via [JSON schema][1].

```json
"schema": {
  "type": "array",
  "minItems": 0,
  "maxItems": 12,
  "items": {
    "type": "object",
    "properties": {
      "id": "integer",
      "username": "string",
      "email": "string"
    }
  }
}
```

## Parameter Object

* "in": the location of the parameter
  * "path": parameter is part of the request path
  * "query": parameter is a query string parameter of the request
  * "header": parameter is a header of the request.
* "name": the name of the parameter

```json
{
  "in": "path|query|header",
  "name": "q"
}
```

## Request Body Object

```json
{
  "requestBody": {
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "properties": {
            "username": "string",
            "email": "string"
          }
        }
      }
    }
  }
}
```

[1]: https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00