Documentation
¶
Overview ¶
datetime.go - Date/Time validation builder for Queryfy
dependent.go - Dependent fields validation for Queryfy
diff.go - Schema structural diff
equality.go - Schema equality and hashing
formats.go - Custom format registry for string validation
transform.go - Transformation support for Queryfy
walk.go - Schema tree traversal
Index ¶
- func Equal(a, b queryfy.Schema) bool
- func Hash(schema queryfy.Schema) string
- func LookupFormat(name string) queryfy.ValidatorFunc
- func RegisterFormat(name string, validator queryfy.ValidatorFunc)
- func RegisteredFormats() []string
- func Walk(schema queryfy.Schema, visitor FieldVisitor) error
- type AndSchema
- func (s *AndSchema) Nullable() *AndSchema
- func (s *AndSchema) Optional() *AndSchema
- func (s *AndSchema) Required() *AndSchema
- func (s *AndSchema) Schemas() []queryfy.Schema
- func (s *AndSchema) Type() queryfy.SchemaType
- func (s *AndSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
- type ArraySchema
- func (s *ArraySchema) AsyncCustom(fn queryfy.AsyncValidatorFunc) *ArraySchema
- func (s *ArraySchema) Custom(fn queryfy.ValidatorFunc) *ArraySchema
- func (s *ArraySchema) ElementSchema() queryfy.Schema
- func (s *ArraySchema) HasAsyncValidators() bool
- func (s *ArraySchema) IsUniqueItems() bool
- func (s *ArraySchema) ItemCountConstraints() (min, max *int)
- func (s *ArraySchema) Items(schema queryfy.Schema) *ArraySchema
- func (s *ArraySchema) Length(length int) *ArraySchema
- func (s *ArraySchema) MaxItems(max int) *ArraySchema
- func (s *ArraySchema) Meta(key string, value interface{}) *ArraySchema
- func (s *ArraySchema) MinItems(min int) *ArraySchema
- func (s *ArraySchema) Nullable() *ArraySchema
- func (s *ArraySchema) Of(schema queryfy.Schema) *ArraySchema
- func (s *ArraySchema) Optional() *ArraySchema
- func (s *ArraySchema) Required() *ArraySchema
- func (s *ArraySchema) Transform(transformer Transformer) *TransformSchema
- func (s *ArraySchema) Type() queryfy.SchemaType
- func (s *ArraySchema) UniqueItems() *ArraySchema
- func (s *ArraySchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
- func (s *ArraySchema) ValidateAndTransform(value interface{}, ctx *queryfy.ValidationContext) (interface{}, error)
- func (s *ArraySchema) ValidateAndTransformAsync(goCtx context.Context, value interface{}, ctx *queryfy.ValidationContext) (interface{}, error)
- func (s *ArraySchema) Validators() []queryfy.ValidatorFunc
- type BoolSchema
- func (s *BoolSchema) Custom(fn queryfy.ValidatorFunc) *BoolSchema
- func (s *BoolSchema) Meta(key string, value interface{}) *BoolSchema
- func (s *BoolSchema) Nullable() *BoolSchema
- func (s *BoolSchema) Optional() *BoolSchema
- func (s *BoolSchema) Required() *BoolSchema
- func (s *BoolSchema) Transform(transformer Transformer) *TransformSchema
- func (s *BoolSchema) Type() queryfy.SchemaType
- func (s *BoolSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
- func (s *BoolSchema) Validators() []queryfy.ValidatorFunc
- type CustomSchema
- func (s *CustomSchema) Meta(key string, value interface{}) *CustomSchema
- func (s *CustomSchema) Nullable() *CustomSchema
- func (s *CustomSchema) Optional() *CustomSchema
- func (s *CustomSchema) Required() *CustomSchema
- func (s *CustomSchema) Type() queryfy.SchemaType
- func (s *CustomSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
- type DateTimeSchema
- func (s *DateTimeSchema) Age(minAge, maxAge int) *DateTimeSchema
- func (s *DateTimeSchema) Between(min, max time.Time) *DateTimeSchema
- func (s *DateTimeSchema) BetweenStrings(min, max string) *DateTimeSchema
- func (s *DateTimeSchema) BusinessDay() *DateTimeSchema
- func (s *DateTimeSchema) Custom(fn queryfy.ValidatorFunc) *DateTimeSchema
- func (s *DateTimeSchema) DMY() *DateTimeSchema
- func (s *DateTimeSchema) DateOnly() *DateTimeSchema
- func (s *DateTimeSchema) Format(format string) *DateTimeSchema
- func (s *DateTimeSchema) FormatString() string
- func (s *DateTimeSchema) Future() *DateTimeSchema
- func (s *DateTimeSchema) ISO8601() *DateTimeSchema
- func (s *DateTimeSchema) IsStrictFormat() bool
- func (s *DateTimeSchema) MDY() *DateTimeSchema
- func (s *DateTimeSchema) Max(max time.Time) *DateTimeSchema
- func (s *DateTimeSchema) MaxString(max string) *DateTimeSchema
- func (s *DateTimeSchema) Meta(key string, value interface{}) *DateTimeSchema
- func (s *DateTimeSchema) Min(min time.Time) *DateTimeSchema
- func (s *DateTimeSchema) MinString(min string) *DateTimeSchema
- func (s *DateTimeSchema) Nullable() *DateTimeSchema
- func (s *DateTimeSchema) Optional() *DateTimeSchema
- func (s *DateTimeSchema) Past() *DateTimeSchema
- func (s *DateTimeSchema) Required() *DateTimeSchema
- func (s *DateTimeSchema) StrictFormat() *DateTimeSchema
- func (s *DateTimeSchema) TimeConstraints() (min, max *time.Time)
- func (s *DateTimeSchema) Transform(transformer Transformer) *TransformSchema
- func (s *DateTimeSchema) Type() queryfy.SchemaType
- func (s *DateTimeSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
- func (s *DateTimeSchema) Weekday(days ...time.Weekday) *DateTimeSchema
- func (s *DateTimeSchema) YMD() *DateTimeSchema
- type DependencyCondition
- func WhenAll(conditions ...DependencyCondition) DependencyCondition
- func WhenAny(conditions ...DependencyCondition) DependencyCondition
- func WhenEquals(field string, value interface{}) DependencyCondition
- func WhenExists(field string) DependencyCondition
- func WhenFalse(field string) DependencyCondition
- func WhenGreaterThan(field string, threshold float64) DependencyCondition
- func WhenIn(field string, values ...interface{}) DependencyCondition
- func WhenLessThan(field string, threshold float64) DependencyCondition
- func WhenNotEquals(field string, value interface{}) DependencyCondition
- func WhenNotExists(field string) DependencyCondition
- func WhenTrue(field string) DependencyCondition
- type DependentSchema
- func (s *DependentSchema) Custom(fn queryfy.ValidatorFunc) *DependentSchema
- func (s *DependentSchema) Else(elseSchema queryfy.Schema) *DependentSchema
- func (s *DependentSchema) On(fields ...string) *DependentSchema
- func (s *DependentSchema) Optional() *DependentSchema
- func (s *DependentSchema) Required() *DependentSchema
- func (s *DependentSchema) Then(schema queryfy.Schema) *DependentSchema
- func (s *DependentSchema) Type() queryfy.SchemaType
- func (s *DependentSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
- func (s *DependentSchema) ValidateWithParent(value interface{}, parentData map[string]interface{}, ...) error
- func (s *DependentSchema) When(condition DependencyCondition) *DependentSchema
- type FieldChange
- type FieldVisitor
- type NotSchema
- func (s *NotSchema) InnerSchema() queryfy.Schema
- func (s *NotSchema) Nullable() *NotSchema
- func (s *NotSchema) Optional() *NotSchema
- func (s *NotSchema) Required() *NotSchema
- func (s *NotSchema) Type() queryfy.SchemaType
- func (s *NotSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
- type NumberSchema
- func (s *NumberSchema) Custom(fn queryfy.ValidatorFunc) *NumberSchema
- func (s *NumberSchema) Integer() *NumberSchema
- func (s *NumberSchema) IsInteger() bool
- func (s *NumberSchema) Max(max float64) *NumberSchema
- func (s *NumberSchema) Meta(key string, value interface{}) *NumberSchema
- func (s *NumberSchema) Min(min float64) *NumberSchema
- func (s *NumberSchema) MultipleOf(value float64) *NumberSchema
- func (s *NumberSchema) MultipleOfValue() *float64
- func (s *NumberSchema) Negative() *NumberSchema
- func (s *NumberSchema) Nullable() *NumberSchema
- func (s *NumberSchema) Optional() *NumberSchema
- func (s *NumberSchema) Positive() *NumberSchema
- func (s *NumberSchema) Range(min, max float64) *NumberSchema
- func (s *NumberSchema) RangeConstraints() (min, max *float64)
- func (s *NumberSchema) Required() *NumberSchema
- func (s *NumberSchema) Transform(transformer Transformer) *TransformSchema
- func (s *NumberSchema) Type() queryfy.SchemaType
- func (s *NumberSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
- func (s *NumberSchema) Validators() []queryfy.ValidatorFunc
- type ObjectSchema
- func (s *ObjectSchema) AllowAdditional(allow bool) *ObjectSchema
- func (s *ObjectSchema) AllowsAdditional() (allow bool, explicit bool)
- func (s *ObjectSchema) AsyncCustom(fn queryfy.AsyncValidatorFunc) *ObjectSchema
- func (s *ObjectSchema) Custom(fn queryfy.ValidatorFunc) *ObjectSchema
- func (s *ObjectSchema) Field(name string, schema queryfy.Schema) *ObjectSchema
- func (s *ObjectSchema) FieldNames() []string
- func (s *ObjectSchema) Fields(fields map[string]queryfy.Schema) *ObjectSchema
- func (s *ObjectSchema) GetField(name string) (queryfy.Schema, bool)
- func (s *ObjectSchema) HasAsyncValidators() bool
- func (s *ObjectSchema) Meta(key string, value interface{}) *ObjectSchema
- func (s *ObjectSchema) Nullable() *ObjectSchema
- func (s *ObjectSchema) Optional() *ObjectSchema
- func (s *ObjectSchema) Required() *ObjectSchema
- func (s *ObjectSchema) RequiredFieldNames() []string
- func (s *ObjectSchema) RequiredFields(names ...string) *ObjectSchema
- func (s *ObjectSchema) String() string
- func (s *ObjectSchema) Transform(transformer Transformer) *TransformSchema
- func (s *ObjectSchema) Type() queryfy.SchemaType
- func (s *ObjectSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
- func (s *ObjectSchema) ValidateAndTransform(value interface{}, ctx *queryfy.ValidationContext) (interface{}, error)
- func (s *ObjectSchema) ValidateAndTransformAsync(goCtx context.Context, value interface{}, ctx *queryfy.ValidationContext) (interface{}, error)
- func (s *ObjectSchema) Validators() []queryfy.ValidatorFunc
- func (s *ObjectSchema) WithDependencies() *ObjectSchemaWithDependencies
- type ObjectSchemaWithDependencies
- func (s *ObjectSchemaWithDependencies) Custom(fn queryfy.ValidatorFunc) *ObjectSchemaWithDependencies
- func (s *ObjectSchemaWithDependencies) DependentField(name string, dependent *DependentSchema) *ObjectSchemaWithDependencies
- func (s *ObjectSchemaWithDependencies) Field(name string, schema queryfy.Schema) *ObjectSchemaWithDependencies
- func (s *ObjectSchemaWithDependencies) Fields(fields map[string]queryfy.Schema) *ObjectSchemaWithDependencies
- func (s *ObjectSchemaWithDependencies) Nullable() *ObjectSchemaWithDependencies
- func (s *ObjectSchemaWithDependencies) Optional() *ObjectSchemaWithDependencies
- func (s *ObjectSchemaWithDependencies) Required() *ObjectSchemaWithDependencies
- func (s *ObjectSchemaWithDependencies) RequiredFields(names ...string) *ObjectSchemaWithDependencies
- func (s *ObjectSchemaWithDependencies) Validate(value interface{}, ctx *queryfy.ValidationContext) error
- type OrSchema
- type SchemaDiff
- type StringSchema
- func (s *StringSchema) Custom(fn queryfy.ValidatorFunc) *StringSchema
- func (s *StringSchema) Email() *StringSchema
- func (s *StringSchema) Enum(values ...string) *StringSchema
- func (s *StringSchema) EnumValues() []string
- func (s *StringSchema) FormatString(name string) *StringSchema
- func (s *StringSchema) FormatType() string
- func (s *StringSchema) Length(length int) *StringSchema
- func (s *StringSchema) LengthConstraints() (min, max *int)
- func (s *StringSchema) MaxLength(max int) *StringSchema
- func (s *StringSchema) Meta(key string, value interface{}) *StringSchema
- func (s *StringSchema) MinLength(min int) *StringSchema
- func (s *StringSchema) Nullable() *StringSchema
- func (s *StringSchema) Optional() *StringSchema
- func (s *StringSchema) Pattern(pattern string) *StringSchema
- func (s *StringSchema) PatternMatch(str string) bool
- func (s *StringSchema) PatternString() string
- func (s *StringSchema) Required() *StringSchema
- func (s *StringSchema) Transform(transformer Transformer) *TransformSchema
- func (s *StringSchema) Type() queryfy.SchemaType
- func (s *StringSchema) URL() *StringSchema
- func (s *StringSchema) UUID() *StringSchema
- func (s *StringSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
- func (s *StringSchema) Validators() []queryfy.ValidatorFunc
- type TransformSchema
- func (s *TransformSchema) Add(transformer Transformer) *TransformSchema
- func (s *TransformSchema) AsyncCustom(fn queryfy.AsyncValidatorFunc) *TransformSchema
- func (s *TransformSchema) HasAsyncValidators() bool
- func (s *TransformSchema) InnerSchema() queryfy.Schema
- func (s *TransformSchema) IsRequired() bool
- func (s *TransformSchema) Meta(key string, value interface{}) *TransformSchema
- func (s *TransformSchema) Optional() *TransformSchema
- func (s *TransformSchema) Required() *TransformSchema
- func (s *TransformSchema) Type() queryfy.SchemaType
- func (s *TransformSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
- func (s *TransformSchema) ValidateAndTransform(value interface{}, ctx *queryfy.ValidationContext) (interface{}, error)
- func (s *TransformSchema) ValidateAndTransformAsync(goCtx context.Context, value interface{}, ctx *queryfy.ValidationContext) (interface{}, error)
- type Transformer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Equal ¶ added in v0.3.0
Equal reports whether two schemas are structurally equivalent.
Like Hash, this excludes custom validators and async validators. Two schemas that differ only in custom validators are considered equal.
func Hash ¶ added in v0.3.0
Hash returns a deterministic SHA-256 hash of the schema's structure and constraints. Two schemas that are structurally identical produce the same hash.
Custom validators and async validators are excluded from the hash because Go functions are not comparable or serialisable. Two schemas that differ only in custom validators will produce the same hash.
The hash is stable across process restarts.
func LookupFormat ¶ added in v0.3.0
func LookupFormat(name string) queryfy.ValidatorFunc
LookupFormat returns the validator for a registered format, or nil if the format is not registered.
func RegisterFormat ¶ added in v0.3.0
func RegisterFormat(name string, validator queryfy.ValidatorFunc)
RegisterFormat adds a named format with its validation function. Registered formats can be used via the FormatString() builder method on StringSchema.
Formats are typically registered at init time:
func init() {
builders.RegisterFormat("semver", func(value interface{}) error {
// validate semver...
})
}
Calling RegisterFormat with a name that already exists overwrites the previous validator.
func RegisteredFormats ¶ added in v0.3.0
func RegisteredFormats() []string
RegisteredFormats returns the names of all registered formats.
func Walk ¶ added in v0.3.0
func Walk(schema queryfy.Schema, visitor FieldVisitor) error
Walk traverses the schema tree depth-first, calling the visitor at each node. Object fields are visited with their full dot-notation path. Array element schemas are visited with [*] appended.
The root schema itself is visited with an empty path "".
If the visitor returns a non-nil error, traversal stops and Walk returns that error.
Types ¶
type AndSchema ¶
type AndSchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
AndSchema validates that all schemas pass.
func (*AndSchema) Schemas ¶ added in v0.3.0
Validate implements the Schema interface. Schemas returns the list of sub-schemas in this And composite.
func (*AndSchema) Type ¶
func (s *AndSchema) Type() queryfy.SchemaType
Type implements the Schema interface.
type ArraySchema ¶
type ArraySchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
ArraySchema validates array/slice values.
func (*ArraySchema) AsyncCustom ¶ added in v0.3.0
func (s *ArraySchema) AsyncCustom(fn queryfy.AsyncValidatorFunc) *ArraySchema
AsyncCustom adds an async validator to the array schema. Async validators are only invoked by ValidateAndTransformAsync; sync methods ignore them.
func (*ArraySchema) Custom ¶
func (s *ArraySchema) Custom(fn queryfy.ValidatorFunc) *ArraySchema
Custom adds a custom validator function.
func (*ArraySchema) ElementSchema ¶ added in v0.3.0
func (s *ArraySchema) ElementSchema() queryfy.Schema
ElementSchema returns the schema for array elements, or nil if not set.
func (*ArraySchema) HasAsyncValidators ¶ added in v0.3.0
func (s *ArraySchema) HasAsyncValidators() bool
HasAsyncValidators returns true if any async validators are registered on this schema or on its element schema.
func (*ArraySchema) IsUniqueItems ¶ added in v0.3.0
func (s *ArraySchema) IsUniqueItems() bool
IsUniqueItems reports whether the array requires unique items.
func (*ArraySchema) ItemCountConstraints ¶ added in v0.3.0
func (s *ArraySchema) ItemCountConstraints() (min, max *int)
ItemCountConstraints returns the min and max item count pointers, either of which may be nil if not set.
func (*ArraySchema) Items ¶ added in v0.3.0
func (s *ArraySchema) Items(schema queryfy.Schema) *ArraySchema
Items sets the schema for array elements. This is an alias for Of, provided for readability with inline schemas.
func (*ArraySchema) Length ¶
func (s *ArraySchema) Length(length int) *ArraySchema
Length sets both minimum and maximum items to the same value.
func (*ArraySchema) MaxItems ¶
func (s *ArraySchema) MaxItems(max int) *ArraySchema
MaxItems sets the maximum number of items.
func (*ArraySchema) Meta ¶ added in v0.3.0
func (s *ArraySchema) Meta(key string, value interface{}) *ArraySchema
Meta attaches a key-value metadata pair to the schema.
func (*ArraySchema) MinItems ¶
func (s *ArraySchema) MinItems(min int) *ArraySchema
MinItems sets the minimum number of items.
func (*ArraySchema) Nullable ¶
func (s *ArraySchema) Nullable() *ArraySchema
Nullable allows the field to be null.
func (*ArraySchema) Of ¶
func (s *ArraySchema) Of(schema queryfy.Schema) *ArraySchema
Of sets the schema for array elements.
func (*ArraySchema) Optional ¶
func (s *ArraySchema) Optional() *ArraySchema
Optional marks the field as optional (default).
func (*ArraySchema) Required ¶
func (s *ArraySchema) Required() *ArraySchema
Required marks the field as required.
func (*ArraySchema) Transform ¶ added in v0.2.0
func (s *ArraySchema) Transform(transformer Transformer) *TransformSchema
Transform adds transformation capability to ArraySchema.
func (*ArraySchema) Type ¶
func (s *ArraySchema) Type() queryfy.SchemaType
Type implements the Schema interface.
func (*ArraySchema) UniqueItems ¶
func (s *ArraySchema) UniqueItems() *ArraySchema
UniqueItems requires all items to be unique.
func (*ArraySchema) Validate ¶
func (s *ArraySchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
Validate implements the Schema interface.
func (*ArraySchema) ValidateAndTransform ¶ added in v0.3.0
func (s *ArraySchema) ValidateAndTransform(value interface{}, ctx *queryfy.ValidationContext) (interface{}, error)
ValidateAndTransform validates the array and returns a new slice with all element transformations applied. If the element schema implements ValidateAndTransform, each element is transformed; otherwise elements are validated normally and their original values are preserved.
func (*ArraySchema) ValidateAndTransformAsync ¶ added in v0.3.0
func (s *ArraySchema) ValidateAndTransformAsync(goCtx context.Context, value interface{}, ctx *queryfy.ValidationContext) (interface{}, error)
ValidateAndTransformAsync runs sync validation and transformations first. If sync validation passes, it then runs async validators on elements and on the array itself, sequentially with the provided context.
func (*ArraySchema) Validators ¶ added in v0.3.0
func (s *ArraySchema) Validators() []queryfy.ValidatorFunc
Validators returns the custom validator functions.
type BoolSchema ¶
type BoolSchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
BoolSchema validates boolean values.
func (*BoolSchema) Custom ¶
func (s *BoolSchema) Custom(fn queryfy.ValidatorFunc) *BoolSchema
Custom adds a custom validator function.
func (*BoolSchema) Meta ¶ added in v0.3.0
func (s *BoolSchema) Meta(key string, value interface{}) *BoolSchema
Meta attaches a key-value metadata pair to the schema.
func (*BoolSchema) Nullable ¶
func (s *BoolSchema) Nullable() *BoolSchema
Nullable allows the field to be null.
func (*BoolSchema) Optional ¶
func (s *BoolSchema) Optional() *BoolSchema
Optional marks the field as optional (default).
func (*BoolSchema) Required ¶
func (s *BoolSchema) Required() *BoolSchema
Required marks the field as required.
func (*BoolSchema) Transform ¶ added in v0.2.0
func (s *BoolSchema) Transform(transformer Transformer) *TransformSchema
Transform adds transformation capability to BoolSchema.
func (*BoolSchema) Type ¶
func (s *BoolSchema) Type() queryfy.SchemaType
Type implements the Schema interface.
func (*BoolSchema) Validate ¶
func (s *BoolSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
Validate implements the Schema interface.
func (*BoolSchema) Validators ¶ added in v0.3.0
func (s *BoolSchema) Validators() []queryfy.ValidatorFunc
Validators returns the custom validator functions.
type CustomSchema ¶
type CustomSchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
CustomSchema allows custom validation logic.
func Custom ¶
func Custom(validator queryfy.ValidatorFunc) *CustomSchema
Custom creates a new custom schema with a validator function.
func (*CustomSchema) Meta ¶ added in v0.3.0
func (s *CustomSchema) Meta(key string, value interface{}) *CustomSchema
Meta attaches a key-value metadata pair to the schema.
func (*CustomSchema) Nullable ¶
func (s *CustomSchema) Nullable() *CustomSchema
Nullable allows the field to be null.
func (*CustomSchema) Optional ¶
func (s *CustomSchema) Optional() *CustomSchema
Optional marks the field as optional (default).
func (*CustomSchema) Required ¶
func (s *CustomSchema) Required() *CustomSchema
Required marks the field as required.
func (*CustomSchema) Type ¶
func (s *CustomSchema) Type() queryfy.SchemaType
Type implements the Schema interface.
func (*CustomSchema) Validate ¶
func (s *CustomSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
Validate implements the Schema interface.
type DateTimeSchema ¶
type DateTimeSchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
DateTimeSchema validates date/time values.
By default, DateTimeSchema is lenient with format matching: if the specified format fails to parse the input, it falls back to trying common date/time formats. Use StrictFormat() to disable this fallback and enforce the exact format specified.
func (*DateTimeSchema) Age ¶
func (s *DateTimeSchema) Age(minAge, maxAge int) *DateTimeSchema
Age validates that the date represents an age within the specified range. Useful for birth dates.
func (*DateTimeSchema) Between ¶
func (s *DateTimeSchema) Between(min, max time.Time) *DateTimeSchema
Between sets both minimum and maximum date/time.
func (*DateTimeSchema) BetweenStrings ¶
func (s *DateTimeSchema) BetweenStrings(min, max string) *DateTimeSchema
BetweenStrings sets both minimum and maximum date/time from strings.
func (*DateTimeSchema) BusinessDay ¶
func (s *DateTimeSchema) BusinessDay() *DateTimeSchema
BusinessDay validates that the date is a business day (Mon-Fri).
func (*DateTimeSchema) Custom ¶
func (s *DateTimeSchema) Custom(fn queryfy.ValidatorFunc) *DateTimeSchema
Custom adds a custom validator function.
func (*DateTimeSchema) DMY ¶
func (s *DateTimeSchema) DMY() *DateTimeSchema
DMY sets the format to DD/MM/YYYY (used in UK, Europe, Latin America, and most of the world).
func (*DateTimeSchema) DateOnly ¶
func (s *DateTimeSchema) DateOnly() *DateTimeSchema
DateOnly sets the format to date only (YYYY-MM-DD).
func (*DateTimeSchema) Format ¶
func (s *DateTimeSchema) Format(format string) *DateTimeSchema
Format sets the expected date/time format. Common formats:
- time.RFC3339: "2006-01-02T15:04:05Z07:00"
- time.DateOnly: "2006-01-02"
- "2006-01-02 15:04:05"
- "01/02/2006"
- "02-Jan-2006"
func (*DateTimeSchema) FormatString ¶ added in v0.3.0
func (s *DateTimeSchema) FormatString() string
FormatString returns the Go time format string configured on this schema.
func (*DateTimeSchema) Future ¶
func (s *DateTimeSchema) Future() *DateTimeSchema
Future requires the date/time to be in the future.
func (*DateTimeSchema) ISO8601 ¶
func (s *DateTimeSchema) ISO8601() *DateTimeSchema
ISO8601 sets the format to ISO8601 (RFC3339).
func (*DateTimeSchema) IsStrictFormat ¶ added in v0.3.0
func (s *DateTimeSchema) IsStrictFormat() bool
IsStrictFormat reports whether StrictFormat() was called on this schema.
func (*DateTimeSchema) MDY ¶
func (s *DateTimeSchema) MDY() *DateTimeSchema
MDY sets the format to MM/DD/YYYY (used primarily in the US).
func (*DateTimeSchema) Max ¶
func (s *DateTimeSchema) Max(max time.Time) *DateTimeSchema
Max sets the maximum allowed date/time.
func (*DateTimeSchema) MaxString ¶
func (s *DateTimeSchema) MaxString(max string) *DateTimeSchema
MaxString sets the maximum allowed date/time from a string.
func (*DateTimeSchema) Meta ¶ added in v0.3.0
func (s *DateTimeSchema) Meta(key string, value interface{}) *DateTimeSchema
Meta attaches a key-value metadata pair to the schema.
func (*DateTimeSchema) Min ¶
func (s *DateTimeSchema) Min(min time.Time) *DateTimeSchema
Min sets the minimum allowed date/time.
func (*DateTimeSchema) MinString ¶
func (s *DateTimeSchema) MinString(min string) *DateTimeSchema
MinString sets the minimum allowed date/time from a string.
func (*DateTimeSchema) Nullable ¶
func (s *DateTimeSchema) Nullable() *DateTimeSchema
Nullable allows the field to be null.
func (*DateTimeSchema) Optional ¶
func (s *DateTimeSchema) Optional() *DateTimeSchema
Optional marks the field as optional (default).
func (*DateTimeSchema) Past ¶
func (s *DateTimeSchema) Past() *DateTimeSchema
Past requires the date/time to be in the past.
func (*DateTimeSchema) Required ¶
func (s *DateTimeSchema) Required() *DateTimeSchema
Required marks the field as required.
func (*DateTimeSchema) StrictFormat ¶ added in v0.3.0
func (s *DateTimeSchema) StrictFormat() *DateTimeSchema
StrictFormat disables the common-format fallback. When enabled, the input string must match the exact format specified (via Format, DateOnly, DMY, MDY, ISO8601, etc.). Without StrictFormat, the schema will attempt to parse using common date/time formats if the specified format fails.
func (*DateTimeSchema) TimeConstraints ¶ added in v0.3.0
func (s *DateTimeSchema) TimeConstraints() (min, max *time.Time)
TimeConstraints returns the min and max time pointers, either of which may be nil if not set.
func (*DateTimeSchema) Transform ¶ added in v0.2.0
func (s *DateTimeSchema) Transform(transformer Transformer) *TransformSchema
Transform adds transformation capability to DateTimeSchema.
func (*DateTimeSchema) Type ¶
func (s *DateTimeSchema) Type() queryfy.SchemaType
Type implements the Schema interface.
func (*DateTimeSchema) Validate ¶
func (s *DateTimeSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
Validate implements the Schema interface.
func (*DateTimeSchema) Weekday ¶
func (s *DateTimeSchema) Weekday(days ...time.Weekday) *DateTimeSchema
Weekday validates that the date falls on specific weekdays.
func (*DateTimeSchema) YMD ¶
func (s *DateTimeSchema) YMD() *DateTimeSchema
YMD sets the format to YYYY-MM-DD (ISO format).
type DependencyCondition ¶ added in v0.2.0
DependencyCondition is a function that receives the parent object and returns whether the dependent validation should be applied.
func WhenAll ¶ added in v0.2.0
func WhenAll(conditions ...DependencyCondition) DependencyCondition
WhenAll creates a condition that requires all sub-conditions to be true.
func WhenAny ¶ added in v0.2.0
func WhenAny(conditions ...DependencyCondition) DependencyCondition
WhenAny creates a condition that requires at least one sub-condition to be true.
func WhenEquals ¶ added in v0.2.0
func WhenEquals(field string, value interface{}) DependencyCondition
WhenEquals creates a condition that checks if a field equals a specific value.
func WhenExists ¶ added in v0.2.0
func WhenExists(field string) DependencyCondition
WhenExists creates a condition that checks if a field exists and is not nil.
func WhenFalse ¶ added in v0.2.0
func WhenFalse(field string) DependencyCondition
WhenFalse creates a condition that checks if a boolean field is false.
func WhenGreaterThan ¶ added in v0.2.0
func WhenGreaterThan(field string, threshold float64) DependencyCondition
WhenGreaterThan creates a condition for numeric comparisons.
func WhenIn ¶ added in v0.2.0
func WhenIn(field string, values ...interface{}) DependencyCondition
WhenIn creates a condition that checks if a field's value is in a list.
func WhenLessThan ¶ added in v0.2.0
func WhenLessThan(field string, threshold float64) DependencyCondition
WhenLessThan creates a condition for numeric comparisons.
func WhenNotEquals ¶ added in v0.2.0
func WhenNotEquals(field string, value interface{}) DependencyCondition
WhenNotEquals creates a condition that checks if a field does not equal a specific value.
func WhenNotExists ¶ added in v0.2.0
func WhenNotExists(field string) DependencyCondition
WhenNotExists creates a condition that checks if a field does not exist or is nil.
func WhenTrue ¶ added in v0.2.0
func WhenTrue(field string) DependencyCondition
WhenTrue creates a condition that checks if a boolean field is true.
type DependentSchema ¶ added in v0.2.0
type DependentSchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
DependentSchema validates fields based on conditions from other fields.
func Dependent ¶ added in v0.2.0
func Dependent(fieldName string) *DependentSchema
Dependent creates a new dependent field schema.
func RequiredUnless ¶ added in v0.2.0
func RequiredUnless(condition DependencyCondition, schema queryfy.Schema) *DependentSchema
RequiredUnless creates a schema that makes a field required unless a condition is met.
func RequiredWhen ¶ added in v0.2.0
func RequiredWhen(condition DependencyCondition, schema queryfy.Schema) *DependentSchema
RequiredWhen creates a schema that makes a field required when a condition is met.
func (*DependentSchema) Custom ¶ added in v0.2.0
func (s *DependentSchema) Custom(fn queryfy.ValidatorFunc) *DependentSchema
Custom adds a custom validator function.
func (*DependentSchema) Else ¶ added in v0.2.0
func (s *DependentSchema) Else(elseSchema queryfy.Schema) *DependentSchema
Else sets the schema to apply when the condition is false.
func (*DependentSchema) On ¶ added in v0.2.0
func (s *DependentSchema) On(fields ...string) *DependentSchema
On specifies which fields this validation depends on.
func (*DependentSchema) Optional ¶ added in v0.2.0
func (s *DependentSchema) Optional() *DependentSchema
Optional marks the field as optional.
func (*DependentSchema) Required ¶ added in v0.2.0
func (s *DependentSchema) Required() *DependentSchema
Required marks the field as required (when the condition is met).
func (*DependentSchema) Then ¶ added in v0.2.0
func (s *DependentSchema) Then(schema queryfy.Schema) *DependentSchema
Then sets the schema to apply when the condition is true.
func (*DependentSchema) Type ¶ added in v0.2.0
func (s *DependentSchema) Type() queryfy.SchemaType
Type implements the Schema interface.
func (*DependentSchema) Validate ¶ added in v0.2.0
func (s *DependentSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
Validate implements the Schema interface.
func (*DependentSchema) ValidateWithParent ¶ added in v0.2.0
func (s *DependentSchema) ValidateWithParent(value interface{}, parentData map[string]interface{}, ctx *queryfy.ValidationContext) error
ValidateWithParent validates the field considering the parent object context.
func (*DependentSchema) When ¶ added in v0.2.0
func (s *DependentSchema) When(condition DependencyCondition) *DependentSchema
When sets the condition function that determines when validation applies.
type FieldChange ¶ added in v0.3.0
type FieldChange struct {
Path string // dot-notation path
OldType queryfy.SchemaType
NewType queryfy.SchemaType
Details string // human-readable description
}
FieldChange describes a change between two versions of a field.
type FieldVisitor ¶ added in v0.3.0
FieldVisitor is called for each node during schema traversal. The path argument is the dot-notation path to the current node (e.g., "user.address.street" or "items[*].name"). The schema argument is the schema at that node.
type NotSchema ¶
type NotSchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
NotSchema inverts the result of another schema.
func (*NotSchema) InnerSchema ¶ added in v0.3.0
Validate implements the Schema interface. InnerSchema returns the negated schema.
func (*NotSchema) Type ¶
func (s *NotSchema) Type() queryfy.SchemaType
Type implements the Schema interface.
type NumberSchema ¶
type NumberSchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
NumberSchema validates numeric values.
func (*NumberSchema) Custom ¶
func (s *NumberSchema) Custom(fn queryfy.ValidatorFunc) *NumberSchema
Custom adds a custom validator function.
func (*NumberSchema) Integer ¶
func (s *NumberSchema) Integer() *NumberSchema
Integer validates that the number is an integer (no decimal part).
func (*NumberSchema) IsInteger ¶ added in v0.3.0
func (s *NumberSchema) IsInteger() bool
IsInteger reports whether the Integer() constraint was applied.
func (*NumberSchema) Max ¶
func (s *NumberSchema) Max(max float64) *NumberSchema
Max sets the maximum value (inclusive).
func (*NumberSchema) Meta ¶ added in v0.3.0
func (s *NumberSchema) Meta(key string, value interface{}) *NumberSchema
Meta attaches a key-value metadata pair to the schema.
func (*NumberSchema) Min ¶
func (s *NumberSchema) Min(min float64) *NumberSchema
Min sets the minimum value (inclusive).
func (*NumberSchema) MultipleOf ¶
func (s *NumberSchema) MultipleOf(value float64) *NumberSchema
MultipleOf validates that the number is a multiple of the given value.
func (*NumberSchema) MultipleOfValue ¶ added in v0.3.0
func (s *NumberSchema) MultipleOfValue() *float64
MultipleOfValue returns the multipleOf constraint, or nil if not set.
func (*NumberSchema) Negative ¶
func (s *NumberSchema) Negative() *NumberSchema
Negative validates that the number is negative (< 0).
func (*NumberSchema) Nullable ¶
func (s *NumberSchema) Nullable() *NumberSchema
Nullable allows the field to be null.
func (*NumberSchema) Optional ¶
func (s *NumberSchema) Optional() *NumberSchema
Optional marks the field as optional (default).
func (*NumberSchema) Positive ¶
func (s *NumberSchema) Positive() *NumberSchema
Positive validates that the number is positive (> 0).
func (*NumberSchema) Range ¶
func (s *NumberSchema) Range(min, max float64) *NumberSchema
Range sets both minimum and maximum values.
func (*NumberSchema) RangeConstraints ¶ added in v0.3.0
func (s *NumberSchema) RangeConstraints() (min, max *float64)
RangeConstraints returns the min and max value pointers, either of which may be nil if not set.
func (*NumberSchema) Required ¶
func (s *NumberSchema) Required() *NumberSchema
Required marks the field as required.
func (*NumberSchema) Transform ¶ added in v0.2.0
func (s *NumberSchema) Transform(transformer Transformer) *TransformSchema
Transform adds transformation capability to NumberSchema.
func (*NumberSchema) Type ¶
func (s *NumberSchema) Type() queryfy.SchemaType
Type implements the Schema interface.
func (*NumberSchema) Validate ¶
func (s *NumberSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
Validate implements the Schema interface.
func (*NumberSchema) Validators ¶ added in v0.3.0
func (s *NumberSchema) Validators() []queryfy.ValidatorFunc
Validators returns the custom validator functions.
type ObjectSchema ¶
type ObjectSchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
ObjectSchema validates object/map values.
func (*ObjectSchema) AllowAdditional ¶ added in v0.3.0
func (s *ObjectSchema) AllowAdditional(allow bool) *ObjectSchema
AllowAdditional controls whether fields not declared in the schema are accepted, independent of the validation mode. When set to true, extra fields are always accepted; when false, always rejected. When not called (nil), the behaviour follows the validation mode (Strict rejects, Loose accepts).
func (*ObjectSchema) AllowsAdditional ¶ added in v0.3.0
func (s *ObjectSchema) AllowsAdditional() (allow bool, explicit bool)
AllowsAdditional reports the current additional-properties policy. Returns (value, explicit) where explicit is false if no policy has been set (nil — mode default applies).
func (*ObjectSchema) AsyncCustom ¶ added in v0.3.0
func (s *ObjectSchema) AsyncCustom(fn queryfy.AsyncValidatorFunc) *ObjectSchema
AsyncCustom adds an async validator to the object schema. Async validators are only invoked by ValidateAndTransformAsync; sync methods ignore them. Object-level async validators receive the full result map and are useful for cross-field checks that require I/O (e.g. uniqueness across fields).
func (*ObjectSchema) Custom ¶
func (s *ObjectSchema) Custom(fn queryfy.ValidatorFunc) *ObjectSchema
Custom adds a custom validator function.
func (*ObjectSchema) Field ¶
func (s *ObjectSchema) Field(name string, schema queryfy.Schema) *ObjectSchema
Field adds a field schema to the object.
Note: Do not pass a *DependentSchema directly to Field — it will be treated as a regular schema and the dependency condition will be ignored. Use ObjectSchemaWithDependencies (via WithDependencies()) and its DependentField method instead.
func (*ObjectSchema) FieldNames ¶
func (s *ObjectSchema) FieldNames() []string
FieldNames returns the names of all defined fields.
func (*ObjectSchema) Fields ¶
func (s *ObjectSchema) Fields(fields map[string]queryfy.Schema) *ObjectSchema
Fields adds multiple field schemas at once.
func (*ObjectSchema) GetField ¶ added in v0.3.0
func (s *ObjectSchema) GetField(name string) (queryfy.Schema, bool)
GetField returns the schema for a named field and whether it exists.
func (*ObjectSchema) HasAsyncValidators ¶ added in v0.3.0
func (s *ObjectSchema) HasAsyncValidators() bool
HasAsyncValidators returns true if any async validators are registered on this schema or on any of its field schemas.
func (*ObjectSchema) Meta ¶ added in v0.3.0
func (s *ObjectSchema) Meta(key string, value interface{}) *ObjectSchema
Meta attaches a key-value metadata pair to the schema.
func (*ObjectSchema) Nullable ¶
func (s *ObjectSchema) Nullable() *ObjectSchema
Nullable allows the field to be null.
func (*ObjectSchema) Optional ¶
func (s *ObjectSchema) Optional() *ObjectSchema
Optional marks the object as optional (default).
func (*ObjectSchema) Required ¶
func (s *ObjectSchema) Required() *ObjectSchema
Required marks the object itself as required.
func (*ObjectSchema) RequiredFieldNames ¶ added in v0.3.0
func (s *ObjectSchema) RequiredFieldNames() []string
RequiredFieldNames returns the names of all required fields, sorted.
func (*ObjectSchema) RequiredFields ¶
func (s *ObjectSchema) RequiredFields(names ...string) *ObjectSchema
RequiredFields marks specific fields as required. This overrides the required status set on individual field schemas.
func (*ObjectSchema) String ¶
func (s *ObjectSchema) String() string
String returns a string representation of the object schema.
func (*ObjectSchema) Transform ¶ added in v0.2.0
func (s *ObjectSchema) Transform(transformer Transformer) *TransformSchema
Transform adds transformation capability to ObjectSchema.
func (*ObjectSchema) Type ¶
func (s *ObjectSchema) Type() queryfy.SchemaType
Type implements the Schema interface.
func (*ObjectSchema) Validate ¶
func (s *ObjectSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
Validate implements the Schema interface.
func (*ObjectSchema) ValidateAndTransform ¶ added in v0.3.0
func (s *ObjectSchema) ValidateAndTransform(value interface{}, ctx *queryfy.ValidationContext) (interface{}, error)
ValidateAndTransform validates the object and returns a new map with all transformations applied. Fields whose schemas implement TransformableSchema (e.g. TransformSchema) will have their transformed values in the result. Non-transformable fields are validated normally and their original values are preserved. Nested objects and arrays are handled recursively.
func (*ObjectSchema) ValidateAndTransformAsync ¶ added in v0.3.0
func (s *ObjectSchema) ValidateAndTransformAsync(goCtx context.Context, value interface{}, ctx *queryfy.ValidationContext) (interface{}, error)
ValidateAndTransformAsync runs sync validation and transformations first. If sync validation passes, it then runs async validators on fields and on the object itself, sequentially with the provided context.
func (*ObjectSchema) Validators ¶ added in v0.3.0
func (s *ObjectSchema) Validators() []queryfy.ValidatorFunc
Validators returns the custom validator functions.
func (*ObjectSchema) WithDependencies ¶ added in v0.2.0
func (s *ObjectSchema) WithDependencies() *ObjectSchemaWithDependencies
WithDependencies converts an ObjectSchema to support dependent field validation.
type ObjectSchemaWithDependencies ¶ added in v0.2.0
type ObjectSchemaWithDependencies struct {
*ObjectSchema
// contains filtered or unexported fields
}
ObjectSchemaWithDependencies extends the regular ObjectSchema to support dependent fields.
func (*ObjectSchemaWithDependencies) Custom ¶ added in v0.2.0
func (s *ObjectSchemaWithDependencies) Custom(fn queryfy.ValidatorFunc) *ObjectSchemaWithDependencies
Custom adds a custom validator (override to return correct type).
func (*ObjectSchemaWithDependencies) DependentField ¶ added in v0.2.0
func (s *ObjectSchemaWithDependencies) DependentField(name string, dependent *DependentSchema) *ObjectSchemaWithDependencies
DependentField adds a dependent field to the schema.
func (*ObjectSchemaWithDependencies) Field ¶ added in v0.2.0
func (s *ObjectSchemaWithDependencies) Field(name string, schema queryfy.Schema) *ObjectSchemaWithDependencies
Field adds a regular field to the schema (override to return correct type).
func (*ObjectSchemaWithDependencies) Fields ¶ added in v0.2.0
func (s *ObjectSchemaWithDependencies) Fields(fields map[string]queryfy.Schema) *ObjectSchemaWithDependencies
Fields adds multiple fields at once (override to return correct type).
func (*ObjectSchemaWithDependencies) Nullable ¶ added in v0.2.0
func (s *ObjectSchemaWithDependencies) Nullable() *ObjectSchemaWithDependencies
Nullable allows the object to be null (override to return correct type).
func (*ObjectSchemaWithDependencies) Optional ¶ added in v0.2.0
func (s *ObjectSchemaWithDependencies) Optional() *ObjectSchemaWithDependencies
Optional marks the object as optional (override to return correct type).
func (*ObjectSchemaWithDependencies) Required ¶ added in v0.2.0
func (s *ObjectSchemaWithDependencies) Required() *ObjectSchemaWithDependencies
Required marks the object as required (override to return correct type).
func (*ObjectSchemaWithDependencies) RequiredFields ¶ added in v0.2.0
func (s *ObjectSchemaWithDependencies) RequiredFields(names ...string) *ObjectSchemaWithDependencies
RequiredFields marks specific fields as required (override to return correct type).
func (*ObjectSchemaWithDependencies) Validate ¶ added in v0.2.0
func (s *ObjectSchemaWithDependencies) Validate(value interface{}, ctx *queryfy.ValidationContext) error
Validate overrides the base validate to handle dependent fields.
type OrSchema ¶
type OrSchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
OrSchema validates that at least one schema passes.
func (*OrSchema) Schemas ¶ added in v0.3.0
Validate implements the Schema interface. Schemas returns the list of sub-schemas in this Or composite.
func (*OrSchema) Type ¶
func (s *OrSchema) Type() queryfy.SchemaType
Type implements the Schema interface.
type SchemaDiff ¶ added in v0.3.0
type SchemaDiff struct {
Added []string // field paths present in new but not old
Removed []string // field paths present in old but not new
Changed []FieldChange // fields present in both but structurally different
}
SchemaDiff describes the structural differences between two schemas.
func Diff ¶ added in v0.3.0
func Diff(old, new queryfy.Schema) (*SchemaDiff, error)
Diff compares two schemas and returns a structured diff describing what changed: added fields, removed fields, and changed fields.
Both schemas must be ObjectSchema (or ObjectSchemaWithDependencies). For non-object schemas, Diff compares them as single values.
func (*SchemaDiff) HasChanges ¶ added in v0.3.0
func (d *SchemaDiff) HasChanges() bool
HasChanges reports whether any differences were found.
type StringSchema ¶
type StringSchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
StringSchema validates string values.
func (*StringSchema) Custom ¶
func (s *StringSchema) Custom(fn queryfy.ValidatorFunc) *StringSchema
Custom adds a custom validator function.
func (*StringSchema) Email ¶
func (s *StringSchema) Email() *StringSchema
Email validates that the string is a valid email address.
func (*StringSchema) Enum ¶
func (s *StringSchema) Enum(values ...string) *StringSchema
Enum restricts the string to one of the specified values.
func (*StringSchema) EnumValues ¶ added in v0.3.0
func (s *StringSchema) EnumValues() []string
EnumValues returns the declared enum values, or nil if no enum is set.
func (*StringSchema) FormatString ¶ added in v0.3.0
func (s *StringSchema) FormatString(name string) *StringSchema
FormatString sets a registered format on the StringSchema. The format validator is looked up from the registry at schema construction time. If the format is not registered, validation will produce an error.
This is the extensible alternative to the built-in Email(), URL(), and UUID() methods.
func (*StringSchema) FormatType ¶ added in v0.3.0
func (s *StringSchema) FormatType() string
FormatType returns the declared format ("email", "url", "uuid", or "").
func (*StringSchema) Length ¶
func (s *StringSchema) Length(length int) *StringSchema
Length sets both minimum and maximum length to the same value.
func (*StringSchema) LengthConstraints ¶ added in v0.3.0
func (s *StringSchema) LengthConstraints() (min, max *int)
LengthConstraints returns the min and max length pointers, either of which may be nil if not set.
func (*StringSchema) MaxLength ¶
func (s *StringSchema) MaxLength(max int) *StringSchema
MaxLength sets the maximum string length.
func (*StringSchema) Meta ¶ added in v0.3.0
func (s *StringSchema) Meta(key string, value interface{}) *StringSchema
Meta attaches a key-value metadata pair to the schema.
func (*StringSchema) MinLength ¶
func (s *StringSchema) MinLength(min int) *StringSchema
MinLength sets the minimum string length.
func (*StringSchema) Nullable ¶
func (s *StringSchema) Nullable() *StringSchema
Nullable allows the field to be null.
func (*StringSchema) Optional ¶
func (s *StringSchema) Optional() *StringSchema
Optional marks the field as optional (default).
func (*StringSchema) Pattern ¶
func (s *StringSchema) Pattern(pattern string) *StringSchema
Pattern sets a regular expression pattern that the string must match.
func (*StringSchema) PatternMatch ¶ added in v0.3.0
func (s *StringSchema) PatternMatch(str string) bool
PatternMatch tests a string against the compiled pattern. Returns true if no pattern is set.
func (*StringSchema) PatternString ¶ added in v0.3.0
func (s *StringSchema) PatternString() string
PatternString returns the declared regex pattern, or "" if none.
func (*StringSchema) Required ¶
func (s *StringSchema) Required() *StringSchema
Required marks the field as required.
func (*StringSchema) Transform ¶ added in v0.2.0
func (s *StringSchema) Transform(transformer Transformer) *TransformSchema
Transform adds transformation capability to StringSchema.
func (*StringSchema) Type ¶
func (s *StringSchema) Type() queryfy.SchemaType
Type implements the Schema interface.
func (*StringSchema) URL ¶
func (s *StringSchema) URL() *StringSchema
URL validates that the string is a valid URL.
func (*StringSchema) UUID ¶
func (s *StringSchema) UUID() *StringSchema
UUID validates that the string is a valid UUID.
func (*StringSchema) Validate ¶
func (s *StringSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
Validate implements the Schema interface.
func (*StringSchema) Validators ¶ added in v0.3.0
func (s *StringSchema) Validators() []queryfy.ValidatorFunc
Validators returns the custom validator functions.
type TransformSchema ¶ added in v0.2.0
type TransformSchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
TransformSchema adds transformation capabilities to any schema.
func Transform ¶ added in v0.2.0
func Transform(schema queryfy.Schema) *TransformSchema
Transform creates a new transform schema wrapping an existing schema.
func (*TransformSchema) Add ¶ added in v0.2.0
func (s *TransformSchema) Add(transformer Transformer) *TransformSchema
Add adds a transformer to the pipeline.
func (*TransformSchema) AsyncCustom ¶ added in v0.3.0
func (s *TransformSchema) AsyncCustom(fn queryfy.AsyncValidatorFunc) *TransformSchema
AsyncCustom adds an async validator to the schema. Async validators are only invoked by ValidateAndTransformAsync; sync methods ignore them.
func (*TransformSchema) HasAsyncValidators ¶ added in v0.3.0
func (s *TransformSchema) HasAsyncValidators() bool
HasAsyncValidators returns true if async validators are registered.
func (*TransformSchema) InnerSchema ¶ added in v0.3.0
func (s *TransformSchema) InnerSchema() queryfy.Schema
InnerSchema returns the wrapped schema.
func (*TransformSchema) IsRequired ¶ added in v0.3.0
func (s *TransformSchema) IsRequired() bool
IsRequired returns true if either the transform wrapper or the inner schema is marked as required. This ensures that wrapping a Required() schema with Transform() preserves the required semantics.
func (*TransformSchema) Meta ¶ added in v0.3.0
func (s *TransformSchema) Meta(key string, value interface{}) *TransformSchema
Meta attaches a key-value metadata pair to the schema.
func (*TransformSchema) Optional ¶ added in v0.2.0
func (s *TransformSchema) Optional() *TransformSchema
Optional marks the field as optional.
func (*TransformSchema) Required ¶ added in v0.2.0
func (s *TransformSchema) Required() *TransformSchema
Required marks the field as required.
func (*TransformSchema) Type ¶ added in v0.2.0
func (s *TransformSchema) Type() queryfy.SchemaType
Type implements the Schema interface.
func (*TransformSchema) Validate ¶ added in v0.2.0
func (s *TransformSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
Validate implements the Schema interface.
func (*TransformSchema) ValidateAndTransform ¶ added in v0.2.0
func (s *TransformSchema) ValidateAndTransform(value interface{}, ctx *queryfy.ValidationContext) (interface{}, error)
ValidateAndTransform validates and returns the transformed value.
func (*TransformSchema) ValidateAndTransformAsync ¶ added in v0.3.0
func (s *TransformSchema) ValidateAndTransformAsync(goCtx context.Context, value interface{}, ctx *queryfy.ValidationContext) (interface{}, error)
ValidateAndTransformAsync runs sync validation and transformations first. If sync validation passes, it then runs async validators sequentially with the provided context. The async validators receive the transformed value, not the original input.
type Transformer ¶ added in v0.2.0
type Transformer func(value interface{}) (interface{}, error)
Transformer is a function that transforms a value. It returns the transformed value and any error.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package jsonschema converts JSON Schema documents into queryfy schemas.
|
Package jsonschema converts JSON Schema documents into queryfy schemas. |
|
common.go - Common transformation functions
|
common.go - Common transformation functions |