autofiber

package module
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2025 License: MIT Imports: 9 Imported by: 0

README

AutoFiber

A FastAPI-like wrapper for the Fiber web framework in Go, providing automatic request parsing, validation, and OpenAPI/Swagger documentation generation.

Features

  • 🔄 Complete Request/Response Flow: Parse request → Validate request → Execute handler → Validate response → Return JSON
  • 🧠 Smart Parsing: Auto-detect the best source based on HTTP method (GET: path→query, POST: body→path→query)
  • 🏷️ Unified Parse Tag: Single parse tag with options like required and default
  • 🗺️ Map/Interface Parsing: Parse structs from maps, interfaces, and other data structures
  • ✅ Request Validation: Built-in validation using struct tags with go-playground/validator
  • ✅ Response Validation: Validate response data before sending to client
  • 📚 Auto Documentation: Generate OpenAPI 3.0 specification and Swagger UI
  • 🔒 Type Safety: Full type safety with Go generics
  • ⚙️ Route Options: Flexible route configuration with options pattern
  • 🔌 Middleware Integration: Seamless integration with Fiber middleware
  • 🎯 Clean Architecture: Modular design with separate concerns

Installation

go get github.com/vuongtlt13/auto-fiber

Project Structure

auto-fiber/
  app.go            // App core: AutoFiber struct, route registration, group, listen, etc.
  group.go          // Route grouping logic
  handlers.go       // Handler creation, signature validation, error handling
  parser.go         // Request parsing from multiple sources (body, query, path, ...)
  validator.go      // Response validation logic
  map_parser.go     // Parse struct from map/interface
  docs.go           // OpenAPI/Swagger documentation generation
  options.go        // Route option functions (WithRequestSchema, WithResponseSchema, ...)
  types.go          // Core types, RouteOptions, ParseSource, etc.
  example/          // Example usage and demo app
  docs/             // Documentation and guides
  • app.go: Initialize app, register routes, groups, listen.
  • group.go: Support for route groups, group middleware.
  • handlers.go: Create handlers with correct signature, signature validation.
  • parser.go: Automatically parse requests from multiple sources (body, query, path, header, cookie).
  • validator.go: Validate response before returning to client.
  • map_parser.go: Support parsing struct from map/interface (for test, mock, ...).
  • docs.go: Generate OpenAPI spec, serve Swagger UI/docs.
  • options.go: Option functions for routes (schema, tags, description, ...).
  • types.go: Define core types, RouteOptions, ParseSource, ...

Quick Start

package main

import (
    "time"
    "github.com/gofiber/fiber/v2"
    autofiber "github.com/vuongtlt13/auto-fiber"
)

// Request schema with parse tag
// (parse from path, query, header, body)
type CreateUserRequest struct {
    OrgID    int    `parse:"path:org_id" validate:"required"`
    Role     string `parse:"query:role" validate:"required,oneof=admin user"`
    Email    string `json:"email" validate:"required,email"`
    Password string `json:"password" validate:"required,min=8"`
    Name     string `json:"name" validate:"required"`
}

type UserResponse struct {
    ID        int       `json:"id" validate:"required"`
    Email     string    `json:"email" validate:"required,email"`
    Name      string    `json:"name" validate:"required"`
    Role      string    `json:"role" validate:"required,oneof=admin user"`
    CreatedAt time.Time `json:"created_at" validate:"required"`
}

type UserHandler struct{}

// Handler signature for AutoFiber:
func (h *UserHandler) CreateUser(c *fiber.Ctx, req *CreateUserRequest) (interface{}, error) {
    user := UserResponse{
        ID:        1,
        Email:     req.Email,
        Name:      req.Name,
        Role:      req.Role,
        CreatedAt: time.Now(),
    }
    return user, nil
}

func main() {
    app := autofiber.NewWithOptions(
        fiber.Config{EnablePrintRoutes: true},
        autofiber.WithOpenAPI(autofiber.OpenAPIInfo{
            Title:       "AutoFiber API",
            Description: "A sample API with complete request/response flow",
            Version:     "0.3.1",
        }),
    )

    handler := &UserHandler{}

    app.Post("/organizations/:org_id/users", handler.CreateUser,
        autofiber.WithRequestSchema(CreateUserRequest{}),
        autofiber.WithResponseSchema(UserResponse{}),
        autofiber.WithDescription("Create a new user in an organization"),
        autofiber.WithTags("users", "admin"),
    )

    app.ServeDocs("/docs")
    app.ServeSwaggerUI("/swagger", "/docs")
    app.Listen(":3000")
}

