Documentation
¶
Overview ¶
Package swagify provides automatic OpenAPI 3.1 documentation generation for Go web frameworks including Fiber and Gin.
Swagify takes a code-first approach: define your types and handlers, and swagify generates a complete OpenAPI specification with a beautiful interactive docs UI — no comments or annotations required.
Quick start with Fiber:
app := fiber.New()
api := swagify.NewFiber(app)
api.POST("/users", createUserHandler,
swagify.Summary("Create a user"),
swagify.Tags("Users"),
swagify.WithRequest(CreateUserRequest{}),
swagify.WithResponse(UserResponse{}),
)
api.RegisterOpenAPI()
api.RegisterDocs()
app.Listen(":8080")
Quick start with Gin:
r := gin.Default()
api := swagify.NewGin(r)
api.POST("/users", createUserHandler,
swagify.Summary("Create a user"),
swagify.Tags("Users"),
)
api.RegisterOpenAPI()
api.RegisterDocs()
r.Run(":8080")
Index ¶
- func DELETE[Req any, Res any](f *router.FiberAdapter, path string, ...)
- func GET[Req any, Res any](f *router.FiberAdapter, path string, ...)
- func NewFiber(app *fiber.App, configs ...router.FiberConfig) *router.FiberAdapter
- func NewGin(engine *gin.Engine, configs ...router.GinConfig) *router.GinAdapter
- func PATCH[Req any, Res any](f *router.FiberAdapter, path string, ...)
- func POST[Req any, Res any](f *router.FiberAdapter, path string, ...)
- func PUT[Req any, Res any](f *router.FiberAdapter, path string, ...)
- type Contact
- type DiscoverOptions
- type DocsAuthConfig
- type FiberConfig
- type GinConfig
- type Info
- type License
- type RouteOption
- func Deprecated() RouteOption
- func Description(d string) RouteOption
- func ErrorResponse(status int, model any, description string) RouteOption
- func HeaderParams(model any) RouteOption
- func OperationID(id string) RouteOption
- func PathParams(model any) RouteOption
- func QueryParams(model any) RouteOption
- func RequestContentType(ct string) RouteOption
- func Response(status int, model any, description string) RouteOption
- func ResponseContentType(ct string) RouteOption
- func Security(schemes ...map[string][]string) RouteOption
- func SecurityAPIKey() RouteOption
- func SecurityBasic() RouteOption
- func SecurityBearer() RouteOption
- func SuccessStatus(code int) RouteOption
- func Summary(s string) RouteOption
- func Tags(tags ...string) RouteOption
- func WithRequest(model any) RouteOption
- func WithResponse(model any) RouteOption
- type SecurityScheme
- type Server
- type Tag
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DELETE ¶
func DELETE[Req any, Res any](f *router.FiberAdapter, path string, handler func(*fiber.Ctx, Req) (Res, error), opts ...RouteOption)
DELETE registers a typed DELETE handler for Fiber with automatic schema inference.
func GET ¶
func GET[Req any, Res any](f *router.FiberAdapter, path string, handler func(*fiber.Ctx, Req) (Res, error), opts ...RouteOption)
GET registers a typed GET handler for Fiber with automatic schema inference.
func NewFiber ¶
func NewFiber(app *fiber.App, configs ...router.FiberConfig) *router.FiberAdapter
NewFiber creates a new swagify adapter for the Fiber web framework.
func PATCH ¶
func PATCH[Req any, Res any](f *router.FiberAdapter, path string, handler func(*fiber.Ctx, Req) (Res, error), opts ...RouteOption)
PATCH registers a typed PATCH handler for Fiber with automatic schema inference.
Types ¶
type DiscoverOptions ¶
type DiscoverOptions = router.DiscoverOptions
DiscoverOptions configures how route auto-discovery behaves.
type DocsAuthConfig ¶
type DocsAuthConfig = router.DocsAuthConfig
DocsAuthConfig holds credentials for protecting the docs and OpenAPI endpoints.
type FiberConfig ¶
type FiberConfig = router.FiberConfig
FiberConfig holds configuration for the Fiber adapter.
type RouteOption ¶
type RouteOption = router.RouteOption
RouteOption configures a route's documentation metadata.
func Description ¶
func Description(d string) RouteOption
Description sets the operation description.
func ErrorResponse ¶
func ErrorResponse(status int, model any, description string) RouteOption
ErrorResponse adds an error response definition.
func HeaderParams ¶
func HeaderParams(model any) RouteOption
HeaderParams sets the header parameters type for documentation.
func PathParams ¶
func PathParams(model any) RouteOption
PathParams sets the path parameters type for documentation.
func QueryParams ¶
func QueryParams(model any) RouteOption
QueryParams sets the query parameters type for documentation.
func RequestContentType ¶
func RequestContentType(ct string) RouteOption
RequestContentType overrides the request content type.
func Response ¶
func Response(status int, model any, description string) RouteOption
Response adds a custom response definition for a status code.
func ResponseContentType ¶
func ResponseContentType(ct string) RouteOption
ResponseContentType overrides the response content type.
func Security ¶
func Security(schemes ...map[string][]string) RouteOption
Security sets security requirements for a route.
func SecurityAPIKey ¶
func SecurityAPIKey() RouteOption
SecurityAPIKey adds API key security requirement to a route.
func SecurityBasic ¶
func SecurityBasic() RouteOption
SecurityBasic adds basic auth security requirement to a route.
func SecurityBearer ¶
func SecurityBearer() RouteOption
SecurityBearer adds bearer token security requirement to a route.
func SuccessStatus ¶
func SuccessStatus(code int) RouteOption
SuccessStatus sets the default success status code.
func WithRequest ¶
func WithRequest(model any) RouteOption
WithRequest sets the request body type for untyped handlers.
func WithResponse ¶
func WithResponse(model any) RouteOption
WithResponse sets the response body type for untyped handlers.
type SecurityScheme ¶
type SecurityScheme = core.SecurityScheme
SecurityScheme represents a security scheme definition.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package core provides type reflection and JSON Schema generation for the swagify OpenAPI documentation package.
|
Package core provides type reflection and JSON Schema generation for the swagify OpenAPI documentation package. |
|
examples
|
|
|
auth
command
Auth example demonstrating JWT and API key security documentation with swagify.
|
Auth example demonstrating JWT and API key security documentation with swagify. |
|
fiber-basic
command
Fiber basic CRUD example demonstrating swagify with standard Fiber handlers.
|
Fiber basic CRUD example demonstrating swagify with standard Fiber handlers. |
|
fiber-discover
command
Example: Fiber Auto-Discovery
|
Example: Fiber Auto-Discovery |
|
fiber-typed
command
Fiber typed handlers example demonstrating swagify generics-based type inference.
|
Fiber typed handlers example demonstrating swagify generics-based type inference. |
|
gin-basic
command
Gin basic CRUD example demonstrating swagify with Gin framework.
|
Gin basic CRUD example demonstrating swagify with Gin framework. |
|
gin-discover
command
Example: Gin Auto-Discovery
|
Example: Gin Auto-Discovery |
|
nested-schemas
command
Nested schemas example demonstrating complex type handling.
|
Nested schemas example demonstrating complex type handling. |
|
internal
|
|
|
cache
Package cache provides a thread-safe schema cache for the swagify package.
|
Package cache provides a thread-safe schema cache for the swagify package. |
|
errors
Package errors provides structured error types for the swagify package.
|
Package errors provides structured error types for the swagify package. |
|
utils
Package utils provides internal utility functions for the swagify package.
|
Package utils provides internal utility functions for the swagify package. |
|
Package openapi provides OpenAPI 3.1 document generation from the swagify route registry and schema generator.
|
Package openapi provides OpenAPI 3.1 document generation from the swagify route registry and schema generator. |
|
Package router provides route registration, metadata collection, and framework adapter interfaces for the swagify documentation package.
|
Package router provides route registration, metadata collection, and framework adapter interfaces for the swagify documentation package. |
|
Package ui provides embedded API documentation UI assets and handler registration for multiple web frameworks.
|
Package ui provides embedded API documentation UI assets and handler registration for multiple web frameworks. |