Repository navigation
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 4 files
Reply to a comment to ask cubic a question or push back. It learns from your replies.
View guided diff | Re-trigger cubic
|
Addressed both review comments in commit
|
…appings and isolatedModules re-export
- In TypeScriptAngularClientCodegen.postProcessOperationsWithModels, recompute service
model imports so all types mapping to the same external module/package (e.g. via importMappings)
are preserved and imported in the generated API services.
- In TypeScriptAngularClientCodegen.postProcessSupportingFileData, deduplicate external models
per module and re-export them via 'export type { ... }' in models.mustache (with fallback
to 'export { ... }' for Angular 9 / TypeScript < 3.8) to eliminate duplicate 'export *' lines
and prevent TS1205 errors under isolatedModules: true.
- Add unit test testMultipleImportsFromSameModuleAndExternalModelReExport in
TypeScriptAngularClientCodegenTest covering both fixes and Angular 9 backwards compatibility.
Relates to OpenAPITools#7790
Relates to OpenAPITools#6805
8e64533 to
ae43427
Compare
|
Update:
|
|
sorry, my fault - could some1 please re-approve the workflows? =) |
| {{#supportsExportType}} | ||
| export type { {{{ types }}} } from '{{{ module }}}'; | ||
| {{/supportsExportType}} | ||
| {{^supportsExportType}} | ||
| export { {{{ types }}} } from '{{{ module }}}'; | ||
| {{/supportsExportType}} |
There was a problem hiding this comment.
export type drops value side, so re-exported mapped enum or class can't be used as value anymore (Status.Active gives TS1362), while deduped export * alredy passes isolatedModules since TS1205 only hits named re-exports
| {{#supportsExportType}} | |
| export type { {{{ types }}} } from '{{{ module }}}'; | |
| {{/supportsExportType}} | |
| {{^supportsExportType}} | |
| export { {{{ types }}} } from '{{{ module }}}'; | |
| {{/supportsExportType}} | |
| export * from '{{{ module }}}'; |
There was a problem hiding this comment.
Thanks a lot for testing and for the great catch @thekhegay!
You are completely right: deduplicating export * from '{{{ module }}}'; already satisfies isolatedModules without stripping the value side of mapped enums/classes (and also removes the need for any ngVersion / TypeScript version branching).
- Applied your suggestion in
models.mustacheand removedsupportsExportTypeindd874389a95. - Added an explicit unit test covering the [BUG] [typescript-angular] Import mappings with same path do not work properly when generating services #22533 spec (
FooandBarmapped to@foo/bar) as well as asserting single re-export inmodels.ts. - Updated the PR description to link [BUG] [typescript-angular] Import mappings with same path do not work properly when generating services #22533 and Fixes #22533: angular typescript generation import statements from same file or package being overwitten by one another #23758.
There was a problem hiding this comment.
All reported issues were addressed across 3 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
PR checklist
importMappingsfrom the same module).Description of the change
This PR addresses two related issues when using
importMappingswith the TypeScript Angular generator:Service Import Map Collision (
TypeScriptAngularClientCodegen.java):When multiple schemas mapped to the same module/package (e.g.
@contractsor@foo/bar) viaimportMappings, imports were previously reduced by target module key, resulting in only one class being imported into generated API service files.postProcessOperationsWithModelsfrom the operations' imports so all imported symbols are preserved without collision.Duplicate Re-Exports in
models.ts(TypeScriptAngularClientCodegen.java&models.mustache):In
models.ts, models mapped to external packages viaimportMappingswere repeatedly re-exported viaexport * from '<module>';for every mapped model (causing duplicate export statements when multiple models shared the same import path).postProcessSupportingFileDataand deduplicated per module soexport * from '<module>';is emitted only once per external module inmodels.ts.Automated Tests:
Added unit tests in
TypeScriptAngularClientCodegenTest.java(testMultipleImportsFromSameModuleAndExternalModelReExportandtestIssue22533ImportMappingsSamePathInServices) verifying that all external symbols from the same module are imported in services and re-exported without duplicates inmodels.ts.Fixes #22533
Supersedes #23758
Relates to #7790