julianpeeters / avrohugger

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

Optionally limit the depth of nested schemas to reduce number of superfluous imports #120

Closed karolchmist closed 5 years ago

karolchmist commented 5 years ago

We have nested records that produce two classes, Outer and Inner. If the Inner class uses a class from a different package, it would import it. However, the Outer class would import it as well with the current version of avrohugger.

This produces warnings in scala compiler if flag -Ywarn-unused-import:true is used.

This PR fixes it by providing an option to limit the depths that the Importer would go searching for imports of dependent schemas.

The new tests add a case for this scenario. Without this PR, those that would fail because the BarOuter class would have import example.importing.nested.foo.Status.

karolchmist commented 5 years ago

The tests in avrohugger and sbt-avrohugger pass.

karolchmist commented 5 years ago

Maybe there is a better way to achieve it, but that's my naïve approach.

It makes sense to me though to look for imports only at one depth level, since we don't care about indirect dependencies in this case.

karolchmist commented 5 years ago

Closing since it won't be merged