openapi

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package openapi provides OpenAPI request and response validation middleware.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorHandler

type ErrorHandler func(http.ResponseWriter, *http.Request, int, error)

ErrorHandler handles OpenAPI validation failures.

type Middleware

type Middleware struct {
	// contains filtered or unexported fields
}

Middleware validates requests against an OpenAPI spec.

func New

func New(spec *openapi3.T, opts ...Option) (*Middleware, error)

New constructs a validation middleware from a spec.

func NewFromFile

func NewFromFile(path string, opts ...Option) (*Middleware, error)

NewFromFile loads and validates a spec from disk.

func (*Middleware) Handler

func (m *Middleware) Handler(next http.Handler) http.Handler

Handler wraps the next handler with OpenAPI request validation.

func (*Middleware) Middleware

func (m *Middleware) Middleware() func(http.Handler) http.Handler

Middleware implements ports.Middleware by returning the handler adapter.

type Option

type Option func(*Options)

Option customizes middleware behavior.

func WithErrorHandler

func WithErrorHandler(fn ErrorHandler) Option

WithErrorHandler overrides the error writer.

func WithFilterOptions

func WithFilterOptions(opts openapi3filter.Options) Option

WithFilterOptions overrides request validation options.

func WithIgnoreNotFound

func WithIgnoreNotFound(ignore bool) Option

WithIgnoreNotFound controls how unmatched routes are handled.

func WithResponseValidation

func WithResponseValidation(opts ResponseValidationOptions) Option

WithResponseValidation configures response validation.

func WithSpec

func WithSpec(spec *openapi3.T) Option

WithSpec sets the OpenAPI spec to validate against.

type Options

type Options struct {
	Spec               *openapi3.T
	FilterOptions      openapi3filter.Options
	ErrorHandler       ErrorHandler
	IgnoreNotFound     bool
	ResponseValidation ResponseValidationOptions
}

Options configures request validation middleware.

type ResponseValidationOptions

type ResponseValidationOptions struct {
	Enabled      bool
	MaxBodyBytes int64
	ErrorHandler ErrorHandler
}

ResponseValidationOptions configures response validation.

Jump to

Keyboard shortcuts

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