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

Alias clashes #19

Open
cpiemontese opened this issue Nov 18, 2024 · 0 comments
Open

Alias clashes #19

cpiemontese opened this issue Nov 18, 2024 · 0 comments

Comments

@cpiemontese
Copy link
Contributor

Here's a snippet of an Avro schema definition:

fields: [
  %{
    type: [:null, @v1_namespace_prefix <> ".example.MetaData"],
    default: nil,
    name: :metadata,
    doc: "Metadata for example - to be deprecated"
  },
  %{
    type: %{type: :array, items: @v2_namespace_prefix <> ".example.MetaData"},
    name: :metadata_records,
    doc:
      "A list of one metadata for each example in this chain, sorted chronologically (earliest first)."
  },
  ...
]

This generates the following aliases:

alias Schema.Generated.Prefix.V1.Example.MetaData
alias Schema.Generated.Prefix.V2.Example.MetaData

Due to the name clash of the last module part (MetaData), the first alias is overridden.
The generated code actually always expects V2 MetaData despite the avro schema itself expecting V1:

"fields": [
  {
    "name": "metadata",
    "type": [
      "null",
      "schema.v1.example.MetaData"
    ]
  },
  {
    "name": "metadata_records",
    "type": {
      "items": "schema.v2.example.MetaData",
      "type": "array"
    }
  },
  ...
],

We need to either

  • contrive names to not clash, or
  • fix the code in avrogen's lib/avrogen/avro/types/record.ex to make and use aliases that don't clash or
  • just don't use aliases at all.

Related cards:

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

No branches or pull requests

1 participant