Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix union full name typing #161

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Fix union full name typing #161

wants to merge 1 commit into from

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