Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,10 @@ public String toVarName(String name) {
return nameMapping.get(name);
}

// translate @ for properties (like @type) to at_.
// Otherwise an additional "type" property will lead to duplicates
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>


name = sanitizeName(name, "[^\\w$]");

if ("_".equals(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ public void toVarName() {
codegen.processOpts();
Assert.assertEquals(codegen.toVarName("valid_var"), "valid_var");
}

@Test
public void toVarNameWithAtSign() {
TypeScriptFetchClientCodegen codegen = new TypeScriptFetchClientCodegen();
codegen.processOpts();
Assert.assertEquals(codegen.toVarName("@id"), "atId");

codegen = new TypeScriptFetchClientCodegen();
codegen.additionalProperties().put(CodegenConstants.MODEL_PROPERTY_NAMING, "original");
codegen.processOpts();
Assert.assertEquals(codegen.toVarName("@id"), "at_id");
}

@Test
public void toEnumVarName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ public void toVarName() {
Assert.assertEquals(codegen.toVarName("valid_var"), "validVar");
}

@Test
public void toVarNameWithAtSign() {
TypeScriptAngularClientCodegen codegen = new TypeScriptAngularClientCodegen();
codegen.processOpts();
Assert.assertEquals(codegen.toVarName("@id"), "at_id");

codegen = new TypeScriptAngularClientCodegen();
codegen.additionalProperties().put(CodegenConstants.MODEL_PROPERTY_NAMING, "camelCase");
codegen.processOpts();
Assert.assertEquals(codegen.toVarName("@id"), "atId");
}

@Test
public void toEnumVarName() {
TypeScriptAngularClientCodegen codegen = new TypeScriptAngularClientCodegen();
Expand Down
Loading