Skip to content

Commit 94499fa

Browse files
committed
test for the double-prefixed enum names
This proves that following comment is not relevant: #22748 (comment)
1 parent decf2cf commit 94499fa

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/SharedTypeScriptTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,40 @@ public void givenMapWithArrayOfEnumsThenCorrectEnumNameIsUsed() throws Exception
255255
}
256256
}
257257

258+
@Test(description = "Issue #22748 - Inner enums should not be double-prefixed when model has parent")
259+
public void givenChildModelWithInheritedInnerEnumThenEnumNameIsNotDoublePrefixed() throws Exception {
260+
// This tests that when a child model inherits from a parent that has an inner enum property,
261+
// the enum name is not double-prefixed (e.g., Employee.Employee.ProjectRolesEnum instead of
262+
// Employee.ProjectRolesEnum).
263+
//
264+
// We use typescript-angular because it sets supportsMultipleInheritance=true,
265+
// which means cm.parent will be set for child models using allOf.
266+
// typescript-fetch does NOT support inheritance, so cm.parent is always null there.
267+
final String specPath = "src/test/resources/3_0/issue_22748_inherited_inner_enum.yaml";
268+
269+
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
270+
output.deleteOnExit();
271+
272+
CodegenConfigurator configurator = new CodegenConfigurator()
273+
.setGeneratorName("typescript-angular")
274+
.setInputSpec(specPath)
275+
.setOutputDir(output.getAbsolutePath());
276+
277+
Generator generator = new DefaultGenerator();
278+
generator.opts(configurator.toClientOptInput()).generate();
279+
280+
// Find the Employee model file (the child model)
281+
Pattern modelDefinition = Pattern.compile("\\b(interface|type|class)\\s+Employee\\b");
282+
Path modelFile = findModelDefinitionFile(output.toPath(), modelDefinition);
283+
String fileContents = Files.readString(modelFile);
284+
285+
// Should NOT contain double-prefixed enum name (typescript-angular uses "." separator)
286+
Assert.assertFalse(fileContents.contains("Employee.Employee.ProjectRolesEnum"),
287+
"typescript-angular: Should not contain double-prefixed 'Employee.Employee.ProjectRolesEnum' in " + modelFile);
288+
289+
// Should contain correctly prefixed enum name (single prefix with "." separator)
290+
Assert.assertTrue(fileContents.contains("Employee.ProjectRolesEnum"),
291+
"typescript-angular: Should contain 'Employee.ProjectRolesEnum' in " + modelFile);
292+
}
293+
258294
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
openapi: 3.0.0
2+
info:
3+
version: 1.0.0
4+
title: OpenAPI Test API - Inherited Inner Enum
5+
description: Test case for inner enum in child model with inheritance
6+
license:
7+
name: Apache-2.0
8+
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
9+
paths:
10+
/employees:
11+
get:
12+
operationId: getEmployees
13+
responses:
14+
'200':
15+
description: List of employees
16+
content:
17+
application/json:
18+
schema:
19+
type: array
20+
items:
21+
$ref: '#/components/schemas/Employee'
22+
components:
23+
schemas:
24+
# Parent model with discriminator - this is needed for cm.parent to be set
25+
BaseEmployee:
26+
type: object
27+
discriminator:
28+
propertyName: employeeType
29+
properties:
30+
employeeType:
31+
type: string
32+
name:
33+
type: string
34+
# Child model that has its OWN inner enum property (map of array of enums)
35+
# This tests that when cm.parent != null, the child's own properties
36+
# don't get double-prefixed (first in cm.vars loop, then in cm.allVars loop)
37+
Employee:
38+
allOf:
39+
- $ref: '#/components/schemas/BaseEmployee'
40+
- type: object
41+
properties:
42+
employeeId:
43+
type: integer
44+
projectRoles:
45+
type: object
46+
additionalProperties:
47+
type: array
48+
items:
49+
type: string
50+
enum:
51+
- DEVELOPER
52+
- TESTER
53+
- OWNER

0 commit comments

Comments
 (0)