Files
qv/cmd/web/openapi.yml

308 lines
7.4 KiB
YAML
Raw Normal View History

2024-12-27 11:31:05 +01:00
openapi: 3.0.3
info:
title: qv - dlmw
description: |-
This is the documentation for the qv (Quadratic Voting) API.
2025-01-22 20:12:52 +01:00
termsOfService:
2024-12-27 11:31:05 +01:00
contact:
email: dylan@dlmw.ch
license:
name: GNU General Public License Version 3
url: https://www.gnu.org/licenses/gpl-3.0.txt
version: 0.0.1
externalDocs:
2025-01-22 20:12:52 +01:00
description: Get the code
url: https://code.dlmw.ch/dlmw/qv
2024-12-27 11:31:05 +01:00
servers:
2025-01-22 20:12:52 +01:00
- url: https://qv.dlmw.ch/api
2024-12-27 11:31:05 +01:00
tags:
- name: election
description: Retrieve data related to elections
- name: vote
description: Retrieve data related to votes
2024-12-27 11:31:05 +01:00
paths:
/election/{id}:
get:
tags:
- election
summary: Get an election
operationId: getElection
parameters:
- name: id
in: path
required: true
description: The ID of the election
schema:
type: string
responses:
200:
description: Election returned
content:
application/json:
schema:
$ref: "#/components/schemas/Election"
400:
description: Request malformed
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
404:
description: Election not found
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
2024-12-27 11:31:05 +01:00
/election:
post:
tags:
- election
summary: Create a new election
operationId: createElection
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/CreateElectionRequest"
responses:
200:
description: Election created. Body only returned if voterAreKnown is true
headers:
Location:
schema:
type: string
description: The path to the newly created election
content:
application/json:
schema:
$ref: "#/components/schemas/CreateElectionResponse"
422:
description: Unprocessable Content
2024-12-27 11:31:05 +01:00
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
500:
description: Server error
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
/election/{id}/votes:
post:
tags:
- vote
summary: Cast your votes for an election
operationId: createVotes
parameters:
- name: id
in: path
required: true
description: The ID of the election
schema:
type: string
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/CreateVotesRequest"
responses:
201:
description: Votes cast
2025-01-14 12:44:06 +01:00
400:
description: Request malformed
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
404:
description: Election not found
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
422:
description: Unprocessable content
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
500:
description: Server error
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
2024-12-27 11:31:05 +01:00
/election/{id}/results:
get:
tags:
- election
summary: Get the results of an election
2025-01-13 10:59:05 +01:00
operationId: getElectionResults
parameters:
- name: id
in: path
required: true
description: The ID of the election
schema:
type: string
responses:
200:
description: Election results returned
content:
application/json:
schema:
$ref: "#/components/schemas/ElectionResultsResponse"
2025-01-14 16:52:20 +01:00
400:
description: Request malformed
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
404:
description: Election doesn't exist
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
500:
description: Server error
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
2024-12-27 11:31:05 +01:00
components:
schemas:
Election:
type: object
required:
- id
- name
- tokens
- areVotersKnown
- maxVoters
- createdAt
- expiresAt
- choices
properties:
id:
type: string
name:
type: string
tokens:
type: integer
areVotersKnown:
type: boolean
maxVoters:
type: integer
createdAt:
type: string
expiresAt:
type: string
choices:
type: array
items:
type: string
2024-12-27 11:31:05 +01:00
CreateElectionRequest:
type: object
required:
- name
- tokens
- areVotersKnown
- maxVoters
- expiresAt
2024-12-27 11:31:05 +01:00
- choices
properties:
name:
type: string
minLength: 1
tokens:
type: integer
minimum: 1
areVotersKnown:
2024-12-27 11:31:05 +01:00
type: boolean
maxVoters:
2024-12-27 11:31:05 +01:00
type: integer
minimum: 0
description: Must be greater than 0 when voters are known; 0 = no limit
expiresAt:
2024-12-27 11:31:05 +01:00
type: string
format: date-time
choices:
type: array
items:
type: string
minLength: 1
minItems: 1
uniqueItems: true
CreateElectionResponse:
type: object
properties:
voterIdentities:
type: array
items:
type: string
minLength: 1
uniqueItems: true
CreateVotesRequest:
type: object
required:
- choices
properties:
voterIdentity:
type: string
description: Must be filled if election has known voters
choices:
type: array
items:
required:
- choiceText
- tokens
properties:
choiceText:
type: string
minLength: 1
tokens:
type: integer
ElectionResultsResponse:
type: object
2025-01-14 16:52:20 +01:00
properties:
results:
type: array
items:
$ref: "#/components/schemas/VotesForChoice"
VotesForChoice:
type: object
required:
- choice
- votes
properties:
choice:
type: string
votes:
type: integer
2024-12-27 11:31:05 +01:00
ErrorResponse:
type: object
required:
- message
- code
properties:
message:
type: string
description: Human-readable error message
code:
type: integer
2024-12-27 11:31:05 +01:00
description: Machine-readable error code
details:
type: object
2025-01-13 11:26:18 +01:00
description: Additional error details when available