Skip to content

fix(typescript): add trailing commas to as const enums - #24693

Merged
wing328 merged 6 commits into
masterfrom
scarf005-fix/typescript-as-const-trailing-commas
Aug 13, 2026
Merged

fix(typescript): add trailing commas to as const enums#24693
wing328 merged 6 commits into
masterfrom
scarf005-fix/typescript-as-const-trailing-commas

Conversation

@wing328

@wing328 wing328 commented Aug 13, 2026

Copy link
Copy Markdown
Member

based on #23277 with removed EOF and updated samples.

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Add trailing commas to generated TypeScript enum objects and operation enums to reduce diff noise and align with common formatters. Previously the last member had no trailing comma; now every member ends with a comma, so the line before "} as const;" always has one. Formatting-only; no runtime or API changes.

  • Update templates in typescript-angular, typescript-fetch (both export enum and as const maps), and typescript-nestjs-server; no template change for typescript-axios. Regenerate samples.
  • Add a shared test that asserts the line before } as const; ends with a comma across typescript-angular, typescript-axios, typescript-fetch, and typescript-nestjs-server.
  • No config or migration required; consumers will see formatting-only changes in generated TypeScript.

Written for commit f220bee. Summary will update on new commits.

Review in cubic

scarf005 and others added 4 commits March 24, 2026 09:51
Keep enum object diffs smaller across Angular, Fetch, and NestJS server generators.
@wing328 wing328 changed the title Scarf005 fix/typescript as const trailing commas fix(typescript): add trailing commas to as const enums Aug 13, 2026
@wing328
wing328 marked this pull request as ready for review August 13, 2026 11:38

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

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.

1 issue found across 121 files

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="modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/SharedTypeScriptTest.java">

<violation number="1" location="modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/SharedTypeScriptTest.java:361">
P3: The helper asserts that every `} as const;` literal in every generated `.ts` file is preceded by a comma-terminated member line, not just the enum objects this PR targets. For the four generators only enum templates emit `} as const;` today, so the current spec passes, but the check produces false failures for an enum with zero members (the line before `} as const;` is then the opening `= {` line, which has no comma) or for any future non-enum as-const map emitted without a trailing comma. Scope the assertion to the enum object being checked instead of every as-const literal, or skip objects whose previous line is the opening brace.</violation>
</file>

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

Re-trigger cubic

previousLineIndex--;
}

Assert.assertTrue(

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.

P3: The helper asserts that every } as const; literal in every generated .ts file is preceded by a comma-terminated member line, not just the enum objects this PR targets. For the four generators only enum templates emit } as const; today, so the current spec passes, but the check produces false failures for an enum with zero members (the line before } as const; is then the opening = { line, which has no comma) or for any future non-enum as-const map emitted without a trailing comma. Scope the assertion to the enum object being checked instead of every as-const literal, or skip objects whose previous line is the opening brace.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/SharedTypeScriptTest.java, line 361:

<comment>The helper asserts that every `} as const;` literal in every generated `.ts` file is preceded by a comma-terminated member line, not just the enum objects this PR targets. For the four generators only enum templates emit `} as const;` today, so the current spec passes, but the check produces false failures for an enum with zero members (the line before `} as const;` is then the opening `= {` line, which has no comma) or for any future non-enum as-const map emitted without a trailing comma. Scope the assertion to the enum object being checked instead of every as-const literal, or skip objects whose previous line is the opening brace.</comment>

<file context>
@@ -310,4 +337,41 @@ public void givenChildModelWithInheritedInnerEnumThenEnumNameIsNotDoublePrefixed
+                                    previousLineIndex--;
+                                }
+
+                                Assert.assertTrue(
+                                        previousLineIndex >= 0 && lines.get(previousLineIndex).stripTrailing().endsWith(","),
+                                        generatorName + ": Expected trailing comma before '} as const;' in " + path);
</file context>

@wing328 wing328 added this to the 7.25.0 milestone Aug 13, 2026
@wing328
wing328 merged commit 922f3e1 into master Aug 13, 2026
63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants