Skip to content

[typescript-angular] Fix inner enum reference in multi-map property type#22748

Merged
macjohnny merged 5 commits intoOpenAPITools:masterfrom
saxicek:saxicek/issue22747
Feb 10, 2026
Merged

[typescript-angular] Fix inner enum reference in multi-map property type#22748
macjohnny merged 5 commits intoOpenAPITools:masterfrom
saxicek:saxicek/issue22747

Conversation

@saxicek
Copy link
Contributor

@saxicek saxicek commented Jan 20, 2026

Fixes #20877
Fixes #22747

This PR fixes an issue where TypeScript based code generation (Angular, axios, fetch, ...) produces invalid InnerEnum type references for map properties containing arrays of inline enums.

Solution:
Added postProcessModelProperty() override in TypeScriptAngularClientCodegen that:

  1. Detects inner enum properties with map/array containers
  2. Finds the innermost item and its incorrectly assigned enum name
  3. Replaces the wrong enum name in datatypeWithEnum with the correct property.enumName
  4. Lets the existing postProcessModels() in AbstractTypeScriptClientCodegen add the classname prefix

Testing:

  • Added new unit test using existing test resource issue_19393_map_of_inner_enum.yaml
  • All 22 existing TypeScript Angular tests pass
  • Manually verified generated code compiles correctly with the fix

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • 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.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
    @TiFu

Summary by cubic

Fixes invalid inner enum references across TypeScript generators when map or array properties contain inline enums. Models now use the correct enum name and compile cleanly. Fixes #20877, #22747.

  • Bug Fixes
    • Implemented the fix in AbstractTypeScriptClientCodegen by overriding updateDataTypeWithEnumForArray/Map to derive property.enumName and replace inner base types; postProcessModels now prefixes both enum and inner enum properties with the model classname.
    • Updated TypeScript Fetch to respect inner enums and use datatypeWithEnum in interfaces; expanded shared tests across TypeScript generators and added an Angular inheritance test to ensure enum names aren’t double-prefixed ([typescript-angular] Fix inner enum reference in multi-map property type #22748).

Written for commit 213ee3f. Summary will update on new commits.

Copy link
Contributor

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

@wing328
Copy link
Member

wing328 commented Feb 2, 2026

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)

}

@Override
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this fix specific to the angular codegen, or could it be moved to the parent class (abstract typescript) or would it even be useful to fix it in the base class?

also, would this need to be fixed in the template instead of rewriting the data type here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@macjohnny There is a related #20877 which suggests that it could be done in the parent class. Not sure about the base class.

Honestly, I asked GitHub Copilot to fix this for me, I don't have any in-depth knowledge of the code to decide where the fix should land - parent class, base class, template? I expected that reviewers would point me to the right place if the current fix is sub-optimal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a new commit that implements the fix in the parent class. That will resolve both #20877 and #22747.

Copy link
Contributor

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 4 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java">

<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java:805">
P2: Inner enum names can be double-prefixed for child properties when a model has a parent: processCodegenProperty already prefixes isInnerEnum, and the new inheritance loop prefixes isInnerEnum again on cm.allVars, which reuses the same property objects for child vars.</violation>
</file>

<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:1113">
P2: Map-of-enum datatype replacement expects a trailing ">", but TypeScript map types are index signatures without ">", so simple maps won’t update the inner enum name.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.


if (Boolean.TRUE.equals(var.isEnum)) {
// Handle both direct enum properties and inner enums (maps/arrays of enums)
if (Boolean.TRUE.equals(var.isEnum) || Boolean.TRUE.equals(var.isInnerEnum)) {
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Inner enum names can be double-prefixed for child properties when a model has a parent: processCodegenProperty already prefixes isInnerEnum, and the new inheritance loop prefixes isInnerEnum again on cm.allVars, which reuses the same property objects for child vars.

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/TypeScriptFetchClientCodegen.java, line 805:

<comment>Inner enum names can be double-prefixed for child properties when a model has a parent: processCodegenProperty already prefixes isInnerEnum, and the new inheritance loop prefixes isInnerEnum again on cm.allVars, which reuses the same property objects for child vars.</comment>

<file context>
@@ -800,7 +801,8 @@ private ExtendedCodegenModel processCodeGenModel(ExtendedCodegenModel cm) {
 
-                if (Boolean.TRUE.equals(var.isEnum)) {
+                // Handle both direct enum properties and inner enums (maps/arrays of enums)
+                if (Boolean.TRUE.equals(var.isEnum) || Boolean.TRUE.equals(var.isInnerEnum)) {
                     var.datatypeWithEnum = var.datatypeWithEnum
                             .replace(var.enumName, cm.classname + var.enumName);
</file context>
Fix with Cubic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The concern about double-prefixing is theoretical but not an actual bug in practice. My investigation shows:

Why there's no double-prefix bug:

  1. For TypeScriptFetch: cm.parent is always null because TypeScriptFetchClientCodegen does NOT set supportsMultipleInheritance = true. The entire if (cm.parent != null) block is dead code.

  2. For generators that DO support inheritance (typescript-angular, etc.): When supportsMultipleInheritance = true, the cm.allVars collection contains COPIES of the properties, not references to the same object instances as cm.vars.

Therefore, modifying properties in cm.vars does not affect the (different) property objects in cm.allVars. Added commit 94499fa as a proof.

This proves that following comment is not relevant:
OpenAPITools#22748 (comment)
@saxicek saxicek marked this pull request as draft February 6, 2026 09:25
Type annotation in a comment should match the actual field type.
@saxicek saxicek marked this pull request as ready for review February 7, 2026 13:09
@saxicek saxicek requested a review from macjohnny February 7, 2026 13:10
Copy link
Contributor

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 41 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<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:286">
P2: New test references `src/test/resources/3_0/issue_22748_inherited_inner_enum.yaml`, but this spec file is not present in the repository, so the test will fail to load the input spec.</violation>
</file>

<file name="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java">

<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java:805">
P2: Enum/inner-enum properties in subclasses are prefixed twice: processCodegenProperty already prefixes cm.vars, and the new allVars loop repeats it, producing double-prefixed enum names (e.g., ChildChildStatus) and invalid generated types.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Member

@macjohnny macjohnny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx for the fix

@macjohnny macjohnny merged commit a7d57ca into OpenAPITools:master Feb 10, 2026
34 checks passed
@saxicek saxicek deleted the saxicek/issue22747 branch February 11, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

3 participants