Documentation
¶
Overview ¶
Package validate contains validation helpers.
Index ¶
- Variables
- func InvalidContentType(contentType string) error
- func Ogen(name string, value, params any) error
- func RegisterValidator(name string, validator OgenValidator) error
- func UnexpectedStatusCode(statusCode int) errordeprecated
- func UnexpectedStatusCodeWithResponse(response *http.Response) error
- func UniqueItems[S ~[]T, T comparable](arr S) error
- type Array
- type Decimal
- func (t Decimal) Set() bool
- func (t *Decimal) SetExclusiveMaximum(v decimal.Decimal)
- func (t *Decimal) SetExclusiveMinimum(v decimal.Decimal)
- func (t *Decimal) SetMaximum(v decimal.Decimal)
- func (t *Decimal) SetMinimum(v decimal.Decimal)
- func (t *Decimal) SetMultipleOf(d decimal.Decimal)
- func (t Decimal) Validate(v decimal.Decimal) error
- type DepthLimitError
- type DuplicateItemsError
- type Error
- type FieldError
- type Float
- func (t Float) Set() bool
- func (t *Float) SetExclusiveMaximum(v float64)
- func (t *Float) SetExclusiveMinimum(v float64)
- func (t *Float) SetMaximum(v float64)
- func (t *Float) SetMinimum(v float64)
- func (t *Float) SetMultipleOf(rat *big.Rat)
- func (t *Float) SetPattern(v ogenregex.Regexp)
- func (t Float) Validate(v float64) error
- func (t Float) ValidateStringified(v float64) error
- type Int
- type InvalidContentTypeError
- type MaxLengthError
- type MinLengthError
- type NoRegexMatchError
- type Object
- type OgenValidator
- type OgenValidatorRegistry
- type String
- type UnexpectedStatusCodeError
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
var ErrBodyRequired = errors.New("body required")
ErrBodyRequired reports that request body is required but server got empty request.
var ErrFieldRequired = errors.New("field required")
ErrFieldRequired reports that a field is required, but not found.
var ErrNilPointer = errors.New("nil pointer")
ErrNilPointer reports that use Validate, but receiver pointer is nil.
Functions ¶
func InvalidContentType ¶ added in v0.11.1
InvalidContentType creates new InvalidContentTypeError.
func RegisterValidator ¶ added in v1.15.0
func RegisterValidator(name string, validator OgenValidator) error
RegisterValidator registers a validator in the default global registry.
func UnexpectedStatusCode
deprecated
added in
v0.11.1
func UnexpectedStatusCodeWithResponse ¶ added in v1.15.0
UnexpectedStatusCodeWithResponse creates new UnexpectedStatusCode.
func UniqueItems ¶ added in v0.67.0
func UniqueItems[S ~[]T, T comparable](arr S) error
UniqueItems ensures given array has no duplicates.
Types ¶
type Array ¶
type Array struct {
MinLength int
MinLengthSet bool
MaxLength int
MaxLengthSet bool
UniqueItems bool
}
Array validates array length.
func (*Array) SetMaxLength ¶
SetMaxLength sets MaxLength validation.
func (*Array) SetMinLength ¶
SetMinLength sets MinLength validation.
func (*Array) SetUniqueItems ¶ added in v0.67.0
SetUniqueItems sets UniqueItems validation.
func (Array) ValidateLength ¶
ValidateLength returns error if array length v is invalid.
type Decimal ¶ added in v1.16.0
type Decimal struct {
MultipleOf decimal.Decimal
MultipleOfSet bool
Min decimal.Decimal
MinSet bool
MinExclusive bool
Max decimal.Decimal
MaxSet bool
MaxExclusive bool
}
Decimal validates decimal numbers.
func (*Decimal) SetExclusiveMaximum ¶ added in v1.16.0
SetExclusiveMaximum sets exclusive maximum value.
func (*Decimal) SetExclusiveMinimum ¶ added in v1.16.0
SetExclusiveMinimum sets exclusive minimum value.
func (*Decimal) SetMaximum ¶ added in v1.16.0
SetMaximum sets maximum value.
func (*Decimal) SetMinimum ¶ added in v1.16.0
SetMinimum sets minimum value.
func (*Decimal) SetMultipleOf ¶ added in v1.16.0
SetMultipleOf sets multipleOf validator.
type DepthLimitError ¶ added in v1.17.0
type DepthLimitError struct {
// MaxDepth is the configured maximum depth.
MaxDepth int
// TypeName is the type being compared when limit was hit.
TypeName string
}
DepthLimitError indicates nesting depth limit was exceeded.
func (*DepthLimitError) Error ¶ added in v1.17.0
func (e *DepthLimitError) Error() string
Error implements error.
type DuplicateItemsError ¶ added in v1.17.0
type DuplicateItemsError struct {
// Indices contains all indices where duplicates were found.
// First element is the original, subsequent are duplicates.
Indices []int
}
DuplicateItemsError indicates duplicate items in a uniqueItems array.
func (*DuplicateItemsError) Error ¶ added in v1.17.0
func (e *DuplicateItemsError) Error() string
Error implements error.
type FieldError ¶
FieldError is failed validation on field.
type Float ¶ added in v0.16.0
type Float struct {
MultipleOf *big.Rat
MultipleOfSet bool
Min float64
MinSet bool
MinExclusive bool
Max float64
MaxSet bool
MaxExclusive bool
// Pattern constraint for validating string representation
Pattern ogenregex.Regexp
}
Float validates float numbers.
func (*Float) SetExclusiveMaximum ¶ added in v0.16.0
SetExclusiveMaximum sets exclusive maximum value.
func (*Float) SetExclusiveMinimum ¶ added in v0.16.0
SetExclusiveMinimum sets exclusive minimum value.
func (*Float) SetMaximum ¶ added in v0.16.0
SetMaximum sets maximum value.
func (*Float) SetMinimum ¶ added in v0.16.0
SetMinimum sets minimum value.
func (*Float) SetMultipleOf ¶ added in v0.16.0
SetMultipleOf sets multipleOf validator.
func (*Float) SetPattern ¶ added in v1.17.0
SetPattern sets pattern constraint for validating string representation.
func (Float) Validate ¶ added in v0.16.0
Validate returns error if v does not match validation rules.
func (Float) ValidateStringified ¶ added in v0.70.0
ValidateStringified returns error if v does not match validation rules.
type Int ¶
type Int struct {
MultipleOf uint64
MultipleOfSet bool
Min int64
MinSet bool
MinExclusive bool
Max int64
MaxSet bool
MaxExclusive bool
// Pattern constraint for validating string representation
Pattern ogenregex.Regexp
}
Int validates integers.
func (*Int) SetExclusiveMaximum ¶
SetExclusiveMaximum sets exclusive maximum value.
func (*Int) SetExclusiveMinimum ¶
SetExclusiveMinimum sets exclusive minimum value.
func (*Int) SetMultipleOf ¶
SetMultipleOf sets multipleOf validator.
func (*Int) SetPattern ¶ added in v1.17.0
SetPattern sets pattern constraint for validating string representation.
type InvalidContentTypeError ¶ added in v0.11.1
type InvalidContentTypeError struct {
ContentType string
}
InvalidContentTypeError reports that decoder got unexpected content type.
func (*InvalidContentTypeError) Error ¶ added in v0.11.1
func (e *InvalidContentTypeError) Error() string
InvalidContentTypeError implements error.
type MaxLengthError ¶ added in v0.78.0
MaxLengthError reports that len greater than maximum.
func (*MaxLengthError) Error ¶ added in v0.78.0
func (e *MaxLengthError) Error() string
MaxLengthError implements error.
type MinLengthError ¶ added in v0.78.0
MinLengthError reports that len less than minimum.
func (*MinLengthError) Error ¶ added in v0.78.0
func (e *MinLengthError) Error() string
MinLengthError implements error.
type NoRegexMatchError ¶ added in v0.79.0
NoRegexMatchError reports that value have no regexp match.
func (*NoRegexMatchError) Error ¶ added in v0.79.0
func (e *NoRegexMatchError) Error() string
MaxLengthError implements error.
type Object ¶ added in v0.12.0
type Object struct {
MinProperties int
MinPropertiesSet bool
MaxProperties int
MaxPropertiesSet bool
// TODO: add validate to gen
MinLength int
MinLengthSet bool
MaxLength int
MaxLengthSet bool
}
Object validates map length.
func (*Object) SetMaxLength ¶ added in v1.15.0
SetMaxLength sets MaxLength validation.
func (*Object) SetMaxProperties ¶ added in v0.12.0
SetMaxProperties sets MaxProperties validation.
func (*Object) SetMinLength ¶ added in v1.15.0
SetMinLength sets MinLength validation.
func (*Object) SetMinProperties ¶ added in v0.12.0
SetMinProperties sets MinProperties validation.
func (Object) ValidateProperties ¶ added in v0.12.0
ValidateProperties returns error if object length (properties number) v is invalid.
type OgenValidator ¶ added in v1.15.0
OgenValidator is a function that performs custom validation.
func GetValidator ¶ added in v1.15.0
func GetValidator(name string) (OgenValidator, bool)
GetValidator returns a validator from the default global registry.
type OgenValidatorRegistry ¶ added in v1.15.0
type OgenValidatorRegistry struct {
// contains filtered or unexported fields
}
OgenValidatorRegistry holds custom validators that can be registered and used for validation.
func NewOgenValidatorRegistry ¶ added in v1.15.0
func NewOgenValidatorRegistry() *OgenValidatorRegistry
NewOgenValidatorRegistry creates a new OgenValidatorRegistry.
func (*OgenValidatorRegistry) Get ¶ added in v1.15.0
func (r *OgenValidatorRegistry) Get(name string) (OgenValidator, bool)
func (*OgenValidatorRegistry) Register ¶ added in v1.15.0
func (r *OgenValidatorRegistry) Register(name string, validator OgenValidator) error
type String ¶
type String struct {
MinLength int
MinLengthSet bool
MaxLength int
MaxLengthSet bool
Email bool
Regex ogenregex.Regexp
Hostname bool
// Numeric constraints for strings representing numbers
MinNumeric float64
MinNumericSet bool
MaxNumeric float64
MaxNumericSet bool
}
String validator.
func (*String) SetMaxLength ¶
SetMaxLength sets maximum string length (in Unicode code points).
func (*String) SetMaximumNumeric ¶ added in v1.17.0
SetMaximumNumeric sets maximum numeric value for numeric strings.
func (*String) SetMinLength ¶
SetMinLength sets minimum string length (in Unicode code points).
func (*String) SetMinimumNumeric ¶ added in v1.17.0
SetMinimumNumeric sets minimum numeric value for numeric strings.
type UnexpectedStatusCodeError ¶ added in v0.11.1
UnexpectedStatusCodeError reports that client got unexpected status code.
func (*UnexpectedStatusCodeError) Error ¶ added in v0.11.1
func (e *UnexpectedStatusCodeError) Error() string
UnexpectedStatusCodeError implements error.
type ValidationError ¶ added in v1.15.0
ValidationError represents a validation error from a custom validator.
func (*ValidationError) Error ¶ added in v1.15.0
func (e *ValidationError) Error() string
Error implements the error interface.