Documentation
¶
Overview ¶
Package validation provides shared rule parsing and runtime validation helpers used by server request parsing, OpenAPI generation, and servergen.
Index ¶
- func FieldRequired(f reflect.StructField, tagKey string) bool
- func FieldRequiredFromTag(tag string, typ reflect.Type) bool
- func HasMultipartTag(f reflect.StructField) bool
- func HasParamTag(f reflect.StructField) bool
- func HasTagOption(tag, option string) bool
- func IndirectType(t reflect.Type) reflect.Type
- func IsJSONBodyField(f reflect.StructField) bool
- func JSONFieldName(f reflect.StructField) (string, bool)
- func JSONPointer(parts ...string) string
- func JoinPointer(base string, parts ...string) string
- func JoinPointerWithIndex(base string, index int) string
- func StringLength(value string) int
- func TagName(tag string) string
- func ValidateStructValue(v reflect.Value, spec *StructSpec, scope string) error
- func ValidateUUID(value string) bool
- type Error
- func (e *Error) Add(pointer, code, message string)
- func (e *Error) AddInvalidRule(pointer string, err error)
- func (e *Error) AddInvalidType(pointer string)
- func (e *Error) AddProblem(problem Problem)
- func (e *Error) AddRequired(pointer string)
- func (e *Error) AddRule(pointer string, kind RuleKind, subject Subject, value int)
- func (e *Error) Empty() bool
- func (e *Error) Error() string
- func (e *Error) Merge(other *Error)
- type FieldRules
- type FieldSpec
- type FlattenedField
- type Problem
- type Rule
- type RuleKind
- type SchemaConstraints
- type StructSpec
- type Subject
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FieldRequired ¶
func FieldRequired(f reflect.StructField, tagKey string) bool
FieldRequired reports whether a bound field must be present in the request. Query, header, and cookie parameters are optional unless marked required:"true" or validate:"required" (matching OpenAPI's default for non-path parameters). Body, form, and file fields are required unless the field is a pointer or opts out via omitempty / required:"false".
func HasMultipartTag ¶
func HasMultipartTag(f reflect.StructField) bool
func HasParamTag ¶
func HasParamTag(f reflect.StructField) bool
func HasTagOption ¶
func IsJSONBodyField ¶
func IsJSONBodyField(f reflect.StructField) bool
func JSONFieldName ¶
func JSONFieldName(f reflect.StructField) (string, bool)
func JSONPointer ¶
func JoinPointer ¶
func JoinPointerWithIndex ¶
func StringLength ¶
func ValidateStructValue ¶
func ValidateStructValue(v reflect.Value, spec *StructSpec, scope string) error
func ValidateUUID ¶
Types ¶
type Error ¶
type Error struct {
Problems []Problem `json:"errors"`
}
func (*Error) AddInvalidRule ¶
func (*Error) AddInvalidType ¶
func (*Error) AddProblem ¶
func (*Error) AddRequired ¶
type FieldRules ¶
func ParseFieldRules ¶
func ParseFieldRules(tag reflect.StructTag) (FieldRules, error)
type FieldSpec ¶
type FieldSpec struct {
Type reflect.Type
ElementType reflect.Type
Nested *StructSpec
ElemNested *StructSpec
Name string
Pointer string
FullPointer string
Rules FieldRules
Index int
IndexPath []int
HasParam bool
Required bool
}
type FlattenedField ¶ added in v1.1.0
type FlattenedField struct {
Field reflect.StructField
Index []int
}
func FlattenFields ¶ added in v1.1.0
func FlattenFields(t reflect.Type) ([]FlattenedField, error)
type Problem ¶
type Problem struct {
Pointer string `json:"pointer"`
Code string `json:"code"`
Message string `json:"message"`
}
func InvalidRuleProblem ¶
func InvalidTypeProblem ¶
func RequiredProblem ¶
func RuleProblem ¶
func (Problem) MarshalJSON ¶
type RuleKind ¶
type RuleKind string
const ( RuleMin RuleKind = "min" RuleMax RuleKind = "max" RuleLen RuleKind = "len" RuleMinItems RuleKind = "minItems" RuleMaxItems RuleKind = "maxItems" RuleOneOf RuleKind = "oneof" RulePattern RuleKind = "pattern" RuleEmail RuleKind = "email" RuleURL RuleKind = "url" RuleUUID RuleKind = "uuid" RuleRequired RuleKind = "required" RuleOmitEmpty RuleKind = "omitempty" )
type SchemaConstraints ¶
type SchemaConstraints struct {
Format string
MinLength *int
MaxLength *int
Minimum *float64
Maximum *float64
Pattern string
MinItems *int
MaxItems *int
Enum []any
}
func ConstraintsForField ¶
func ConstraintsForField(f reflect.StructField, schemaType string) (SchemaConstraints, error)
type StructSpec ¶
Click to show internal directories.
Click to hide internal directories.