Skip to content

feat: add support for translating @ to at_ in variable names for TypeScript clients#24427

Open
ceesvanegmond wants to merge 2 commits into
OpenAPITools:masterfrom
ceesvanegmond:feature/typescript/at-sign-fix
Open

feat: add support for translating @ to at_ in variable names for TypeScript clients#24427
ceesvanegmond wants to merge 2 commits into
OpenAPITools:masterfrom
ceesvanegmond:feature/typescript/at-sign-fix

Conversation

@ceesvanegmond

@ceesvanegmond ceesvanegmond commented Jul 24, 2026

Copy link
Copy Markdown

I'm having the same issue as #12171. This PR applies the same principe, but for TypeScript clients


Summary by cubic

Translate leading @ in OpenAPI property names to at_ for TypeScript clients to avoid collisions and duplicate type fields (e.g., @type becomes atType/at_type). Implemented in AbstractTypeScriptClientCodegen, so it applies to all TS client generators.

  • Bug Fixes
    • Map leading @ to at_ in toVarName within AbstractTypeScriptClientCodegen.
    • Respect MODEL_PROPERTY_NAMING (e.g., camelCase vs original) when forming the final name.
    • Add tests for typescript-fetch and typescript-angular confirming @id => atId/at_id.

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

Review in cubic

@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 3 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/main/java/org/openapitools/codegen/languages/AbstractTypeScriptClientCodegen.java">

<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractTypeScriptClientCodegen.java:593">
P2: Schemas containing both `@foo` and `at_foo` now generate the same TypeScript member name (`atFoo`), so one property's value overwrites/aliases the other in clients such as typescript-fetch. Preserve uniqueness after this translation (or disambiguate colliding model property names) rather than relying on a fixed `at_` prefix.</violation>
</file>

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

Re-trigger cubic


// translate @ for properties (like @type) to at_.
// Otherwise an additional "type" property will leed to duplcates
name = name.replaceAll("^@", "at_");

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: Schemas containing both @foo and at_foo now generate the same TypeScript member name (atFoo), so one property's value overwrites/aliases the other in clients such as typescript-fetch. Preserve uniqueness after this translation (or disambiguate colliding model property names) rather than relying on a fixed at_ prefix.

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

<comment>Schemas containing both `@foo` and `at_foo` now generate the same TypeScript member name (`atFoo`), so one property's value overwrites/aliases the other in clients such as typescript-fetch. Preserve uniqueness after this translation (or disambiguate colliding model property names) rather than relying on a fixed `at_` prefix.</comment>

<file context>
@@ -588,6 +588,10 @@ public String toVarName(String name) {
 
+        // translate @ for properties (like @type) to at_.
+        // Otherwise an additional "type" property will leed to duplcates
+        name = name.replaceAll("^@", "at_");
+
         name = sanitizeName(name, "[^\\w$]");
</file context>

…en/languages/AbstractTypeScriptClientCodegen.java

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
@wing328

wing328 commented Jul 25, 2026

Copy link
Copy Markdown
Member

thanks for the PR

cc @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02) @davidgamero (2022/03) @mkusaka (2022/04) @joscha (2024/10) @KannaKim (2026/07)

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.

2 participants