Documentation
¶
Index ¶
- func EnsureArrayFieldRequired[TTargetVal any](val []TTargetVal) error
- func EnsureNonDefault[TTargetVal comparable](val TTargetVal) error
- type AggregatedBindingError
- type BindingContext
- type BindingError
- type FieldBindingError
- type FieldValidator
- func NewArrayValidator[TValue any](validateField FieldValidator[[]TValue], validateItems FieldValidator[TValue]) FieldValidator[[]TValue]
- func NewErrorValidator() FieldValidator[*Error]
- func NewObjectFieldValidator[TTargetVal any](params ObjectFieldValidatorParams, modelValidator FieldValidator[*TTargetVal]) FieldValidator[*TTargetVal]
- func NewPetResponseValidator() FieldValidator[*PetResponse]
- func NewPetValidator() FieldValidator[*Pet]
- func NewPetsResponseValidator() FieldValidator[*PetsResponse]
- func NewSimpleFieldValidator[TValue any](validators ...ValueValidator[TValue]) FieldValidator[TValue]
- func SkipNullFieldValidator[TTargetVal any](target FieldValidator[*TTargetVal]) FieldValidator[*TTargetVal]
- type Measurable
- type ObjectFieldValidatorParams
- type OptionalVal
- type ValueValidator
- func NewMinMaxLengthValidator[TTargetVal any, TValidatorVal Measurable[TTargetVal]](threshold int, isMin bool) ValueValidator[TValidatorVal]
- func NewMinMaxValueValidator[TTargetVal constraints.Ordered](threshold TTargetVal, exclusive bool, isMin bool) ValueValidator[TTargetVal]
- func NewPatternValidator[TTargetValue string](patternStr string) ValueValidator[string]
- func SkipNullValidator[TTargetVal any](target ValueValidator[TTargetVal]) ValueValidator[*TTargetVal]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureArrayFieldRequired ¶
EnsureArrayFieldRequired will validate if given array is not empty.
func EnsureNonDefault ¶
func EnsureNonDefault[TTargetVal comparable](val TTargetVal) error
EnsureNonDefault will validate if given value is non default for given type.
There is no easy way to make a truly required validation (e.g if field is present) without a custom marshaler and shadow models, which will impact performance. So keeping a non default validation as a reasonable tradeoff.
Types ¶
type AggregatedBindingError ¶
type AggregatedBindingError struct {
Errors []FieldBindingError `json:"errors"`
}
func (AggregatedBindingError) Error ¶
func (c AggregatedBindingError) Error() string
type BindingContext ¶
type BindingContext struct {
// contains filtered or unexported fields
}
func (BindingContext) AggregatedError ¶
func (c BindingContext) AggregatedError() error
func (*BindingContext) AppendFieldError ¶
func (c *BindingContext) AppendFieldError(err FieldBindingError)
func (*BindingContext) BuildPath ¶
func (c *BindingContext) BuildPath() string
func (*BindingContext) Fork ¶
func (c *BindingContext) Fork(field string) *BindingContext
type BindingError ¶
type BindingError string
const ( // ErrBadValueFormat error means data provided can not be parsed to a target type. ErrBadValueFormat BindingError = "BAD_FORMAT" // ErrValueRequired error code indicates that the required value has not been provided. ErrValueRequired BindingError = "INVALID_REQUIRED" // ErrInvalidValueOutOfRange error code indicates that the value is out of range of allowable values // this is usually when number is out of min/max range, or string is outside of limits. ErrInvalidValueOutOfRange BindingError = "INVALID_OUT_OF_RANGE" // ErrInvalidValue error code a generic validation error. ErrInvalidValue BindingError = "INVALID" )
func (BindingError) Error ¶
func (c BindingError) Error() string
type FieldBindingError ¶
type FieldBindingError struct { Location string `json:"location"` Err error `json:"-"` Code string `json:"code"` }
FieldBindingError occurs at parsing/validation stage and holds context on field that the error is related to.
func (FieldBindingError) Error ¶
func (be FieldBindingError) Error() string
type FieldValidator ¶
type FieldValidator[TValue any] func( bindingCtx *BindingContext, value TValue, )
func NewArrayValidator ¶
func NewArrayValidator[ TValue any, ]( validateField FieldValidator[[]TValue], validateItems FieldValidator[TValue], ) FieldValidator[[]TValue]
func NewErrorValidator ¶
func NewErrorValidator() FieldValidator[*Error]
func NewObjectFieldValidator ¶
func NewObjectFieldValidator[TTargetVal any]( params ObjectFieldValidatorParams, modelValidator FieldValidator[*TTargetVal], ) FieldValidator[*TTargetVal]
func NewPetResponseValidator ¶
func NewPetResponseValidator() FieldValidator[*PetResponse]
func NewPetValidator ¶
func NewPetValidator() FieldValidator[*Pet]
func NewPetsResponseValidator ¶
func NewPetsResponseValidator() FieldValidator[*PetsResponse]
func NewSimpleFieldValidator ¶
func NewSimpleFieldValidator[ TValue any, ](validators ...ValueValidator[TValue]) FieldValidator[TValue]
func SkipNullFieldValidator ¶
func SkipNullFieldValidator[TTargetVal any](target FieldValidator[*TTargetVal]) FieldValidator[*TTargetVal]
type Measurable ¶
type OptionalVal ¶
type ValueValidator ¶
func NewMinMaxLengthValidator ¶
func NewMinMaxLengthValidator[TTargetVal any, TValidatorVal Measurable[TTargetVal]]( threshold int, isMin bool, ) ValueValidator[TValidatorVal]
func NewMinMaxValueValidator ¶
func NewMinMaxValueValidator[TTargetVal constraints.Ordered]( threshold TTargetVal, exclusive bool, isMin bool, ) ValueValidator[TTargetVal]
func NewPatternValidator ¶
func NewPatternValidator[TTargetValue string](patternStr string) ValueValidator[string]
func SkipNullValidator ¶
func SkipNullValidator[TTargetVal any](target ValueValidator[TTargetVal]) ValueValidator[*TTargetVal]
Click to show internal directories.
Click to hide internal directories.