From 13b30cf5ea94cdf656758b2b9b89041b156eb86d Mon Sep 17 00:00:00 2001 From: Jared O'Connell Date: Wed, 17 Jan 2024 17:14:14 -0500 Subject: [PATCH] Fixed ValidateCompatibility with scopes into an object schema --- schema/object.go | 5 +++++ schema/object_test.go | 3 +++ 2 files changed, 8 insertions(+) diff --git a/schema/object.go b/schema/object.go index ebc2c2f..110f285 100644 --- a/schema/object.go +++ b/schema/object.go @@ -343,6 +343,11 @@ func (o *ObjectSchema) convertToObjectSchema(typeOrData any) (Object, bool) { if ok { return refSchemaType.referencedObjectCache, true } + // Next, try scope schema. + scopeSchemaType, ok := typeOrData.(*ScopeSchema) + if ok { + return scopeSchemaType.Objects()[scopeSchemaType.Root()], true + } // Try getting the inlined ObjectSchema for objects, like TypedObjectSchema, that do that. value := reflect.ValueOf(typeOrData) if reflect.Indirect(value).Kind() == reflect.Struct { diff --git a/schema/object_test.go b/schema/object_test.go index aa73da1..e329af3 100644 --- a/schema/object_test.go +++ b/schema/object_test.go @@ -518,6 +518,9 @@ func TestObjectSchema_ValidateCompatibility(t *testing.T) { objectTestRef.ApplyScope(testStructScope) assert.NoError(t, objectTestRef.ValidateCompatibility(testStructSchema)) assert.NoError(t, testStructSchema.ValidateCompatibility(objectTestRef)) + // Schema validation with scope + testStructScopeSchema := schema.NewScopeSchema(&testStructSchema.ObjectSchema) + assert.NoError(t, objectTestRef.ValidateCompatibility(testStructScopeSchema)) // map verification validData := map[string]any{