castle icon indicating copy to clipboard operation
castle copied to clipboard

Fix union full name typing

Open zatlodan opened this issue 6 months ago • 2 comments

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.

zatlodan avatar Feb 03 '24 05:02 zatlodan