Skip to content

Commit

Permalink
fix field style compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Ковалев Георгий Алексеевич committed Sep 23, 2024
1 parent 7370dd6 commit 78cc34b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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](
Expand Down

0 comments on commit 78cc34b

Please sign in to comment.