-
Notifications
You must be signed in to change notification settings - Fork 1
/
spec.yaml
798 lines (790 loc) · 21.9 KB
/
spec.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
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
openapi: 3.1.0
info:
title: Llama Store API
description: "The llama store API! Get details on all your favorite llamas.\n\n\
## To use this API\n\n- You will need to register a user, once done you can request\
\ an API token.\n- You can then use your API token to get details about the llamas.\n\
\n## User registration\n\nTo register a user, send a POST request to `/user` with\
\ the following body:\n \n```json\n{\n \"email\": \"<your email>\",\n \
\ \"password\": \"<your password>\"\n}\n```\nThis API has a maximum of 1000 current\
\ users. Once this is exceeded, older users will be deleted. If your user is deleted,\
\ you will need to register again.\n## Get an API token\n\nTo get an API token,\
\ send a POST request to `/token` with the following body:\n \n```json\n{\n\
\ \"email\": \"<your email>\",\n \"password\": \"<your password>\"\n}\n\
```\n\nThis will return a token that you can use to authenticate with the API:\n\
\n```json\n{\n \"access_token\": \"<your new token>\",\n \"token_type\": \"\
bearer\"\n}\n```\n\n## Use the API token\n\nTo use the API token, add it to the\
\ `Authorization` header of your request:\n\n```\nAuthorization: Bearer <your\
\ token>\n```\n\n\n"
contact:
name: liblab
url: https://liblab.com/
version: 0.1.7
servers:
- url: http://localhost:8080
description: Prod
paths:
/llama/{llama_id}/picture:
get:
tags:
- LlamaPicture
summary: Get Llama Picture
description: Get a llama's picture by the llama ID. Pictures are in PNG format.
operationId: GetLlamaPictureByLlamaID
security:
- Bearer: []
parameters:
- name: llama_id
in: path
required: true
schema:
type: integer
description: The ID of the llama to get the picture for
examples:
- '1'
- '2'
title: Llama Id
description: The ID of the llama to get the picture for
responses:
'200':
description: Llamas
content:
image/png: {}
'401':
description: Invalid API token
'403':
description: Not authenticated. Send a valid API token in the Authorization
header.
'404':
description: Llama or llama picture not found
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
post:
tags:
- LlamaPicture
summary: Create Llama Picture
description: Create a picture for a llama. The picture is sent as a PNG as binary
data in the body of the request.
operationId: CreateLlamaPicture
security:
- Bearer: []
parameters:
- name: llama_id
in: path
required: true
schema:
type: integer
description: The ID of the llama that this picture is for
examples:
- '1'
- '2'
title: Llama Id
description: The ID of the llama that this picture is for
responses:
'201':
description: Llama picture created successfully
content:
application/json:
schema:
$ref: '#/components/schemas/LlamaId'
'400':
description: The request body is empty
'401':
description: Invalid API token
'403':
description: Not authenticated. Send a valid API token in the Authorization
header.
'404':
description: Llama not found
'409':
description: Llama picture already exists
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
requestBody:
content:
image/png: {}
put:
tags:
- LlamaPicture
summary: Update Llama Picture
description: "Update a picture for a llama. The picture is sent as a PNG as\
\ binary data in the body of the request.\n\nIf the llama does not have a\
\ picture, one will be created. If the llama already has a picture,\n it will\
\ be overwritten.\nIf the llama does not exist, a 404 will be returned."
operationId: UpdateLlamaPicture
security:
- Bearer: []
parameters:
- name: llama_id
in: path
required: true
schema:
type: integer
description: The ID of the llama that this picture is for
examples:
- '1'
- '2'
title: Llama Id
description: The ID of the llama that this picture is for
responses:
'200':
description: Llama picture created successfully
content:
application/json:
schema:
$ref: '#/components/schemas/LlamaId'
'400':
description: The request body is empty
'401':
description: Invalid API token
'403':
description: Not authenticated. Send a valid API token in the Authorization
header.
'404':
description: Llama not found
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
requestBody:
content:
image/png: {}
delete:
tags:
- LlamaPicture
summary: Delete Llama Picture
description: Delete a llama's picture by ID.
operationId: DeleteLlamaPicture
security:
- Bearer: []
parameters:
- name: llama_id
in: path
required: true
schema:
type: integer
description: The ID of the llama to delete the picture for
examples:
- '1'
- '2'
title: Llama Id
description: The ID of the llama to delete the picture for
responses:
'204':
description: Llama picture deleted successfully
'401':
description: Invalid API token
'403':
description: Not authenticated. Send a valid API token in the Authorization
header.
'404':
description: Llama or picture not found
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/llama:
get:
tags:
- Llama
summary: Get Llamas
description: Get all the llamas.
operationId: GetLlamas
responses:
'200':
description: Llamas
content:
application/json:
schema:
items:
$ref: '#/components/schemas/Llama'
type: array
title: Response 200 Getllamas
'401':
description: Invalid API token
'403':
description: Not authenticated. Send a valid API token in the Authorization
header.
security:
- Bearer: []
post:
tags:
- Llama
summary: Create Llama
description: Create a new llama. Llama names must be unique.
operationId: CreateLlama
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/LlamaCreate'
required: true
responses:
'201':
description: Llama created successfully
content:
application/json:
schema:
$ref: '#/components/schemas/Llama'
'401':
description: Invalid API token
'403':
description: Not authenticated. Send a valid API token in the Authorization
header.
'409':
description: Llama already exists
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
security:
- Bearer: []
/llama/{llama_id}:
get:
tags:
- Llama
summary: Get Llama
description: Get a llama by ID.
operationId: GetLlamaByID
security:
- Bearer: []
parameters:
- name: llama_id
in: path
required: true
schema:
type: integer
description: The llama's ID
examples:
- '1'
- '2'
title: Llama Id
description: The llama's ID
responses:
'200':
description: Llamas
content:
application/json:
schema:
$ref: '#/components/schemas/Llama'
type: array
items:
$ref: '#/components/schemas/Llama'
title: Response 200 Getllamabyid
'401':
description: Invalid API token
'403':
description: Not authenticated. Send a valid API token in the Authorization
header.
'404':
description: Llama not found
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
put:
tags:
- Llama
summary: Update Llama
description: 'Update a llama. If the llama does not exist, create it.
When updating a llama, the llama name must be unique. If the llama name is
not unique, a 409 will be returned.'
operationId: UpdateLlama
security:
- Bearer: []
parameters:
- name: llama_id
in: path
required: true
schema:
type: integer
description: The llama's ID
examples:
- '1'
- '2'
title: Llama Id
description: The llama's ID
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/LlamaCreate'
responses:
'200':
description: Successful Response
content:
application/json:
schema:
$ref: '#/components/schemas/Llama'
'201':
description: New llama created successfully
content:
application/json:
schema:
$ref: '#/components/schemas/Llama'
'401':
description: Invalid API token
'403':
description: Not authenticated. Send a valid API token in the Authorization
header.
'409':
description: The llama name is already in use
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
delete:
tags:
- Llama
summary: Delete Llama
description: Delete a llama. If the llama does not exist, this will return a
404.
operationId: DeleteLlama
security:
- Bearer: []
parameters:
- name: llama_id
in: path
required: true
schema:
type: integer
description: The llama's ID
examples:
- '1'
- '2'
title: Llama Id
description: The llama's ID
responses:
'204':
description: Llama deleted successfully
'401':
description: Invalid API token
'403':
description: Not authenticated. Send a valid API token in the Authorization
header.
'404':
description: Llama not found
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/token:
post:
tags:
- Token
summary: Create Api Token
description: 'Create an API token for a user. These tokens expire after 30 minutes.
Once you have this token, you need to pass it to other endpoints in the Authorization
header as a Bearer token.'
operationId: CreateAPIToken
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/APITokenRequest'
required: true
responses:
'201':
description: A new API token for the user
content:
application/json:
schema:
$ref: '#/components/schemas/APIToken'
'404':
description: User not found or the password is invalid
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/user/{email}:
get:
tags:
- User
summary: Get User By Email
description: 'Get a user by email.
This endpoint will return a 404 if the user does not exist. Otherwise, it
will return a 200.'
operationId: GetUserByEmail
security:
- Bearer: []
parameters:
- name: email
in: path
required: true
schema:
type: string
minLength: 5
maxLength: 254
pattern: .+\@.+\..+
description: The user's email address
title: Email
description: The user's email address
responses:
'200':
description: User
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'401':
description: Invalid API token
'403':
description: Not authenticated. Send a valid API token in the Authorization
header.
'404':
description: User not found
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/user:
post:
tags:
- User
summary: Register User
description: 'Register a new user.
This endpoint will return a 400 if the user already exists. Otherwise, it
will return a 201.'
operationId: RegisterUser
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/UserRegistration'
required: true
responses:
'201':
description: User registered successfully
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'400':
description: User already registered
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
components:
schemas:
APIToken:
properties:
accessToken:
type: string
title: Access Token
description: The bearer token to use with the API. Pass this in the Authorization
header as a bearer token.
examples:
- 'Authorization: Bearer 1234567890abcdef'
tokenType:
type: string
title: Token Type
description: The type of token. This will always be bearer.
default: bearer
examples:
- bearer
type: object
required:
- accessToken
title: APIToken
description: An API token to use for authentication.
examples:
- accessToken: 1234567890abcdef
tokenType: bearer
APITokenRequest:
properties:
email:
type: string
maxLength: 254
minLength: 5
pattern: .+\@.+\..+
title: Email
description: The email address of the user. This must be unique across all
users.
examples:
- llama@liblab.com
password:
type: string
maxLength: 254
minLength: 8
title: Password
description: The password of the user. This must be at least 8 characters
long, and contain at least one letter, one number, and one special character.
examples:
- Password123!
type: object
required:
- email
- password
title: APITokenRequest
description: A request to get an API token for a given user.
examples:
- email: noone@example.com
password: Password123!
HTTPValidationError:
properties:
detail:
items:
$ref: '#/components/schemas/ValidationError'
type: array
title: Detail
type: object
title: HTTPValidationError
Llama:
properties:
name:
type: string
maxLength: 100
title: Name
description: The name of the llama. This must be unique across all llamas.
examples:
- libby the llama
- labby the llama
age:
type: integer
title: Age
description: The age of the llama in years.
examples:
- 5
- 6
- 7
color:
allOf:
- $ref: '#/components/schemas/LlamaColor'
description: The color of the llama.
examples:
- brown
- white
- black
- gray
rating:
type: integer
maximum: 5.0
minimum: 1.0
title: Rating
description: The rating of the llama from 1 to 5.
examples:
- 1
- 2
- 3
- 4
- 5
llamaId:
type: integer
title: Llama Id
description: The ID of the llama.
examples:
- 1
type: object
required:
- name
- age
- color
- rating
- llamaId
title: Llama
description: A llama, with details of its name, age, color, and rating from
1 to 5.
examples:
- age: 5
color: brown
llama_id: '1'
name: libby the llama
rating: 4
LlamaColor:
type: string
enum:
- brown
- white
- black
- gray
title: LlamaColor
description: The color of a llama.
LlamaCreate:
properties:
name:
type: string
maxLength: 100
title: Name
description: The name of the llama. This must be unique across all llamas.
examples:
- libby the llama
- labby the llama
age:
type: integer
title: Age
description: The age of the llama in years.
examples:
- 5
- 6
- 7
color:
allOf:
- $ref: '#/components/schemas/LlamaColor'
description: The color of the llama.
examples:
- brown
- white
- black
- gray
rating:
type: integer
maximum: 5.0
minimum: 1.0
title: Rating
description: The rating of the llama from 1 to 5.
examples:
- 1
- 2
- 3
- 4
- 5
type: object
required:
- name
- age
- color
- rating
title: LlamaCreate
description: A new llama for the llama store.
examples:
- age: 5
color: brown
name: libby the llama
rating: 4
LlamaId:
properties:
llamaId:
type: integer
title: Llama Id
description: The ID of the llama.
examples:
- 1
type: object
required:
- llamaId
title: LlamaId
description: A llama id.
examples:
- llama_id: '1'
User:
properties:
email:
type: string
maxLength: 254
minLength: 5
pattern: .+\@.+\..+
title: Email
description: The email address of the user. This must be unique across all
users.
examples:
- llama@liblab.com
id:
type: integer
title: Id
description: The ID of the user. This is unique across all users.
examples:
- 1
- 2
- 3
type: object
required:
- email
- id
title: User
description: A user of the llama store
examples:
- email: noone@example.com
id: '1'
UserRegistration:
properties:
email:
type: string
maxLength: 254
minLength: 5
pattern: .+\@.+\..+
title: Email
description: The email address of the user. This must be unique across all
users.
examples:
- llama@liblab.com
password:
type: string
maxLength: 254
minLength: 8
title: Password
description: The password of the user. This must be at least 8 characters
long, and contain at least one letter, one number, and one special character.
examples:
- Password123!
type: object
required:
- email
- password
title: UserRegistration
description: A new user of the llama store.
examples:
- email: noone@example.com
password: Password123!
ValidationError:
properties:
loc:
items:
anyOf:
- type: string
- type: integer
type: array
title: Location
msg:
type: string
title: Message
type:
type: string
title: Error Type
type: object
required:
- loc
- msg
- type
title: ValidationError
securitySchemes:
Bearer:
type: http
scheme: bearer
bearerFormat: JWT
tags:
- name: Llama
description: Get the llamas
- name: LlamaPicture
description: Get the llama pictures
- name: User
description: Register users
- name: Token
description: Manage API Tokens