-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Description
Hello,
I would to know if there is a way to add z.any() that matches with everything in zog.
Piece of a code that matches my need :
package zog
import (
"reflect"
"github.com/Oudwins/zog/conf"
p "github.com/Oudwins/zog/internals"
"github.com/Oudwins/zog/zconst"
)
var _ ComplexZogSchema = &AnySchema{}
type AnySchema struct {
}
func (v *AnySchema) getType() zconst.ZogType {
return zconst.TypePtr
}
func (v *AnySchema) setCoercer(c conf.CoercerFunc) {
}
// Any creates a Any ZogSchema
func Any() *AnySchema {
return &AnySchema{}
}
// Parse the data into the destination Any
func (v *AnySchema) Parse(data any, dest any, options ...ExecOption) p.ZogIssueMap {
errs := p.NewErrsMap()
defer errs.Free()
ctx := p.NewExecCtx(errs, conf.IssueFormatter)
defer ctx.Free()
for _, opt := range options {
opt(ctx)
}
path := p.NewPathBuilder()
defer path.Free()
v.process(ctx.NewSchemaCtx(data, dest, path, v.getType()))
return errs.M
}
func (v *AnySchema) process(ctx *p.SchemaCtx) {
d := reflect.ValueOf(ctx.Val)
if !d.IsValid() {
return
}
k := d.Kind()
if (k == reflect.Ptr || k == reflect.Slice || k == reflect.Map || k == reflect.Chan) && d.IsNil() {
return
}
rv := reflect.ValueOf(ctx.DestPtr)
rv.Elem().Set(d)
}
// Validates a Any Any
func (v *AnySchema) Validate(data any, options ...ExecOption) p.ZogIssueMap {
errs := p.NewErrsMap()
defer errs.Free()
ctx := p.NewExecCtx(errs, conf.IssueFormatter)
defer ctx.Free()
for _, opt := range options {
opt(ctx)
}
path := p.NewPathBuilder()
defer path.Free()
v.validate(ctx.NewValidateSchemaCtx(data, path, v.getType()))
return errs.M
}
func (v *AnySchema) validate(ctx *p.SchemaCtx) {
}
// Validate Existing Anynegokaz
Metadata
Metadata
Assignees
Labels
No labels