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] 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](