tyding up and tryinng to get tokens in docs to work

This commit is contained in:
Samuel Högbom Aronson 2024-03-19 00:27:31 +01:00
parent ad85194d4f
commit 8711f9a20d
3 changed files with 28 additions and 11 deletions

View file

@ -73,6 +73,11 @@ const docTemplate = `{
}, },
"/loginerenew": { "/loginerenew": {
"post": { "post": {
"security": [
{
"bererToken": []
}
],
"description": "renews the users token", "description": "renews the users token",
"consumes": [ "consumes": [
"application/json" "application/json"
@ -83,7 +88,7 @@ const docTemplate = `{
"tags": [ "tags": [
"User" "User"
], ],
"summary": "renews the users token", "summary": "LoginRenews",
"responses": { "responses": {
"200": { "200": {
"description": "Successfully signed token for user", "description": "Successfully signed token for user",
@ -118,7 +123,7 @@ const docTemplate = `{
"tags": [ "tags": [
"User" "User"
], ],
"summary": "promote user to admin", "summary": "PromoteToAdmin",
"parameters": [ "parameters": [
{ {
"description": "user info", "description": "user info",
@ -170,7 +175,7 @@ const docTemplate = `{
"tags": [ "tags": [
"User" "User"
], ],
"summary": "Register a new user", "summary": "Register",
"parameters": [ "parameters": [
{ {
"description": "User to register", "description": "User to register",
@ -216,7 +221,7 @@ const docTemplate = `{
"tags": [ "tags": [
"User" "User"
], ],
"summary": "Deletes a user", "summary": "UserDelete",
"responses": { "responses": {
"200": { "200": {
"description": "User deleted", "description": "User deleted",
@ -257,7 +262,7 @@ const docTemplate = `{
"tags": [ "tags": [
"User" "User"
], ],
"summary": "Lists users", "summary": "ListsAllUsers",
"responses": { "responses": {
"200": { "200": {
"description": "Successfully signed token for user", "description": "Successfully signed token for user",
@ -294,6 +299,13 @@ const docTemplate = `{
} }
} }
}, },
"securityDefinitions": {
"bererToken": {
"type": "apiKey",
"name": "Authorization",
"in": "header"
}
},
"externalDocs": { "externalDocs": {
"description": "OpenAPI", "description": "OpenAPI",
"url": "https://swagger.io/resources/open-api/" "url": "https://swagger.io/resources/open-api/"

View file

@ -11,7 +11,7 @@ import (
// Register is a simple handler that registers a new user // Register is a simple handler that registers a new user
// //
// @Summary Register a new user // @Summary Register
// @Description Register a new user // @Description Register a new user
// @Tags User // @Tags User
// @Accept json // @Accept json
@ -40,7 +40,7 @@ func (gs *GState) Register(c *fiber.Ctx) error {
// This path should obviously be protected in the future // This path should obviously be protected in the future
// UserDelete deletes a user from the database // UserDelete deletes a user from the database
// //
// @Summary Deletes a user // @Summary UserDelete
// @Description UserDelete deletes a user from the database // @Description UserDelete deletes a user from the database
// @Tags User // @Tags User
// @Accept json // @Accept json
@ -120,8 +120,9 @@ func (gs *GState) Login(c *fiber.Ctx) error {
// LoginRenew is a simple handler that renews the token // LoginRenew is a simple handler that renews the token
// //
// @Summary renews the users token // @Summary LoginRenews
// @Description renews the users token // @Description renews the users token
// @Security bererToken
// @Tags User // @Tags User
// @Accept json // @Accept json
// @Produce plain // @Produce plain
@ -149,7 +150,7 @@ func (gs *GState) LoginRenew(c *fiber.Ctx) error {
// ListAllUsers is a handler that returns a list of all users in the application database // ListAllUsers is a handler that returns a list of all users in the application database
// //
// @Summary Lists users // @Summary ListsAllUsers
// @Description lists all users // @Description lists all users
// @Tags User // @Tags User
// @Accept json // @Accept json
@ -169,7 +170,7 @@ func (gs *GState) ListAllUsers(c *fiber.Ctx) error {
return c.JSON(users) return c.JSON(users)
} }
// @Summary promote user to admin // @Summary PromoteToAdmin
// @Description promote chosen user to admin // @Description promote chosen user to admin
// @Tags User // @Tags User
// @Accept json // @Accept json

View file

@ -22,6 +22,10 @@ import (
// @license.name AGPL // @license.name AGPL
// @license.url https://www.gnu.org/licenses/agpl-3.0.html // @license.url https://www.gnu.org/licenses/agpl-3.0.html
//@securityDefinitions.apikey bererToken
//@in header
//@name Authorization
// @host localhost:8080 // @host localhost:8080
// @BasePath /api // @BasePath /api
@ -83,7 +87,7 @@ func main() {
server.Post("/api/signReport", gs.SignReport) server.Post("/api/signReport", gs.SignReport)
server.Put("/api/addUserToProject", gs.AddUserToProjectHandler) server.Put("/api/addUserToProject", gs.AddUserToProjectHandler)
server.Post("/api/promoteToAdmin", gs.PromoteToAdmin) server.Post("/api/promoteToAdmin", gs.PromoteToAdmin)
server.Get("/api/users/all", gs.ListAllUsers)
// Announce the port we are listening on and start the server // Announce the port we are listening on and start the server
err = server.Listen(fmt.Sprintf(":%d", conf.Port)) err = server.Listen(fmt.Sprintf(":%d", conf.Port))
if err != nil { if err != nil {