Documentation
¶
Index ¶
- func CoerceMultipartData(rule *SchemaRule, data map[string]any)
- func CoerceValue(rule *SchemaRule, val any) any
- func ToJSONString(rule *SchemaRule) (string, error)
- type FileValidator
- type JSONSchemaNode
- type RuleType
- type SchemaRule
- func Array(itemRule *SchemaRule) *SchemaRule
- func Boolean() *SchemaRule
- func File() *SchemaRule
- func FromStruct(s any) *SchemaRule
- func Integer() *SchemaRule
- func Number() *SchemaRule
- func Object(props map[string]*SchemaRule) *SchemaRule
- func Optional(rule *SchemaRule) *SchemaRule
- func String() *SchemaRule
- func (r *SchemaRule) AllowedMimes(mimes ...string) *SchemaRule
- func (r *SchemaRule) Describe(desc string) *SchemaRule
- func (r *SchemaRule) Email() *SchemaRule
- func (r *SchemaRule) Max(max int) *SchemaRule
- func (r *SchemaRule) MaxFiles(max int) *SchemaRule
- func (r *SchemaRule) MaxSize(bytes int64) *SchemaRule
- func (r *SchemaRule) MaxValue(max float64) *SchemaRule
- func (r *SchemaRule) Min(min int) *SchemaRule
- func (r *SchemaRule) MinFiles(min int) *SchemaRule
- func (r *SchemaRule) MinValue(min float64) *SchemaRule
- func (r *SchemaRule) WithDefault(val any) *SchemaRule
- type ValidationErrorDetail
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CoerceMultipartData ¶ added in v1.0.1
func CoerceMultipartData(rule *SchemaRule, data map[string]any)
CoerceMultipartData coerces string values in data to numbers or booleans if the schema rule requires it
func CoerceValue ¶ added in v1.0.1
func CoerceValue(rule *SchemaRule, val any) any
CoerceValue recursively walks any schema structure (objects, multi-dimensional arrays, scalars)
func ToJSONString ¶
func ToJSONString(rule *SchemaRule) (string, error)
ToJSONString converts a SchemaRule to a pretty-printed JSON Schema string
Types ¶
type FileValidator ¶
FileValidator is the interface required for multipart file validation
type JSONSchemaNode ¶
type JSONSchemaNode struct {
Type string `json:"type,omitempty"`
Description string `json:"description,omitempty"`
Format string `json:"format,omitempty"`
Properties map[string]*JSONSchemaNode `json:"properties,omitempty"`
Required []string `json:"required,omitempty"`
Items *JSONSchemaNode `json:"items,omitempty"`
AdditionalProperties *bool `json:"additionalProperties,omitempty"`
Default any `json:"default,omitempty"`
MinLength *int `json:"minLength,omitempty"`
MaxLength *int `json:"maxLength,omitempty"`
Minimum *float64 `json:"minimum,omitempty"`
Maximum *float64 `json:"maximum,omitempty"`
}
JSONSchemaNode represents standard JSON Schema Draft 7/2020-12 structure
func ToJSONSchema ¶
func ToJSONSchema(rule *SchemaRule) *JSONSchemaNode
ToJSONSchema converts a SchemaRule into a standard JSON Schema node
type SchemaRule ¶
type SchemaRule struct {
Type RuleType `json:"type"`
Optional bool `json:"optional,omitempty"`
Description string `json:"description,omitempty"`
MinLength *int `json:"minLength,omitempty"`
MaxLength *int `json:"maxLength,omitempty"`
Pattern string `json:"pattern,omitempty"`
Format string `json:"format,omitempty"` // e.g. "email", "binary"
Minimum *float64 `json:"minimum,omitempty"`
Maximum *float64 `json:"maximum,omitempty"`
Properties map[string]*SchemaRule `json:"properties,omitempty"`
Items *SchemaRule `json:"items,omitempty"`
MaxSizeBytes int64 `json:"maxSizeBytes,omitempty"`
MimeTypes []string `json:"mimeTypes,omitempty"`
Required []string `json:"required,omitempty"`
Default any `json:"default,omitempty"`
}
SchemaRule defines a single validation constraint & documentation node
func Array ¶
func Array(itemRule *SchemaRule) *SchemaRule
func Boolean ¶
func Boolean() *SchemaRule
func File ¶
func File() *SchemaRule
func FromStruct ¶
func FromStruct(s any) *SchemaRule
FromStruct derives a SchemaRule automatically from a standard Go struct definition
func Integer ¶
func Integer() *SchemaRule
func Number ¶
func Number() *SchemaRule
func Object ¶
func Object(props map[string]*SchemaRule) *SchemaRule
func Optional ¶
func Optional(rule *SchemaRule) *SchemaRule
func String ¶
func String() *SchemaRule
func (*SchemaRule) AllowedMimes ¶
func (r *SchemaRule) AllowedMimes(mimes ...string) *SchemaRule
func (*SchemaRule) Describe ¶
func (r *SchemaRule) Describe(desc string) *SchemaRule
func (*SchemaRule) Email ¶
func (r *SchemaRule) Email() *SchemaRule
func (*SchemaRule) Max ¶
func (r *SchemaRule) Max(max int) *SchemaRule
func (*SchemaRule) MaxFiles ¶ added in v1.0.1
func (r *SchemaRule) MaxFiles(max int) *SchemaRule
MaxFiles sets the maximum file count constraint on an array of files
func (*SchemaRule) MaxSize ¶
func (r *SchemaRule) MaxSize(bytes int64) *SchemaRule
func (*SchemaRule) MaxValue ¶
func (r *SchemaRule) MaxValue(max float64) *SchemaRule
func (*SchemaRule) Min ¶
func (r *SchemaRule) Min(min int) *SchemaRule
func (*SchemaRule) MinFiles ¶ added in v1.0.1
func (r *SchemaRule) MinFiles(min int) *SchemaRule
MinFiles sets the minimum file count constraint on an array of files
func (*SchemaRule) MinValue ¶
func (r *SchemaRule) MinValue(min float64) *SchemaRule
func (*SchemaRule) WithDefault ¶
func (r *SchemaRule) WithDefault(val any) *SchemaRule
type ValidationErrorDetail ¶
ValidationErrorDetail represents a single field-level schema validation failure
func Validate ¶
func Validate(rule *SchemaRule, data any, currentPath string) []ValidationErrorDetail
Validate checks a generic payload map against a SchemaRule, enforcing strict contracts