Documentation
¶
Overview ¶
Package mock provides an HTTP handler that serves mock responses from OpenAPI schemas.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CORSMiddleware ¶
CORSMiddleware adds CORS headers to all responses and handles OPTIONS preflight.
Types ¶
type HandlerConfig ¶
HandlerConfig controls mock handler behavior.
type MockHandler ¶
type MockHandler struct {
// contains filtered or unexported fields
}
MockHandler serves mock HTTP responses from OpenAPI schemas.
func NewMockHandler ¶
func NewMockHandler(v *cvt.Validator, schemaIDs []string, cfg HandlerConfig) *MockHandler
NewMockHandler creates a new mock HTTP handler.
func (*MockHandler) RecoverMiddleware ¶
func (h *MockHandler) RecoverMiddleware(next http.Handler) http.Handler
RecoverMiddleware wraps an http.Handler with panic recovery that returns 500 JSON.
func (*MockHandler) ServeHTTP ¶
func (h *MockHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles incoming HTTP requests by matching them against registered OpenAPI schemas and returning generated mock responses.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a mock HTTP server that generates responses from OpenAPI schemas.
func NewServer ¶
func NewServer(cfg ServerConfig) *Server
NewServer creates a new mock server with the given configuration.
type ServerConfig ¶
type ServerConfig struct {
Host string
Port int
SchemaFiles []string // file paths or URLs
Watch bool
ValidateRequests bool
UseExamples bool
LatencyMs int
Quiet bool
Seed *uint64 // Random seed for deterministic responses (nil = random)
}
ServerConfig holds configuration for the mock server.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher watches schema files for changes and triggers a reload callback.
func NewWatcher ¶
NewWatcher creates a file watcher that calls onReload when any watched file changes.