Docs example

This commit is contained in:
Imbus 2024-03-18 19:59:14 +01:00
parent fe6942aa81
commit 2aade5d2fe
2 changed files with 28 additions and 3 deletions

View file

@ -32,6 +32,17 @@ const docTemplate = `{
"User" "User"
], ],
"summary": "Register a new user", "summary": "Register a new user",
"parameters": [
{
"description": "User to register",
"name": "{string}",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/types.NewUser"
}
}
],
"responses": { "responses": {
"200": { "200": {
"description": "User added", "description": "User added",
@ -55,6 +66,19 @@ const docTemplate = `{
} }
} }
}, },
"definitions": {
"types.NewUser": {
"type": "object",
"properties": {
"password": {
"type": "string"
},
"username": {
"type": "string"
}
}
}
},
"externalDocs": { "externalDocs": {
"description": "OpenAPI", "description": "OpenAPI",
"url": "https://swagger.io/resources/open-api/" "url": "https://swagger.io/resources/open-api/"

View file

@ -16,9 +16,10 @@ import (
// @Tags User // @Tags User
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 200 {string} string "User added" // @Param {string} body types.NewUser true "User to register"
// @Failure 400 {string} string "Bad request" // @Success 200 {string} string "User added"
// @Failure 500 {string} string "Internal server error" // @Failure 400 {string} string "Bad request"
// @Failure 500 {string} string "Internal server error"
// @Router /api/register [post] // @Router /api/register [post]
func (gs *GState) Register(c *fiber.Ctx) error { func (gs *GState) Register(c *fiber.Ctx) error {
u := new(types.NewUser) u := new(types.NewUser)