Complete Request/Response Flow

AutoFiber provides a complete flow similar to FastAPI:

Parse Request → Validate Request → Execute Handler → Validate Response → Return JSON
Flow Details
  1. Parse Request: Automatically parse from multiple sources (body, query, path, headers, cookies)
  2. Validate Request: Validate parsed data against struct tags
  3. Execute Handler: Run your business logic
  4. Validate Response: Validate response data before sending
  5. Return JSON: Send validated response to client

Handler Signatures

Recommended:

// Standard handler: return data and error, AutoFiber will marshal JSON automatically
func (h *Handler) CompleteHandler(c *fiber.Ctx, req *RequestSchema) (interface{}, error) {
    return ResponseSchema{...}, nil
}

Use only for health check or custom response:

func (h *Handler) Health(c *fiber.Ctx) error {
    return c.JSON(fiber.Map{"status": "ok"})
}

NOT recommended:

// Do not call c.JSON manually if you already have a request schema
func (h *Handler) BadHandler(c *fiber.Ctx, req *RequestSchema) error {
    return c.JSON(...)
}

Documentation

Contributing

If you find any issues or want to improve the documentation:

  1. Check the existing documentation first
  2. Create an issue or pull request
  3. Follow the same format and style as existing docs
  4. Include practical examples and use cases

License

MIT

Documentation

Overview

Package autofiber provides a FastAPI-like wrapper for the Fiber web framework. It enables automatic request parsing, validation, and OpenAPI/Swagger documentation generation.

Package autofiber provides OpenAPI 3.0 specification generation for automatic API documentation.

Package autofiber provides OpenAPI/Swagger documentation configuration and serving utilities.

Package autofiber provides route group functionality with automatic request parsing, validation, and documentation generation.

Package autofiber provides handler creation utilities for automatic request parsing, validation, and response handling.

Package autofiber provides map and interface parsing utilities for converting data structures to Go structs.

Package autofiber provides middleware functions for automatic request parsing, validation, and response handling.

Package autofiber provides route configuration options for building APIs with automatic parsing, validation, and documentation.

Package autofiber provides request parsing utilities for extracting and validating data from multiple sources.

Package autofiber provides HTTP route registration methods with automatic request parsing, validation, and documentation generation.

Package autofiber provides core types and configuration for the AutoFiber web framework.

Package autofiber provides response validation utilities for ensuring API responses match expected schemas.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoParseRequest

func AutoParseRequest(schema interface{}, customValidator *validator.Validate) fiber.Handler

AutoParseRequest returns middleware for automatic request parsing and validation. The middleware parses request data from multiple sources (body, query, path, headers, cookies, form) based on struct tags and validates the parsed data using the provided schema. If customValidator is nil, it uses the global validator instance.

func GetParsedRequest

func GetParsedRequest[T any](c *fiber.Ctx) *T

GetParsedRequest retrieves the parsed request from context. This function extracts the parsed request data that was stored by AutoParseRequest middleware. It returns nil if no parsed request is found or if the type assertion fails.

func GetValidator

func GetValidator() *validator.Validate

GetValidator returns the global validator instance for validation.

func ParseFromInterface

func ParseFromInterface(data interface{}, schema interface{}) error

ParseFromInterface parses a struct from any interface{} (map, struct, etc.). It supports map[string]interface{}, map[string]string, and struct types. The schema parameter must be a pointer to the target struct.

func ParseFromMap

func ParseFromMap(data map[string]interface{}, schema interface{}) error

ParseFromMap parses a struct from a map[string]interface{}. It uses JSON tags to map keys to struct fields and sets the values accordingly. The schema parameter must be a pointer to the target struct.

func Simple

func Simple(handler func(*fiber.Ctx) error) fiber.Handler

Simple wraps a simple handler function. This is a utility function for creating Fiber handlers from simple functions.

func ValidateAndJSON

func ValidateAndJSON(c *fiber.Ctx, data interface{}) error

ValidateAndJSON validates response data and returns JSON. If response validation is configured, it validates the data against the response schema before returning the JSON response. If validation fails, it returns an error response. If no validation is configured, it simply returns the JSON response.

Types

type AutoFiber

type AutoFiber struct {
	App *fiber.App
	// contains filtered or unexported fields
}

