2022-11-12 01:34:03 +00:00
openapi : 3.0 .3
info :
title : "Distributed Arcade"
2022-11-12 22:36:28 +00:00
version : 0.2 .0
2022-11-12 01:34:03 +00:00
description : |-
A super-fast high score gatherer using Rust and Redis.
2022-11-12 22:36:28 +00:00
It allows the creation of _boards_, [sorted sets](https://redis.io/docs/data-types/sorted-sets/) that can be used to track the scores of players in videogames.
It is written to be extremely fast and scalable : it should be able to receive bursts of many requests.
Errors can be distinguished from successful requests via HTTP status codes >=400.
contact :
name : "Stefano Pigozzi"
url : "https://www.steffo.eu"
email : "me@steffo.eu"
license :
name : "GNU Affero General Public License v3.0 or later"
url : https://github.com/Steffo99/distributed-arcade/blob/main/LICENSE.txt"
2022-11-12 01:34:03 +00:00
servers :
2022-11-12 22:36:28 +00:00
- url : "https://arcade.steffo.eu"
description : "Experimental production server"
2022-11-12 01:34:03 +00:00
- url : "http://127.0.0.1:30000"
2022-11-12 22:36:28 +00:00
description : "Local development server"
2022-11-12 01:34:03 +00:00
tags :
- name : "Home"
2022-11-12 22:36:28 +00:00
description : "Launch checklist"
2022-11-12 01:34:03 +00:00
- name : "Board"
description : "About boards"
- name : "Score"
description : "Submit scores"
paths :
/ :
get :
2022-11-12 22:36:28 +00:00
operationId : "getHome"
2022-11-12 01:34:03 +00:00
summary : "Verify that the web server is working as expected"
2022-11-12 22:36:28 +00:00
description : |-
This method simply echoes back a response, and can be used to verify that the API web server is working.
2022-11-12 01:34:03 +00:00
tags : [ "Home" ]
responses :
2022-11-12 22:36:28 +00:00
204 :
2022-11-12 01:34:03 +00:00
description : "Working as expected"
2022-11-12 22:36:28 +00:00
post :
operationId : "postHome"
2022-11-12 01:34:03 +00:00
summary : "Verify that everything is working as expected"
2022-11-12 22:36:28 +00:00
description : |-
This method is like `GET /`, but it also `PING`s the Redis server to ensure it is working and configured properly.
2022-11-12 01:34:03 +00:00
tags : [ "Home" ]
responses :
2022-11-12 22:36:28 +00:00
204 :
2022-11-12 01:34:03 +00:00
description : "Working as expected"
500 :
description : "Did not receive `PONG` from redis"
content :
application/json :
schema :
type : string
example : "Redis gave an unexpected response"
502 :
$ref : "#/components/responses/RedisCmdFailed"
504 :
$ref : "#/components/responses/RedisConnFailed"
/board/ :
2022-11-12 16:38:01 +00:00
get :
2022-11-12 22:36:28 +00:00
operationId : "getBoard"
2022-11-12 16:38:01 +00:00
summary : "Get the scores of a board"
2022-11-12 22:36:28 +00:00
description : |-
This method requests a page of scores from a board using the [`ZSCAN`](https://redis.io/commands/zscan/) Redis command.
An offset must be specified to start returning scores from a certain index.
The number of responses to return must be specified as well.
2022-11-12 16:38:01 +00:00
tags : [ "Board" ]
parameters :
- $ref : "#/components/parameters/board"
- $ref : "#/components/parameters/offset"
- $ref : "#/components/parameters/size"
responses :
200 :
description : "Scores retrieved successfully"
content :
application/json :
schema :
2022-11-12 22:36:28 +00:00
type : array
items :
type : object
description : "A score submitted by an user."
properties :
name :
type : string
description : "The name of the user who submitted the score."
example : "Steffo"
score :
type : number
description : "The submitted score."
example : 1234.56
2022-11-12 16:38:01 +00:00
502 :
$ref : "#/components/responses/RedisCmdFailed"
504 :
$ref : "#/components/responses/RedisConnFailed"
2022-11-12 01:34:03 +00:00
post :
2022-11-12 22:36:28 +00:00
operationId : "postBoard"
2022-11-12 01:34:03 +00:00
summary : "Create a new board"
2022-11-12 22:36:28 +00:00
description : |-
This method creates a new board.
It returns its _score submission token_ (`XBoardToken` in this spec), which is required to submit new scores to the board.
Boards can use two different orders :
- using the `Ascending` order, lower scores are better ranked than higher scores, like in racing games or golf;
- using the `Descending` order, higher scores are better ranked than lower scores, like in arcade games or athletics.
**WARNING: Once created, a board cannot be edited or deleted, and its token will not be accessible any longer!**
2022-11-12 01:34:03 +00:00
tags : [ "Board" ]
requestBody :
required : true
content :
application/json :
schema :
type : object
properties :
name :
type : string
2022-11-12 22:36:28 +00:00
description : "The name of the board to create. It will be converted to kebab-case."
2022-11-12 01:34:03 +00:00
example : "gravityfusion"
order :
type : string
2022-11-12 22:36:28 +00:00
example : "Descending"
2022-11-12 01:34:03 +00:00
description : "The ordering of the board, either ascending or descending."
enum :
2022-11-12 22:36:28 +00:00
- "Ascending"
- "Descending"
2022-11-12 01:34:03 +00:00
responses :
201 :
description : "Board created successfully"
content :
application/json :
schema :
type : string
example : "W4SbhbJ3tnGaIM1S"
2022-11-12 22:36:28 +00:00
links :
getScore :
operationId : "getScore"
parameters :
board : "$response.body/name"
putScore :
operationId : "putScore"
parameters :
board : "$response.body/name"
2022-11-12 01:34:03 +00:00
409 :
description : "Board already exists"
content :
application/json :
schema :
type : string
example : "Board already exists"
500 :
description : "Could not generate secure board token"
content :
application/json :
schema :
type : string
example : "Could not generate secure board token"
502 :
$ref : "#/components/responses/RedisCmdFailed"
504 :
$ref : "#/components/responses/RedisConnFailed"
/score/ :
2022-11-12 15:34:22 +00:00
get :
2022-11-12 22:36:28 +00:00
operationId : "getScore"
2022-11-12 15:34:22 +00:00
summary : "Get a score from a board"
2022-11-12 22:36:28 +00:00
description : |-
Retrieve the score and the position that the given user has on the leaderboard.
2022-11-12 15:34:22 +00:00
tags : [ "Score" ]
parameters :
- $ref : "#/components/parameters/board"
- $ref : "#/components/parameters/player"
responses :
200 :
description : "Score retrieved successfully"
content :
application/json :
schema :
2022-11-12 22:36:28 +00:00
type : object
properties :
score :
type : number
description : "The score of the specified player."
example : 1234.56
rank :
type : integer
description : "The zero-indexed rank of the specified player. (You may probably want to add `1` before displaying it to an user.)"
example : 0
2022-11-12 15:34:22 +00:00
502 :
$ref : "#/components/responses/RedisCmdFailed"
504 :
$ref : "#/components/responses/RedisConnFailed"
2022-11-12 01:34:03 +00:00
put :
2022-11-12 22:36:28 +00:00
operationId : "putScore"
2022-11-12 01:34:03 +00:00
summary : "Submit a score to a board"
tags : [ "Score" ]
2022-11-12 15:34:22 +00:00
parameters :
- $ref : "#/components/parameters/board"
- $ref : "#/components/parameters/player"
2022-11-12 01:34:03 +00:00
requestBody :
required : true
content :
application/json :
schema :
2022-11-12 15:34:22 +00:00
type : number
description : "The score to submit to the board."
example : 1234.56
2022-11-12 01:34:03 +00:00
security :
- XBoardToken : [ ]
responses :
2022-11-12 15:47:00 +00:00
200 :
description : "Score discarded as it was worse than the previous one"
content :
application/json :
schema :
2022-11-12 22:36:28 +00:00
type : object
properties :
score :
type : number
description : "The score of the specified player."
example : 1234.56
rank :
type : integer
description : "The zero-indexed rank of the specified player. (You may probably want to add `1` before displaying it to an user.)"
example : 0
2022-11-12 15:47:00 +00:00
201 :
description : "Score submitted and updated"
content :
application/json :
schema :
2022-11-12 22:36:28 +00:00
type : object
properties :
score :
type : number
description : "The score of the specified player."
example : 2468.13
rank :
type : integer
description : "The zero-indexed rank of the specified player. (You may probably want to add `1` before displaying it to an user.)"
example : 0
2022-11-12 01:34:03 +00:00
401 :
description : "Missing, invalid or malformed Authorization header"
content :
application/json :
schema :
type : string
example : "Missing Authorization header"
502 :
$ref : "#/components/responses/RedisCmdFailed"
504 :
$ref : "#/components/responses/RedisConnFailed"
components :
securitySchemes :
XBoardToken :
2022-11-12 22:36:28 +00:00
type : http
scheme : "Bearer"
bearerFormat : "gVsuzIxgVfRx4RNl"
2022-11-12 01:34:03 +00:00
2022-11-12 15:34:22 +00:00
parameters :
board :
name : "board"
description : "The name of the board to operate on."
in : query
schema :
type : string
player :
name : "player"
description : "The name of the player to operate on."
in : query
schema :
type : string
2022-11-12 16:38:01 +00:00
offset :
name : "offset"
description : "The offset to start returning results from."
in : query
schema :
type : integer
size :
name : "size"
description : "How many results to return."
in : query
schema :
type : integer
minimum : 0
maximum : 500
2022-11-12 15:34:22 +00:00
2022-11-12 01:34:03 +00:00
responses :
RedisCmdFailed :
description : "Could not execute Redis command"
content :
application/json :
schema :
type : string
example : "Could not execute Redis command"
RedisConnFailed :
description : "Could not connect to Redis"
content :
application/json :
schema :
type : string
example : "Could not connect to Redis"