Skip to content

Commit 3bfe499

Browse files
authored
Merge pull request #3 from ChetanBhasin/META-13447-camelCaseWarn
META-13447: Generator Should Produce Came Case Warnings For Fields That Will Be Disregarded By JSON Ser
2 parents bb4463b + 50291d0 commit 3bfe499

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

openapi-scala/src/main/scala/com/enfore/apis/ast/ASTTranslationFunctions.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import com.enfore.apis.repr.TypeRepr._
99
import com.enfore.apis.repr._
1010

1111
import scala.collection.immutable
12+
import scala.util.matching.Regex
1213

1314
object ASTTranslationFunctions {
1415

16+
val camelCaseExpr: Regex = "(([^_A-Z])([A-Z])+)".r
17+
1518
final case class PackageName(name: String)
1619

1720
// Helper functions
@@ -271,6 +274,8 @@ object ASTTranslationFunctions {
271274
): Option[NewType] = {
272275
val mapped: immutable.Iterable[Option[Symbol]] = properties map {
273276
case (name: String, repr: SchemaOrReferenceObject) =>
277+
if (camelCaseExpr.findAllIn(name).nonEmpty)
278+
println(s"[WARN] You are using camel case name in $name. JSON serialiser will only respect snake cases.")
274279
val loaded: Option[TypeRepr] = getTypeRepr(required, name, repr, allSchemas)
275280
assert(loaded.isDefined, s"$name in $typeName could not be parsed.")
276281
loaded map (makeSymbolFromTypeRepr(name, _))

openapi-scala/src/test/scala/com/enfore/apis/ast/AstTranslationSpec.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,4 +616,13 @@ class AstTranslationSpec extends AnyFlatSpec with Matchers {
616616
filtered.get("regularComponent") shouldBe components.get("regularComponent")
617617
}
618618

619+
"Helper functions" should "ensure that a warning is produced on camelCase strings" in {
620+
val expr = ASTTranslationFunctions.camelCaseExpr
621+
622+
expr.findAllIn("myCamelCase").toList shouldBe List("yC", "lC")
623+
expr.findAllIn("SimpleCase").toList shouldBe List("eC")
624+
expr.findAllIn("myMix_case_Expr").toList shouldBe List("yM")
625+
expr.findAllIn("my_snake_case").toList shouldBe List()
626+
}
627+
619628
}

0 commit comments

Comments
 (0)