AutoFiber is the main application struct for building APIs with automatic parsing, validation, and documentation.

func New

func New(config fiber.Config, options ...AutoFiberOption) *AutoFiber

New creates a new AutoFiber application instance with custom options.

func (*AutoFiber) All

func (af *AutoFiber) All(path string, handler interface{}, options ...RouteOption) fiber.Router

All registers a route for all HTTP methods with automatic request parsing, validation, and documentation generation. The handler can be a simple function or a function that accepts a parsed request struct. Options can be provided to configure request/response schemas, middleware, and documentation.

func (*AutoFiber) Delete

func (af *AutoFiber) Delete(path string, handler interface{}, options ...RouteOption) fiber.Router

Delete registers a DELETE route with automatic request parsing, validation, and documentation generation. The handler can be a simple function or a function that accepts a parsed request struct. Options can be provided to configure request/response schemas, middleware, and documentation.

func (*AutoFiber) Get

func (af *AutoFiber) Get(path string, handler interface{}, options ...RouteOption) fiber.Router

Get registers a GET route with automatic request parsing, validation, and documentation generation. The handler can be a simple function or a function that accepts a parsed request struct. Options can be provided to configure request/response schemas, middleware, and documentation.

func (*AutoFiber) GetOpenAPIJSON

func (af *AutoFiber) GetOpenAPIJSON() ([]byte, error)

GetOpenAPIJSON returns the OpenAPI specification as JSON bytes. This is useful for serving the specification via HTTP or saving to a file.

func (*AutoFiber) GetOpenAPISpec

func (af *AutoFiber) GetOpenAPISpec() *OpenAPISpec

GetOpenAPISpec returns the complete OpenAPI specification as a struct. If no documentation info is set, it uses default values.

func (*AutoFiber) Group

func (af *AutoFiber) Group(prefix string, handlers ...fiber.Handler) *AutoFiberGroup

Group creates a new route group with the given prefix.

func (*AutoFiber) Head

func (af *AutoFiber) Head(path string, handler interface{}, options ...RouteOption) fiber.Router

Head registers a HEAD route with automatic request parsing, validation, and documentation generation. The handler can be a simple function or a function that accepts a parsed request struct. Options can be provided to configure request/response schemas, middleware, and documentation.

func (*AutoFiber) Listen

func (af *AutoFiber) Listen(addr string) error

Listen starts the Fiber application on the specified address.

func (*AutoFiber) Options

func (af *AutoFiber) Options(path string, handler interface{}, options ...RouteOption) fiber.Router

Options registers an OPTIONS route with automatic request parsing, validation, and documentation generation. The handler can be a simple function or a function that accepts a parsed request struct. Options can be provided to configure request/response schemas, middleware, and documentation.

func (*AutoFiber) Patch

func (af *AutoFiber) Patch(path string, handler interface{}, options ...RouteOption) fiber.Router

Patch registers a PATCH route with automatic request parsing, validation, and documentation generation. The handler can be a simple function or a function that accepts a parsed request struct. Options can be provided to configure request/response schemas, middleware, and documentation.

func (*AutoFiber) Post

func (af *AutoFiber) Post(path string, handler interface{}, options ...RouteOption) fiber.Router

Post registers a POST route with automatic request parsing, validation, and documentation generation. The handler can be a simple function or a function that accepts a parsed request struct. Options can be provided to configure request/response schemas, middleware, and documentation.

func (*AutoFiber) Put

func (af *AutoFiber) Put(path string, handler interface{}, options ...RouteOption) fiber.Router

Put registers a PUT route with automatic request parsing, validation, and documentation generation. The handler can be a simple function or a function that accepts a parsed request struct. Options can be provided to configure request/response schemas, middleware, and documentation.

func (*AutoFiber) ServeDocs

func (af *AutoFiber) ServeDocs(path string)

ServeDocs serves the OpenAPI specification as JSON at the specified path. This creates a GET route that returns the OpenAPI specification.

func (*AutoFiber) ServeSwaggerUI

func (af *AutoFiber) ServeSwaggerUI(swaggerPath, docsPath string)

ServeSwaggerUI serves Swagger UI for the OpenAPI documentation. This creates a GET route that serves an HTML page with Swagger UI interface. swaggerPath is the URL path where Swagger UI will be served. docsPath is the URL path where the OpenAPI JSON specification is served.

func (*AutoFiber) Test

