forked from Applifting/fullstack-exercise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.yml
559 lines (523 loc) · 15 KB
/
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
openapi: "3.0.0"
info:
version: 1.0.0
title: Applifting Blog Engine
description: >-
This OpenAPI specification describes APIs available in the Applifing Blog Engine application.
**Following APIs are exposed:**
- Authentication - This API is used for login and access token acquisition
- Blog - This API is a CRUD over blog entries
- Comments - This API is used for comment creation and voting
- Image - This API serves as an image store. It is assumed that images are uploaded during article creation.
- Multitenancy - This API allows multiple blog instances to be active in a single application.
**Authorization**
All APIs except the Multitenancy API, are protected using API-KEY Token,
which has either been given to the candidate during the exercise introduction or the candidate can create
it themselves using the Multitenancy API `POST /tenants` endpoint. If you were already given a token, please prefer
to use it instead of creating a new one.
API-KEY Token MUST be sent like so `X-API-KEY: my-x-api-key` in the HTTP header.
Comments, Blog and Images APIs are also protected using the Access Token acquired from the `/login` EndPoint.
Access Token MUST be sent like so `Authorization: my-access-token` in the HTTP header.
servers:
- url: https://fullstack.exercise.applifting.cz
paths:
/login:
post:
summary: Sign in into the application
security:
- ApiKeyAuth: []
tags:
- Authentication
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- password
properties:
username:
type: string
password:
type: string
format: password
responses:
"201":
description: Access token detail
content:
application/json:
schema:
$ref: "#/components/schemas/AccessToken"
"400":
description: Invalid login credentials
content:
application/json:
example:
code: INVALID_CREDENTIALS
message: Password is invalid
"401":
$ref: "#/components/responses/ApiKeyInvalidError"
/articles:
get:
summary: List of all articles
operationId: listArticles
tags:
- Blog
parameters:
- $ref: "#/components/parameters/offset"
- $ref: "#/components/parameters/limit"
responses:
"200":
description: Article list
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/Article"
"401":
$ref: "#/components/responses/ApiKeyInvalidError"
post:
summary: Create an article
operationId: createArticle
tags:
- Blog
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/ArticleDetail"
responses:
"200":
description: Detail of the created article
content:
application/json:
schema:
$ref: "#/components/schemas/ArticleDetail"
"401":
$ref: "#/components/responses/ApiKeyInvalidError"
"403":
$ref: "#/components/responses/UnauthorizedError"
/articles/{articleId}:
get:
summary: Article detail with content and comments
operationId: getArticle
tags:
- Blog
parameters:
- $ref: "#/components/parameters/articleId"
responses:
"200":
description: Article detail
content:
application/json:
schema:
$ref: "#/components/schemas/ArticleDetail"
"401":
$ref: "#/components/responses/ApiKeyInvalidError"
patch:
summary: Update article detail
operationId: updateArticle
tags:
- Blog
parameters:
- $ref: "#/components/parameters/articleId"
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/ArticleDetail"
responses:
"200":
description: Updated article detail
content:
application/json:
schema:
$ref: "#/components/schemas/ArticleDetail"
"401":
$ref: "#/components/responses/ApiKeyInvalidError"
"403":
$ref: "#/components/responses/UnauthorizedError"
delete:
summary: Delete article
operationId: deleteArticle
tags:
- Blog
parameters:
- $ref: "#/components/parameters/articleId"
responses:
"204":
description: Article no longer exists
"401":
$ref: "#/components/responses/ApiKeyInvalidError"
"403":
$ref: "#/components/responses/UnauthorizedError"
/comments:
post:
summary: Create comment
tags:
- Comments
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/Comment"
responses:
"201":
description: Detail of the created comment
content:
application/json:
schema:
$ref: "#/components/schemas/Comment"
"401":
$ref: "#/components/responses/ApiKeyInvalidError"
/comments/{commentId}/vote/up:
post:
summary: Upvote comment
tags:
- Comments
parameters:
- $ref: "#/components/parameters/commentId"
responses:
"201":
description: Updated comment detail
content:
application/json:
schema:
$ref: "#/components/schemas/Comment"
"401":
$ref: "#/components/responses/ApiKeyInvalidError"
/comments/{commentId}/vote/down:
post:
summary: Downvote comment
tags:
- Comments
parameters:
- $ref: "#/components/parameters/commentId"
responses:
"201":
description: Updated comment detail
content:
application/json:
schema:
$ref: "#/components/schemas/Comment"
"401":
$ref: "#/components/responses/ApiKeyInvalidError"
/images:
post:
summary: Upload an image
tags:
- Images
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
properties:
image:
type: array
items:
type: string
format: binary
responses:
"201":
description: Image uploaded successfully
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/ImageInfo"
"401":
$ref: "#/components/responses/ApiKeyInvalidError"
/images/{imageId}:
get:
summary: Download image
tags:
- Images
parameters:
- $ref: "#/components/parameters/imageId"
responses:
"200":
description: Image file
"401":
$ref: "#/components/responses/ApiKeyInvalidError"
delete:
summary: Delete image
tags:
- Images
parameters:
- $ref: "#/components/parameters/imageId"
responses:
"204":
description: Image no longer exists
"401":
$ref: "#/components/responses/ApiKeyInvalidError"
/tenants:
post:
summary: Create tenant
security: []
tags:
- Multitenancy
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/Tenant"
responses:
"201":
description: Detail of the created tenant
content:
application/json:
schema:
$ref: "#/components/schemas/Tenant"
/tenants/{tenantId}:
get:
summary: Info for a specific tenant
security: []
tags:
- Multitenancy
parameters:
- $ref: "#/components/parameters/tenantId"
responses:
"200":
description: Tenant detail
content:
application/json:
schema:
$ref: "#/components/schemas/Tenant"
components:
parameters:
tenantId:
name: tenantId
in: path
required: true
description: Id of the tenant to retrieve
schema:
type: string
format: uuid
imageId:
name: imageId
in: path
required: true
description: Id of the image to retrieve
schema:
type: string
format: uuid
articleId:
name: articleId
in: path
required: true
description: Id of an article
schema:
type: string
format: uuid
commentId:
name: commentId
in: path
required: true
description: Id of an comment
schema:
type: string
format: uuid
offset:
name: offset
in: query
required: false
description: Number of items to skip during pagination
schema:
default: 0
minimum: 0
type: number
limit:
name: limit
in: query
required: false
description: >-
Number of items to return per page.
All items are returned if `limit` is omitted.
schema:
minimum: 0
type: number
securitySchemes:
BearerAuth:
description: Access token acquired from the /login call
type: http
scheme: bearer
ApiKeyAuth:
description: API key for multitenancy
type: apiKey
in: header
name: X-API-KEY
responses:
ApiKeyInvalidError:
description: API key is missing or invalid
content:
application/json:
example:
code: API_KEY_INVALID
message: API key missing or invalid
UnauthorizedError:
description: Access token is missing or invalid
content:
application/json:
example:
code: UNAUTHORIZED
message: Access token is missing, invalid or expired
schemas:
Pagination:
type: object
properties:
offset:
type: number
description: Number of items skipped during pagination
limit:
type: number
description: Number of items returned
total:
type: number
description: Total number of items
ArticleList:
type: object
properties:
pagination:
$ref: "#/components/schemas/Pagination"
items:
type: array
items:
$ref: "#/components/schemas/Article"
Article:
type: object
properties:
articleId:
type: string
format: uuid
title:
type: string
example: Lorem Ipsum
perex:
type: string
example: Lorem Ipsum is simply dummy text of the printing and typesetting industry.
imageId:
type: string
format: uuid
createdAt:
readOnly: true
type: string
format: date-time
lastUpdatedAt:
readOnly: true
type: string
format: date-time
ArticleDetail:
allOf:
- $ref: "#/components/schemas/Article"
- type: object
properties:
content:
type: string
format: markdown
example: >
# Lorem Ipsum
**Lorem Ipsum** is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
comments:
type: array
readOnly: true
items:
$ref: "#/components/schemas/Comment"
Comment:
type: object
required:
- articleId
- author
- content
properties:
commentId:
type: string
format: uuid
readOnly: true
articleId:
type: string
format: uuid
author:
type: string
example: Jan Novak
content:
type: string
example: This article is on point and very inspirational.
postedAt:
type: string
format: date-time
readOnly: true
score:
type: integer
example: 42
readOnly: true
ImageInfo:
type: object
required:
- imageId
properties:
imageId:
type: string
format: uuid
readOnly: true
name:
type: string
example: "screenshot.png"
Tenant:
type: object
properties:
tenantId:
type: string
format: uuid
readOnly: true
apiKey:
type: string
format: uuid
description: API key to be used in the `api-key` header
readOnly: true
name:
type: string
description: Human readable name of the tenant
example: Jan Novak
password:
type: string
format: password
description: Authentication password of the tenant
example: correct horse battery staple
writeOnly: true
createdAt:
type: string
format: date-time
readOnly: true
lastUsedAt:
type: string
format: date-time
readOnly: true
AccessToken:
type: object
properties:
access_token:
type: string
description: Use this when requesting authenticated API endpoints
format: uuid
readOnly: true
expires_in:
type: integer
description: Number of seconds before the access_token expires
readOnly: true
example: 3600
token_type:
type: string
description: Token type. Will always be bearer
example: bearer
security:
- ApiKeyAuth: []
- BearerAuth: []