-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenapi.yaml
704 lines (699 loc) · 21.9 KB
/
openapi.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
openapi: 3.0.1
info:
title: Kilo API
description: >
The following is the API specification for
[Kilo](https://kilo-games.netlify.app/)
# termsOfService: http://swagger.io/terms/
# contact:
# email: apiteam@swagger.io
license:
name: Dual MIT/Apache 2.0
url: https://github.com/search?q=repo%3ATeamKilo%2Fkilo_server+filename%3ALICENSE&type=Code
version: 1.0.0
servers:
- url: https://team-kilo-server.herokuapp.com/api
tags:
- name: Game management
description: Game creation and searching
- name: Game
description: Game viewing and playing
paths:
/create-game:
post:
tags:
- Game management
summary: Create a game
description: Create a game given a type of game
operationId: createGame
requestBody:
content:
application/json:
schema:
required:
- game_type
type: object
properties:
game_type:
$ref: '#/components/schemas/GameType'
required: true
responses:
200:
description: Game successfully added
content:
application/json:
schema:
required:
- game_id
type: object
properties:
game_id:
$ref: '#/components/schemas/GameId'
links:
Join game:
$ref: '#/components/links/GameIdJoinGame'
Get state:
$ref: '#/components/links/GameIdGetState'
Submit move:
$ref: '#/components/links/GameIdSubmitMove'
400:
description: JSON deserialization error
content:
text/plain:
schema:
$ref: '#/components/schemas/JSONDeserializeError'
/list-games:
get:
tags:
- Game management
summary: List existing games
description: >
List the ID, game type, players, stage and last updated time of up to 20
existing games and give the total number of existing games
operationId: listGames
parameters:
- in: query
name: page
schema:
type: integer
minimum: 1
default: 1
description: >
The page of the pagination of game summaries, with the first page
having the first 20 results, the second having the next 20 and so
on
required: false
- in: query
name: sort_order
schema:
type: string
enum:
- asc
- desc
default: desc
description: >
Whether the results are sorted in **asc**ending or **desc**ending
order, where ascending is from A to Z
required: false
- in: query
name: sort_key
schema:
type: string
enum:
- game_type
- players
- stage
- last_updated
default: last_updated
description: >
What the game summary list is sorted by
- `game_type` - Sort by the type of game
- `players` - Sort by the number of players
- `stage` - Sort by the game stage
- `last_updated` - Sort by the time the game was lasted updated
Game summaries with equal values for each key are sorted by the
following key in the above list
required: false
- in: query
name: game_type
schema:
$ref: '#/components/schemas/GameType'
description: >
If this is parameter present, only games of this type are
searched for
required: false
- in: query
name: players
schema:
type: integer
minimum: 0
description: >
If this is parameter present, only games with this number
of players are searched for
required: false
- in: query
name: stage
schema:
$ref: '#/components/schemas/Stage'
description: >
If this is parameter present, only games in this stage are
searched for
required: false
responses:
200:
description: A list of game summaries and the number of games existing
content:
application/json:
schema:
type: object
required:
- game_summaries
- number_of_games
properties:
game_summaries:
type: array
description: A list of game summaries
items:
allOf:
- type: object
required:
- game_id
- game_type
properties:
game_id:
$ref: '#/components/schemas/GameId'
game_type:
$ref: '#/components/schemas/GameType'
- $ref: '#/components/schemas/GameSummaryBase'
number_of_games:
type: number
description: The number of games existing
minimum: 0
400:
description: Query deserialization error
content:
text/plain:
schema:
$ref: '#/components/schemas/QueryDeserializeError'
/{game_id}/join-game:
post:
tags:
- Game
summary: Join a game
description: Attempt to join a game, creating a session
operationId: joinGame
parameters:
- in: path
name: game_id
schema:
$ref: '#/components/schemas/GameId'
required: true
description: ID of a game
requestBody:
content:
application/json:
schema:
required:
- username
type: object
properties:
username:
$ref: '#/components/schemas/Username'
required: true
responses:
200:
description: Session successfully created
content:
application/json:
schema:
required:
- session_id
type: object
properties:
session_id:
$ref: '#/components/schemas/SessionId'
links:
Submit move:
$ref: '#/components/links/SessionIdSubmitMove'
400:
description: >
Path deserialization error, username is invalid or game has already started
content:
text/plain:
schema:
oneOf:
- $ref: '#/components/schemas/PathDeserializeError'
- $ref: '#/components/schemas/InvalidUsername'
- $ref: '#/components/schemas/GameInProgress'
404:
description: Game not found
content:
text/plain:
schema:
$ref: '#/components/schemas/GameNotFound'
/{game_id}/get-state:
get:
tags:
- Game
summary: Get a game's state
description: >
Get a game's state, including the current players, the stage, the
players that have won so far, the type of the game and a
game-specific payload with additional information
operationId: getState
parameters:
- in: path
name: game_id
schema:
$ref: '#/components/schemas/GameId'
required: true
description: ID of a game
responses:
200:
description: The game's state
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/GameSummaryBase'
- type: object
required:
- can_move
- winners
- game_name
- payload
properties:
players:
type: array
items:
$ref: '#/components/schemas/Username'
description: The usernames of players currently in the game
example:
- Player 1
- Player 2
stage:
type: string
enum:
- waiting
- in_progress
- ended
description: >
Whether the game is waiting for players, in progress or
over
example: in_progress
can_move:
type: array
items:
$ref: '#/components/schemas/Username'
description: >
Usernames from `players` that can use
`POST /{game_id}/submit-move/`
winners:
type: array
items:
$ref: '#/components/schemas/Username'
description: >
Usernames from `players` that are winners
(this is empty if there is a draw)
example: [ ]
payload:
oneOf:
- $ref: '#/components/schemas/Connect4Request'
- $ref: '#/components/schemas/SnakeRequest'
discriminator:
propertyName: game_type
400:
description: Path or JSON deserialization error
content:
text/plain:
schema:
oneOf:
- $ref: '#/components/schemas/PathDeserializeError'
- $ref: '#/components/schemas/JSONDeserializeError'
404:
description: Game not found
content:
text/plain:
schema:
$ref: '#/components/schemas/GameNotFound'
/{game_id}/submit-move:
post:
tags:
- Game
summary: Submit a move
description: >
Attempt to submit a player's move in a game
operationId: submitMove
requestBody:
content:
application/json:
schema:
required:
- session_id
- payload
type: object
properties:
session_id:
$ref: '#/components/schemas/SessionId'
payload:
oneOf:
- $ref: '#/components/schemas/Connect4Response'
- $ref: '#/components/schemas/SnakeResponse'
discriminator:
propertyName: game_type
required: true
parameters:
- in: path
name: game_id
schema:
$ref: '#/components/schemas/GameId'
required: true
description: ID of a game
responses:
200:
description: Move successfully made
content:
application/json:
schema:
required:
- clock
type: object
properties:
clock:
$ref: '#/components/schemas/SessionId'
400:
description: >
Path or JSON deserialization error, game is not in progress,
session does not match game, move is invalid or player cannot
currently move
content:
text/plain:
schema:
oneOf:
- $ref: '#/components/schemas/PathDeserializeError'
- $ref: '#/components/schemas/JSONDeserializeError'
- $ref: '#/components/schemas/GameWaiting'
- $ref: '#/components/schemas/GameEnded'
- $ref: '#/components/schemas/InvalidMove'
- $ref: '#/components/schemas/InvalidPlayer'
404:
description: Game or session not found
content:
text/plain:
schema:
oneOf:
- $ref: '#/components/schemas/GameNotFound'
- $ref: '#/components/schemas/SessionNotFound'
/{game_id}/wait-for-update:
get:
tags:
- Game
summary: Wait for update
description: >
Receive a response when the clock exceeds the given value
(defaulting to the current clock value) or the request times out
operationId: waitForUpdate
parameters:
- in: path
name: game_id
schema:
$ref: '#/components/schemas/GameId'
required: true
description: ID of a game
- in: query
name: since
schema:
type: integer
description: >
The clock value that must be exceeded for a non-timeout
response (defaults to the current clock value)
required: false
responses:
200:
description: Clock exceeded `since` or request timed out
content:
application/json:
schema:
required:
- clock
type: object
properties:
clock:
type: integer
description: The current clock value at the server
400:
description: >
Path or query deserialization error
content:
text/plain:
schema:
oneOf:
- $ref: '#/components/schemas/PathDeserializeError'
- $ref: '#/components/schemas/QueryDeserializeError'
components:
schemas:
GameTypeBase:
type: string
example: connect_4
description: Type of game
GameType:
allOf:
- $ref: '#/components/schemas/GameTypeBase'
- enum:
- connect_4
- snake
GameId:
type: string
example: game_NF6G5NI
description: ID of a game
pattern: game_[A-Z0-9]+
SessionId:
type: string
example: session_AOHL56GENZPMVKFHA2LD5MOYRA
description: ID of a session
pattern: session_[A-Z0-9]+
Username:
type: string
minLength: 1
maxLength: 12
example: Player 1
description: Name of a player
GameSummaryBase:
type: object
required:
- players
- stage
- last_updated
properties:
players:
type: array
items:
$ref: '#/components/schemas/Username'
description: The usernames of players currently in the game
example:
- Player 1
- Player 2
stage:
$ref: '#/components/schemas/Stage'
last_updated:
type: string
format: date-time
description: >
The time of the most recent update to the game's state
example: 2022-02-22T12:33:30+0000
Stage:
type: string
enum:
- waiting
- in_progress
- ended
description: >
Whether a game is waiting for players, in progress or
over
example: in_progress
Connect4Request:
type: object
required:
- game_type
- cells
properties:
game_type:
allOf:
- $ref: '#/components/schemas/GameTypeBase'
- enum: [ 'connect_4' ]
cells:
type: array
items:
type: array
items:
$ref: '#/components/schemas/Username'
description: >
A column from a connect 4 game, with tokens being
represented by the usernames of the players who
placed them and the bottom token being the
leftmost
maxItems: 6
description: An array of a connect 4 game's columns
minItems: 7
maxItems: 7
example:
- [ ]
- [ "Player 1", "Player 2" ]
- [ "Player 2" ]
- [ "Player 1" ]
- [ ]
- [ ]
- [ ]
description: Payload for a connect 4 game's state
Connect4Response:
type: object
required:
- game_type
- column
properties:
game_type:
allOf:
- $ref: '#/components/schemas/GameTypeBase'
- enum: [ 'connect_4' ]
column:
type: integer
minimum: 1
maximum: 7
description: Payload for a connect 4 game move
JSONDeserializeError:
type: string
pattern: '^Json deserialize error:'
PathDeserializeError:
type: string
pattern: '^Path deserialize error:'
QueryDeserializeError:
type: string
pattern: '^Query deserialize error:'
Point2D:
type: object
required:
- x
- y
properties:
x:
type: integer
description: The x coordinate of this point
example: 47
y:
type: integer
description: The y coordinate of this point
example: -38
SnakeRequest:
type: object
required:
- game_type
- players
- fruits
- world_min
- world_max
properties:
game_type:
allOf:
- $ref: '#/components/schemas/GameTypeBase'
- enum: [ 'snake' ]
players:
type: object
additionalProperties:
type: array
items:
$ref: '#/components/schemas/Point2D'
description: >
The list of points occupied by a player. The first
element in the list is the front of the snake.
minItems: 1
description: An map from players to arrays of occupied points.
example:
henry:
- x: 3
y: 4
- x: 4
y: 4
- x: 5
y: 4
fruits:
type: array
items:
$ref: '#/components/schemas/Point2D'
description: >
A list of 2D points representing the locations of
fruit.
example:
- x: 7
y: 14
- x: -6
y: 8
world_min:
$ref: '#/components/schemas/Point2D'
description: The point in the world with minimum x and y values (inclusive)
world_max:
$ref: '#/components/schemas/Point2D'
description: The point in the world with maximum x and y values (inclusive)
description: Payload for a snake game's state
SnakeResponse:
type: object
required:
- game_type
- direction
properties:
game_type:
allOf:
- $ref: '#/components/schemas/GameTypeBase'
- enum: [ 'snake' ]
direction:
type: string
enum:
- up
- down
- left
- right
description: Payload for a snake game move
PayloadSizeError:
type: string
pattern: '^Json payload size is bigger than allowed$'
example: 'Json payload size is bigger than allowed'
GameNotFound:
type: string
pattern: '^game game_[A-Z0-9]+ does not exist$'
example: 'game game_NF6G5NI does not exist'
SessionNotFound:
type: string
pattern: '^session session_[A-Z0-9]+ does not exist$'
example: 'session session_AOHL56GENZPMVKFHA2LD5MOYRA does not exist'
InvalidUsername:
type: string
pattern: '^invalid username \((already in game game_[A-Z0-9]+|too short|longer than 12 characters)\): .*$'
example: 'invalid username (already in game): Player 1'
GameWaiting:
type: string
pattern: '^game has not started yet (game_[A-Z0-9]+)$'
example: 'game has not started yet (game_NF6G5NI)'
GameInProgress:
type: string
pattern: '^game has already started (game_[A-Z0-9]+)$'
example: 'game has already started (game_NF6G5NI)'
GameEnded:
type: string
pattern: '^game game_[A-Z0-9]+ has already ended (game_[A-Z0-9]+)$'
example: 'game has already ended (game_NF6G5NI)'
InvalidMove:
type: string
pattern: '^invalid move: .* (game_[A-Z0-9]+)$'
example: 'invalid move: column 3 is already full (game_NF6G5NI)'
InvalidPlayer:
type: string
pattern: '^player .+ cannot move at the moment (game_[A-Z0-9]+)$'
example: 'player Player 1 cannot move at the moment (game_NF6G5NI)'
links:
GameIdJoinGame:
operationId: joinGame
parameters:
game_id: '$response.body#/game_id'
description: >
The `game_id` value returned in the response can be used as
the `game_id` parameter in `POST /{game_id}/join-game`
GameIdGetState:
operationId: getState
parameters:
game_id: '$response.body#/game_id'
description: >
The `game_id` value returned in the response can be used as
the `game_id` parameter in `GET /{game_id}/get-state`
GameIdSubmitMove:
operationId: submitMove
parameters:
game_id: '$response.body#/game_id'
description: >
The `game_id` value returned in the response can be used as
the `game_id` parameter in `POST /{game_id}/submit-move/`
SessionIdSubmitMove:
operationId: submitMove
x-apigraph-requestBodyParameters:
/session_id: '$response.body#/session_id'
description: >
The `session_id` value returned in the response can be used as
the `session_id` field in `POST /{game_id}/submit-move/`