Skip to content

fix: load OpenAPI spec via static JSON require so bundlers include it#2

Open
max-programming wants to merge 1 commit into
clearoutio:mainfrom
max-programming:fix/bundler-safe-spec-loading
Open

fix: load OpenAPI spec via static JSON require so bundlers include it#2
max-programming wants to merge 1 commit into
clearoutio:mainfrom
max-programming:fix/bundler-safe-spec-loading

Conversation

@max-programming

Copy link
Copy Markdown

Fixes #1

what's happening

the sdk passes a yaml file path to openapi-client-axios, which reads and parses it from disk on init(). bundlers can't see a runtime string-concat file dependency, so the yaml never makes it into the deployed bundle and the first api call throws ENOENT in production (full details + repro in #1).

the fix

converted the spec to json and load it with a static require instead:

definition: require('./Clearout-OpenAPI-Spec-V3.json')

bundlers statically inline json requires, so the spec always ships inside the bundle. definition already accepts a pre-parsed document object (Document | string in the v5 types), so nothing else changes.

the yaml stays as the source of truth — the json is generated from it. added npm run spec:build so you can regenerate after editing the yaml (uses js-yaml, which is already around as a peer dep of openapi-client-axios).

side benefit: js-yaml isn't needed at runtime anymore for consumers, and the spec file read on cold start goes away.

tests

added test/openapi-spec.test.js (runs with npx jest openapi-spec, no api token needed — left the npm test script untouched):

  • generated json stays in sync with the yaml source
  • client initializes with the yaml removed from disk, which is what a bundled deployment looks like

verified

bundled the package with npx esbuild --bundle --platform=node and ran the output from a directory with no node_modules:

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.

ENOENT reading Clearout-OpenAPI-Spec-V3.yaml when the SDK is bundled (Next.js on Vercel)

1 participant