Skip to content

fix(cli-internal): dedup Gen2 backend namespace import aliases#14926

Draft
sarayev wants to merge 1 commit into
devfrom
fix/gen2-dedup-namespace-alias
Draft

fix(cli-internal): dedup Gen2 backend namespace import aliases#14926
sarayev wants to merge 1 commit into
devfrom
fix/gen2-dedup-namespace-alias

Conversation

@sarayev

@sarayev sarayev commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Problem

When two Gen1 resources of different categories share a name (e.g. a REST API and a Lambda function both named mergeStudents), backend.ts emitted two import * as <name> declarations — TS2300 duplicate identifier, plus TS2339 because the second import shadowed the first.

Fix

BackendGenerator.addNamespaceImport performed no de-duplication. Added a centralized reserveAlias(preferred, category) that returns the preferred alias when free, else disambiguates by appending the capitalized category (then a numeric suffix). All category generators reserve their import-binding alias through it. Import paths and defineBackend keys keep the original resource name; only the import binding alias is disambiguated. Also fixes the REST API generator using the (possibly-suffixed) alias in the import path instead of the on-disk apiName.

Test

Added a dedup test to backend.generator.test.ts. Existing snapshots are unchanged (reserveAlias returns the preferred alias when there is no collision).

Risk

Medium surface (touches all category generators) but mechanical; no behavior change when names don't collide.

When two Gen1 resources of different categories shared a name (e.g. a
REST API and a Lambda function both named 'mergeStudents'), backend.ts
emitted two 'import * as <name>' declarations, causing TS2300 duplicate
identifier and TS2339 (the second import shadowed the first).

BackendGenerator.addNamespaceImport performed no alias de-duplication.
Add a centralized reserveAlias(preferred, category) that returns the
preferred alias when free, else disambiguates by appending the
capitalized category (then a numeric suffix). All category generators
reserve their import-binding alias through it. Import paths and
defineBackend keys keep the original resource name; only the import
binding alias is disambiguated. Also fixes the REST API generator using
the (now possibly-suffixed) alias in the import path instead of the
on-disk apiName.
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.

1 participant