specval

package module
v0.0.0-...-08a8310 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package specval validates incoming HTTP requests against a service's embedded OpenAPI spec and writes house RFC 9457 problem+json responses on schema failures, so every service enforces its contract the same way instead of hand-rolling per-handler checks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(opts Options) func(http.Handler) http.Handler

Middleware validates requests against opts.Spec and writes a house problem+json response (invalid_param or invalid_body) on schema failures. Routes absent from the spec pass through, so the wrapped handler's own 404/405 handling still applies. Security requirements are accepted unconditionally here (kin-openapi requires an AuthenticationFunc or every secured operation 401s); authentication is jwtauth's job, earlier in the chain.

Types

type Options

type Options struct {
	// Spec is the service's embedded OpenAPI document (e.g. the generated api package's
	// GetSpec()). Middleware validates from a shallow copy with Servers cleared; Spec itself
	// is never mutated.
	Spec *openapi3.T

	// MaxBodyBytes caps the request body size read during validation, via
	// http.MaxBytesReader. A value <= 0 leaves the body size unbounded.
	MaxBodyBytes int64
}

Options configures the request-validation middleware for one service.

Jump to

Keyboard shortcuts

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