Documentation ¶
Index ¶
- Variables
- func AgainstSchema(schema *spec.Schema, data interface{}, formats strfmt.Registry) error
- func Enum(path, in string, data interface{}, enum interface{}) *errors.Validation
- func FormatOf(path, in, format, data string, registry strfmt.Registry) *errors.Validation
- func MaxItems(path, in string, size, max int64) *errors.Validation
- func MaxLength(path, in, data string, maxLength int64) *errors.Validation
- func Maximum(path, in string, data, max float64, exclusive bool) *errors.Validation
- func MaximumInt(path, in string, data, max int64, exclusive bool) *errors.Validation
- func MaximumUint(path, in string, data, max uint64, exclusive bool) *errors.Validation
- func MinItems(path, in string, size, min int64) *errors.Validation
- func MinLength(path, in, data string, minLength int64) *errors.Validation
- func Minimum(path, in string, data, min float64, exclusive bool) *errors.Validation
- func MinimumInt(path, in string, data, min int64, exclusive bool) *errors.Validation
- func MinimumUint(path, in string, data, min uint64, exclusive bool) *errors.Validation
- func MultipleOf(path, in string, data, factor float64) *errors.Validation
- func Pattern(path, in, data, pattern string) *errors.Validation
- func Required(path, in string, data interface{}) *errors.Validation
- func RequiredNumber(path, in string, data float64) *errors.Validation
- func RequiredString(path, in, data string) *errors.Validation
- func Spec(doc *loads.Document, formats strfmt.Registry) error
- func UniqueItems(path, in string, data interface{}) *errors.Validation
- type Defaulter
- type DefaulterFunc
- type EntityValidator
- type HeaderValidator
- type ParamValidator
- type Result
- type SchemaValidator
- type SpecValidator
Constants ¶
This section is empty.
Variables ¶
var ( // Debug is true when the SWAGGER_DEBUG env var is not empty Debug = os.Getenv("SWAGGER_DEBUG") != "" )
Functions ¶
func AgainstSchema ¶
AgainstSchema validates the specified data with the provided schema, when no schema is provided it uses the json schema as default
func Enum ¶
func Enum(path, in string, data interface{}, enum interface{}) *errors.Validation
Enum validates if the data is a member of the enum
func FormatOf ¶
func FormatOf(path, in, format, data string, registry strfmt.Registry) *errors.Validation
FormatOf validates if a string matches a format in the format registry
func MaxItems ¶
func MaxItems(path, in string, size, max int64) *errors.Validation
MaxItems validates that there are at most n items in a slice
func MaxLength ¶
func MaxLength(path, in, data string, maxLength int64) *errors.Validation
MaxLength validates a string for maximum length
func Maximum ¶
func Maximum(path, in string, data, max float64, exclusive bool) *errors.Validation
Maximum validates if a number is smaller than a given maximum
func MaximumInt ¶
func MaximumInt(path, in string, data, max int64, exclusive bool) *errors.Validation
MaximumInt validates if a number is smaller than a given maximum
func MaximumUint ¶
func MaximumUint(path, in string, data, max uint64, exclusive bool) *errors.Validation
MaximumUint validates if a number is smaller than a given maximum
func MinItems ¶
func MinItems(path, in string, size, min int64) *errors.Validation
MinItems validates that there are at least n items in a slice
func MinLength ¶
func MinLength(path, in, data string, minLength int64) *errors.Validation
MinLength validates a string for minimum length
func Minimum ¶
func Minimum(path, in string, data, min float64, exclusive bool) *errors.Validation
Minimum validates if a number is smaller than a given minimum
func MinimumInt ¶
func MinimumInt(path, in string, data, min int64, exclusive bool) *errors.Validation
MinimumInt validates if a number is smaller than a given minimum
func MinimumUint ¶
func MinimumUint(path, in string, data, min uint64, exclusive bool) *errors.Validation
MinimumUint validates if a number is smaller than a given minimum
func MultipleOf ¶
func MultipleOf(path, in string, data, factor float64) *errors.Validation
MultipleOf validates if the provided number is a multiple of the factor
func Pattern ¶
func Pattern(path, in, data, pattern string) *errors.Validation
Pattern validates a string against a regular expression
func Required ¶
func Required(path, in string, data interface{}) *errors.Validation
Required validates an interface for requiredness
func RequiredNumber ¶
func RequiredNumber(path, in string, data float64) *errors.Validation
RequiredNumber validates a number for requiredness
func RequiredString ¶
func RequiredString(path, in, data string) *errors.Validation
RequiredString validates a string for requiredness
func Spec ¶
Spec validates a spec document It validates the spec json against the json schema for swagger and then validates a number of extra rules that can't be expressed in json schema:
- definition can't declare a property that's already defined by one of its ancestors
- definition's ancestor can't be a descendant of the same model
- each api path should be non-verbatim (account for path param names) unique per method
- each security reference should contain only unique scopes
- each security scope in a security definition should be unique
- each path parameter should correspond to a parameter placeholder and vice versa
- each referencable definition must have references
- each definition property listed in the required array must be defined in the properties of the model
- each parameter should have a unique `name` and `type` combination
- each operation should have only 1 parameter of type body
- each reference must point to a valid object
- every default value that is specified must validate against the schema for that property
- items property is required for all schemas/definitions of type `array`
func UniqueItems ¶
func UniqueItems(path, in string, data interface{}) *errors.Validation
UniqueItems validates that the provided slice has unique elements
Types ¶
type DefaulterFunc ¶
type DefaulterFunc func()
func (DefaulterFunc) Apply ¶
func (f DefaulterFunc) Apply()
type EntityValidator ¶
type EntityValidator interface {
Validate(interface{}) *Result
}
An EntityValidator is an interface for things that can validate entities
type HeaderValidator ¶
type HeaderValidator struct { KnownFormats strfmt.Registry // contains filtered or unexported fields }
A HeaderValidator has very limited subset of validations to apply
func NewHeaderValidator ¶
NewHeaderValidator creates a new header validator object
func (*HeaderValidator) Validate ¶
func (p *HeaderValidator) Validate(data interface{}) *Result
Validate the value of the header against its schema
type ParamValidator ¶
type ParamValidator struct { KnownFormats strfmt.Registry // contains filtered or unexported fields }
A ParamValidator has very limited subset of validations to apply
func NewParamValidator ¶
func NewParamValidator(param *spec.Parameter, formats strfmt.Registry) *ParamValidator
NewParamValidator creates a new param validator object
func (*ParamValidator) Validate ¶
func (p *ParamValidator) Validate(data interface{}) *Result
Validate the data against the description of the parameter
type Result ¶
Result represents a validation result
func (*Result) ApplyDefaults ¶
func (r *Result) ApplyDefaults()
type SchemaValidator ¶
type SchemaValidator struct { Path string Schema *spec.Schema Root interface{} KnownFormats strfmt.Registry // contains filtered or unexported fields }
SchemaValidator like param validator but for a full json schema
func NewSchemaValidator ¶
func NewSchemaValidator(schema *spec.Schema, rootSchema interface{}, root string, formats strfmt.Registry) *SchemaValidator
NewSchemaValidator creates a new schema validator
func (*SchemaValidator) Applies ¶
func (s *SchemaValidator) Applies(source interface{}, kind reflect.Kind) bool
Applies returns true when this schema validator applies
func (*SchemaValidator) SetPath ¶
func (s *SchemaValidator) SetPath(path string)
SetPath sets the path for this schema valdiator
func (*SchemaValidator) Validate ¶
func (s *SchemaValidator) Validate(data interface{}) *Result
Validate validates the data against the schema
type SpecValidator ¶
type SpecValidator struct { KnownFormats strfmt.Registry // contains filtered or unexported fields }
SpecValidator validates a swagger spec
func NewSpecValidator ¶
func NewSpecValidator(schema *spec.Schema, formats strfmt.Registry) *SpecValidator
NewSpecValidator creates a new swagger spec validator instance
func (*SpecValidator) Validate ¶
func (s *SpecValidator) Validate(data interface{}) (errs *Result, warnings *Result)
Validate validates the swagger spec