From 0a211997049b93a2e9c6ee9e23ee7d7786cdb623 Mon Sep 17 00:00:00 2001 From: Vassil Kovatchev Date: Fri, 26 Jul 2024 10:44:05 -0400 Subject: [PATCH] Switch from typed parent descriptor to map[string]interface{} for parent implementation --- compiler.go | 2 +- schema.go | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/compiler.go b/compiler.go index f102d4c..4d783d4 100644 --- a/compiler.go +++ b/compiler.go @@ -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 diff --git a/schema.go b/schema.go index aeadf3e..edf6007 100644 --- a/schema.go +++ b/schema.go @@ -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 { @@ -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) { @@ -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