From e0f083bc802350e2f665feebe9b7c1ace12a713e Mon Sep 17 00:00:00 2001 From: Scala Steward Date: Thu, 29 Aug 2024 19:17:18 +0000 Subject: [PATCH 01/16] Update sbt-scalafmt to 2.5.2 --- project/plugins.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/plugins.sbt b/project/plugins.sbt index e251e47..8556b9d 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,3 +1,3 @@ addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.4") addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12") -addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2") From b44450d8189a8a12ec4c43126726c90409fd1f89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D0=B2=D0=B0=D0=BB=D0=B5=D0=B2=20=D0=93=D0=B5?= =?UTF-8?q?=D0=BE=D1=80=D0=B3=D0=B8=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2=D0=B8=D1=87?= Date: Sun, 1 Sep 2024 14:33:14 +0500 Subject: [PATCH 02/16] fixed readme --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 71d9e97..5bc077f 100644 --- a/README.md +++ b/README.md @@ -210,9 +210,9 @@ json.jsonAs[Session] == Right(session) session.asJson == json ``` -## Sealed traits and enums +### Sealed traits and enums To derive **JsonReader** you **must** provide a discriminator. -This can be done via **selector** annotation +This can be done via **selector** annotation. Discriminator for **JsonWriter** is optional. If you don't need readers/writers for subtypes, you can omit them, @@ -388,7 +388,7 @@ case object Direction extends Enum[Direction] ### migration notes When migrating to **scala 3** you should use **0.28.1** version. -Scala 3 derivation API in **1.0.0** has a lot of deprecations and is not fully compatible with **0.28.1**, including: +Scala 3 derivation API in **0.29.0** has a lot of deprecations and is not fully compatible in compile time with **0.28.4**, including: 1. **WriterDescription** and **ReaderDescription** are deprecated along with **describe** macro. You can use **WriterBuilder** and **ReaderBuilder** directly instead @@ -407,7 +407,7 @@ Scala 3 derivation API in **1.0.0** has a lot of deprecations and is not fully c .extract(_.i).from(_.d).and[Double]("e")((d, e) => (d + e).toInt) ``` -3. **0.28.1 scala 3 enum support** will not compile to prevent runtime effects during migration +3. **0.28.4 scala 3 enum support** will not compile to prevent runtime effects during migration 4. `updatePartial` for **WriterBuilder** is deprecated. You can use ```update``` instead @@ -417,7 +417,7 @@ Scala 3 derivation API in **1.0.0** has a lot of deprecations and is not fully c * WriterBuilder * ReaderBuilder -6. **auto** derivation is removed +6. **auto** derivation is deprecated and not compile for recursive types. Use derives on toplevel type instead ### Quick start From 545095efd8687c0124dc48cede14db93df1a6c5a Mon Sep 17 00:00:00 2001 From: Vadim Chelyshov Date: Tue, 3 Sep 2024 13:00:53 +0400 Subject: [PATCH 03/16] docs_additions (#5) Co-authored-by: Vadim Chelyshov --- README.md | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5bc077f..abd995c 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,13 @@ It's advantages: * Configurable recursive semiauto derivation * Discriminator support for sum types derivation - +Read more about library usage bellow: +- [Scala 3](https://github.com/tethys-json/tethys?tab=readme-ov-file#scala-3) +- [Scala 2](https://github.com/tethys-json/tethys?tab=readme-ov-file#scala-2) + + +# Scala 3 + ## Quick start ```scala @@ -383,15 +389,14 @@ case object Direction extends Enum[Direction] ``` -## scala 2 +### Migration notes -### migration notes -When migrating to **scala 3** you should use **0.28.1** version. +When migrating to **scala 3** you should use **0.29.0** version. Scala 3 derivation API in **0.29.0** has a lot of deprecations and is not fully compatible in compile time with **0.28.4**, including: 1. **WriterDescription** and **ReaderDescription** are deprecated along with **describe** macro. - You can use **WriterBuilder** and **ReaderBuilder** directly instead + Use **WriterBuilder** and **ReaderBuilder** directly instead 2. **DependentField** model for **ReaderBuilder** has changed. @@ -407,20 +412,21 @@ Scala 3 derivation API in **0.29.0** has a lot of deprecations and is not fully .extract(_.i).from(_.d).and[Double]("e")((d, e) => (d + e).toInt) ``` -3. **0.28.4 scala 3 enum support** will not compile to prevent runtime effects during migration +3. **0.28.4 scala 3 enum support** was changed. [See more](https://github.com/tethys-json/tethys?tab=readme-ov-file#basic-enums) -4. `updatePartial` for **WriterBuilder** is deprecated. You can use ```update``` instead +4. `updatePartial` for **WriterBuilder** is deprecated. Use ```update``` instead -5. all derivation api is moved directly into core module in **tethys** package, including +5. all derivation api were moved directly into core module in **tethys** package, including * FieldStyle * WriterBuilder * ReaderBuilder -6. **auto** derivation is deprecated and not compile for recursive types. Use derives on toplevel type instead +6. **auto** derivation is deprecated. Use derives on toplevel type instead +# Scala 2 -### Quick start +## Quick start Add dependencies to your `build.sbt` ```scala From 3034857ea5c06d82b6e3a1fdbec847a7a0848934 Mon Sep 17 00:00:00 2001 From: Scala Steward Date: Fri, 6 Sep 2024 19:06:57 +0000 Subject: [PATCH 04/16] Update circe-core to 0.14.10 --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index a15dbc9..7283ee0 100644 --- a/build.sbt +++ b/build.sbt @@ -195,7 +195,7 @@ lazy val circe = project .settings( name := "tethys-circe", libraryDependencies ++= Seq( - "io.circe" %% "circe-core" % "0.14.8" + "io.circe" %% "circe-core" % "0.14.10" ) ) .dependsOn(core, `jackson-212` % Test) From 78cc34b920cb1f3d6c39ffbaec788fc1c0682158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D0=B2=D0=B0=D0=BB=D0=B5=D0=B2=20=D0=93=D0=B5?= =?UTF-8?q?=D0=BE=D1=80=D0=B3=D0=B8=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2=D0=B8=D1=87?= Date: Mon, 23 Sep 2024 13:26:57 +0500 Subject: [PATCH 05/16] fix field style compatibility --- .../derivation/ConfigurationMacroUtils.scala | 12 ++++++++++++ .../tethys/derivation/builder/FieldStyle.scala | 3 +++ .../SemiautoReaderDerivationTest.scala | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/modules/core/src/main/scala-3/tethys/derivation/ConfigurationMacroUtils.scala b/modules/core/src/main/scala-3/tethys/derivation/ConfigurationMacroUtils.scala index 2ec0bae..b4193ba 100644 --- a/modules/core/src/main/scala-3/tethys/derivation/ConfigurationMacroUtils.scala +++ b/modules/core/src/main/scala-3/tethys/derivation/ConfigurationMacroUtils.scala @@ -1148,6 +1148,18 @@ trait ConfigurationMacroUtils: Some(FieldStyle.CapitalizedSnakeCase) case '{ tethys.derivation.builder.FieldStyle.capitalizedSnakeCase } => Some(FieldStyle.CapitalizedSnakeCase) + case '{ tethys.derivation.builder.FieldStyle.snakecase } => + Some(FieldStyle.SnakeCase) + case '{ tethys.derivation.builder.FieldStyle.kebabcase } => + Some(FieldStyle.KebabCase) + case '{ tethys.derivation.builder.FieldStyle.lowerSnakecase } => + Some(FieldStyle.LowerSnakeCase) + case '{ tethys.derivation.builder.FieldStyle.lowerKebabcase } => + Some(FieldStyle.LowerKebabCase) + case '{ tethys.derivation.builder.FieldStyle.upperSnakecase } => + Some(FieldStyle.UpperSnakeCase) + case '{ tethys.derivation.builder.FieldStyle.upperKebabcase } => + Some(FieldStyle.UpperKebabCase) case _ => None @deprecated diff --git a/modules/core/src/main/scala-3/tethys/derivation/builder/FieldStyle.scala b/modules/core/src/main/scala-3/tethys/derivation/builder/FieldStyle.scala index 8b29e5c..c7001b7 100644 --- a/modules/core/src/main/scala-3/tethys/derivation/builder/FieldStyle.scala +++ b/modules/core/src/main/scala-3/tethys/derivation/builder/FieldStyle.scala @@ -13,4 +13,7 @@ enum FieldStyle { case capitalize, uncapitalize, lowercase, uppercase case kebabCase, lowerKebabCase, upperKebabCase, capitalizedKebabCase case snakeCase, lowerSnakeCase, upperSnakeCase, capitalizedSnakeCase + + case kebabcase, lowerKebabcase, upperKebabcase + case snakecase, lowerSnakecase, upperSnakecase } diff --git a/modules/macro-derivation/src/test/scala-3/tethys/derivation/SemiautoReaderDerivationTest.scala b/modules/macro-derivation/src/test/scala-3/tethys/derivation/SemiautoReaderDerivationTest.scala index 573a03d..25951ad 100644 --- a/modules/macro-derivation/src/test/scala-3/tethys/derivation/SemiautoReaderDerivationTest.scala +++ b/modules/macro-derivation/src/test/scala-3/tethys/derivation/SemiautoReaderDerivationTest.scala @@ -435,6 +435,24 @@ class SemiautoReaderDerivationTest extends AnyFlatSpec with Matchers { ) } + it should "derive reader for fieldStyle from description 3" in { + given JsonReader[CamelCaseNames] = JsonReader.derived[CamelCaseNames] { + ReaderDerivationConfig.empty.withFieldStyle(tethys.derivation.builder.FieldStyle.lowerSnakecase) + } + + read[CamelCaseNames]( + obj( + "some_param" -> 1, + "id_param" -> 2, + "simple" -> 3 + ) + ) shouldBe CamelCaseNames( + someParam = 1, + IDParam = 2, + simple = 3 + ) + } + it should "derive strict reader" in { implicit val reader: JsonReader[CamelCaseNames] = jsonReader[CamelCaseNames]( From e1ddfc9cb81e33edd50eee174a3df2961aeba024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D0=B2=D0=B0=D0=BB=D0=B5=D0=B2=20=D0=93=D0=B5?= =?UTF-8?q?=D0=BE=D1=80=D0=B3=D0=B8=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2=D0=B8=D1=87?= Date: Mon, 23 Sep 2024 13:29:21 +0500 Subject: [PATCH 06/16] fix field style compatibility --- .../main/scala-3/tethys/derivation/builder/FieldStyle.scala | 2 +- .../tethys/derivation/SemiautoReaderDerivationTest.scala | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/scala-3/tethys/derivation/builder/FieldStyle.scala b/modules/core/src/main/scala-3/tethys/derivation/builder/FieldStyle.scala index c7001b7..bad9393 100644 --- a/modules/core/src/main/scala-3/tethys/derivation/builder/FieldStyle.scala +++ b/modules/core/src/main/scala-3/tethys/derivation/builder/FieldStyle.scala @@ -13,7 +13,7 @@ enum FieldStyle { case capitalize, uncapitalize, lowercase, uppercase case kebabCase, lowerKebabCase, upperKebabCase, capitalizedKebabCase case snakeCase, lowerSnakeCase, upperSnakeCase, capitalizedSnakeCase - + case kebabcase, lowerKebabcase, upperKebabcase case snakecase, lowerSnakecase, upperSnakecase } diff --git a/modules/macro-derivation/src/test/scala-3/tethys/derivation/SemiautoReaderDerivationTest.scala b/modules/macro-derivation/src/test/scala-3/tethys/derivation/SemiautoReaderDerivationTest.scala index 25951ad..27d164b 100644 --- a/modules/macro-derivation/src/test/scala-3/tethys/derivation/SemiautoReaderDerivationTest.scala +++ b/modules/macro-derivation/src/test/scala-3/tethys/derivation/SemiautoReaderDerivationTest.scala @@ -437,7 +437,9 @@ class SemiautoReaderDerivationTest extends AnyFlatSpec with Matchers { it should "derive reader for fieldStyle from description 3" in { given JsonReader[CamelCaseNames] = JsonReader.derived[CamelCaseNames] { - ReaderDerivationConfig.empty.withFieldStyle(tethys.derivation.builder.FieldStyle.lowerSnakecase) + ReaderDerivationConfig.empty.withFieldStyle( + tethys.derivation.builder.FieldStyle.lowerSnakecase + ) } read[CamelCaseNames]( From 4adea7228420dc7d0a886f1275e60f6a2e05400e Mon Sep 17 00:00:00 2001 From: Scala Steward Date: Thu, 26 Sep 2024 19:30:54 +0000 Subject: [PATCH 07/16] Update scala-library, scala-reflect to 2.13.15 --- .github/workflows/scala.yml | 2 +- build.sbt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scala.yml b/.github/workflows/scala.yml index e75e6a3..ade36c4 100644 --- a/.github/workflows/scala.yml +++ b/.github/workflows/scala.yml @@ -14,7 +14,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - scala: [2.12.19, 2.13.14, 3.3.0] + scala: [2.12.19, 2.13.15, 3.3.0] steps: - uses: actions/checkout@v4 diff --git a/build.sbt b/build.sbt index a15dbc9..ee6b133 100644 --- a/build.sbt +++ b/build.sbt @@ -1,5 +1,5 @@ lazy val scala212 = "2.12.19" -lazy val scala213 = "2.13.14" +lazy val scala213 = "2.13.15" /* FIXME Return to use a stable version when 'scala.quoted.Quotes.reflectModuleSymbol.newClass' and 'scala.quoted.Quotes.reflectModule.ClassDef.apply' are no longer experimental methods From 3669227518b6d407b218d02584bc9c269518bbfe Mon Sep 17 00:00:00 2001 From: Scala Steward Date: Sun, 29 Sep 2024 00:57:26 +0000 Subject: [PATCH 08/16] Update scala3-library to 3.3.4 --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index a15dbc9..ba519b7 100644 --- a/build.sbt +++ b/build.sbt @@ -4,7 +4,7 @@ lazy val scala213 = "2.13.14" Return to use a stable version when 'scala.quoted.Quotes.reflectModuleSymbol.newClass' and 'scala.quoted.Quotes.reflectModule.ClassDef.apply' are no longer experimental methods */ -lazy val scala3 = "3.3.0" +lazy val scala3 = "3.3.4" ThisBuild / scalaVersion := scala3 From 9c3bf62ae2f6d8bbc40c21d06fe9c1ca7615538d Mon Sep 17 00:00:00 2001 From: Scala Steward Date: Fri, 4 Oct 2024 18:59:36 +0000 Subject: [PATCH 09/16] Update enumeratum to 1.7.5 --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index a15dbc9..e03d008 100644 --- a/build.sbt +++ b/build.sbt @@ -223,7 +223,7 @@ lazy val enumeratum = project libraryDependencies ++= { CrossVersion.partialVersion(scalaVersion.value) match { case Some((2, y)) => - Seq("com.beachape" %% "enumeratum" % "1.7.3") + Seq("com.beachape" %% "enumeratum" % "1.7.5") case _ => Seq.empty } } From 613d1700d744ebd32ece03fe8a66daddbdf3288e Mon Sep 17 00:00:00 2001 From: Scala Steward Date: Wed, 23 Oct 2024 00:07:59 +0000 Subject: [PATCH 10/16] Update sbt-ci-release to 1.9.0 --- project/plugins.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/plugins.sbt b/project/plugins.sbt index e251e47..ab1bd70 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,3 +1,3 @@ addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.4") -addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12") +addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.9.0") addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6") From 0c971ccfcf555638179f29297296c9854c97a3f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D0=B2=D0=B0=D0=BB=D0=B5=D0=B2=20=D0=93=D0=B5?= =?UTF-8?q?=D0=BE=D1=80=D0=B3=D0=B8=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2=D0=B8=D1=87?= Date: Wed, 23 Oct 2024 22:29:48 +0500 Subject: [PATCH 11/16] fixed incorrect (but working) writer/reader generation for complex sum types --- .../scala-3/tethys/derivation/ConfigurationMacroUtils.scala | 2 +- .../core/src/main/scala-3/tethys/derivation/Derivation.scala | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/core/src/main/scala-3/tethys/derivation/ConfigurationMacroUtils.scala b/modules/core/src/main/scala-3/tethys/derivation/ConfigurationMacroUtils.scala index b4193ba..519b8c7 100644 --- a/modules/core/src/main/scala-3/tethys/derivation/ConfigurationMacroUtils.scala +++ b/modules/core/src/main/scala-3/tethys/derivation/ConfigurationMacroUtils.scala @@ -689,7 +689,7 @@ trait ConfigurationMacroUtils: ) ) - val discriminators: List[Term] = getAllChildren(tpe).map { + val discriminators: List[Term] = getAllChildren(tpe).distinct.map { case tpe: TypeRef => Select(stub(tpe), symbol) case tpe: TermRef => diff --git a/modules/core/src/main/scala-3/tethys/derivation/Derivation.scala b/modules/core/src/main/scala-3/tethys/derivation/Derivation.scala index 688c9bc..234ae70 100644 --- a/modules/core/src/main/scala-3/tethys/derivation/Derivation.scala +++ b/modules/core/src/main/scala-3/tethys/derivation/Derivation.scala @@ -149,7 +149,7 @@ private[derivation] class DerivationMacro(val quotes: Quotes) ): Expr[JsonObjectWriter[T]] = val tpe = TypeRepr.of[T] val parsedConfig = parseSumConfig[T] - val types = getAllChildren(tpe) + val types = getAllChildren(tpe).distinct val (missingWriters, refs) = deriveMissingWritersForSum(types) val mirror = '{ summonInline[Mirror.SumOf[T]] } val writer = Block( @@ -492,7 +492,7 @@ private[derivation] class DerivationMacro(val quotes: Quotes) def deriveJsonReaderForSum[T: Type]: Expr[JsonReader[T]] = val tpe = TypeRepr.of[T] val parsed = parseSumConfig[T] - val children = getAllChildren(tpe) + val children = getAllChildren(tpe).distinct parsed.discriminator match case Some(DiscriminatorConfig(label, tpe, discriminators)) => tpe.asType match From aa560cb79d9c3960728009766b70832746ba0ed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D0=B2=D0=B0=D0=BB=D0=B5=D0=B2=20=D0=93=D0=B5?= =?UTF-8?q?=D0=BE=D1=80=D0=B3=D0=B8=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2=D0=B8=D1=87?= Date: Wed, 23 Oct 2024 22:58:17 +0500 Subject: [PATCH 12/16] fixed incorrect (but working) writer/reader generation for complex sum types --- .../derivation/ConfigurationMacroUtils.scala | 26 ++++++++++--------- .../tethys/derivation/Derivation.scala | 4 +-- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/modules/core/src/main/scala-3/tethys/derivation/ConfigurationMacroUtils.scala b/modules/core/src/main/scala-3/tethys/derivation/ConfigurationMacroUtils.scala index 519b8c7..7f57a5d 100644 --- a/modules/core/src/main/scala-3/tethys/derivation/ConfigurationMacroUtils.scala +++ b/modules/core/src/main/scala-3/tethys/derivation/ConfigurationMacroUtils.scala @@ -689,7 +689,7 @@ trait ConfigurationMacroUtils: ) ) - val discriminators: List[Term] = getAllChildren(tpe).distinct.map { + val discriminators: List[Term] = getAllChildren(tpe).map { case tpe: TypeRef => Select(stub(tpe), symbol) case tpe: TermRef => @@ -752,17 +752,19 @@ trait ConfigurationMacroUtils: case '[t *: ts] => TypeRepr.of[t] :: typeReprsOf[ts] def getAllChildren(tpe: TypeRepr): List[TypeRepr] = - tpe.asType match - case '[t] => - Expr.summon[scala.deriving.Mirror.Of[t]] match - case Some('{ - $m: scala.deriving.Mirror.SumOf[t] { - type MirroredElemTypes = subs - } - }) => - typeReprsOf[subs].flatMap(getAllChildren) - case _ => - List(tpe) + def loop(tpe: TypeRepr): List[TypeRepr] = + tpe.asType match + case '[t] => + Expr.summon[scala.deriving.Mirror.Of[t]] match + case Some('{ + $m: scala.deriving.Mirror.SumOf[t] { + type MirroredElemTypes = subs + } + }) => + typeReprsOf[subs].flatMap(loop) + case _ => + List(tpe) + loop(tpe).distinct case class SelectedField(name: String, selector: Term) diff --git a/modules/core/src/main/scala-3/tethys/derivation/Derivation.scala b/modules/core/src/main/scala-3/tethys/derivation/Derivation.scala index 234ae70..688c9bc 100644 --- a/modules/core/src/main/scala-3/tethys/derivation/Derivation.scala +++ b/modules/core/src/main/scala-3/tethys/derivation/Derivation.scala @@ -149,7 +149,7 @@ private[derivation] class DerivationMacro(val quotes: Quotes) ): Expr[JsonObjectWriter[T]] = val tpe = TypeRepr.of[T] val parsedConfig = parseSumConfig[T] - val types = getAllChildren(tpe).distinct + val types = getAllChildren(tpe) val (missingWriters, refs) = deriveMissingWritersForSum(types) val mirror = '{ summonInline[Mirror.SumOf[T]] } val writer = Block( @@ -492,7 +492,7 @@ private[derivation] class DerivationMacro(val quotes: Quotes) def deriveJsonReaderForSum[T: Type]: Expr[JsonReader[T]] = val tpe = TypeRepr.of[T] val parsed = parseSumConfig[T] - val children = getAllChildren(tpe).distinct + val children = getAllChildren(tpe) parsed.discriminator match case Some(DiscriminatorConfig(label, tpe, discriminators)) => tpe.asType match From 216429701490ddb441efb50506739480b2712ad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D0=B2=D0=B0=D0=BB=D0=B5=D0=B2=20=D0=93=D0=B5?= =?UTF-8?q?=D0=BE=D1=80=D0=B3=D0=B8=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2=D0=B8=D1=87?= Date: Mon, 11 Nov 2024 10:24:57 +0500 Subject: [PATCH 13/16] make tethys.FieldStyle companion non private --- modules/core/src/main/scala-3/tethys/FieldStyle.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/scala-3/tethys/FieldStyle.scala b/modules/core/src/main/scala-3/tethys/FieldStyle.scala index ded1b2b..ae9abe4 100644 --- a/modules/core/src/main/scala-3/tethys/FieldStyle.scala +++ b/modules/core/src/main/scala-3/tethys/FieldStyle.scala @@ -10,7 +10,7 @@ enum FieldStyle { case SnakeCase, LowerSnakeCase, UpperSnakeCase, CapitalizedSnakeCase } -private[tethys] object FieldStyle: +object FieldStyle: private val regexp1: Pattern = Pattern.compile("([A-Z]+)([A-Z][a-z])") private val regexp2: Pattern = Pattern.compile("([a-z\\d])([A-Z])") private val replacement: String = "$1_$2" @@ -22,7 +22,7 @@ private[tethys] object FieldStyle: private val lowercase: String => String = _.toLowerCase() private val uppercase: String => String = _.toUpperCase() - def applyStyle(string: String, style: FieldStyle): String = + private[tethys] def applyStyle(string: String, style: FieldStyle): String = style match case FieldStyle.Capitalize => capitalize(string) case FieldStyle.Uncapitalize => uncapitalize(string) From 94ee3bb43f0aa7eb6bfae103f4b7843f5bccf6b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D0=B2=D0=B0=D0=BB=D0=B5=D0=B2=20=D0=93=D0=B5?= =?UTF-8?q?=D0=BE=D1=80=D0=B3=D0=B8=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2=D0=B8=D1=87?= Date: Mon, 11 Nov 2024 10:42:44 +0500 Subject: [PATCH 14/16] fix reader message on missing fields --- .../main/scala-3/tethys/derivation/Derivation.scala | 2 +- .../scala-3/tethys/derivation/DerivationSpec.scala | 9 +++++++++ .../derivation/impl/derivation/ReaderDerivation.scala | 2 +- .../derivation/SemiautoReaderDerivationTest.scala | 11 +++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/scala-3/tethys/derivation/Derivation.scala b/modules/core/src/main/scala-3/tethys/derivation/Derivation.scala index 688c9bc..300eacc 100644 --- a/modules/core/src/main/scala-3/tethys/derivation/Derivation.scala +++ b/modules/core/src/main/scala-3/tethys/derivation/Derivation.scala @@ -398,7 +398,7 @@ private[derivation] class DerivationMacro(val quotes: Quotes) } ReaderError.wrongJson( "Can not extract fields from json: " + uninitializedFields - .mkString(", ") + .mkString("'", "', '", "'") )(${ fieldName }) } diff --git a/modules/core/src/test/scala-3/tethys/derivation/DerivationSpec.scala b/modules/core/src/test/scala-3/tethys/derivation/DerivationSpec.scala index 981dac1..5571234 100644 --- a/modules/core/src/test/scala-3/tethys/derivation/DerivationSpec.scala +++ b/modules/core/src/test/scala-3/tethys/derivation/DerivationSpec.scala @@ -20,6 +20,15 @@ class DerivationSpec extends AnyFlatSpec with Matchers { res } + it should "build message correctly" in { + case class Foo(bar: Int, baz: String, faz: Boolean) derives JsonReader + + util.Try(read[Foo](obj("bar" -> 1))) should matchPattern { + case util.Failure(ex) + if ex.getMessage == """Illegal json at '[ROOT]': Can not extract fields from json: 'baz', 'faz'""" => + } + } + it should "compile and correctly write and read product" in { case class Person( id: Int, diff --git a/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/derivation/ReaderDerivation.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/derivation/ReaderDerivation.scala index 2709dc0..37a7e40 100644 --- a/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/derivation/ReaderDerivation.scala +++ b/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/derivation/ReaderDerivation.scala @@ -459,7 +459,7 @@ trait ReaderDerivation if($predicate) { val $uninitializedFields = new scala.collection.mutable.ArrayBuffer[String](${xs.size}) ..$fields - $readerErrorCompanion.wrongJson("Can not extract fields from json" + $uninitializedFields.mkString("'", "', '", "'")) + $readerErrorCompanion.wrongJson("Can not extract fields from json: " + $uninitializedFields.mkString("'", "', '", "'")) } """ } diff --git a/modules/macro-derivation/src/test/scala-2.13+/tethys/derivation/SemiautoReaderDerivationTest.scala b/modules/macro-derivation/src/test/scala-2.13+/tethys/derivation/SemiautoReaderDerivationTest.scala index e1ea2cc..88faccb 100644 --- a/modules/macro-derivation/src/test/scala-2.13+/tethys/derivation/SemiautoReaderDerivationTest.scala +++ b/modules/macro-derivation/src/test/scala-2.13+/tethys/derivation/SemiautoReaderDerivationTest.scala @@ -21,6 +21,17 @@ class SemiautoReaderDerivationTest extends AnyFlatSpec with Matchers { behavior of "semiauto derivation" + + it should "build message correctly" in { + case class Foo(bar: Int, baz: String, faz: Boolean) + + implicit val reader: JsonReader[Foo] = tethys.derivation.semiauto.jsonReader + + util.Try(read[Foo](obj("bar" -> 1))) should matchPattern { + case util.Failure(ex) if ex.getMessage == """Illegal json at '[ROOT]': Can not extract fields from json: 'baz', 'faz'""" => + } + } + it should "derive readers for simple case class hierarchy" in { implicit val dReader: JsonReader[D] = jsonReader[D] implicit val cReader: JsonReader[C] = jsonReader[C] From 5ac7a3dde5176f5bd91004297966ebe5159feb75 Mon Sep 17 00:00:00 2001 From: Vadim Chelyshov Date: Mon, 11 Nov 2024 14:08:17 +0300 Subject: [PATCH 15/16] fix: proper scala3 version in workflows --- .github/workflows/scala.yml | 2 +- build.sbt | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/scala.yml b/.github/workflows/scala.yml index ade36c4..d56f9cf 100644 --- a/.github/workflows/scala.yml +++ b/.github/workflows/scala.yml @@ -14,7 +14,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - scala: [2.12.19, 2.13.15, 3.3.0] + scala: [2.12.19, 2.13.15, 3.3.4] steps: - uses: actions/checkout@v4 diff --git a/build.sbt b/build.sbt index 381ff06..c591467 100644 --- a/build.sbt +++ b/build.sbt @@ -1,9 +1,5 @@ lazy val scala212 = "2.12.19" lazy val scala213 = "2.13.15" -/* FIXME -Return to use a stable version when 'scala.quoted.Quotes.reflectModuleSymbol.newClass' -and 'scala.quoted.Quotes.reflectModule.ClassDef.apply' are no longer experimental methods - */ lazy val scala3 = "3.3.4" ThisBuild / scalaVersion := scala3 From e8f24f1ee3368c65a9edbccc1fe8595ccd381b05 Mon Sep 17 00:00:00 2001 From: Vadim Chelyshov Date: Mon, 11 Nov 2024 14:09:34 +0300 Subject: [PATCH 16/16] upgrade: scala 2.12.20 --- .github/workflows/scala.yml | 2 +- build.sbt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scala.yml b/.github/workflows/scala.yml index d56f9cf..bf5a6c5 100644 --- a/.github/workflows/scala.yml +++ b/.github/workflows/scala.yml @@ -14,7 +14,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - scala: [2.12.19, 2.13.15, 3.3.4] + scala: [2.12.20, 2.13.15, 3.3.4] steps: - uses: actions/checkout@v4 diff --git a/build.sbt b/build.sbt index c591467..6efc06c 100644 --- a/build.sbt +++ b/build.sbt @@ -1,4 +1,4 @@ -lazy val scala212 = "2.12.19" +lazy val scala212 = "2.12.20" lazy val scala213 = "2.13.15" lazy val scala3 = "3.3.4"