Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix: Collapse CDN Zones spec onto one tag to unblock generation (@W-23234552@) - #453

#453
Merged
joeluong-sfcc merged 3 commits into
mainSalesforceCommerceCloud/commerce-sdk:mainfrom
ju/cdn-zones-classname-W-23234552SalesforceCommerceCloud/commerce-sdk:ju/cdn-zones-classname-W-23234552Copy head branch name to clipboard
Jul 13, 2026
Merged

Fix: Collapse CDN Zones spec onto one tag to unblock generation (@W-23234552@)#453
joeluong-sfcc merged 3 commits into
mainSalesforceCommerceCloud/commerce-sdk:mainfrom
ju/cdn-zones-classname-W-23234552SalesforceCommerceCloud/commerce-sdk:ju/cdn-zones-classname-W-23234552Copy head branch name to clipboard

Conversation

@joeluong-sfcc

@joeluong-sfcc joeluong-sfcc commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • The Zones OAS spec ships a spec-level x-sdk-classname: CDNZones that openapi-generator threads to every emitted API file's class. When operations span multiple tags (zones-oas 1.3.0 introduces a Turnstile tag), the generator emits one file per tag — each declaring export class CDNZones — and the auto-generated barrel fails TS2308 on the duplicate. Any bump past zones-oas 1.2.0 is blocked.

    Concretely, generating zones-oas-v1=1.3.0 on main (without this fix):

    renderedTemplates/cdnApiProcessApis/apis/
    ├── DefaultApi.ts     # untagged zone ops    -> export class CDNZones
    ├── TurnstileApi.ts   # Turnstile-tagged ops -> export class CDNZones   <-- duplicate
    └── index.ts          # export * from './DefaultApi'
                          # export * from './TurnstileApi'                   <-- TS2308 here
    

    npm run compile fails with TS2308: Module './DefaultApi' has already exported a member named 'CDNZones' at apis/index.ts:2.

  • Fix: pass --openapi-normalizer SET_TAGS_FOR_ALL_OPERATIONS=default to the openapi-generator invocation for the Zones spec only. That collapses every operation onto the default tag, so the generator emits a single DefaultApi.ts with all operations (Turnstile included) on one class — preserving the filename convention every other spec in the SDK already uses.

    Generating zones-oas-v1=1.3.0 on this branch (with the fix):

    renderedTemplates/cdnApiProcessApis/apis/
    ├── DefaultApi.ts     # every op incl. Turnstile -> export class CDNZones
    └── index.ts          # export * from './DefaultApi'
    

    npm run compile exits clean.

  • Consumer surface is unchanged: import { CDNZones } from "commerce-sdk" resolves through the same barrel chain to the same class. At pinned 1.2.0 the emitted DefaultApi.ts, model files, and every downstream barrel are byte-identical to base.

Test plan

  • Regression test at src/generate-oas.test.ts — proven red on base (TS2305: Module './generate-oas' has no exported member 'resolveGeneratorFlags', i.e. the test can't compile without the fix's carrier function) and green on fix (52 passing).
  • npm run test:unit — 52 passing.
  • npm run compile — clean typecheck.
  • npm run lint — clean.
  • Re-rendered locally at pinned zones-oas 1.2.0 with and without the fix — DefaultApi.ts, apis/index.ts, all 98 model files, models/index.ts, cdnApiProcessApis/index.ts, cdnApiProcessApis/runtime.ts, and the top-level renderedTemplates/index.ts are byte-identical between base and fix.
  • Re-rendered locally at target zones-oas 1.3.0: single DefaultApi.ts, single export class CDNZones, all previous zone endpoints plus the 5 new Turnstile operations (createTurnstileWidget, deleteTurnstileWidget, getTurnstileWidget, etc.) on one class. Clean apis/index.ts barrel, no TS2308.

Reviewer manual smoke test

To reproduce the 1.3.0 generation locally on this branch:

# 1. Check out the branch
git fetch origin
git checkout ju/cdn-zones-classname-W-23234552
npm install

# 2. Bump the CDN Zones spec pin. Edit api-versions.txt line 5:
#      zones-oas-v1=1.2.0   ->   zones-oas-v1=1.3.0
#    Do NOT commit this edit — it's for local smoke only. The pin bump ships in
#    a separate release ticket.

# 3. Pull the 1.3.0 spec from Anypoint (needs Anypoint creds in your env):
export ANYPOINT_USERNAME=...
export ANYPOINT_PASSWORD=...
npm run updateApis

# 4. Regenerate + build.
npm run renderTemplates
npm run compile

Expected result:

  • renderedTemplates/cdnApiProcessApis/apis/ contains exactly one API file, DefaultApi.ts, with export class CDNZones extends BaseClient. No TurnstileApi.ts, no duplicate class.
  • DefaultApi.ts has all pre-existing zone endpoints plus the 5 new Turnstile operations (createTurnstileWidget, deleteTurnstileWidget, getTurnstileWidget, getTurnstileWidgets, updateTurnstileWidget).
  • 6 new TurnstileWidget* model files under renderedTemplates/cdnApiProcessApis/models/.
  • npm run compile exits 0 (no TS2308 on the barrel).

Sanity check on main first (optional): repeat steps 2–4 on main and npm run compile will fail with TS2308: Module './DefaultApi' has already exported a member named 'CDNZones' at renderedTemplates/cdnApiProcessApis/apis/index.ts:2 — this is the failure this PR resolves.

To restore local state after smoke: git checkout -- api-versions.txt && rm -rf apis/zones-oas-1.3.0 renderedTemplates.

