Skip to content

fix(typescript-angular): resolve model imports with lowercase modelSuffix - #25386

Open
thekhegay wants to merge 1 commit into
OpenAPITools:masterfrom
thekhegay:fix/ts-angular-lowercase-model-suffix
Open

thekhegay wants to merge 1 commit into
OpenAPITools:masterfrom
thekhegay:fix/ts-angular-lowercase-model-suffix

Conversation

@thekhegay

@thekhegay thekhegay commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

toModelName appends modelSuffix with _ and camelizes result, so modelSuffix=dto gives PetDto class, same as Dto
removeModelPrefixSuffix compares class name with raw dto, nothing gets stripped and suffix is added once more when file name is built
So with dto model file is petDto.ts, while imports in models and services point to petDtoDto, generated client fails with TS2307 as soon as one model references another or service uses model
Same for any suffix that starts with lowercase letter, example from issue gives ./municipalityRestDtoExampleExample

Now removeModelPrefixSuffix strips capitalize(modelSuffix), it alredy does same for modelNamePrefix and modelNameSuffix few lines below
Suffix validation allows only letters and digits, so capitalized suffix is exactly what camelize puts into class name

With lowercase suffix model files now get same names as with capitalized one (pet.ts for PetDto), barrel models.ts follows them
Only handwritten deep import like model/petDto would notice rename, and before this such client compiled only when no model referenced another and no service used model

Added testModelImportsWithLowercaseModelSuffix, it generates petstore with Dto and dto and checks file name and imports in model and service, dto case fails on master
Sample configs use only modelSuffix: Model, regenerated typescript-angular samples have no diff

Fixes #20726

PR checklist

  • Read the contribution guidelines.
  • 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
    
    Commit all changed files.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Fixes broken model imports in typescript-angular when modelSuffix starts with a lowercase letter (e.g. dto).

The generator camelizes the suffix when building class names, so dto becomes Dto. removeModelPrefixSuffix still compared against the raw dto, leaving the suffix in place, which made imports point to files like petDtoDto.ts while the actual file was petDto.ts — failing with TS2307.

  • Strips capitalize(modelSuffix) so model file names match the class names produced by toModelName.
  • Adds a test that generates the petstore with both Dto and dto suffixes and verifies file names and imports in models and services.

Written for commit 1cb9446. Summary will update on new commits.

View guided diff

@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.

No issues found across 2 files

View guided diff | Re-trigger cubic

This branch has not been deployed

No deployments
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.

[BUG][TypeScript] angular modelSuffix nested model bad import

1 participant