feat: add support for translating @ to at_ in variable names for TypeScript clients#24427
feat: add support for translating @ to at_ in variable names for TypeScript clients#24427ceesvanegmond wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
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_"); |
There was a problem hiding this comment.
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>
|
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) |
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 toat_for TypeScript clients to avoid collisions and duplicatetypefields (e.g.,@typebecomesatType/at_type). Implemented inAbstractTypeScriptClientCodegen, so it applies to all TS client generators.@toat_intoVarNamewithinAbstractTypeScriptClientCodegen.MODEL_PROPERTY_NAMING(e.g., camelCase vs original) when forming the final name.typescript-fetchandtypescript-angularconfirming@id=>atId/at_id.Written for commit c8f02db. Summary will update on new commits.