-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswagger.yaml
716 lines (716 loc) · 20.9 KB
/
swagger.yaml
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
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
openapi: 3.0.0
info:
title: Blogs API
description: API for Blog
version: 1.0.0
servers:
- url: http://localhost:3001
paths:
/login:
post:
tags:
- Registration
summary: Route to authenticate and obtain access token
description: |
This endpoint allows users to authenticate and obtain an access token by providing valid credentials.
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Login'
responses:
'200':
description: Successfully generated access token
content:
application/json:
schema:
type: object
properties:
token:
type: string
example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7ImlkIjo1LCJkaXNwbGF5TmFtZSI6InVzdWFyaW8gZGUgdGVzdGUiLCJlbWFpbCI6InRlc3RlQGVtYWlsLmNvbSIsImltYWdlIjoibnVsbCJ9LCJpYXQiOjE2MjAyNDQxODcsImV4cCI6MTYyMDY3NjE4N30.Roc4byj6mYakYqd9LTCozU1hd9k_Vw5IWKGL4hcCVG8"
'400':
$ref: '#/components/responses/InvalidLogin'
content:
application/json:
schema:
type: object
properties:
message:
type: string
example: "O \"password\" deve ter pelo menos 6 caracteres"
/user:
post:
tags:
- Registration
summary: Route to register a new user
description: |
This endpoint allows users to register a new account by providing required information.
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/User'
responses:
'201':
description: Successfully registered user and generated access token
content:
application/json:
schema:
type: object
properties:
token:
type: string
example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7ImlkIjo1LCJkaXNwbGF5TmFtZSI6InVzdWFyaW8gZGUgdGVzdGUiLCJlbWFpbCI6InRlc3RlQGVtYWlsLmNvbSIsImltYWdlIjoibnVsbCJ9LCJpYXQiOjE2MjAyNDQxODcsImV4cCI6MTYyMDY3NjE4N30.Roc4byj6mYakYqd9LTCozU1hd9k_Vw5IWKGL4hcCVG8"
'400':
$ref: '#/components/responses/InvalidUser'
'409':
$ref: '#/components/responses/UserAlreadyRegistered'
get:
security:
- bearerAuth: []
tags:
- User
summary: Retrieve all registered users
description: |
This endpoint allows users to retrieve all registered users.
responses:
'200':
description: Successfully retrieved all registered users
content:
application/json:
schema:
$ref: '#/components/schemas/UserList'
example:
- id: 1
displayName: "Lewis Hamilton"
email: "[email protected]"
image: "https://upload.wikimedia.org/wikipedia/commons/1/18/Lewis_Hamilton_2016_Malaysia_2.jpg"
- id: 2
displayName: "Michael Schumacher"
email: "[email protected]"
image: "https://sportbuzz.uol.com.br/media/_versions/gettyimages-52491565_widelg.jpg"
'401':
$ref: '#/components/responses/TokenIssues'
/user/me:
delete:
security:
- bearerAuth: []
tags:
- User
summary: Delete current user's post by ID
description: |
This endpoint allows the current user to delete itself.
responses:
'204':
description: Successfully deleted current user
'401':
$ref: '#/components/responses/TokenIssues'
/user/{id}:
get:
security:
- bearerAuth: []
tags:
- User
summary: Retrieve user by ID
description: |
This endpoint allows users to retrieve a specific user by ID.
parameters:
- in: path
name: id
required: true
schema:
type: string
description: The ID of the user to retrieve.
responses:
'200':
description: Successfully retrieved the user
content:
application/json:
schema:
$ref: '#/components/schemas/UserById'
'401':
$ref: '#/components/responses/TokenIssues'
'404':
$ref: '#/components/responses/UserNotFound'
/categories:
post:
security:
- bearerAuth: []
tags:
- Category
summary: Route to register a new category
description: |
This endpoint allows users to register a new category by providing required information.
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Category'
responses:
'201':
description: Successfully registered category
content:
application/json:
schema:
type: object
properties:
id:
type: integer
example: 3
name:
type: string
example: Typescript
'401':
$ref: '#/components/responses/TokenIssues'
'400':
$ref: '#/components/responses/MissingName'
get:
security:
- bearerAuth: []
tags:
- Category
summary: Retrieve all registered categories
description: |
This endpoint allows users to retrieve all registered categories.
responses:
'200':
description: Successfully retrieved all registered categories
content:
application/json:
schema:
$ref: '#/components/schemas/Categories'
example:
- id: 1
name: "Inovação"
- id: 2
name: "Escola"
'401':
$ref: '#/components/responses/TokenIssues'
/post:
post:
security:
- bearerAuth: []
tags:
- Posts
summary: Route to create a new post
description: |
This endpoint allows users to create a new post by providing necessary information such as title, content, etc.
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CreatePost'
responses:
'201':
description: Successfully created a new post
content:
application/json:
schema:
$ref: '#/components/schemas/CreatePostResponse'
'401':
$ref: '#/components/responses/TokenIssues'
'400':
$ref: '#/components/responses/InvalidPost'
get:
security:
- bearerAuth: []
tags:
- Posts
summary: Retrieve all registered posts
description: |
This endpoint allows users to retrieve all registered posts.
responses:
'200':
description: Successfully retrieved all registered posts
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/CreatePostResponse'
example:
- id: 1
title: "Post do Ano"
content: "Melhor post do ano"
userId: 1
published: "2011-08-01T19:58:00.000Z"
updated: "2011-08-01T19:58:51.000Z"
user:
id: 1
displayName: "Lewis Hamilton"
email: "[email protected]"
image: "https://upload.wikimedia.org/wikipedia/commons/1/18/Lewis_Hamilton_2016_Malaysia_2.jpg"
categories:
- id: 1
name: "Inovação"
'401':
$ref: '#/components/responses/TokenIssues'
/post/search:
get:
security:
- ApiKeyAuth: []
tags:
- Posts
summary: Search posts based on filters
description: |
This endpoint allows users to search for posts based on filters tittle and content.
parameters:
- in: query
name: q
description: Title or content filter. Enter the search query here.
schema:
type: string
responses:
'200':
description: Posts found successfully
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/FoundPosts'
- $ref: '#/components/schemas/NotFoundPosts'
examples:
FoundPosts:
$ref: '#/components/schemas/PostById'
NotFoundPosts:
value: []
'401':
$ref: '#/components/responses/TokenIssues'
/post/{id}:
get:
security:
- bearerAuth: []
tags:
- Posts
summary: Retrieve post by ID
description: |
This endpoint allows users to retrieve a specific post by ID.
parameters:
- in: path
name: id
required: true
schema:
type: string
description: The ID of the post to retrieve.
responses:
'200':
description: Successfully retrieved the post
content:
application/json:
schema:
$ref: '#/components/schemas/PostById'
'401':
$ref: '#/components/responses/TokenIssues'
'404':
$ref: '#/components/responses/PostNotFound'
put:
security:
- bearerAuth: []
tags:
- Posts
summary: Update an existing post
description: |
This endpoint allows users to update an existing post by providing the required information.
parameters:
- in: path
name: id
required: true
schema:
type: string
description: The ID of the post to update.
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UpdatePost'
responses:
'200':
description: Successful update of the post
content:
application/json:
schema:
type: object
properties:
id:
type: integer
example: 3
title:
type: string
example: "Latest updates, August 1st"
content:
type: string
example: "The whole text for the blog post goes here in this key"
userId:
type: integer
example: 1
published:
type: string
format: date-time
example: "2022-05-18T18:00:01.000Z"
updated:
type: string
format: date-time
example: "2022-05-18T18:07:32.000Z"
user:
type: object
properties:
id:
type: integer
example: 1
displayName:
type: string
example: "Lewis Hamilton"
email:
type: string
format: email
example: "[email protected]"
image:
type: string
format: uri
example: "https://upload.wikimedia.org/wikipedia/commons/1/18/Lewis_Hamilton_2016_Malaysia_2.jpg"
categories:
type: array
items:
type: object
properties:
id:
type: integer
name:
type: string
example:
- id: 1
name: Inovação
- id: 2
name: Escola
'401':
$ref: '#/components/responses/UnauthorizedUser'
'400':
$ref: '#/components/responses/RequiredFieldMissing'
delete:
security:
- bearerAuth: []
tags:
- Posts
summary: Delete a post by ID
description: |
This endpoint enables users to delete a specific post identified by its unique ID.
parameters:
- in: path
name: id
required: true
schema:
type: string
description: The ID of the post to be deleted.
responses:
'204':
description: Successfully deleted the post
'401':
$ref: '#/components/responses/UnauthorizedUser'
'404':
$ref: '#/components/responses/PostNotFound'
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
schemas:
Login:
type: object
properties:
email:
type: string
example: [email protected]
password:
type: string
example: 123456
User:
type: object
properties:
displayName:
type: string
example: Brett Wiltshire
email:
type: string
example: [email protected]
password:
type: string
example: 123456
image:
type: string
example: http://4.bp.blogspot.com/_YA50adQ-7vQ/S1gfR_6ufpI/AAAAAAAAAAk/1ErJGgRWZDg/S45/brett.png
UserById:
type: object
properties:
id:
type: integer
example: 1
displayName:
type: string
example: Lewis Hamilton
email:
type: string
example: [email protected]
image:
type: string
example: "https://upload.wikimedia.org/wikipedia/commons/1/18/Lewis_Hamilton_2016_Malaysia_2.jpg"
UserList:
type: array
items:
type: object
properties:
id:
type: string
description: The unique identifier of the user
displayName:
type: string
description: The display name of the user
email:
type: string
format: email
description: The email address of the user
image:
type: string
format: uri
description: The URL of the user's image
Category:
type: object
properties:
name:
type: string
example: "Typescript"
required:
- name
CategoryID:
type: object
properties:
id:
type: integer
example: 1
name:
type: string
example: "Inovação"
required:
- id
- name
Categories:
type: array
items:
$ref: '#/components/schemas/CategoryID'
CreatePost:
type: object
properties:
title:
type: string
example: "Latest updates, August 1st"
content:
type: string
example: "The whole text for the blog post goes here in this key"
categoryIds:
type: array
items:
type: integer
example: [1, 2]
required:
- title
- content
- categoryIds
CreatePostResponse:
type: object
properties:
id:
type: integer
example: 3
title:
type: string
example: "Latest updates, August 1st"
content:
type: string
example: "The whole text for the blog post goes here in this key"
userId:
type: integer
example: 1
updated:
type: string
format: date-time
example: "2022-05-18T18:00:01.196Z"
published:
type: string
format: date-time
example: "2022-05-18T18:00:01.196Z"
PostById:
type: object
properties:
id:
type: integer
example: 1
title:
type: string
example: "Post do Ano"
content:
type: string
example: "Melhor post do ano"
userId:
type: integer
example: 1
published:
type: string
format: date-time
example: "2011-08-01T19:58:00.000Z"
updated:
type: string
format: date-time
example: "2011-08-01T19:58:51.000Z"
user:
type: object
properties:
id:
type: integer
example: 1
displayName:
type: string
example: "Lewis Hamilton"
email:
type: string
example: "[email protected]"
image:
type: string
example: "https://upload.wikimedia.org/wikipedia/commons/1/18/Lewis_Hamilton_2016_Malaysia_2.jpg"
categories:
type: array
items:
type: object
properties:
id:
type: integer
example: 1
name:
type: string
example: "Inovação"
UpdatePost:
type: object
properties:
title:
type: string
example: "How to post awesome"
content:
type: string
example: "I am posting something awesome here in this key."
required:
- title
- content
NotFoundPosts:
type: array
items: []
FoundPosts:
type: array
items:
$ref: '#/components/schemas/PostById'
responses:
InvalidLogin:
description: Invalid login data
content:
application/json:
examples:
RequiredFieldsMissing:
value:
message: "Some required fields are missing"
InvalidFields:
value:
message: "Invalid fields"
InvalidUser:
description: Invalid user data
content:
application/json:
examples:
DisplayNameMinChar:
value:
message: "\"displayName\" length must be at least 8 characters long"
InvalidEmailFormat:
value:
message: "\"email\" must be a valid email"
PasswordMinChar:
value:
message: "\"password\" length must be at least 6 characters long"
UserNotFound:
description: User not found
content:
application/json:
examples:
NotExistingUser:
value:
message: "User does not exist"
UserAlreadyRegistered:
description: User already registered
content:
application/json:
examples:
UserAlreadyRegistered:
value:
message: "User already registered"
TokenIssues:
description: Token issue
content:
application/json:
examples:
NotFoundToken:
value:
message: "Token not found"
InvalidToken:
value:
message: "Expired or invalid token"
MissingName:
description: Invalid login data
content:
application/json:
examples:
MissingName:
value:
message: "\"name\" is required"
InvalidPost:
description: Invalid post data
content:
application/json:
examples:
MissingRequiredFields:
value:
message: "Some required fields are missing"
CategoryNotFound:
value:
message: "one or more \"categoryIds\" not found"
PostNotFound:
description: Post not found
content:
application/json:
examples:
PostNotFound:
value:
message: "Post does not exist"
RequiredFieldMissing:
description: Required fields are missing
content:
application/json:
examples:
RequiredFieldMissing:
value:
message: "Some required fields are missing"
UnauthorizedUser:
description: User unauthorized
content:
application/json:
examples:
Unauthorized:
value:
message: "Unauthorized user"
NotFoundToken:
value:
message: "Token not found"
InvalidToken:
value:
message: "Expired or invalid token"