Skip to content

Fix union full name typing#161

Open
zatlodan wants to merge 1 commit intoovotech:mainfrom
zatlodan:main
Open

Fix union full name typing#161
zatlodan wants to merge 1 commit intoovotech:mainfrom
zatlodan:main

Conversation

@zatlodan
Copy link

@zatlodan zatlodan commented Feb 5, 2025

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 zatlodan requested a review from a team as a code owner February 5, 2025 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant