-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswagger.yaml
825 lines (801 loc) · 24 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
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
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
openapi: '3.0.2'
info:
title: Survey API
license:
name: MIT
url: https://github.com/SheepCreativeSoftware/survey-api/blob/main/LICENSE
description: 'Simple API to manage a survey'
version: '1.0.0'
servers:
- url: https://{subdomain}.{domain}/api/v1
description: 'Public URL'
variables:
domain:
default: sheepcs.de
subdomain:
default: survey
- url: http://localhost:{port}/api/v1
description: 'Local testing URL'
variables:
port:
default: '3000'
paths:
/security/register-user:
post:
tags:
- security
description: 'Registers a new user account on the server'
requestBody:
content:
application/json:
schema:
type: object
description: 'User account credentials'
properties:
firstName:
type: string
minLength: 1
maxLength: 50
lastName:
type: string
minLength: 1
maxLength: 50
email:
type: string
format: email
minLength: 1
maxLength: 50
password:
type: string
minLength: 8
maxLength: 50
example: {
"firstName": "Jane",
"lastName": "Doe",
"email": "[email protected]",
"password": "12345678"
}
responses:
'201':
description: 'Created'
content:
application/json:
schema:
$ref: '#/components/schemas/UserId'
'400':
$ref: '#/components/responses/400'
'409':
$ref: '#/components/responses/409'
'500':
$ref: '#/components/responses/500'
/security/login-user:
post:
tags:
- security
description: 'Login a user existing account on the server'
requestBody:
content:
application/json:
schema:
type: object
description: 'User account credentials'
properties:
email:
type: string
format: email
minLength: 1
maxLength: 50
password:
type: string
minLength: 8
maxLength: 50
example: {
"email": "[email protected]",
"password": "12345678"
}
responses:
'200':
description: 'OK'
content:
application/json:
schema:
type: object
description: 'Access Creator token for the user'
properties:
token:
type: string
format: jwt
example: {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiQ3JlYXRvciIsImlhdCI6MTcxMzUzOTQ4OSwiZXhwIjoxNzEzNTQxMjg5LCJpc3MiOiJsb2NhbGhvc3QiLCJzdWIiOiIxMTAyMTU2ZS1iMWYxLTRlY2YtOTEwYS1mZDAxMmI3ZDhlNDEiLCJqdGkiOiI2NjJjODBmNy1mZDVlLTRkNTItODExNC05ZmZiNDAyYjQ1ZDUifQ.-Dj5uC5mOn2oIC6M3lpCTdMWJbGW1EuDfee4F6BB9C0"
}
'400':
$ref: '#/components/responses/400'
'401':
$ref: '#/components/responses/401'
'403':
$ref: '#/components/responses/403'
'404':
$ref: '#/components/responses/404'
'500':
$ref: '#/components/responses/500'
/security/generate-answer-token:
post:
tags:
- security
description: Generates a Access Answerer Token for answering surveys
security:
- BearerCreatorToken: []
requestBody:
content:
application/json:
schema:
type: object
description: 'Survey Id for answer'
properties:
surveyId:
type: string
format: uuid
example: {
"surveyId": "af6f94a5-2cc5-4fac-868a-ab70a5bdc033"
}
responses:
'200':
description: 'OK'
content:
application/json:
schema:
type: object
description: 'Access Creator token for the user'
properties:
token:
type: string
format: jwt
example: {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiQ3JlYXRvciIsImlhdCI6MTcxMzUzOTQ4OSwiZXhwIjoxNzEzNTQxMjg5LCJpc3MiOiJsb2NhbGhvc3QiLCJzdWIiOiIxMTAyMTU2ZS1iMWYxLTRlY2YtOTEwYS1mZDAxMmI3ZDhlNDEiLCJqdGkiOiI2NjJjODBmNy1mZDVlLTRkNTItODExNC05ZmZiNDAyYjQ1ZDUifQ.-Dj5uC5mOn2oIC6M3lpCTdMWJbGW1EuDfee4F6BB9C0"
}
'400':
$ref: '#/components/responses/400'
'403':
$ref: '#/components/responses/403'
'500':
$ref: '#/components/responses/500'
/survey-list/open-surveys:
get:
tags:
- survey-list
description: 'Returns a list of open surveys of that user'
security:
- BearerCreatorToken: []
responses:
'200':
description: OK
content:
application/json:
schema:
type: array
minItems: 1
items:
allOf:
- $ref: '#/components/schemas/SurveyWithId'
- $ref: '#/components/schemas/OptionsResponse'
'401':
$ref: '#/components/responses/401'
'404':
$ref: '#/components/responses/404'
'500':
$ref: '#/components/responses/500'
/survey-list/completed-surveys:
get:
tags:
- survey-list
description: 'Returns a list of completed surveys (open for answering) of that user'
security:
- BearerCreatorToken: []
responses:
'200':
description: OK
content:
application/json:
schema:
type: array
minItems: 1
items:
allOf:
- $ref: '#/components/schemas/SurveyWithId'
- $ref: '#/components/schemas/OptionsResponse'
'401':
$ref: '#/components/responses/401'
'404':
$ref: '#/components/responses/404'
'500':
$ref: '#/components/responses/500'
/survey-list/create-survey:
post:
tags:
- survey-list
description: 'Creates a new survey'
security:
- BearerCreatorToken: []
requestBody:
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/Survey'
- $ref: '#/components/schemas/OptionsCreation'
responses:
'201':
description: Created
content:
application/json:
schema:
$ref: '#/components/schemas/SurveyCreatedResponse'
'400':
$ref: '#/components/responses/400'
'401':
$ref: '#/components/responses/401'
'500':
$ref: '#/components/responses/500'
/survey-list/adjust-survey:
post:
tags:
- survey-list
description: 'Adjusts parameters of a survey'
security:
- BearerCreatorToken: []
requestBody:
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/SurveyWithId'
- $ref: '#/components/schemas/OptionsAdjust'
responses:
'200':
description: OK
'400':
$ref: '#/components/responses/400'
'401':
$ref: '#/components/responses/401'
'500':
$ref: '#/components/responses/500'
/survey-list/complete-survey:
post:
tags:
- survey-list
description: 'Completes a survey / Opens them for answering'
security:
- BearerCreatorToken: []
requestBody:
content:
application/json:
schema:
type: object
description: 'Id of the survey'
properties:
surveyId:
type: string
format: uuid
example: {
"surveyId": "e1b3f489-ae9b-4bcc-8a17-a5bf9e841fb4",
}
responses:
'200':
description: OK
'400':
$ref: '#/components/responses/400'
'401':
$ref: '#/components/responses/401'
'500':
$ref: '#/components/responses/500'
/survey-result/open-result:
get:
tags:
- survey-result
description: Returns the results of a survey
security:
- BearerAnswererToken: []
- BearerCreatorToken: []
parameters:
- in: query
name: surveyId
schema:
type: string
format: uuid
description: 'Id of the survey (Only required when using Creator Token | Answerer Token already provides a Survey Id)'
example: 87145350-a26a-4e59-af19-bb72f25cdb81
required: false
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
description: 'List with result count to each of the options'
properties:
surveyId:
type: string
format: uuid
totalCount:
type: number
results:
type: array
items:
type: object
properties:
optionId:
type: string
format: uuid
resultCount:
type: number
example: {
"surveyId": "87145350-a26a-4e59-af19-bb72f25cdb81",
"totalCount": 2,
"results": [
{
"optionId": "583704ab-f5f9-4fbd-84a4-8351758d19ad",
"resultCount": 1
},
{
"optionId": "af6f94a5-2cc5-4fac-868a-ab70a5bdc033",
"resultCount": 1
}
]
}
'400':
$ref: '#/components/responses/400'
'401':
$ref: '#/components/responses/401'
'404':
$ref: '#/components/responses/404'
'500':
$ref: '#/components/responses/500'
/answer/open-survey:
get:
tags:
- answer
description: Returns the survey that is related to the Answerer Token
security:
- BearerAnswererToken: []
responses:
'200':
description: OK
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/SurveyWithId'
- $ref: '#/components/schemas/OptionsResponse'
'401':
$ref: '#/components/responses/401'
'404':
$ref: '#/components/responses/404'
'500':
$ref: '#/components/responses/500'
/answer/answer-survey:
post:
tags:
- answer
description: Answers the survey that is related to the Answerer Token (Can only be used once per Answerer Token)
security:
- BearerAnswererToken: []
requestBody:
content:
application/json:
schema:
description: Depending on the suvery choice type, it requieres either an array of options or a single option
oneOf:
- type: object
properties:
optionId:
type: string
format: uuid
example: {
"optionId": "fced3fe3-bcea-4b2d-9e8b-9920ae963f5c"
}
- type: array
items:
type: object
properties:
optionId:
type: string
format: uuid
example: [
{
"optionId": "583704ab-f5f9-4fbd-84a4-8351758d19ad"
},
{
"optionId": "af6f94a5-2cc5-4fac-868a-ab70a5bdc033"
}
]
responses:
'200':
description: OK
'401':
$ref: '#/components/responses/401'
'404':
$ref: '#/components/responses/404'
'409':
$ref: '#/components/responses/409'
'500':
$ref: '#/components/responses/500'
/open-api-spec:
get:
tags:
- open-api-spec
description: Shows this Open API specification
responses:
'200':
description: OK
content:
text/yaml:
schema:
description: Shows this Open API specification
components:
securitySchemes:
BearerCreatorToken:
type: http
scheme: bearer
bearerFormat: JWT
BearerAnswererToken:
type: http
scheme: bearer
bearerFormat: JWT
schemas:
UserId:
type: object
description: 'Returns the user id'
properties:
status:
type: string
format: uuid
example:
id: 'f197ea8b-da1b-4197-8cbd-600733ce6c45'
Survey:
type: object
required:
- surveyName
- surveyDescription
- choicesType
- endDate
properties:
surveyName:
description: 'Name of the survey'
type: string
surveyDescription:
description: 'Description of the survey'
type: string
choicesType:
description: 'Survey is single or multiple choice?'
type: string
enum:
- 'single'
- 'multiple'
endDate:
description: 'When will the survey end?'
type: string
format: ISO-DateString
example:
surveyName: 'The Survey'
surveyDescription: 'What do you think about?'
choicesType: 'single'
endDate: '2024-02-19T18:09:00.967Z'
SurveyWithId:
type: object
required:
- surveyId
- surveyName
- surveyDescription
- choicesType
- endDate
properties:
surveyId:
description: 'Name of the survey'
type: string
format: uuid
surveyName:
description: 'Name of the survey'
type: string
surveyDescription:
description: 'Description of the survey'
type: string
choicesType:
description: 'Survey is single or multiple choice?'
type: string
enum:
- 'single'
- 'multiple'
created:
description: 'When has this survey been created'
type: string
format: ISO-DateString
endDate:
description: 'When will the survey end?'
type: string
format: ISO-DateString
example: {
"surveyId": "53f79b77-2db2-4a55-bcca-05d82dfbeb1a",
"surveyName": "The postman survey Updated",
"surveyDescription": "Some test Haha",
"choicesType": "single",
"created": "2024-04-16T18:25:40.000Z",
"endDate": "2024-05-03T23:00:00.000Z",
}
SurveyCreatedResponse:
type: object
description: 'The Ids of the survey for later editing'
required:
- options
properties:
surveyId:
type: string
format: uuid
options:
type: array
minItems: 1
items:
type: object
properties:
optionId:
type: string
format: uuid
example: {
"surveyId": "0e84a131-6f74-45d7-b382-483a667e73e6",
"options": [
{
"optionId": "fced3fe3-bcea-4b2d-9e8b-9920ae963f5c"
},
{
"optionId": "1e101da6-cd0d-4748-a52c-efeaa3679d2b"
}
]
}
OptionsCreation:
type: object
description: 'Different options of the survey'
required:
- options
properties:
options:
type: array
minItems: 2
items:
type: object
required:
- optionName
- content
properties:
optionName:
description: 'Question of the option'
type: string
content:
description: 'Additional context of the survey'
type: string
example:
options: [
{
optionName: 'Choice Name 1',
content: 'Context of the choice'
},
{
optionName: 'Choice Name 2',
content: 'Context of the choice'
}
]
OptionsResponse:
type: object
description: 'Different options of the survey'
required:
- options
properties:
options:
type: array
minItems: 2
items:
type: object
required:
- optionName
- optionId
- content
properties:
optionId:
type: string
format: uuid
description: 'Id of that option'
optionName:
description: 'Question of the option'
type: string
content:
description: 'Additional context of the survey'
type: string
example:
options: [
{
optionName: 'Choice Name 1',
optionId: '28dc30d0-de6c-4566-83b6-b51b2bc1e59f',
content: 'Context of the choice'
},
{
optionName: 'Choice Name 2',
optionId: '211c623d-b18b-4df8-a531-4c7a68e9fcb2',
content: 'Context of the choice'
}
]
OptionsAdjust:
type: object
description: 'Adjusts Options from the survey'
required:
- options
properties:
options:
type: array
minItems: 1
items:
type: object
required:
- optionId
- status
properties:
optionId:
type: string
format: uuid
description: 'Id of that option'
optionName:
description: 'Question of the option'
type: string
content:
description: 'Additional context of the survey'
type: string
status:
description: 'Defines what kind of adjustment should be done'
type: string
enum:
- 'Delete'
- 'New'
- 'Insert'
example:
options: [
{
optionId: '28dc30d0-de6c-4566-83b6-b51b2bc1e59f',
status: 'Delete'
},
{
optionId: '28dc30d0-de6c-4566-83b6-b51b2bc1e59f',
optionName: 'Choice Name 2',
content: 'Context of the choice',
status: 'New'
},
{
optionId: '28dc30d0-de6c-4566-83b6-b51b2bc1e59f',
optionName: 'Choice Name 2',
content: 'Context of the choice',
status: 'Update'
},
]
responses:
'400':
description: 'Bad Request: The request is invalid.'
content:
application/json:
schema:
type: object
properties:
error:
description: Type of Error
type: string
message:
description: Clear message describing the error (optional)
type: string
statusCode:
description: HTTP Standard Status Code
type: number
example: {
error: "Bad Request",
message: "Missing data field in request body",
statusCode: 400
}
'401':
description: 'Unauthorized: The request requires a specific access token to authorize.'
content:
application/json:
schema:
type: object
properties:
error:
description: Type of Error
type: string
message:
description: Clear message describing the error (optional)
type: string
statusCode:
description: HTTP Standard Status Code
type: number
example: {
error: "Unauthorized",
message: "Invalid Token: JWT expired",
statusCode: 401
}
'403':
description: 'Forbidden: The client does not have access rights to the content.'
content:
application/json:
schema:
type: object
properties:
error:
description: Type of Error
type: string
message:
description: Clear message describing the error (optional)
type: string
statusCode:
description: HTTP Standard Status Code
type: number
example: {
error: "Forbidden",
message: "Credentials are wrong",
statusCode: 403
}
'404':
description: 'Not Found: The ressource was not found.'
content:
application/json:
schema:
type: object
properties:
error:
description: Type of Error
type: string
message:
description: Clear message describing the error (optional)
type: string
statusCode:
description: HTTP Standard Status Code
type: number
example: {
error: "Not Found",
message: "Ressouce with ID: xxxx not found",
statusCode: 404
}
'409':
description: 'Conflict: There is a conflict with the provided data.'
content:
application/json:
schema:
type: object
properties:
error:
description: Type of Error
type: string
message:
description: Clear message describing the error (optional)
type: string
statusCode:
description: HTTP Standard Status Code
type: number
example: {
error: "Conflict",
message: "Already answered or invalid option",
statusCode: 409
}
'500':
description: 'Internal Server Error: The server has encountered a situation it does not know how to handle.'
content:
application/json:
schema:
type: object
properties:
error:
description: Type of Error
type: string
message:
description: Clear message describing the error (optional)
type: string
statusCode:
description: HTTP Standard Status Code
type: number
example: {
error: "Internal Server Error",
statusCode: 500
}