func (af *AutoFiber) Test(req *http.Request, msTimeout ...int) (*http.Response, error)

Test creates a test request for the Fiber application.

func (*AutoFiber) Use

func (af *AutoFiber) Use(args ...interface{}) fiber.Router

Use adds middleware to the app.

type AutoFiberGroup

type AutoFiberGroup struct {
	Group *fiber.Group // Underlying Fiber group

	Prefix string // Prefix of the group
	// contains filtered or unexported fields
}

AutoFiberGroup represents a group of routes with a common prefix and shared middleware.

func (*AutoFiberGroup) All

func (ag *AutoFiberGroup) All(path string, handler interface{}, options ...RouteOption) fiber.Router

All registers a route for all HTTP methods with automatic request parsing, validation, and documentation generation in the group. The handler can be a simple function or a function that accepts a parsed request struct. Options can be provided to configure request/response schemas, middleware, and documentation.

func (*AutoFiberGroup) Delete

func (ag *AutoFiberGroup) Delete(path string, handler interface{}, options ...RouteOption) fiber.Router

Delete registers a DELETE route with automatic request parsing, validation, and documentation generation in the group. The handler can be a simple function or a function that accepts a parsed request struct. Options can be provided to configure request/response schemas, middleware, and documentation.

func (*AutoFiberGroup) Get

func (ag *AutoFiberGroup) Get(path string, handler interface{}, options ...RouteOption) fiber.Router

Get registers a GET route with automatic request parsing, validation, and documentation generation in the group. The handler can be a simple function or a function that accepts a parsed request struct. Options can be provided to configure request/response schemas, middleware, and documentation.

func (*AutoFiberGroup) Head

func (ag *AutoFiberGroup) Head(path string, handler interface{}, options ...RouteOption) fiber.Router

Head registers a HEAD route with automatic request parsing, validation, and documentation generation in the group. The handler can be a simple function or a function that accepts a parsed request struct. Options can be provided to configure request/response schemas, middleware, and documentation.

func (*AutoFiberGroup) Options

func (ag *AutoFiberGroup) Options(path string, handler interface{}, options ...RouteOption) fiber.Router

Options registers an OPTIONS route with automatic request parsing, validation, and documentation generation in the group. The handler can be a simple function or a function that accepts a parsed request struct. Options can be provided to configure request/response schemas, middleware, and documentation.

func (*AutoFiberGroup) Patch

func (ag *AutoFiberGroup) Patch(path string, handler interface{}, options ...RouteOption) fiber.Router

Patch registers a PATCH route with automatic request parsing, validation, and documentation generation in the group. The handler can be a simple function or a function that accepts a parsed request struct. Options can be provided to configure request/response schemas, middleware, and documentation.

func (*AutoFiberGroup) Post

func (ag *AutoFiberGroup) Post(path string, handler interface{}, options ...RouteOption) fiber.Router

Post registers a POST route with automatic request parsing, validation, and documentation generation in the group. The handler can be a simple function or a function that accepts a parsed request struct. Options can be provided to configure request/response schemas, middleware, and documentation.

func (*AutoFiberGroup) Put

func (ag *AutoFiberGroup) Put(path string, handler interface{}, options ...RouteOption) fiber.Router

Put registers a PUT route with automatic request parsing, validation, and documentation generation in the group. The handler can be a simple function or a function that accepts a parsed request struct. Options can be provided to configure request/response schemas, middleware, and documentation.

func (*AutoFiberGroup) Use

func (ag *AutoFiberGroup) Use(args ...interface{}) fiber.Router

Use adds middleware to the group. This middleware will be applied to all routes registered in this group.

type AutoFiberOption added in v0.3.0

type AutoFiberOption func(*AutoFiber)

AutoFiberOption is a function type for configuring AutoFiber options

func WithOpenAPI added in v0.3.0

func WithOpenAPI(info OpenAPIInfo) AutoFiberOption

WithOpenAPI sets the OpenAPI info for the documentation (no server info).

type DocsGenerator

type DocsGenerator struct {
	DocsInfo *OpenAPIInfo
	// contains filtered or unexported fields
}

DocsGenerator handles API documentation generation and OpenAPI specification creation.

func NewDocsGenerator

func NewDocsGenerator() *DocsGenerator

NewDocsGenerator creates a new documentation generator with the specified base path.

func (*DocsGenerator) AddRoute

func (dg *DocsGenerator) AddRoute(path, method string, handler interface{}, options *RouteOptions)

