julianpeeters / avrohugger

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

avroScalaCustomNamespace regression in 1.4.0+ #176

Closed gafiatulin closed 1 year ago

gafiatulin commented 1 year ago

Changes introduced in https://github.com/julianpeeters/avrohugger/pull/169 might result in generating invalid type references for fields when avroScalaCustomNamespace is used.

For example, using sbt-avrohugger 2.5.1:

Compile / avroScalaCustomNamespace := Map("a.b.c" -> "aa.bb.cc")
Compile / sourceGenerators += (Compile / avroScalaGenerate).taskValue

and

@namespace("a.b.c")

protocol Test{
  record Inner {
    string a;
    long b;
    boolean c;
  }

  record Outer{
    Inner inner;
  }
}

produces:

/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */
package aa.bb.cc

final case class Inner(a: String, b: Long, c: Boolean)

final case class Outer(inner: a.b.c.Inner)

Probably customNamespaces needs to be taken into account when using schema.getFullName here: https://github.com/julianpeeters/avrohugger/blob/main/avrohugger-core/src/main/scala/matchers/TypeMatcher.scala#L69

julianpeeters commented 1 year ago

Thanks for the report, @gafiatulin. I expect to have a fix out in the next few days.

julianpeeters commented 1 year ago

Your example has been added to the tests, and the fix is out now in avrohugger 1.5.2 and sbt-avrohugger 2.5.2