Skip to content

Commit

Permalink
Merge pull request #317 from goshacodes/fix_compat
Browse files Browse the repository at this point in the history
fix field style compatibility
  • Loading branch information
dos65 authored Sep 23, 2024
2 parents 8f2a09d + e1ddfc9 commit 16c3f2f
Show file tree
Hide file tree
Showing 3 changed files with 35 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,26 @@ 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 16c3f2f

Please sign in to comment.