From 13e9c88a8eec60665ffd5d0bb2b1372da83a6727 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Mon, 2 Dec 2024 17:26:03 +0100 Subject: [PATCH] feat(docs): First model for swagger --- docs/docs.go | 58 ++++++++++++++++++++++++++++++++++++++++++++ docs/swagger.json | 58 ++++++++++++++++++++++++++++++++++++++++++++ docs/swagger.yaml | 37 ++++++++++++++++++++++++++++ handlers/contract.go | 1 + models/contract.go | 19 +++++++++++++++ 5 files changed, 173 insertions(+) create mode 100644 models/contract.go diff --git a/docs/docs.go b/docs/docs.go index ec3d7a6..88c2812 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -28,9 +28,67 @@ const docTemplate = `{ "contracts" ], "summary": "Generate a contract", + "parameters": [ + { + "description": "Contract data", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.Contract" + } + } + ], "responses": {} } } + }, + "definitions": { + "models.Contract": { + "type": "object", + "properties": { + "runners": { + "type": "array", + "items": { + "$ref": "#/definitions/models.Runner" + } + } + } + }, + "models.Group": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "parent_group": { + "$ref": "#/definitions/models.Group" + } + } + }, + "models.Runner": { + "type": "object", + "properties": { + "first_name": { + "type": "string" + }, + "group": { + "$ref": "#/definitions/models.Group" + }, + "id": { + "type": "integer" + }, + "last_name": { + "type": "string" + }, + "middle_name": { + "type": "string" + } + } + } } }` diff --git a/docs/swagger.json b/docs/swagger.json index bc6fc3c..2fd44f1 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -19,8 +19,66 @@ "contracts" ], "summary": "Generate a contract", + "parameters": [ + { + "description": "Contract data", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.Contract" + } + } + ], "responses": {} } } + }, + "definitions": { + "models.Contract": { + "type": "object", + "properties": { + "runners": { + "type": "array", + "items": { + "$ref": "#/definitions/models.Runner" + } + } + } + }, + "models.Group": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "parent_group": { + "$ref": "#/definitions/models.Group" + } + } + }, + "models.Runner": { + "type": "object", + "properties": { + "first_name": { + "type": "string" + }, + "group": { + "$ref": "#/definitions/models.Group" + }, + "id": { + "type": "integer" + }, + "last_name": { + "type": "string" + }, + "middle_name": { + "type": "string" + } + } + } } } \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 81de8de..7da2257 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1,3 +1,33 @@ +definitions: + models.Contract: + properties: + runners: + items: + $ref: '#/definitions/models.Runner' + type: array + type: object + models.Group: + properties: + id: + type: integer + name: + type: string + parent_group: + $ref: '#/definitions/models.Group' + type: object + models.Runner: + properties: + first_name: + type: string + group: + $ref: '#/definitions/models.Group' + id: + type: integer + last_name: + type: string + middle_name: + type: string + type: object info: contact: {} description: This is the API documentation for the LfK Document Server - a tool @@ -9,6 +39,13 @@ paths: consumes: - application/json description: Generate a contract based on the provided data + parameters: + - description: Contract data + in: body + name: data + required: true + schema: + $ref: '#/definitions/models.Contract' produces: - application/pdf responses: {} diff --git a/handlers/contract.go b/handlers/contract.go index ec15634..61f06c1 100644 --- a/handlers/contract.go +++ b/handlers/contract.go @@ -7,6 +7,7 @@ import "github.com/gofiber/fiber/v2" // @Description Generate a contract based on the provided data // @Tags contracts // @Accept json +// @Param data body models.Contract true "Contract data" // @Produce application/pdf // @Router /contracts [post] func GenerateContract(c *fiber.Ctx) error { diff --git a/models/contract.go b/models/contract.go new file mode 100644 index 0000000..6b38fd8 --- /dev/null +++ b/models/contract.go @@ -0,0 +1,19 @@ +package models + +type Contract struct { + Runners []Runner `json:"runners"` +} + +type Runner struct { + ID int `json:"id"` + FirstName string `json:"first_name"` + MiddleName string `json:"middle_name"` + LastName string `json:"last_name"` + Group Group `json:"group"` +} + +type Group struct { + ID int `json:"id"` + Name string `json:"name"` + ParentGroup *Group `json:"parent_group"` +}