ImFlog/schema-registry-plugin

Duplicate type definitions occur when a reference is used more than once.

chriskn opened this issue · 4 comments

Hi, after updating from version 1.8.0 to 1.10.0 I get the error org.apache.avro.SchemaParseException: Can't redefine: com.mycompany.B when using the same type-reference multiple times in one avro schema.

Given this schema:

{
  "type": "record",
  "name": "A",
  "namespace": "com.mycompany",
  "fields": [
    {
      "name": "nested",
      "type": "B"
    },
    {
      "name": "nested1",
      "type": "B"
    }
  ]
}

which references the following type twice:

{
  "type": "enum",
  "name": "B",
  "namespace": "com.mycompany",
  "symbols" : ["X1", "X2"]
}

Instead of defining the type only once and referencing it, the resulting schema contains two type definitions for B:


                   {
                     "name": "A",
                     "namespace": "com.mycompany",
                     "type": "record",
                     "fields":
                       [
                         {
                           "name": "nested",
                           "type":
                             {
                               "name": "B",
                               "namespace": "com.mycompany",
                               "type": "enum",
                               "symbols": ["X1", "X2"],
                             },
                         },
                         {
                           "name": "nested1",
                           "type":
                             {
                               "name": "B",
                               "namespace": "com.mycompany",
                               "type": "enum",
                               "symbols": ["X1", "X2"],
                             },
                         },
                       ],
                   }

I create this commit to reproduce the issue with 2 tests: chriskn@a6197c3

The issue was introduced with version 1.9.0. Likely with this commit 3507e56

Would be great to get a fix. Thank you!

ImFlog commented

Hello @chriskn,
I think this is the same issue as #126 and a fix would solve both issues.

Thank you for providing reproducing tests, can you open a MR with the commit that contains the tests ? I will update the MR with the fix.

I'll try to find some time ASAP.

PR created: #132

Thank you for the support!

ImFlog commented

@chriskn, I've just released the version 1.11.1. Can you try with this version to see if the issue is fixed ?
NB: It requires to add Jitpack in the build repository because we are now using a custom Avro version.
Thanks

ImFlog commented

Should be good. Thanks for the support.