Skip to content

Commit

Permalink
Fixed ValidateCompatibility with scopes into an object schema (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredoconnell authored Jan 17, 2024
1 parent 870c2cf commit f5ab86d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions schema/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions schema/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit f5ab86d

Please sign in to comment.