Follow-ups

  • The api-versions.txt bump of zones-oas-v1 from 1.2.0 to 1.3.0 belongs in a separate release ticket per the ticket's AC.
  • src/generate-oas.ts:58resolveApiName's "CDN API - Process APIs OAS" branch is dead (no shipping spec uses that name); the current name is "Zones OAS", handled at line 82. Chore ticket to clean up.
  • The three parallel per-spec switches (resolveApiName, resolveDirectoryName, resolveGeneratorFlags) could collapse into one data-driven config table. Separate Refactor ticket.
  • The mustache template at templatesOas/apis.endpoint.mustache:242 emits const pathParams = {} without a type annotation. VS Code's default noImplicitAny lights up every generated DefaultApi.ts in the repo with editor squiggles — cosmetic only, the repo tsconfig.json compiles cleanly. Chore ticket to add Record<string, unknown> to the mustache emit.

Ticket

W-23234552

@joeluong-sfcc
joeluong-sfcc force-pushed the ju/cdn-zones-classname-W-23234552 branch from 824e2f8 to a559f45 Compare July 9, 2026 16:23
…llision (@W-23234552@)

The Zones OAS spec ships with a spec-level `x-sdk-classname: CDNZones` that
openapi-generator threads to every emitted API file's class. When the spec's
operations are split across multiple tags (as of zones-oas 1.3.0 introducing
a `Turnstile` tag), the generator emits one file per tag, each declaring
`export class CDNZones` — causing the auto-generated barrel to fail
`TS2308` on the duplicate name and blocking any bump past 1.2.0.

Passing `--openapi-normalizer SET_TAGS_FOR_ALL_OPERATIONS=zones` to the
generator for the Zones spec forces every operation onto one tag, so the
generator emits a single `ZonesApi.ts` with all operations (Turnstile ops
included) on one class. Consumer surface is unchanged: `import { CDNZones }
from "commerce-sdk"` resolves through the same barrel chain to the same
class.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@joeluong-sfcc
joeluong-sfcc force-pushed the ju/cdn-zones-classname-W-23234552 branch from a559f45 to 0c1a593 Compare July 9, 2026 16:58
@joeluong-sfcc
joeluong-sfcc marked this pull request as ready for review July 13, 2026 16:08
@joeluong-sfcc
joeluong-sfcc requested a review from a team as a code owner July 13, 2026 16:08
Comment thread src/generate-oas.ts Outdated
* preserves the DefaultApi.ts filename shared with every other spec.
*/
export function resolveGeneratorFlags(apiSpecDetail: ApiSpecDetail): string {
if (apiSpecDetail.name === ZONES_SPEC_NAME) {

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.

nit: this matches on name ("Zones OAS"). If Zones ever ships as v2, name becomes "Zones OAS V2" (see getAPIDetailsFromExchange), this check is skipped, and the bug comes back with no failing test.

apiName is always "CDNZones" no matter the version, so it is safer. Bonus: it also covers the old "CDN API - Process APIs OAS" name that resolveApiName maps to CDNZones too.

Suggested change
if (apiSpecDetail.name === ZONES_SPEC_NAME) {
if (apiSpecDetail.apiName === "CDNZones") {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, done — resolveGeneratorFlags now keys off apiSpecDetail.apiName === "CDNZones", so a future Zones v2 rename and the legacy "CDN API - Process APIs OAS" title are both covered.

Comment thread src/generate-oas.test.ts
expect(flags).to.include("--reserved-words-mappings delete=delete");
});

it("returns the base flags unchanged for every other spec", () => {

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.

Nice test. If you switch the check to apiName, consider adding one more case for a "Zones OAS V2" spec so a future v2 rename can't silently bring the bug back.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done — added a "Zones OAS V2" case in src/generate-oas.test.ts that asserts the normalizer flag still gets appended when only the spec title changes.

Comment thread src/generate-oas.ts
flags: resolveGeneratorFlags(apiSpecDetail),
});
} catch (error) {
console.error(`Error generating SDK for ${name}: ${error}`);

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.

nit: this catch logs but does not rethrow, so renderTemplates still exits 0 when a spec fails to generate. A bad normalizer flag would fail silently and only surface later at compile.

Rethrow so the build fails loudly:

Suggested change
console.error(`Error generating SDK for ${name}: ${error}`);
console.error(`Error generating SDK for ${name}: ${error}`);
throw error;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good callout, done — generateSDKs now rethrows after the console.error so a bad flag fails the render immediately instead of surfacing as a downstream compile error.

joeluong-sfcc and others added 2 commits July 13, 2026 17:46
…ision back (@W-23234552@)

- resolveGeneratorFlags now keys off apiSpecDetail.apiName === "CDNZones"
  instead of the spec title. apiName is the version-stable identifier —
  a future "Zones OAS V2" or the legacy "CDN API - Process APIs OAS"
  title both map to CDNZones and are now covered.
- generateSDKs rethrows after logging so a bad generator flag fails the
  render immediately instead of surfacing as a downstream compile error.
- Added a test case for the "Zones OAS V2" title to lock in the guard.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…t 100% (@W-23234552@)

The `overrides = {}` default introduced a branch (called-with-arg vs
called-without) that no test exercised, dragging the file's branch
coverage to 0% and failing CI's 80% threshold. All three call sites
already pass an object explicitly, so requiring it costs nothing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@joeluong-sfcc
joeluong-sfcc merged commit db074bb into main Jul 13, 2026
6 checks passed
@joeluong-sfcc
joeluong-sfcc deleted the ju/cdn-zones-classname-W-23234552 branch July 13, 2026 22:04
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.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.