castle
castle copied to clipboard
Fix union full name typing
The algorithm for generating Avro Union types did not match the Avro specification: https://avro.apache.org/docs/1.11.1/specification/#names
Issue: Union properties with additional "undefined" namespace in the property name.
export interface RootRecord {
unionField: {
"undefined.RecordANamespace.SomeRecordA": RecordANamespaceSomeRecordA;
"undefined.RecordBNamespace.SomeRecordB"?: never;
} | {
"undefined.RecordANamespace.SomeRecordA"?: never;
"undefined.RecordBNamespace.SomeRecordB": RecordBNamespaceSomeRecordB;
};
}
When did this occur
- When there was no namespace provided anywhere
- When the union records/enums used a full name (including dots)
Example:
{
"type": "record",
"name": "RootRecord",
"fields": [
{
"name": "unionField",
"type": [
{
"type": "record",
"name": "RecordANamespace.SomeRecordA",
"fields": [
{
"name": "someRecordAField",
"type": "string"
}
]
},
{
"type": "record",
"name": "RecordBNamespace.SomeRecordB",
"fields": [
{
"name": "someRecordBField",
"type": "string"
}
]
}
]
}
]
}
Tests
I have added tests that use the avsc
library encoding/decoding to confirm that the fix actually matches the avsc
implementation.