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

View file

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

View file

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