julianpeeters / avrohugger

Generate Scala case class definitions from Avro schemas
Apache License 2.0
201 stars 120 forks source link

Generating Fixed types is missing imports #155

Closed dr4ke616 closed 2 years ago

dr4ke616 commented 2 years ago

When dealing with avro schema's that rely on fixed types within a different namepspace, the generated code for the standard avrohugger generator is missing an import for that fixed type.

A simple example, where we have a record with a fixed type within a different namespace to the outter.

{
  "type" : "record",
  "name" : "HashRecord",
  "namespace" : "example.shanested.foo",
  "fields" : [
    {
      "name" : "my_hash",
      "type" : [
        {
          "type" : "fixed",
          "name" : "Sha256",
          "namespace" : "example.shanested",
          "size" : 32
        }
      ]
    }
  ]
}

The generated code for the outter HashRecord excludes the required import for the Sha256 record.

/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */
package example.shanested.foo

final case class HashRecord(my_hash: Sha256)
/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */
package example.shanested

final case class Sha256(bytes: Array[Byte])

Note I have not tested in much depth the behaviour for either specific or scavro.