feat: Adding openapi generated without server just models
This commit is contained in:
@@ -3,10 +3,6 @@
|
|||||||
// Code generated by github.com/deepmap/oapi-codegen version v1.16.3 DO NOT EDIT.
|
// Code generated by github.com/deepmap/oapi-codegen version v1.16.3 DO NOT EDIT.
|
||||||
package openapi
|
package openapi
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/gofiber/fiber/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
BearerAuthScopes = "bearerAuth.Scopes"
|
BearerAuthScopes = "bearerAuth.Scopes"
|
||||||
)
|
)
|
||||||
@@ -63,85 +59,3 @@ type PostAuthLogoutJSONRequestBody = RevokeRequest
|
|||||||
|
|
||||||
// PostAuthRefreshJSONRequestBody defines body for PostAuthRefresh for application/json ContentType.
|
// PostAuthRefreshJSONRequestBody defines body for PostAuthRefresh for application/json ContentType.
|
||||||
type PostAuthRefreshJSONRequestBody = RefreshRequest
|
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)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"github.com/gofiber/fiber/v2/middleware/helmet"
|
"github.com/gofiber/fiber/v2/middleware/helmet"
|
||||||
"github.com/gofiber/fiber/v2/middleware/logger"
|
"github.com/gofiber/fiber/v2/middleware/logger"
|
||||||
|
|
||||||
"cloud.etaviaporte.com/api/libs/openapi"
|
|
||||||
"cloud.etaviaporte.com/api/libs/services/auth"
|
"cloud.etaviaporte.com/api/libs/services/auth"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,7 +29,13 @@ func main() {
|
|||||||
return c.SendString("Hello, World!")
|
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")
|
app.Listen(":3000")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package: openapi
|
package: openapi
|
||||||
output: libs/openapi/generated.go
|
output: libs/openapi/generated.go
|
||||||
generate:
|
generate:
|
||||||
fiber-server: true
|
|
||||||
models: true
|
models: true
|
||||||
output-options:
|
output-options:
|
||||||
skip-prune: true
|
skip-prune: true
|
||||||
|
|||||||
Reference in New Issue
Block a user