Documentation
ยถ
Index ยถ
Constants ยถ
This section is empty.
Variables ยถ
This section is empty.
Functions ยถ
func DefaultErrorEncoder ยถ
func DefaultErrorEncoder(w http.ResponseWriter, r *http.Request, err error)
DefaultErrorEncoder is a built-in implementation of ErrorEncoder. It sends a JSON response with a 400 Bad Request status code.
Types ยถ
type ErrorEncoder ยถ
type ErrorEncoder func(w http.ResponseWriter, r *http.Request, err error)
ErrorEncoder is a function type used to encode validation errors into an HTTP response.
type Option ยถ
type Option func(*Options)
Option is a function type used to configure the Options struct.
func WithErrorEncoder ยถ
func WithErrorEncoder(encoder ErrorEncoder) Option
WithErrorEncoder returns an Option that sets a custom error encoder.
func WithRouter ยถ
WithRouter returns an Option that sets a custom router.
func WithSwaggerUIPath ยถ
WithSwaggerUIPath returns an Option that sets the URL path for the Swagger UI.
func WithValidateRequests ยถ
WithValidateRequests returns an Option that enables or disables request validation.
func WithValidateResponses ยถ
WithValidateResponses returns an Option that enables or disables response validation.
type Options ยถ
type Options struct {
// ValidateRequests specifies whether incoming requests should be validated against the spec.
ValidateRequests bool
// ValidateResponses specifies whether outgoing responses should be validated against the spec.
ValidateResponses bool
// SwaggerUIPath is the URL path where Swagger UI will be served.
SwaggerUIPath string
// ErrorEncoder is used to format and send validation error responses.
ErrorEncoder ErrorEncoder
// Router is used for matching requests to OpenAPI paths.
Router routers.Router
}
Options contains the configuration for the OpenAPI validator.
func DefaultOptions ยถ
func DefaultOptions() *Options
DefaultOptions returns the default configuration for the validator.
type Registrar ยถ
type Registrar interface {
HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
}
Registrar is an interface that matches both http.ServeMux and gorilla/mux.Router.
type ValidationError ยถ
type ValidationError struct {
Message string `json:"message"`
Errors []string `json:"errors,omitempty"`
}
ValidationError represents a failed validation attempt. It includes a top-level message and an optional list of detailed error strings.
func (*ValidationError) Error ยถ
func (e *ValidationError) Error() string
Error implements the error interface for ValidationError.
type Validator ยถ
type Validator struct {
// Options holds the configuration for the validator.
Options *Options
// Swagger is the parsed OpenAPI 3 specification.
Swagger *openapi3.T
}
Validator is the core component that manages OpenAPI validation and Swagger UI.
func New ยถ
New creates a new Validator instance from an OpenAPI spec file and optional configuration. It parses and validates the spec, and initializes the router.
func (*Validator) HandleSwaggerUI ยถ
HandleSwaggerUI registers the necessary routes to serve the Swagger UI and the OpenAPI spec.
func (*Validator) Middleware ยถ
Middleware returns an http.Handler that validates incoming requests and/or outgoing responses.
func (*Validator) SwaggerUIHandler ยถ
SwaggerUIHandler returns an http.Handler that serves the Swagger UI and the OpenAPI spec.
Directories
ยถ
| Path | Synopsis |
|---|---|
|
examples
|
|
|
gin
command
|
|
|
gin-handler-mapping
command
|
|
|
gorilla
command
|
|
|
standard
command
|