Skip to content

feat(opapi)!: generate transport-agnostic client code instead of axios#698

Merged
slvnperron merged 4 commits into
masterfrom
sp/opapi-fetch
Jul 22, 2026
Merged

feat(opapi)!: generate transport-agnostic client code instead of axios#698
slvnperron merged 4 commits into
masterfrom
sp/opapi-fetch

Conversation

@slvnperron

Copy link
Copy Markdown
Member

What

Bumps @bpinternal/opapi to 2.0.0. The opapi client generator no longer emits axios-based code:

  • The generated Client constructor now takes any transport implementing a minimal generated HttpClient interface ({ request: <T>(config: RequestConfig) => Promise<{ data: T }> }) instead of an AxiosInstance, and stores it as httpClient.
  • to-axios.tsto-request.ts: toAxiosRequesttoRequest, returning a RequestConfig ({ method, url, headers, data }) instead of an AxiosRequestConfig. The ClientProps.toAxiosRequest override is now ClientProps.toRequest.
  • The generated toApiError and the generated request handler detect http errors structurally (any error carrying response.data) instead of via axios.isAxiosError, so axios-based transports keep working unchanged.

The legacy openapi-generator path (remote typescript-axios template) is untouched.

Why

This lets @botpress/client (and other generated clients) drop axios entirely in favor of a small fetch-based transport — smaller bundles and one less dependency to hoist. The botpress monorepo change consuming this is prepared separately; until @botpress/api ships with opapi 2.0.0 it post-processes the generated output into this exact shape.

Testing

  • pnpm build, pnpm check:type pass.
  • pnpm test: 25/26 pass; the one failure (server.test.ts bun-types/@types/node lib conflicts) is pre-existing and reproduces on master.

🤖 Generated with Claude Code

slvnperron and others added 2 commits July 22, 2026 17:16
The opapi client generator now emits a Client that takes any transport
implementing a minimal generated HttpClient interface instead of an
AxiosInstance. to-axios.ts becomes to-request.ts (toAxiosRequest ->
toRequest, AxiosRequestConfig -> RequestConfig), and both the generated
toApiError and the generated handler detect http errors structurally
rather than via axios.isAxiosError, so axios-based transports keep
working.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Jul 22, 2026

Copy link
Copy Markdown

Greptile Summary

This PR makes generated opapi clients independent of Axios. The main changes are:

  • Adds generated request and HTTP transport interfaces.
  • Renames the Axios request mapper to a transport-neutral mapper.
  • Replaces Axios-specific error checks with structural checks.
  • Publishes the changes as opapi 2.0.0.

Confidence Score: 4/5

Consumer builds and fetch-based error handling can break on the new generated client path.

  • Strict TypeScript module settings can reject the generated import.
  • Fetch-style transports can return HTTP error bodies as successful results.
  • Plain structural HTTP errors lose their response details in generated handlers.

opapi/src/generators/client-node.ts and opapi/src/handler-generator/export-handler.ts

Important Files Changed

Filename Overview
opapi/src/generator.ts Renames the generated request helper and calls the matching generator.
opapi/src/generators/client-node.ts Adds the transport-neutral client contract, with build compatibility and HTTP-status handling bugs.
opapi/src/handler-generator/export-handler.ts Removes the Axios import, but excludes structurally valid HTTP errors that are not Error instances.
opapi/CHANGELOG.md Documents the breaking API and provides a fetch-based transport example.
opapi/package.json Updates the package version to 2.0.0.

Reviews (1): Last reviewed commit: "style(opapi): prettier formatting" | Re-trigger Greptile

Comment thread opapi/src/generators/client-node.ts Outdated
Comment thread opapi/src/generators/client-node.ts
Comment thread opapi/src/handler-generator/export-handler.ts Outdated
slvnperron and others added 2 commits July 22, 2026 17:22
- import RequestConfig with an inline type modifier so generated code
  survives verbatimModuleSyntax consumers
- document the HttpClient transport contract: implementations must
  reject on unsuccessful statuses with the error body under
  response.data (and fix the changelog example accordingly)
- accept structural http errors in the generated handler even when the
  thrown value is not an Error instance (e.g. cross-realm errors)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Generated errors.ts now uses globalThis.crypto (browsers, web workers,
node >= 19, edge runtimes) with a Math.random fallback instead of
importing the node crypto module, so generated clients have no node
builtin dependencies.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@slvnperron
slvnperron merged commit 56bde50 into master Jul 22, 2026
1 check passed
@slvnperron
slvnperron deleted the sp/opapi-fetch branch July 22, 2026 21:36
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