Skip to content

refactor(cli): drop @redocly/openapi-core in favor of forge's overlay CLI - #846

Merged
Swimburger merged 5 commits into
mainfrom
swimburger/openapi-overlay-via-forge
Nov 30, 2026
Merged

Swimburger merged 5 commits into
mainfrom
swimburger/openapi-overlay-via-forge

Conversation

@Swimburger

@Swimburger Swimburger commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Removes @redocly/openapi-core and its 17 transitive npm dependencies (18 fewer third-party packages in pnpm-lock.yaml / node_modules) by applying the CLI compatibility overlay through forge openapi overlay - <path> on @cloudflare/forge@0.4.0 — a first-party binary we already pin and execute in the same generation pipeline.

Why this matters

  • Smaller supply-chain attack surface: drops 18 third-party npm packages from the workspace (including @redocly/openapi-core, @redocly/config, @redocly/ajv, ajv, ajv-formats, require-from-string, js-yaml, yaml-ast-parser, jsonpath-rfc9535, and friends) with zero new dependencies added.
  • Single first-party overlay engine: overlay validation/application and downstream code generation (forge normalize / forge generate) now share one implementation and error model instead of maintaining a second third-party OpenAPI engine just for the compat overlay.
  • Faster generation as a bonus: ~4.1× faster overlay application on the full 29.9 MB Cloudflare OpenAPI spec (~0.5 s off pnpm generate), with an identical _generated/ output tree.

Changes

  • packages/cli/package.json & pnpm-lock.yaml — drops @redocly/openapi-core (18 packages removed from lockfile) and bumps @cloudflare/forge to 0.4.0 (which adds forge openapi overlay).
  • packages/cli/generator/openapi-overlay.ts — resolves the installed @cloudflare/forge CLI via createRequire(import.meta.url) (same pattern as packages/cli/src/__tests__/helpers/forge-cli.ts) and runs forge openapi overlay - <overlayPath> with piped stdio and a 256 MiB output buffer. On failure, strips the forge: prefix from stderr (falling back to error.message if stderr is empty) and ensures the overlay path is included in the thrown error.
  • packages/cli/src/__tests__/generator/openapi-overlay.test.ts — updates the invalid-JSONPath assertion to "JSONPath" and replaces the post-overlay unresolved-$ref rejection test with one asserting unresolved $refs pass through to forge generate downstream.
  • docs/architecture.md — updates both the repository map and the overlay-engine description to reference forge openapi overlay.

Semantic deltas

  • Invalid-JSONPath error wording moves from "Invalid JSONPath" to "invalid RFC 9535 JSONPath target \"<expr>\": …".
  • Unresolved $ref introduced by an overlay now fails at forge generate (one stage later), not inside applyOpenApiOverlay. The pipeline still rejects it.

No other semantic changes: all 24 cli-compat-overlay.test.ts scenarios pass and pnpm generate produces an identical _generated/ tree.

Performance (local benchmark, pinned 29.9 MB spec)

Metric main (@redocly/openapi-core) This PR (@cloudflare/forge@0.4.0) Delta
Workspace node_modules packages 483 465 −18 packages
Isolated applyOpenApiOverlay (5 runs, mean) 974.1 ms 239.4 ms −75.4% (4.1× faster)
Full tsx generate.ts with cached spec (3 runs, mean) 9,094.5 ms 8,591.0 ms −5.5% (−504 ms)
Overlay unit tests (29 tiny fixtures, 3 runs, mean) 409.5 ms 452.3 ms +10.5% (+43 ms)

Test plan

  • pnpm install --frozen-lockfile succeeds
  • pnpm --filter cf test src/__tests__/generator/openapi-overlay.test.ts passes
  • pnpm --filter cf test src/__tests__/generator/cli-compat-overlay.test.ts passes (24 scenarios)
  • pnpm check passes end-to-end
  • pnpm generate produces the same _generated/ tree as before

Upstream

Shells `openapi-overlay.ts` out to `forge openapi overlay - <path>` on
`@cloudflare/forge@0.4.0` instead of pulling `@redocly/openapi-core` in
as a second overlay engine. One overlay implementation runs through the
pipeline (overlay apply, then `forge generate`), keeping error wording
and semantics consistent.

Two overlay semantics change:

