Skip to content

Commit

Permalink
fix: deref the reference schema (#108)
Browse files Browse the repository at this point in the history
When getting the schema type name for a union, a reference schema must be dereferenced before finding the name.
  • Loading branch information
nrwiersma authored Jul 13, 2021
1 parent a432358 commit 4fbe61a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,10 @@ func isValidDefault(schema Schema, def interface{}) (interface{}, bool) {
}

func schemaTypeName(schema Schema) string {
if schema.Type() == Ref {
schema = schema.(*RefSchema).Schema()
}

if n, ok := schema.(NamedSchema); ok {
return n.FullName()
}
Expand Down
6 changes: 6 additions & 0 deletions schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,12 @@ func TestUnionSchema(t *testing.T) {
wantFingerprint: [32]byte{0xb4, 0x94, 0x95, 0xc5, 0xb1, 0xc2, 0x6f, 0x4, 0x89, 0x6a, 0x5f, 0x68, 0x65, 0xf, 0xe2, 0xb7, 0x64, 0x23, 0x62, 0xc3, 0x41, 0x98, 0xd6, 0xbc, 0x74, 0x65, 0xa1, 0xd9, 0xf7, 0xe1, 0xaf, 0xce},
wantErr: false,
},
{
name: "Dereferences Ref Schemas",
schema: `[{"type":"fixed", "name":"test", "namespace": "org.hamba.avro", "size": 12}, {"type":"enum", "name":"test1", "namespace": "org.hamba.avro", "symbols":["TEST"]}, {"type":"record", "name":"test2", "namespace": "org.hamba.avro", "fields":[{"name": "a", "type": ["null","org.hamba.avro.test","org.hamba.avro.test1"]}]}]`,
wantFingerprint: [32]byte{0xc1, 0x42, 0x87, 0xde, 0x24, 0x3d, 0xee, 0x1d, 0xa5, 0x47, 0xa0, 0x13, 0x9e, 0xb, 0xe0, 0x6, 0xfd, 0xa, 0x76, 0xd9, 0xe8, 0x92, 0x9a, 0xd3, 0x46, 0xf, 0xbd, 0x86, 0x21, 0x72, 0x81, 0x1b},
wantErr: false,
},
{
name: "No Nested Union Type",
schema: `["null", ["string"]]`,
Expand Down

0 comments on commit 4fbe61a

Please sign in to comment.