Documentation ¶
Overview ¶
Package validate provides utilities that allow to validate request and response data against OpenAPI Specification parameter and schema definitions.
Note that errors returned from validation functions are generally of type Error, so they can be asserted to corresponding interface(s) to retrieve error's field and value.
errs := validate.Query(ps, q) for _, err := range errs { if e, ok := err.(validate.Error) { field, value := e.Field(), e.Value() // ... } }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterFormat ¶ added in v0.3.0
RegisterFormat registers custom format and validator for it. See default OAS formatRegistry here: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types
Types ¶
type ValidationError ¶
type ValidationError interface { error // Field returns field name where error occurred. Field() string // Value returns original value passed by client on field where error // occurred. Value() interface{} }
ValidationError describes validation error.
func ValidationErrorf ¶
func ValidationErrorf(field string, value interface{}, format string, args ...interface{}) ValidationError
ValidationErrorf returns a new formatted ValidationError.
type ValidationErrors ¶
type ValidationErrors []ValidationError
ValidationErrors is a set of validation errors.
func (ValidationErrors) Errors ¶
func (es ValidationErrors) Errors() []error
Errors returns ValidationErrors in form of Go builtin errors.