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 784819d..b693b31 100644 --- a/schema/object_test.go +++ b/schema/object_test.go @@ -555,6 +555,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{