feat: Adding openapi example API
This commit is contained in:
147
app/libs/openapi/generated.go
Normal file
147
app/libs/openapi/generated.go
Normal file
@@ -0,0 +1,147 @@
|
||||
// Package openapi provides primitives to interact with the openapi HTTP API.
|
||||
//
|
||||
// Code generated by github.com/deepmap/oapi-codegen version v1.16.3 DO NOT EDIT.
|
||||
package openapi
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
const (
|
||||
BearerAuthScopes = "bearerAuth.Scopes"
|
||||
)
|
||||
|
||||
// Error defines model for Error.
|
||||
type Error struct {
|
||||
Code *string `json:"code,omitempty"`
|
||||
Message *string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
// LoginRequest defines model for LoginRequest.
|
||||
type LoginRequest struct {
|
||||
Password string `json:"password"`
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
// RefreshRequest defines model for RefreshRequest.
|
||||
type RefreshRequest struct {
|
||||
RefreshToken string `json:"refreshToken"`
|
||||
}
|
||||
|
||||
// RevokeRequest defines model for RevokeRequest.
|
||||
type RevokeRequest struct {
|
||||
RefreshToken string `json:"refreshToken"`
|
||||
}
|
||||
|
||||
// TokenResponse defines model for TokenResponse.
|
||||
type TokenResponse struct {
|
||||
AccessToken *string `json:"accessToken,omitempty"`
|
||||
|
||||
// ExpiresIn Seconds until access token expiration
|
||||
ExpiresIn *int `json:"expiresIn,omitempty"`
|
||||
RefreshToken *string `json:"refreshToken,omitempty"`
|
||||
}
|
||||
|
||||
// UserProfile defines model for UserProfile.
|
||||
type UserProfile struct {
|
||||
Email *string `json:"email,omitempty"`
|
||||
Id *string `json:"id,omitempty"`
|
||||
Username *string `json:"username,omitempty"`
|
||||
}
|
||||
|
||||
// BadRequest defines model for BadRequest.
|
||||
type BadRequest = Error
|
||||
|
||||
// Unauthorized defines model for Unauthorized.
|
||||
type Unauthorized = Error
|
||||
|
||||
// PostAuthLoginJSONRequestBody defines body for PostAuthLogin for application/json ContentType.
|
||||
type PostAuthLoginJSONRequestBody = LoginRequest
|
||||
|
||||
// PostAuthLogoutJSONRequestBody defines body for PostAuthLogout for application/json ContentType.
|
||||
type PostAuthLogoutJSONRequestBody = RevokeRequest
|
||||
|
||||
// PostAuthRefreshJSONRequestBody defines body for PostAuthRefresh for application/json ContentType.
|
||||
type PostAuthRefreshJSONRequestBody = RefreshRequest
|
||||
|
||||
// ServerInterface represents all server handlers.
|
||||
type ServerInterface interface {
|
||||
// Obtain access and refresh tokens
|
||||
// (POST /auth/login)
|
||||
PostAuthLogin(c *fiber.Ctx) error
|
||||
// Revoke refresh token / logout
|
||||
// (POST /auth/logout)
|
||||
PostAuthLogout(c *fiber.Ctx) error
|
||||
// Get current authenticated user
|
||||
// (GET /auth/me)
|
||||
GetAuthMe(c *fiber.Ctx) error
|
||||
// Refresh access token using a refresh token
|
||||
// (POST /auth/refresh)
|
||||
PostAuthRefresh(c *fiber.Ctx) error
|
||||
}
|
||||
|
||||
// ServerInterfaceWrapper converts contexts to parameters.
|
||||
type ServerInterfaceWrapper struct {
|
||||
Handler ServerInterface
|
||||
}
|
||||
|
||||
type MiddlewareFunc fiber.Handler
|
||||
|
||||
// PostAuthLogin operation middleware
|
||||
func (siw *ServerInterfaceWrapper) PostAuthLogin(c *fiber.Ctx) error {
|
||||
|
||||
return siw.Handler.PostAuthLogin(c)
|
||||
}
|
||||
|
||||
// PostAuthLogout operation middleware
|
||||
func (siw *ServerInterfaceWrapper) PostAuthLogout(c *fiber.Ctx) error {
|
||||
|
||||
c.Context().SetUserValue(BearerAuthScopes, []string{})
|
||||
|
||||
return siw.Handler.PostAuthLogout(c)
|
||||
}
|
||||
|
||||
// GetAuthMe operation middleware
|
||||
func (siw *ServerInterfaceWrapper) GetAuthMe(c *fiber.Ctx) error {
|
||||
|
||||
c.Context().SetUserValue(BearerAuthScopes, []string{})
|
||||
|
||||
return siw.Handler.GetAuthMe(c)
|
||||
}
|
||||
|
||||
// PostAuthRefresh operation middleware
|
||||
func (siw *ServerInterfaceWrapper) PostAuthRefresh(c *fiber.Ctx) error {
|
||||
|
||||
return siw.Handler.PostAuthRefresh(c)
|
||||
}
|
||||
|
||||
// FiberServerOptions provides options for the Fiber server.
|
||||
type FiberServerOptions struct {
|
||||
BaseURL string
|
||||
Middlewares []MiddlewareFunc
|
||||
}
|
||||
|
||||
// RegisterHandlers creates http.Handler with routing matching OpenAPI spec.
|
||||
func RegisterHandlers(router fiber.Router, si ServerInterface) {
|
||||
RegisterHandlersWithOptions(router, si, FiberServerOptions{})
|
||||
}
|
||||
|
||||
// RegisterHandlersWithOptions creates http.Handler with additional options
|
||||
func RegisterHandlersWithOptions(router fiber.Router, si ServerInterface, options FiberServerOptions) {
|
||||
wrapper := ServerInterfaceWrapper{
|
||||
Handler: si,
|
||||
}
|
||||
|
||||
for _, m := range options.Middlewares {
|
||||
router.Use(m)
|
||||
}
|
||||
|
||||
router.Post(options.BaseURL+"/auth/login", wrapper.PostAuthLogin)
|
||||
|
||||
router.Post(options.BaseURL+"/auth/logout", wrapper.PostAuthLogout)
|
||||
|
||||
router.Get(options.BaseURL+"/auth/me", wrapper.GetAuthMe)
|
||||
|
||||
router.Post(options.BaseURL+"/auth/refresh", wrapper.PostAuthRefresh)
|
||||
|
||||
}
|
||||
52
app/libs/services/auth/services.go
Normal file
52
app/libs/services/auth/services.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"cloud.etaviaporte.com/api/libs/openapi"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type Handler struct{}
|
||||
|
||||
// GetAuthMe implements openapi.ServerInterface.
|
||||
func (handler Handler) GetAuthMe(c *fiber.Ctx) error {
|
||||
err_code := fiber.StatusInternalServerError
|
||||
code := "Something went wrong!"
|
||||
message := "This endpoint is not yet implemented"
|
||||
return c.Status(err_code).JSON(openapi.Error{
|
||||
Code: &code,
|
||||
Message: &message,
|
||||
})
|
||||
}
|
||||
|
||||
// PostAuthLogin implements openapi.ServerInterface.
|
||||
func (handler Handler) PostAuthLogin(c *fiber.Ctx) error {
|
||||
err_code := fiber.StatusInternalServerError
|
||||
code := "Something went wrong!"
|
||||
message := "This endpoint is not yet implemented"
|
||||
return c.Status(err_code).JSON(openapi.Error{
|
||||
Code: &code,
|
||||
Message: &message,
|
||||
})
|
||||
}
|
||||
|
||||
// PostAuthLogout implements openapi.ServerInterface.
|
||||
func (handler Handler) PostAuthLogout(c *fiber.Ctx) error {
|
||||
err_code := fiber.StatusInternalServerError
|
||||
code := "Something went wrong!"
|
||||
message := "This endpoint is not yet implemented"
|
||||
return c.Status(err_code).JSON(openapi.Error{
|
||||
Code: &code,
|
||||
Message: &message,
|
||||
})
|
||||
}
|
||||
|
||||
// PostAuthRefresh implements openapi.ServerInterface.
|
||||
func (handler Handler) PostAuthRefresh(c *fiber.Ctx) error {
|
||||
err_code := fiber.StatusInternalServerError
|
||||
code := "Something went wrong!"
|
||||
message := "This endpoint is not yet implemented"
|
||||
return c.Status(err_code).JSON(openapi.Error{
|
||||
Code: &code,
|
||||
Message: &message,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user