apivalidation

package
v1.8.3-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidSchemaName = errors.New("invalid schema name")
)

Functions

This section is empty.

Types

type Policy

type Policy string

Policy controls what the validator does when it encounters a condition it cannot fully validate (unknown route, method not allowed for a matched path, security scheme type the WAF cannot enforce).

const (
	// PolicyDrop treats the condition as a validation failure.
	PolicyDrop Policy = "drop"
	// PolicyIgnore lets the request through as if the condition had passed.
	PolicyIgnore Policy = "ignore"
)

type RequestValidator

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

func NewRequestValidator

func NewRequestValidator(logger *log.Entry) *RequestValidator

func (*RequestValidator) LoadSchema

func (rv *RequestValidator) LoadSchema(ref string, schema string, opts *SchemaOptions) error

func (*RequestValidator) RegisterBodyDecoder

func (rv *RequestValidator) RegisterBodyDecoder(contentType, decoderName string) error

RegisterBodyDecoder registers a decoder for the given Content-Type so that a loaded OpenAPI schema can declare and validate requests of that type. decoderName must be one of the built-in identifiers: "json", "urlencoded", "multipart", "yaml", "csv", "plain", "file". Note that this mutates kin-openapi's process-global decoder registry — see the note on NewRequestValidator.

func (*RequestValidator) ValidateRequest

func (rv *RequestValidator) ValidateRequest(ctx context.Context, ref string, r *http.Request) error

type SchemaData

type SchemaData struct {
	Schema  *openapi3.T
	Router  routers.Router
	Options SchemaOptions
}

type SchemaOptions

type SchemaOptions struct {
	OnRouteNotFound             Policy
	OnMethodNotAllowed          Policy
	OnUnsupportedSecurityScheme Policy
}

SchemaOptions configures per-schema validation behavior. A nil *SchemaOptions passed to LoadSchema means "use defaults" (all policies = drop, matching pre-option behavior).

type ValidationError

type ValidationError struct {
	Reason        string
	Field         string
	SchemaPath    string
	Message       string
	Value         string
	Expected      string
	OriginalError error
}

ValidationError provides detailed information about validation failures

func (*ValidationError) Error

func (ve *ValidationError) Error() string

Jump to

Keyboard shortcuts

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