Skip to content

[scala-http4s] Preserve underscores in enum names#23842

Open
anupamchaubey wants to merge 2 commits into
OpenAPITools:masterfrom
anupamchaubey:fix-scala-http4s-enum-underscores
Open

[scala-http4s] Preserve underscores in enum names#23842
anupamchaubey wants to merge 2 commits into
OpenAPITools:masterfrom
anupamchaubey:fix-scala-http4s-enum-underscores

Conversation

@anupamchaubey
Copy link
Copy Markdown

@anupamchaubey anupamchaubey commented May 21, 2026

Summary

This fixes an issue in the scala-http4s generator where enum entries containing underscores are incorrectly camelized during generation.

For example:

enum:
  - ACTIVE_STATUS

was previously generated as:

ActiveStatus

instead of preserving the valid Scala identifier:

ACTIVE_STATUS

Root Cause

EnumEntryLambda currently calls:

formatIdentifier(fragment, true)

which delegates to camelize() and removes underscores.

This behavior is appropriate for general identifiers, but not for enum entries that are already valid Scala identifiers.

Fix

Added a dedicated formatEnumIdentifier() helper in AbstractScalaCodegen which:

  • preserves valid Scala identifiers unchanged
  • avoids camelization for enum entries
  • still applies reserved-word escaping when needed

ScalaHttp4sClientCodegen.EnumEntryLambda now uses this helper instead of formatIdentifier().

Verification

Generated models using:

enum:
  - ACTIVE_STATUS
  - INACTIVE_STATUS

now correctly produce:

case ACTIVE_STATUS extends MyStatus("ACTIVE_STATUS")
case INACTIVE_STATUS extends MyStatus("INACTIVE_STATUS")

Fixes #23841


PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work.
  • Run the full sample regeneration scripts.
  • File the PR against the master branch.
  • Reference the reported issue using GitHub linking syntax.

Summary by cubic

Preserves SCREAMING_SNAKE_CASE enum entry names in the scala-http4s generator by avoiding camelization, so values like ACTIVE_STATUS stay unchanged. Reserved words are escaped and names are sanitized.

  • Bug Fixes
    • Added formatEnumIdentifier() in AbstractScalaCodegen to preserve SCREAMING_SNAKE_CASE, apply special-char replacements and sanitization, escape reserved words, otherwise fall back to formatIdentifier().
    • Updated ScalaHttp4sClientCodegen.EnumEntryLambda to use formatEnumIdentifier() instead of formatIdentifier().

Written for commit 7630370. Summary will update on new commits. Review in cubic

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 15 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="output/src/main/scala/org/openapitools/client/models/package.scala">

<violation number="1" location="output/src/main/scala/org/openapitools/client/models/package.scala:37">
P1: Custom circe codecs for Json break native JSON handling: decode only accepts string tokens, encode double-encodes non-string values</violation>
</file>

<file name="output/src/main/scala/org/openapitools/client/apis/BaseClient.scala">

<violation number="1" location="output/src/main/scala/org/openapitools/client/apis/BaseClient.scala:77">
P2: Form parameters collapse repeated keys into comma-joined single values, breaking multi-valued form field serialization. UrlForm supports multiple values per key natively; values should be mapped directly without grouping and comma-joining.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@@ -0,0 +1,46 @@
/** Test
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Custom circe codecs for Json break native JSON handling: decode only accepts string tokens, encode double-encodes non-string values

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At output/src/main/scala/org/openapitools/client/models/package.scala, line 37:

<comment>Custom circe codecs for Json break native JSON handling: decode only accepts string tokens, encode double-encodes non-string values</comment>

<file context>
@@ -0,0 +1,46 @@
+  given encodeLocalDate: Encoder[LocalDate] =
+    Encoder.encodeString.contramap[LocalDate](_.toString)
+
+  given decodeJson: Decoder[Json] =
+    Decoder.decodeString.map(str => Json.fromString(str))
+
</file context>

case _Authorization.ApiKey(name, value) =>
request.putHeaders(Header.Raw(CIString(name), value))
}
val formBody = formParameters.map { x =>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Form parameters collapse repeated keys into comma-joined single values, breaking multi-valued form field serialization. UrlForm supports multiple values per key natively; values should be mapped directly without grouping and comma-joining.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At output/src/main/scala/org/openapitools/client/apis/BaseClient.scala, line 77:

<comment>Form parameters collapse repeated keys into comma-joined single values, breaking multi-valued form field serialization. UrlForm supports multiple values per key natively; values should be mapped directly without grouping and comma-joining.</comment>

<file context>
@@ -0,0 +1,89 @@
+      case _Authorization.ApiKey(name, value) =>
+        request.putHeaders(Header.Raw(CIString(name), value))
+    }
+    val formBody = formParameters.map { x =>
+      UrlForm(x.groupBy(_._1).map { case (k, v) => (k, v.map(_._2).mkString(",")) }.toSeq*)
+    }
</file context>

@anupamchaubey anupamchaubey force-pushed the fix-scala-http4s-enum-underscores branch 2 times, most recently from 7e29255 to 0becbda Compare May 22, 2026 06:35
@anupamchaubey anupamchaubey force-pushed the fix-scala-http4s-enum-underscores branch from 0becbda to 7630370 Compare May 22, 2026 06:41
Copy link
Copy Markdown
Author

@anupamchaubey anupamchaubey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maintainers could someone approve/re-run the workflows?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] [scala-http4s] Enum names lose underscores due to camelCase conversion

1 participant