AddRoute adds a route to the documentation generator with its metadata and options.

func (*DocsGenerator) GenerateJSON

func (dg *DocsGenerator) GenerateJSON() ([]byte, error)

GenerateJSON generates the OpenAPI specification as JSON bytes. This is useful for serving the specification via HTTP or saving to a file.

func (*DocsGenerator) GenerateOpenAPISpec

func (dg *DocsGenerator) GenerateOpenAPISpec() *OpenAPISpec

GenerateOpenAPISpec generates the complete OpenAPI specification from collected route information.

type FieldInfo

type FieldInfo struct {
	Source      ParseSource // Source to parse the field from
	Key         string      // Custom key name (e.g., "user_id" for "UserId")
	Required    bool        // Whether the field is required
	Default     interface{} // Default value if not provided
	Description string      // Description for documentation
}

FieldInfo contains parsing information for a struct field.

type HandlerFunc

type HandlerFunc func(*fiber.Ctx) error

HandlerFunc is a Fiber handler function.

type HandlerWithRequest

type HandlerWithRequest[T any] func(*fiber.Ctx, *T) (interface{}, error)

HandlerWithRequest is a generic handler function with request parsing and response. T is the type of the parsed request struct.

type OpenAPIComponents

type OpenAPIComponents struct {
	Schemas         map[string]OpenAPISchema     `json:"schemas,omitempty"`
	SecuritySchemes map[string]map[string]string `json:"securitySchemes,omitempty"`
}

OpenAPIComponents represents reusable components like schemas and security schemes.

type OpenAPIContact

type OpenAPIContact struct {
	Name  string `json:"name,omitempty"`
	URL   string `json:"url,omitempty"`
	Email string `json:"email,omitempty"`
}

OpenAPIContact represents contact information for the API.

type OpenAPIInfo

type OpenAPIInfo struct {
	Title       string          `json:"title"`
	Description string          `json:"description,omitempty"`
	Version     string          `json:"version"`
	Contact     *OpenAPIContact `json:"contact,omitempty"`
	License     *OpenAPILicense `json:"license,omitempty"`
}

OpenAPIInfo represents the API information including title, description, version, and contact details.

type OpenAPILicense

type OpenAPILicense struct {
	Name string `json:"name"`
	URL  string `json:"url,omitempty"`
}

OpenAPILicense represents license information for the API.

type OpenAPIMediaType

type OpenAPIMediaType struct {
	Schema *OpenAPISchema `json:"schema,omitempty"`
}

OpenAPIMediaType represents media type content (e.g., application/json).

type OpenAPIOperation

type OpenAPIOperation struct {
	Tags        []string                   `json:"tags,omitempty"`
	Summary     string                     `json:"summary,omitempty"`
	Description string                     `json:"description,omitempty"`
	OperationID string                     `json:"operationId,omitempty"`
	Parameters  []OpenAPIParameter         `json:"parameters,omitempty"`
	RequestBody *OpenAPIRequestBody        `json:"requestBody,omitempty"`
	Responses   map[string]OpenAPIResponse `json:"responses"`
	Security    []map[string][]string      `json:"security,omitempty"`
}

OpenAPIOperation represents an API operation with parameters, request body, and responses.

type OpenAPIParameter

type OpenAPIParameter struct {
	Name        string         `json:"name"`
	In          string         `json:"in"`
	Description string         `json:"description,omitempty"`
	Required    bool           `json:"required,omitempty"`
	Schema      *OpenAPISchema `json:"schema,omitempty"`
}

OpenAPIParameter represents a parameter (query, path, header, cookie) for an API operation.

type OpenAPIPath

type OpenAPIPath struct {
	Get     *OpenAPIOperation `json:"get,omitempty"`
	Post    *OpenAPIOperation `json:"post,omitempty"`
	Put     *OpenAPIOperation `json:"put,omitempty"`
	Delete  *OpenAPIOperation `json:"delete,omitempty"`
	Patch   *OpenAPIOperation `json:"patch,omitempty"`
	Head    *OpenAPIOperation `json:"head,omitempty"`
	Options *OpenAPIOperation `json:"options,omitempty"`
}

OpenAPIPath represents a path in the API with all supported HTTP methods.

type OpenAPIRequestBody

type OpenAPIRequestBody struct {
	Description string                      `json:"description,omitempty"`
	Required    bool                        `json:"required,omitempty"`
	Content     map[string]OpenAPIMediaType `json:"content"`
}

