-
Notifications
You must be signed in to change notification settings - Fork 1
/
swagger.yml
425 lines (420 loc) · 10.8 KB
/
swagger.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
swagger: "2.0"
info:
description: "This is the oficial documentation for the EasyPoll API. If you have any problems or requests, please contact us on GitHub."
version: "1.0.0"
title: "EasyPoll"
contact:
email: "noreply@easypoll.com.br"
basePath: "/v1"
tags:
- name: "auth"
description: "Operations about authentication"
- name: "poll"
description: "Operations to get, create, update and delete polls"
- name: "vote"
description: "Operations to vote"
schemes:
- "http"
securityDefinitions:
Bearer:
type: apiKey
name: Authorization
in: header
paths:
/login:
post:
tags:
- auth
summary: Login to the application
description: Authenticates an user and returns a token to be used in requests
operationId: "loginUser"
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- in: "body"
name: "body"
description: "Account credentials"
required: true
schema:
type: object
properties:
email:
type: string
description: Email of the account
password:
type: string
description: Password of the account
format: password
required:
- email
- password
responses:
200:
description: Login successful
schema:
allOf:
- $ref: '#/definitions/Token'
- type: object
properties:
user:
$ref: '#/definitions/User'
400:
description: Incorrect password or invalid input
schema:
$ref: '#/definitions/Error'
404:
description: Email not registered
schema:
$ref: '#/definitions/Error'
422:
description: Missing required fields
/register:
post:
tags:
- auth
summary: Create a new account
description: Create a new account and returns a token to be used in requests
operationId: "registerUser"
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- in: "body"
name: "body"
description: "Account details"
required: true
schema:
type: object
properties:
name:
type: string
description: Name of the user
email:
type: string
description: Email of the account
password:
type: string
description: Password of the account
format: password
required:
- name
- email
- password
responses:
200:
description: Account created
schema:
allOf:
- $ref: '#/definitions/Token'
- type: object
properties:
user:
$ref: '#/definitions/User'
400:
description: Email already registered or invalid input
422:
description: Missing required fields
/user:
get:
tags:
- auth
summary: Get the logged user info
security:
- Bearer: []
description: Get the authenticated user account details
operationId: "getAuthenticatedUser"
consumes:
- "application/json"
produces:
- "application/json"
responses:
200:
description: Return the account of the authenticated user
schema:
allOf:
- $ref: '#/definitions/User'
401:
description: Invalid token
/polls:
get:
tags:
- "poll"
summary: "List all polls"
description: "Gets a list with all the polls in the database"
operationId: "getPolls"
consumes:
- "application/json"
produces:
- "application/json"
responses:
200:
schema:
type: array
items:
$ref: "#/definitions/Poll"
description: "Poll list fetched successfully"
post:
tags:
- "poll"
summary: "Create a new poll"
description: "Inserts a new poll in the database"
operationId: "createPoll"
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- in: "body"
name: "body"
description: "Poll that will be created"
required: true
schema:
allOf:
- $ref: "#/definitions/PollRequest"
required:
- question
- answers
- multipleAnswers
responses:
200:
schema:
$ref: "#/definitions/Poll"
description: "Poll created"
400:
description: "Invalid input"
422:
description: "Missing required fields"
/polls/{id}:
get:
tags:
- "poll"
summary: "Display a single poll by id"
description: "Gets a single poll by id"
operationId: "getPollById"
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- name: id
in: path
type: integer
required: true
description: The id of the poll
responses:
200:
schema:
$ref: "#/definitions/Poll"
description: "Poll fetched successfully"
404:
description: "Resource not found"
put:
tags:
- "poll"
summary: "Update a poll by id"
description: |
Updates the whole poll object with a new one
Unspecified optional fields will be counted as zero-value and will be overwritten
operationId: "updatePollById"
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- name: id
in: path
type: integer
required: true
description: The id of the poll
- in: "body"
name: "body"
description: "New poll data"
required: true
schema:
allOf:
- $ref: "#/definitions/PollRequest"
required:
- question
- answers
- multipleAnswers
responses:
200:
schema:
$ref: "#/definitions/Poll"
description: "Poll updated"
400:
description: "Invalid input"
404:
description: "Resource not found"
422:
description: "Missing required fields"
patch:
tags:
- "poll"
summary: "Update (part of) a poll by id"
description: |
Updates (part of) a poll properties, all fields are optional
Unspecified fields will be ignored and won't be updated
operationId: "patchPollById"
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- name: id
in: path
type: integer
required: true
description: The id of the poll
- in: "body"
name: "body"
description: "Properties of the poll that will be updated"
required: true
schema:
$ref: "#/definitions/PollRequest"
responses:
200:
schema:
$ref: "#/definitions/Poll"
description: "Poll updated"
400:
description: "Invalid input"
404:
description: "Resource not found"
delete:
tags:
- "poll"
summary: "Delete a poll by id"
description: "Removes a poll from the database by id"
operationId: "deletePollById"
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- name: id
in: path
type: integer
required: true
description: The id of the poll
responses:
204:
description: "Poll deleted"
404:
description: "Resource not found"
/polls/{id}/votes:
post:
tags:
- "vote"
summary: "Votes in answers of a poll"
description: |
Adds one vote to answers of a poll, the request body is an array with integers, each number is the index of the answer
Sending [1, 3, 2] will add one vote to the 2nd, 4th and 3rd answers of the poll
You can only send more than one value in the array if the poll accepts multiple answers
Repeated numbers will be counted as one
operationId: "addVotePoll"
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- name: id
in: path
type: integer
required: true
description: The id of the poll
- in: "body"
name: "body"
description: "Array with answers to be voted"
required: true
schema:
type: array
items:
type: integer
responses:
204:
description: "Vote(s) added"
400:
description: "Invalid input"
schema:
$ref: '#/definitions/Error'
404:
description: "Resource not found"
422:
description: "Missing required fields"
definitions:
Poll:
type: object
properties:
id:
type: integer
question:
type: string
example: "What's your favorite color?"
answers:
type: array
items:
$ref: '#/definitions/Answer'
votes:
type: integer
x-omitempty: false
multipleAnswers:
type: boolean
createdAt:
type: string
format: date-time
PollRequest:
type: object
properties:
question:
type: string
example: "What's your favorite color?"
answers:
type: array
items:
$ref: '#/definitions/Answer'
multipleAnswers:
type: boolean
Answer:
type: object
properties:
title:
type: string
example: "Blue"
votes:
type: integer
x-omitempty: false
Token:
type: object
properties:
token:
type: string
example: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjEsImlhdCI6MTUzMzY2MTY0Mn0.w_qI2tv8imANq_ys_ZKvLtrGItd7hrfRjifJoYSJzfo'
User:
type: object
properties:
name:
type: string
example: 'John Doe'
description: 'Name of the user'
email:
type: string
example: 'john@doe.com'
description: 'Email of the user'
password:
type: string
example: 'secret'
format: password
description: 'Password of the user'
Error:
type: object
properties:
code:
type: integer
example: 622
message:
type: string
example: "error message"