Skip to content

Commit

Permalink
Test AvroName annotation in scala 3, fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bplommer committed Mar 9, 2022
1 parent 6f4dba0 commit 0114a25
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 48 deletions.
86 changes: 44 additions & 42 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -209,48 +209,50 @@ lazy val buildInfoSettings = Seq(
buildInfoPackage := "vulcan.build",
buildInfoObject := "info",
buildInfoKeys := {
val magnolia: String = if (scalaVersion.value.startsWith("3")) magnolia3Version else magnolia2Version
Seq[BuildInfoKey](
scalaVersion,
scalacOptions,
sourceDirectory,
ThisBuild / latestVersion,
BuildInfoKey.map(ThisBuild / version) {
case (_, v) => "latestSnapshotVersion" -> v
},
BuildInfoKey.map(core / moduleName) {
case (k, v) => "core" ++ k.capitalize -> v
},
BuildInfoKey.map(core / crossScalaVersions) {
case (k, v) => "core" ++ k.capitalize -> v
},
BuildInfoKey.map(enumeratum / moduleName) {
case (k, v) => "enumeratum" ++ k.capitalize -> v
},
BuildInfoKey.map(enumeratum / crossScalaVersions) {
case (k, v) => "enumeratum" ++ k.capitalize -> v
},
BuildInfoKey.map(generic / moduleName) {
case (k, v) => "generic" ++ k.capitalize -> v
},
BuildInfoKey.map(generic / crossScalaVersions) {
case (k, v) => "generic" ++ k.capitalize -> v
},
BuildInfoKey.map(refined / moduleName) {
case (k, v) => "refined" ++ k.capitalize -> v
},
BuildInfoKey.map(refined / crossScalaVersions) {
case (k, v) => "refined" ++ k.capitalize -> v
},
LocalRootProject / organization,
core / crossScalaVersions,
BuildInfoKey("avroVersion" -> avroVersion),
BuildInfoKey("catsVersion" -> catsVersion),
BuildInfoKey("enumeratumVersion" -> enumeratumVersion),
BuildInfoKey("magnoliaVersion" -> magnolia),
BuildInfoKey("refinedVersion" -> refinedVersion),
BuildInfoKey("shapelessVersion" -> shapelessVersion)
)}
val magnolia: String =
if (scalaVersion.value.startsWith("3")) magnolia3Version else magnolia2Version
Seq[BuildInfoKey](
scalaVersion,
scalacOptions,
sourceDirectory,
ThisBuild / latestVersion,
BuildInfoKey.map(ThisBuild / version) {
case (_, v) => "latestSnapshotVersion" -> v
},
BuildInfoKey.map(core / moduleName) {
case (k, v) => "core" ++ k.capitalize -> v
},
BuildInfoKey.map(core / crossScalaVersions) {
case (k, v) => "core" ++ k.capitalize -> v
},
BuildInfoKey.map(enumeratum / moduleName) {
case (k, v) => "enumeratum" ++ k.capitalize -> v
},
BuildInfoKey.map(enumeratum / crossScalaVersions) {
case (k, v) => "enumeratum" ++ k.capitalize -> v
},
BuildInfoKey.map(generic / moduleName) {
case (k, v) => "generic" ++ k.capitalize -> v
},
BuildInfoKey.map(generic / crossScalaVersions) {
case (k, v) => "generic" ++ k.capitalize -> v
},
BuildInfoKey.map(refined / moduleName) {
case (k, v) => "refined" ++ k.capitalize -> v
},
BuildInfoKey.map(refined / crossScalaVersions) {
case (k, v) => "refined" ++ k.capitalize -> v
},
LocalRootProject / organization,
core / crossScalaVersions,
BuildInfoKey("avroVersion" -> avroVersion),
BuildInfoKey("catsVersion" -> catsVersion),
BuildInfoKey("enumeratumVersion" -> enumeratumVersion),
BuildInfoKey("magnoliaVersion" -> magnolia),
BuildInfoKey("refinedVersion" -> refinedVersion),
BuildInfoKey("shapelessVersion" -> shapelessVersion)
)
}
)

lazy val metadataSettings = Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,14 @@ package object generic {
.collectFirst { case AvroNamespace(namespace) => namespace }
.getOrElse(caseClass.typeName.owner)

val shortName =
caseClass.annotations
.collectFirst { case AvroName(namespace) => namespace }
.getOrElse(caseClass.typeName.short)

val typeName =
s"$namespace.${caseClass.typeName.short}"
s"$namespace.$shortName"

val schema =
if (caseClass.isValueClass) {
caseClass.parameters.head.typeclass.schema
Expand Down
12 changes: 9 additions & 3 deletions modules/generic/src/main/scala-3/vulcan/generic/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ package object generic {
.collectFirst { case AvroNamespace(namespace) => namespace }
.getOrElse(caseClass.typeInfo.owner)

val typeName =
s"$namespace.${caseClass.typeInfo.short}"
val shortName =
caseClass.annotations
.collectFirst { case AvroName(namespace) => namespace }
.getOrElse(caseClass.typeInfo.short)

val typeName =
s"$namespace.$shortName"

val schema =
if (caseClass.isValueClass) {
caseClass.params.head.typeclass.schema
Expand Down Expand Up @@ -67,7 +73,7 @@ package object generic {

fields.map { fields =>
Schema.createRecord(
caseClass.typeInfo.short,
shortName,
caseClass.annotations.collectFirst {
case AvroDoc(doc) => doc
}.orNull,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ object SealedTraitCaseClassAvroNamespace {
: Arbitrary[SealedTraitCaseClassAvroNamespace] =
Arbitrary(
Gen.oneOf(
arbitrary[Int].map(FirstInSealedTraitCaseClassAvroNamespace),
arbitrary[String].map(SecondInSealedTraitCaseClassAvroNamespace)
arbitrary[Int].map(FirstInSealedTraitCaseClassAvroNamespace(_)),
arbitrary[String].map(SecondInSealedTraitCaseClassAvroNamespace(_))
)
)

Expand Down

0 comments on commit 0114a25

Please sign in to comment.