OpenAPIRequestBody represents a request body for an API operation.

type OpenAPIResponse

type OpenAPIResponse struct {
	Description string                      `json:"description"`
	Content     map[string]OpenAPIMediaType `json:"content,omitempty"`
}

OpenAPIResponse represents a response for an API operation.

type OpenAPISchema

type OpenAPISchema struct {
	Type        string                   `json:"type,omitempty"`
	Format      string                   `json:"format,omitempty"`
	Description string                   `json:"description,omitempty"`
	Required    []string                 `json:"required,omitempty"`
	Properties  map[string]OpenAPISchema `json:"properties,omitempty"`
	Items       *OpenAPISchema           `json:"items,omitempty"`
	Ref         string                   `json:"$ref,omitempty"`
	Example     interface{}              `json:"example,omitempty"`
}

OpenAPISchema represents a JSON schema for request/response data structures.

type OpenAPIServer

type OpenAPIServer struct {
	URL         string `json:"url"`
	Description string `json:"description,omitempty"`
}

OpenAPIServer represents server information for the API.

type OpenAPISpec

type OpenAPISpec struct {
	OpenAPI    string                 `json:"openapi"`
	Info       OpenAPIInfo            `json:"info"`
	Servers    []OpenAPIServer        `json:"servers,omitempty"`
	Paths      map[string]OpenAPIPath `json:"paths"`
	Components OpenAPIComponents      `json:"components,omitempty"`
	Tags       []OpenAPITag           `json:"tags,omitempty"`
}

OpenAPISpec represents the OpenAPI 3.0 specification structure.

type OpenAPITag

type OpenAPITag struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
}

OpenAPITag represents a tag for grouping API operations.

type ParseError

type ParseError struct {
	Field   string // Name of the field
	Source  string // Source of the field (e.g., body, query)
	Message string // Error message
}

ParseError represents a parsing error for a specific field and source.

func (*ParseError) Error

func (e *ParseError) Error() string

Error returns the error message for a ParseError.

type ParseSource

type ParseSource string

ParseSource defines where a field should be parsed from (e.g., body, query, path, header, etc.).

const (
	// Body indicates the field should be parsed from the request body.
	Body ParseSource = "body"
	// Query indicates the field should be parsed from the query string.
	Query ParseSource = "query"
	// Path indicates the field should be parsed from the URL path parameters.
	Path ParseSource = "path"
	// Header indicates the field should be parsed from the request headers.
	Header ParseSource = "header"
	// Cookie indicates the field should be parsed from cookies.
	Cookie ParseSource = "cookie"
	// Form indicates the field should be parsed from form data.
	Form ParseSource = "form"
	// Auto enables smart parsing based on HTTP method and struct tags.
	Auto ParseSource = "auto"
)

type RouteInfo

type RouteInfo struct {
	Path        string
	Method      string
	Handler     interface{}
	Options     *RouteOptions
	OperationID string
}

RouteInfo stores information about a route for documentation generation.

type RouteOption

type RouteOption func(*RouteOptions)

RouteOption is a function that configures route options for an endpoint.

func WithDescription

func WithDescription(description string) RouteOption

WithDescription sets the route description for API documentation. This description will appear in the generated OpenAPI/Swagger documentation.

func WithMiddleware

func WithMiddleware(middleware ...fiber.Handler) RouteOption

WithMiddleware adds middleware to the route. Multiple middleware can be added and they will be executed in the order provided.

func WithRequestSchema

func WithRequestSchema(schema interface{}) RouteOption

WithRequestSchema sets the request schema for auto-parsing. The schema should be a struct type that defines the expected request structure.

func WithResponseSchema

func WithResponseSchema(schema interface{}) RouteOption

WithResponseSchema sets the response schema for documentation and validation. The schema should be a struct type that defines the expected response structure.

func WithTags

func WithTags(tags ...string) RouteOption

WithTags sets the route tags for API documentation. Tags help organize and categorize routes in the generated documentation.

type RouteOptions

type RouteOptions struct {
	RequestSchema  interface{}     // Struct for request parsing and validation
	ResponseSchema interface{}     // Struct for response validation and documentation
	Middleware     []fiber.Handler // Middleware handlers for the route
	Description    string          // Description for API documentation
	Tags           []string        // Tags for API documentation
}

RouteOptions contains configuration for a route, such as schemas, middleware, and metadata.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL