Skip to content

feat(openapi): generate all spec versions from git history at Docker build time#208

Open
kdhillon-stripe wants to merge 5 commits intov2from
kdhillon/bundled-openapi-spec
Open

feat(openapi): generate all spec versions from git history at Docker build time#208
kdhillon-stripe wants to merge 5 commits intov2from
kdhillon/bundled-openapi-spec

Conversation

@kdhillon-stripe
Copy link
Copy Markdown
Collaborator

Summary

  • Adds packages/openapi/scripts/generate-all-specs.mjs — a standalone Node ESM utility (no npm deps) that walks the stripe/openapi git history to extract every published spec version, writing <version>.json + manifest.json to an output directory
  • Dockerfile gets a new spec-builder stage that does a blobless clone (--filter=blob:none) of stripe/openapi, runs the script, and copies the output into the build stage — so all historical specs land in dist/generated-specs/ in the final image
  • specFetchHelper.ts now checks generated-specs/manifest.json (loaded once, cached in module scope) before falling through to the network; matches by date part so 2026-03-25 hits 2026-03-25.dahlia.json; silently skips if the directory is absent (local dev)

Why no GitHub API

The CDN only retains the last ~4 monthly releases (max_versions: 5 in the api-artifacts namespace config). The GitHub REST API is rate-limited without a token. Walking git history via git show pulls only the blobs we actually need — no auth, no rate limits.

Resolution flow (in order)

  1. explicit_path — user-provided file
  2. bundled — matches BUNDLED_API_VERSION constant (latest, from PR feat(openapi): bundle latest spec (2026-03-25.dahlia) as filesystem fallback #207)
  3. bundled — matches any entry in generated-specs/manifest.json (all historical versions, Docker only)
  4. cache — local filesystem cache from a previous fetch
  5. github — live fetch from raw.githubusercontent.com

Test plan

  • pnpm build in packages/openapi passes locally
  • docker build runs the spec-builder stage and populates dist/generated-specs/
  • Requesting an older version (e.g. 2024-06-20) inside Docker returns source: 'bundled' with no network calls
  • Requesting any version locally (no generated-specs/ dir) falls through to cache/GitHub as before

🤖 Generated with Claude Code

kdhillon-stripe and others added 5 commits March 30, 2026 16:45
…allback

Commits the latest Stripe OpenAPI SDK spec into the package so that
when a user requests the matching API version (2026-03-25.dahlia),
it is served directly from the bundled file with no network calls.

For all other versions the existing cache → GitHub fetch flow is
unchanged.

To update the bundled spec in the future:
  curl -sL https://raw.githubusercontent.com/stripe/openapi/master/latest/openapi.spec3.sdk.json \
    -o packages/openapi/bundled-spec.json
  # then bump BUNDLED_API_VERSION in specFetchHelper.ts to match info.version

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
…build time

Adds a build-time utility that walks the stripe/openapi git history to
extract every published OpenAPI spec version, and wires it into the
Docker image and the spec resolution flow.

Changes:
- packages/openapi/scripts/generate-all-specs.mjs: standalone Node ESM
  script (builtins only) — clones stripe/openapi with --filter=blob:none,
  walks git log for both spec paths (latest/openapi.spec3.sdk.json and
  openapi/spec3.json), deduplicates by info.version, writes
  <version>.json + manifest.json to an output directory
- Dockerfile: new spec-builder stage that runs generate-all-specs.mjs;
  output is copied into the build stage before pnpm deploy so all specs
  land in dist/generated-specs/ in the final image
- specFetchHelper.ts: checks generated-specs/manifest.json (loaded once,
  cached in module scope) before falling through to network; silently
  skips if the directory is absent (local dev with no Docker build)
- package.json build script: copies generated-specs to dist if present

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
…e scope

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
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