From ecdf67f37140a31a30bb1311f6d833435b79b42c Mon Sep 17 00:00:00 2001 From: Vojtech Mares Date: Fri, 3 May 2024 21:58:20 +0200 Subject: [PATCH] feat: add openapi spec --- api/v1/openapi.yaml | 218 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100644 api/v1/openapi.yaml diff --git a/api/v1/openapi.yaml b/api/v1/openapi.yaml new file mode 100644 index 0000000..2408213 --- /dev/null +++ b/api/v1/openapi.yaml @@ -0,0 +1,218 @@ +openapi: "3.1.0" +info: + version: "0.1.0" + title: MaresHQ API + license: + name: Proprietary + contact: + name: Vojtěch Mareš + email: iam@vojtechmares.com + url: https://www.vojtechmares.com + +paths: + /trainings: + get: + summary: List all trainings + operationId: listTrainings + tags: + - Trainings + responses: + "200": + description: A list of trainings + content: + application/json: + schema: + $ref: "#/components/schemas/ListTrainingsResponse" + "500": + $ref: "#/components/responses/InternalError" + + post: + summary: Create a new training + operationId: createTraining + tags: + - Trainings + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/CreateTrainingRequest" + responses: + "201": + description: Training created + content: + application/json: + schema: + $ref: "#/components/schemas/CreateTrainingResponse" + "400": + $ref: "#/components/responses/InvalidInputError" + "500": + $ref: "#/components/responses/InternalError" + + /trainings/{trainingID}: + get: + summary: Get a training by ID + operationId: getTraining + tags: + - Trainings + parameters: + - $ref: "#/components/parameters/TrainingID" + responses: + "200": + description: A training + content: + application/json: + schema: + $ref: "#/components/schemas/GetTrainingResponse" + "404": + $ref: "#/components/responses/NotFoundError" + + "500": + $ref: "#/components/responses/InternalError" + + put: + summary: Update a training by ID + operationId: updateTraining + tags: + - Trainings + parameters: + - $ref: "#/components/parameters/TrainingID" + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/UpdateTrainingRequest" + responses: + "200": + description: Training updated + content: + application/json: + schema: + $ref: "#/components/schemas/UpdateTrainingResponse" + "400": + $ref: "#/components/responses/InvalidInputError" + "404": + $ref: "#/components/responses/NotFoundError" + "500": + $ref: "#/components/responses/InternalError" + + delete: + summary: Delete a training by ID + operationId: deleteTraining + tags: + - Trainings + parameters: + - $ref: "#/components/parameters/TrainingID" + responses: + "204": + description: Training deleted + "404": + $ref: "#/components/responses/NotFoundError" + "500": + $ref: "#/components/responses/InternalError" + +components: + parameters: + TrainingID: + in: path + name: trainingID + required: true + schema: + type: string + format: uuid + description: Training ID + + schemas: + CreateTrainingRequest: + $ref: "#/components/schemas/NewTraining" + + CreateTrainingResponse: + $ref: "#/components/schemas/Training" + + ListTrainingsResponse: + type: array + items: + $ref: "#/components/schemas/Training" + + GetTrainingResponse: + $ref: "#/components/schemas/Training" + + UpdateTrainingRequest: + $ref: "#/components/schemas/NewTraining" + + UpdateTrainingResponse: + $ref: "#/components/schemas/Training" + + NewTraining: + type: object + properties: + name: + type: string + days: + type: integer + format: int32 + required: + - name + - days + + Training: + allOf: + - $ref: "#/components/schemas/NewTraining" + - type: object + - properties: + id: + type: string + format: uuid + - required: + - id + + ProblemDetails: + type: object + description: > + Schema that carries the details of an error in an HTTP response. + See https://datatracker.ietf.org/doc/html/rfc7807 for more information. + properties: + type: + type: string + description: A URI reference that identifies the problem type. + title: + type: string + description: A human-readable summary of the problem type. + status: + type: integer + description: The HTTP status code generated by the origin server for this occurrence of the problem. + detail: + type: string + description: A human-readable explanation specific to this occurrence of the problem. + instance: + type: string + description: A URI reference that identifies the specific occurrence of the problem. + required: + - type + - title + - status + - detail + - instance + + responses: + InvalidInputError: + description: Invalid input error + content: + application/problem+json: + schema: + $ref: "#/components/schemas/ProblemDetails" + + InternalError: + description: Internal error + content: + application/problem+json: + schema: + $ref: "#/components/schemas/ProblemDetails" + + NotFoundError: + description: Not found error + content: + application/problem+json: + schema: + $ref: "#/components/schemas/ProblemDetails"