Skip to content

Commit

Permalink
fix: fields reference with a full name (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
Khalid-Nowaf authored Aug 13, 2023
1 parent 3a17528 commit b89c9a4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion schema_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func parseRecord(typ Type, namespace string, m map[string]any, cache *SchemaCach
}

for i, f := range r.Fields {
field, err := parseField(r.Namespace, f, cache)
field, err := parseField(rec.namespace, f, cache)
if err != nil {
return nil, err
}
Expand Down
32 changes: 32 additions & 0 deletions schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,38 @@ func TestRecordSchema_WithReference(t *testing.T) {
assert.Equal(t, s.Fingerprint(), s.(*avro.RecordSchema).Fields()[1].Type().Fingerprint())
}

func TestRecordSchema_WithReferenceFullName(t *testing.T) {
schm := `
{
"type": "record",
"name": "org.hamba.avro.ValidName",
"fields": [
{
"name": "recordType1",
"type": {
"name": "refIntType",
"type": "record",
"fields": [
{"name": "intField", "type": "int"}
]
}
},
{
"name": "recordType2",
"type": "org.hamba.avro.refIntType"
}
]
}
`

s, err := avro.Parse(schm)

require.NoError(t, err)
assert.Equal(t, avro.Record, s.Type())
assert.Equal(t, avro.Ref, s.(*avro.RecordSchema).Fields()[1].Type().Type())
assert.Equal(t, s.(*avro.RecordSchema).Fields()[0].Type().Fingerprint(), s.(*avro.RecordSchema).Fields()[1].Type().Fingerprint())
}

func TestRecordSchema_WithAliasReference(t *testing.T) {
schm := `
{
Expand Down

0 comments on commit b89c9a4

Please sign in to comment.