- Invalid-JSONPath error wording moves from redocly's "Invalid JSONPath"
  to forge's "invalid RFC 9535 JSONPath target"; the unit test is
  retargeted at the new substring.
- The post-overlay unresolved-`$ref` check goes away. Redocly's
  `bundleFromString` validated refs; `forge openapi overlay` does not
  post-validate. `forge generate` catches unresolved refs downstream, so
  the pipeline still fails on them, just at the next stage. The matching
  unit test is removed.

Drops `@redocly/openapi-core` from `packages/cli/package.json`
devDependencies (nothing else uses it) and bumps `@cloudflare/forge` to
`0.4.0` for the new `openapi overlay` subcommand. Updates
`docs/architecture.md` to describe the new engine.

`pnpm-lock.yaml` is not touched in this commit: regenerating it needs
Cloudflare-internal registry access.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Comment thread packages/cli/package.json Resolved
@ask-bonk

ask-bonk Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Review: 2 findings.

Posted 2 inline findings, including a concrete buffer-limit suggestion.

github run

…path

- The Cloudflare OpenAPI spec is > 1 MiB, so Node's default 1 MiB stdio
  buffer rejects both the piped input and forge's output. Raises
  `maxBuffer` to 512 MiB.
- forge prefixes overlay parse errors with the overlay path but surfaces
  apply-time errors on their own. Always include the path in the thrown
  message so callers can tell which overlay failed (matches redocly's
  behavior and the existing unit test).

Regenerates `pnpm-lock.yaml` for `@cloudflare/forge@0.4.0` and the
removal of `@redocly/openapi-core`.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@pkg-pr-new

pkg-pr-new Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
npm i https://pkg.pr.new/cf@846

commit: 3a71ed0

@ask-bonk

ask-bonk Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

cf --help startup

mean stddev min max
PR 251.3 ms 4.3 ms 243.8 ms 262.5 ms
base 250.8 ms 5.3 ms 242.5 ms 260.0 ms

Δ (PR vs base): — +0.5 ms (+0.2%)

Measured with hyperfine on ubuntu-latest (3 warmup runs, 20 timed runs). CI numbers carry ±a few ms of runner jitter; treat small deltas as noise.

- maxBuffer: 64 MiB is enough headroom over the spec's current ~1.1 MiB.
- Drop the redundant stdio option (pipe is the default when input is set).
- Shorten the function's doc comment and the two inline comments.
- Replace the deleted unresolved-$ref test with one that asserts the ref
  passes through, documenting the new boundary (forge generate catches it
  downstream).
- Loosen the invalid-JSONPath assertion to "JSONPath", not forge's exact
  wording.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@ask-bonk

ask-bonk Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

@ask-bonk

ask-bonk Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

@Swimburger
Swimburger marked this pull request as ready for review November 30, 2026 18:33
@Swimburger
Swimburger requested a review from a team as a code owner November 30, 2026 18:33
@Swimburger
Swimburger requested a review from penalosa November 30, 2026 18:33

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Approved — The forge-based overlay wrapper, the dependency swap, the test updates and the docs changes have no correctness, security, performance or documentation problems.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

This is generator code that runs at build time. The arguments to execFileSync come from a resolved package path and an overlay file in the repository, and the call does not use a shell. maxBuffer limits the output size.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md concerns.


📋 Code Quality: ✅ LGTM

The wrapper finds bin/forge.cjs the same way the existing test helper does.

It runs forge through process.execPath with an argv array, so it does not go through a shell and works the same on Windows, Linux and macOS.

Error handling covers an empty stderr by falling back to error.message. It always includes the overlay path and keeps the original error as cause.

No references to @redocly/openapi-core remain.


⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

The docs/architecture.md updates match the new overlay engine.


Reviewed commit: 3a71ed0f

@Swimburger Swimburger changed the title refactor(cli): apply the compat overlay with forge's own overlay CLI refactor(cli): drop @redocly/openapi-core in favor of forge's overlay CLI Nov 30, 2026
@Swimburger
Swimburger enabled auto-merge November 30, 2026 18:48
@Swimburger
Swimburger added this pull request to the merge queue Nov 30, 2026
@petebacondarwin
petebacondarwin removed the request for review from penalosa November 30, 2026 18:59
Merged via the queue into main with commit a9f9e6b Nov 30, 2026
26 checks passed
@Swimburger
Swimburger deleted the swimburger/openapi-overlay-via-forge branch November 30, 2026 19: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