Skip to content

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

@theresa-fun

Description

@theresa-fun

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The EnumEntryLambda inner class in
ScalaHttp4sClientCodegen.java (line ~628)
calls formatIdentifier(fragment, true) on enum entry values. This delegates to AbstractScalaCodegen.formatIdentifier() which runs camelize() — stripping all underscores.

So an enum value like ACTIVE_STATUS becomes ACTIVESTATUS in the generated Scala code, which is incorrect — ACTIVE_STATUS is a perfectly valid Scala identifier and should be preserved as-is.

openapi-generator version

7.13.0

OpenAPI declaration file content or url
openapi: "3.0.3"
info:
  title: Test
  version: "1.0"
paths: {}
components:
  schemas:
    MyStatus:
      required:
        - status
      type: object
      additionalProperties: false
      properties:
        status:
         description: current status
        enum:
          - ACTIVE_STATUS
          - INACTIVE_STATUS
        type: string
Generation Details
openapi-generator-cli generate \
  -g scala-http4s \
  -i spec.yaml \
  -o output/
  --global-property models
Steps to reproduce
  1. Generate code with the spec above using scala-http4s generator
  2. Look at the generated enum values — ACTIVE_STATUS becomes ACTIVESTATUS, INACTIVE_STATUS becomes INACTIVESTATUS

Expected: ACTIVE_STATUS stays ACTIVE_STATUS .

Actual: All enum values are run through camelize(), which strips underscores.

Related issues/PRs
  • did not find any
Suggest a fix

In ScalaHttp4sClientCodegen.java, change EnumEntryLambda.formatFragment() to preserve valid identifiers and only backtick-escape invalid ones:

private class EnumEntryLambda extends CustomLambda {
    @Override
    public String formatFragment(String fragment) {
        if (fragment.matches("^[A-Za-z_][A-Za-z0-9_]*$") && !isReservedWord(fragment)) {
            return fragment;
        }
        return "`" + fragment + "`";
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions