feat: Adding openapi generated without server just models

This commit is contained in:
Josepablo C.
2025-12-07 23:22:40 -06:00
parent 8787ece0d0
commit a95c4d023e
3 changed files with 7 additions and 89 deletions

View File

@@ -3,10 +3,6 @@
// 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"
)
@@ -63,85 +59,3 @@ 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)
}

View File

@@ -6,7 +6,6 @@ import (
"github.com/gofiber/fiber/v2/middleware/helmet"
"github.com/gofiber/fiber/v2/middleware/logger"
"cloud.etaviaporte.com/api/libs/openapi"
"cloud.etaviaporte.com/api/libs/services/auth"
)
@@ -30,7 +29,13 @@ func main() {
return c.SendString("Hello, World!")
})
openapi.RegisterHandlers(app, auth.Handler{})
handler := auth.Handler{}
// openapi.RegisterHandlers(app, auth.Handler{})
app.Post("/auth/login", handler.PostAuthLogin)
app.Post("/auth/logout", handler.PostAuthLogout)
app.Get("/auth/me", handler.GetAuthMe)
app.Post("/auth/refresh", handler.PostAuthRefresh)
app.Listen(":3000")
}

View File

@@ -1,7 +1,6 @@
package: openapi
output: libs/openapi/generated.go
generate:
fiber-server: true
models: true
output-options:
skip-prune: true