added openapi.yaml

Signed-off-by: Adrian Gunnar Lauterer <adriangl@pvv.ntnu.no>
This commit is contained in:
Adrian Gunnar Lauterer 2024-05-11 22:51:55 +02:00
parent 1293fa0b87
commit e3cc07061c
1 changed files with 259 additions and 0 deletions

259
openapi.yaml Normal file
View File

@ -0,0 +1,259 @@
swagger: "2.0"
info:
version: "0.0.1"
title: vote-rs API
description: API for conducting electronic voting
basePath: /api
schemes:
- https
consumes:
- application/json
produces:
- application/json
securityDefinitions:
JWT:
type: apiKey
name: Authorization
in: header
security:
- JWT: []
definitions:
User:
type: object
properties:
id:
type: string
username:
type: string
password:
type: string
Authorization:
type: object
properties:
to_date:
type: string
format: date-time
from_date:
type: string
format: date-time
user:
type: string
Election:
type: object
properties:
id:
type: string
username:
type: string
name:
type: string
description:
type: string
start_date:
type: string
format: date-time
end_date:
type: string
format: date-time
items:
type: array
items:
$ref: "#/definitions/ElectionItem"
ElectionItem:
type: object
properties:
id:
type: string
name:
type: string
ElectionList:
type: array
items:
$ref: "#/definitions/Election"
VoteItem:
type: object
properties:
item:
$ref: "#/definitions/ElectionItem"
value:
type: number
Vote:
type: object
properties:
authorization:
$ref: "#/definitions/Authorization"
userid:
type: string
data:
type: array
items:
$ref: "#/definitions/VoteItem"
paths:
/auth/login:
post:
summary: Authenticate user
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: credentials
required: true
schema:
type: object
properties:
username:
type: string
password:
type: string
format: password
responses:
200:
description: Login successful
schema:
type: object
properties:
token:
type: string
401:
description: Unauthorized
/auth/token:
post:
summary: Generate authentication token for another user
consumes:
- application/json
produces:
- application/json
parameters:
- in: header
name: Authorization
description: Your authorization token
required: true
type: string
format: JWT
- in: body
name: token
required: true
schema:
$ref: "#/definitions/Authorization"
responses:
200:
description: Token generated successfully
schema:
type: object
properties:
token:
type: string
format: JWT
401:
description: Unauthorized
/elections/create:
post:
summary: Create new election
consumes:
- application/json
produces:
- application/json
parameters:
- in: header
name: Authorization
description: Your authorization token
required: true
type: string
format: JWT
- in: body
name: election
required: true
schema:
$ref: "#/definitions/Election"
responses:
201:
description: Election created successfully
schema:
$ref: "#/definitions/Election"
401:
description: Unauthorized
/elections/all:
get:
summary: Get all existing elections
parameters:
- in: header
name: Authorization
description: Your authorization token
required: true
type: string
format: JWT
responses:
200:
description: List of all existing elections
schema:
$ref: "#/definitions/ElectionList"
401:
description: Unauthorized
/elections/{id}:
get:
summary: Get all existing elections
parameters:
- in: header
name: Authorization
description: Your authorization token
required: true
type: string
format: JWT
- in: path
name: id
type: string
required: true
responses:
200:
description: List of all existing elections
schema:
$ref: "#/definitions/Election"
401:
description: Unauthorized
post:
summary: Vote in exsisting election
consumes:
- application/json
produces:
- application/json
parameters:
- in: header
name: Authorization
description: Your authorization token
required: true
type: string
format: JWT
- in: body
name: election
required: true
schema:
$ref: "#/definitions/Vote"
responses:
201:
description: Election created successfully
schema:
$ref: "#/definitions/Vote"
401:
description: Unauthorized