diff --git a/app/libs/openapi/generated.go b/app/libs/openapi/generated.go index 12f89f7..954cd20 100644 --- a/app/libs/openapi/generated.go +++ b/app/libs/openapi/generated.go @@ -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) - -} diff --git a/app/main.go b/app/main.go index f085583..a5fd33c 100644 --- a/app/main.go +++ b/app/main.go @@ -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") } diff --git a/app/openapi/cfg.yaml b/app/openapi/cfg.yaml index 9a91e0f..1aa6dc3 100644 --- a/app/openapi/cfg.yaml +++ b/app/openapi/cfg.yaml @@ -1,7 +1,6 @@ package: openapi output: libs/openapi/generated.go generate: - fiber-server: true models: true output-options: skip-prune: true