Skip to content

Commit

Permalink
Switch from typed parent descriptor to map[string]interface{} for par…
Browse files Browse the repository at this point in the history
…ent implementation
  • Loading branch information
vassilvk committed Jul 26, 2024
1 parent e5ee36d commit 0a21199
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ func (c *Compiler) validateSchema(r *resource, v interface{}, vloc string) error
}

validate := func(meta *Schema) error {
return meta.validateValue(v, v, vloc, ParentDescriptor{})
return meta.validateValue(v, v, vloc, NewParentDescriptor(nil, nil))
}

meta := r.draft.meta
Expand Down
18 changes: 9 additions & 9 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,13 @@ type Schema struct {
Extensions map[string]ExtSchema
}

type ParentDescriptor struct {
parent *ParentDescriptor
value interface{}
type ParentDescriptor map[string]interface{}

func NewParentDescriptor(parent ParentDescriptor, value interface{}) ParentDescriptor {
return ParentDescriptor{
"parent": parent,
"value": value,
}
}

func (s *Schema) String() string {
Expand Down Expand Up @@ -170,7 +174,7 @@ func (s *Schema) hasVocab(name string) bool {
// returns InfiniteLoopError if it detects loop during validation.
// returns InvalidJSONTypeError if it detects any non json value in v.
func (s *Schema) Validate(v interface{}) (err error) {
return s.validateValue(v, v, "", ParentDescriptor{})
return s.validateValue(v, v, "", NewParentDescriptor(nil, nil))
}

func (s *Schema) validateValue(doc interface{}, v interface{}, vloc string, parent ParentDescriptor) (err error) {
Expand Down Expand Up @@ -235,11 +239,7 @@ func (s *Schema) validate(scope []schemaRef, vscope int, spath string, doc inter

if vpath != "" {
vloc += "/" + vpath
subParent = ParentDescriptor{
parent: &parent,
value: thisValue,
}

subParent = NewParentDescriptor(parent, thisValue)
}
_, err := sch.validate(scope, 0, schPath, doc, v, vloc, subParent)
return err
Expand Down

0 comments on commit 0a21199

Please sign in to comment.