-
Notifications
You must be signed in to change notification settings - Fork 0
/
songs-api.open-api.yml
331 lines (331 loc) · 9.99 KB
/
songs-api.open-api.yml
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
openapi: 3.0.0
info:
title: Songs API
version: 0.0.1
paths:
/:
get:
summary: Returns a greeting message from Songs API
operationId: getGreeting
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
message:
type: string
example: "Hello from Songs API"
/songs:
get:
summary: Returns all songs
operationId: getSongs
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/AllSongs'
post:
summary: Create a new song
operationId: createSong
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/CreateAndPutSongRequestBody'
example:
name: The Thrill is Gone
artist: B.B. King
publish_year: 1969
responses:
'201':
description: Song created successfully.
headers:
Location:
description: URL of the created song.
schema:
type: string
content:
application/json:
schema:
$ref: '#/components/schemas/SongResponse'
example:
id: 7ccc951a-25cf-4009-bfb1-b8ef4300db46
name: The Thrill is Gone
artist: B.B. King
publish_year: 1969
'400':
description: Bad request. Invalid field(s) in request body.
content:
application/json:
schema:
$ref: '#/components/schemas/ValidationErrorRequestBody'
'409':
description: Conflict with already existing song.
content:
application/json:
schema:
$ref: '#/components/schemas/SongAlreadyExists'
/songs/{id}:
get:
summary: Gets a specific song by id.
operationId: getSong
parameters:
- name: id
in: path
required: true
description: The id of the song to retrieve.
schema:
type: string
example: 7ccc951a-25cf-4009-bfb1-b8ef4300db46
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/SongResponse'
example:
id: 7ccc951a-25cf-4009-bfb1-b8ef4300db46
name: The Thrill is Gone
artist: B.B. King
publish_year: 1969
'400':
description: Bad request. Invalid format for id.
content:
application/json:
schema:
$ref: '#/components/schemas/InvalidIdFormat'
'404':
description: Not found. Song with requested id does not exist.
content:
application/json:
schema:
$ref: '#/components/schemas/SongNotFound'
put:
summary: Updates existing song.
operationId: updateSong
parameters:
- name: id
in: path
required: true
description: The id of the song to update.
example: 7ccc951a-25cf-4009-bfb1-b8ef4300db46
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/CreateAndPutSongRequestBody'
example:
name: The Thrill is Not Gone
artist: B.B. King
publish_year: 1969
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/SongResponse'
example:
id: 7ccc951a-25cf-4009-bfb1-b8ef4300db46
name: The Thrill is Not Gone
artist: B.B. King
publish_year: 1969
'400':
description: Bad request. Invalid format for id OR Invalid field(s) in request body.
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/InvalidIdFormat'
- $ref: '#/components/schemas/ValidationErrorRequestBody'
'404':
description: Not found. Song with requested id does not exist.
content:
application/json:
schema:
$ref: '#/components/schemas/SongNotFound'
'409':
description: Conflict with already existing song.
content:
application/json:
schema:
$ref: '#/components/schemas/SongAlreadyExists'
patch:
summary: Partially updates an existing song.
operationId: patchSong
parameters:
- name: id
in: path
required: true
description: The id of the song to update.
example: 7ccc951a-25cf-4009-bfb1-b8ef4300db46
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/PatchSongRequest'
example:
name: The Thrill is Gone Again
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/SongResponse'
example:
id: 7ccc951a-25cf-4009-bfb1-b8ef4300db46
name: The Thrill is Gone Again
artist: B.B. King
publish_year: 1969
'400':
description: Bad request. Invalid format for id OR Invalid field(s) in request body.
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/InvalidIdFormat'
- $ref: '#/components/schemas/ValidationErrorRequestBody'
'404':
description: Not found. Song with requested id does not exist.
content:
application/json:
schema:
$ref: '#/components/schemas/SongNotFound'
'409':
description: Conflict with already existing song.
content:
application/json:
schema:
$ref: '#/components/schemas/SongAlreadyExists'
delete:
summary: Deletes an existing song.
operationId: deleteSong
parameters:
- name: id
in: path
required: true
description: The id of the song to update.
example: 7ccc951a-25cf-4009-bfb1-b8ef4300db46
responses:
'204':
description: No content, successfully deleted a song.
'400':
description: Bad request. Invalid format for id.
content:
application/json:
schema:
$ref: '#/components/schemas/InvalidIdFormat'
'404':
description: Not found. Song with requested id does not exist.
content:
application/json:
schema:
$ref: '#/components/schemas/SongNotFound'
components:
schemas:
AllSongs:
type: array
items:
$ref: '#/components/schemas/SongResponse'
example:
- id: 0fa4ab70-379c-423e-8a89-c1fd344c685c
name: Thunderstruck
artist: AC/DC
publish_year: 1990
- id: 2fd527f0-d068-4834-ad64-5ddc60fcbba8
name: Rokkibaby
artist: Frederik
publish_year: 1975
CreateAndPutSongRequestBody:
type: object
required:
- name
- artist
- publish_year
properties:
name:
type: string
description: The name of the song.
artist:
type: string
description: Artist who recorded the song.
publish_year:
type: integer
format: int32
description: The year the song was recorded.
PatchSongRequest:
type: object
anyOf:
- required: name
- required: artist
- required: publish_year
properties:
name:
type: string
description: The name of the song.
artist:
type: string
description: Artist who recorded the song.
publish_year:
type: integer
description: The year the song was recorded.
SongResponse:
type: object
properties:
id:
type: string
format: uuid
description: The id of the song.
name:
type: string
description: The name of the song.
artist:
type: string
description: Artist who recorded the song.
publish_year:
type: integer
description: The year the song was recorded.
SongAlreadyExists:
type: object
properties:
message:
type: string
example: "Song with provided name(name of the song), artist(artist of the song)
and publish_year(publish_year of the song) already exists."
ValidationErrorRequestBody:
type: object
properties:
message:
type: string
errors:
type: object
additionalProperties:
type: string
description: Validation error message for the specific field
example:
artist: "must not be blank"
name: "must not be blank"
publish_year: "publish_year must be between 1889 and the current year."
required:
- message
- errors
InvalidIdFormat:
type: object
properties:
message:
type: string
example: "Given identifier (ccc951a-25cf-4009-bfb1-b8ef4300db46) is invalid.
Expected format: 8-4-4-4-12 hex."
SongNotFound:
type: object
properties:
message:
type: string
example: "Song with id 9ccc951a-25cf-4009-bfb1-b8ef4300db46 was not found"