validate

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2018 License: MIT Imports: 9 Imported by: 0

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 Body

func Body(ps []spec.Parameter, data interface{}) []error

Body validates request body by spec and returns errors if any.

func BySchema

func BySchema(sch *spec.Schema, data interface{}) []error

BySchema validates data by spec and returns errors if any.

func Query

func Query(ps []spec.Parameter, q url.Values) []error

Query validates request query parameters by spec and returns errors if any.

func RegisterFormat added in v0.3.0

func RegisterFormat(name string, format strfmt.Format, validator strfmt.Validator)

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.

Jump to

Keyboard shortcuts

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