feat(deps): migrate @hey-api/openapi-ts from 0.71.1 to 0.96.1#143
feat(deps): migrate @hey-api/openapi-ts from 0.71.1 to 0.96.1#143dtoxvanilla1991 wants to merge 5 commits into
Conversation
Complete architectural migration from the legacy fetch client to the new
bundled @hey-api/client-fetch client in openapi-ts v0.96.
## Config changes (openapi-ts.config.ts)
- Replace legacy/fetch plugin with @hey-api/client-fetch
- Replace format: 'prettier' with postProcess: ['prettier']
- Replace asClass/classNameBuilder with operations.strategy: 'byTags'
- Replace exportFromIndex with includeInEntry: true
- Replace responseStyle: 'data' option (removed from SDK plugin)
## Generated files (lib/api/)
- Deleted: core/ApiError.ts, ApiRequestOptions.ts, ApiResult.ts,
CancelablePromise.ts, OpenAPI.ts, request.ts (old fetch core)
- Added: client.gen.ts, client/ directory (new client singleton)
- Added: core/auth.gen.ts, bodySerializer.gen.ts, params.gen.ts,
pathSerializer.gen.ts, queryKeySerializer.gen.ts,
serverSentEvents.gen.ts, types.gen.ts, utils.gen.ts
- Regenerated: index.ts, sdk.gen.ts, types.gen.ts, schemas.gen.ts
## Method signature changes (sdk.gen.ts)
- Old: static method(data: XxxData): CancelablePromise<XxxResponse>
- New: static method<ThrowOnError>(options: Options<XxxData, ThrowOnError>)
- Data types now use path/query/body sub-objects instead of flat args
e.g. { appId } -> { path: { app_id } }
## Hand-maintained file updates
- lib/api/callbacks-compat.ts: Removed CancelablePromise dependency;
deprecated method aliases now use new Options<Data> signatures
- lib/api/callbacks-compat.d.ts: Updated to new type signatures
- lib/config.ts: Replace OpenAPI singleton with client.setConfig()
using new baseUrl and auth callback pattern
- lib/utilities/getToken.ts: Replace OpenAPI.BASE with kindeConfig.kindeDomain
- lib/main.ts: Explicitly export all SDK classes from sdk.gen (avoiding
index.ts naming conflicts); export schemas directly from schemas.gen
## Test updates
- lib/main.test.ts: Remove ApiError, CancelablePromise, CancelError,
OpenAPI from expected exports (no longer generated)
- tests/regressions.test.ts: Update all method call args to new
path/query/body format; update type check tests
Closes #121
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (8)
WalkthroughReplaces the legacy OpenAPI runtime with a generated client factory and utilities, updates deprecated Callbacks aliases to accept typed ChangesClient generation & migration
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Set output.clean: false in openapi-ts.config.ts so that spec:generate does not delete callbacks-compat.ts and callbacks-compat.d.ts on every run.
There was a problem hiding this comment.
Actionable comments posted: 7
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
openapi-ts.config.ts (1)
1-30:⚠️ Potential issue | 🔴 CriticalAdd Node.js engine constraint and update CI to version >=22.13.
The migration to
@hey-api/openapi-tsrequires Node >= 22.13, but the repository has no enforcement:
package.jsonis missingengines.node- GitHub CI workflows are set to Node 20.x (incompatible)
Add
"engines": { "node": ">=22.13" }topackage.jsonand update.github/workflowsto use Node 22.x or later.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openapi-ts.config.ts` around lines 1 - 30, Add a Node.js engine constraint and update CI to Node >=22.13: add an "engines" entry to package.json with "node": ">=22.13" (so package.json enforces runtime), and update all GitHub Actions workflow files under .github/workflows that use actions/setup-node or a node-version matrix to use 22.x or a literal >=22.13 (e.g., node-version: '22.x' or matrix value '22.x') so CI runs on Node 22+. Locate package.json and workflows that reference Node versions (search for "actions/setup-node", "node-version", or job names like "test" / "build") and update them accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/api/client/types.gen.ts`:
- Around line 169-176: The SseFn type incorrectly treats TError as the second
generic for ServerSentEventsResult (which expects the stream return slot as the
second generic). Update SseFn to remove TError and introduce proper generics for
the stream return/next slots; for example declare SseFn as <TData = unknown,
TReturn = void, TNext = unknown, ThrowOnError extends boolean = false,
TResponseStyle extends ResponseStyle = "fields">(...) =>
Promise<ServerSentEventsResult<TData, TReturn, TNext>> so the second generic
maps to the generator return type (TReturn) and the third maps to the next/emit
payload (TNext), while keeping the same options parameter shape
(Omit<RequestOptions<never, TResponseStyle, ThrowOnError>, "method">).
In `@lib/api/client/utils.gen.ts`:
- Around line 114-131: The checkForExistence function incorrectly treats falsy
query values as absent and can false-match cookie name substrings; update it to
detect query keys using a proper key-existence check (e.g.,
Object.prototype.hasOwnProperty.call(options.query, name) or equivalent) instead
of truthiness, keep headers.has(name) as-is, and replace the naive
options.headers.get("Cookie")?.includes(`${name}=`) with a cookie-name boundary
check (parse the Cookie header into key=value pairs or use a regex that enforces
start-or-semicolon boundary like /(?:^|;\s*)NAME=/ with NAME replaced safely) so
only exact cookie names match.
In `@lib/api/core/bodySerializer.gen.ts`:
- Around line 54-69: The bodySerializer currently calls Object.entries(body) and
will throw for null or non-object inputs; update bodySerializer to first guard
that body is a plain object (e.g., typeof body === "object" && body !== null)
and if not, return an empty FormData immediately, then proceed to iterate and
call serializeFormDataPair; apply the same guard to the other generated
serializer in this file (the block referenced at lines ~80-95) and ideally fix
the generator/template that emits these serializers so future regenerations
include this non-object guard.
- Around line 41-50: In serializeUrlSearchParamsPair handle Date explicitly:
inside the function serializeUrlSearchParamsPair check if value is an instance
of Date and if so call value.toISOString() and append that string to data;
otherwise keep the existing string branch and fall back to JSON.stringify for
other types—update the generator/template so the serializeUrlSearchParamsPair
function treats Date the same way as the FormData path by emitting ISO strings
instead of JSON-quoted values.
In `@lib/api/core/serverSentEvents.gen.ts`:
- Around line 241-258: The catch block currently retries on all errors; change
it to detect cancellation/abort and stop retrying immediately by returning or
breaking before calling retry logic. In the catch(error) where onSseError is
called, add a guard that checks for abort conditions (e.g.
controller.signal?.aborted or error.name === 'AbortError' or a provider-specific
aborted flag) and if true, call onSseError?.(error) and then exit the loop
(break/return) without computing backoff or awaiting sleep; keep the existing
retry behavior only for non-abort errors (still honoring sseMaxRetryAttempts,
attempt, backoff, retryDelay, sseMaxRetryDelay, sleep).
In `@lib/utilities/getToken.ts`:
- Line 51: The audience value is built from kindeConfig.kindeDomain on line 51
but elsewhere (line 21) token validation expects kindeConfig.audience, creating
a drift risk; to fix, pick a single source of truth by changing the constructed
audience assignment in getToken (the place that currently sets audience:
kindeConfig.kindeDomain + "/api") to use kindeConfig.audience instead, or
alternately update the validation to compare against the constructed
value—ensure both the audience assignment and the validation reference the same
symbol (kindeConfig.audience) so they cannot diverge.
In `@tests/regressions.test.ts`:
- Around line 457-461: Prettier is failing because of repeated inline type casts
around result; refactor by introducing a local typed alias for the expected
shape (e.g., declare a local type or interface for { users?: { billing?: {
customer_id?: string } }[] } and cast result once), then replace the inline
casts in the checks where you access users and create the users variable (the
current usages referencing result and users). This will simplify the if checks
and remove the long inline cast blocks that break formatting; ensure you replace
both occurrences (the creation of users and the later similar block) with the
new alias and a single cast.
---
Outside diff comments:
In `@openapi-ts.config.ts`:
- Around line 1-30: Add a Node.js engine constraint and update CI to Node
>=22.13: add an "engines" entry to package.json with "node": ">=22.13" (so
package.json enforces runtime), and update all GitHub Actions workflow files
under .github/workflows that use actions/setup-node or a node-version matrix to
use 22.x or a literal >=22.13 (e.g., node-version: '22.x' or matrix value
'22.x') so CI runs on Node 22+. Locate package.json and workflows that reference
Node versions (search for "actions/setup-node", "node-version", or job names
like "test" / "build") and update them accordingly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8d09a37f-11ce-4a81-9058-5ec9451bcfdf
⛔ Files ignored due to path filters (2)
package.jsonis excluded by!**/*.jsonpnpm-lock.yamlis excluded by!**/pnpm-lock.yaml,!**/*.yaml
📒 Files selected for processing (30)
lib/api/callbacks-compat.d.tslib/api/callbacks-compat.tslib/api/client.gen.tslib/api/client/client.gen.tslib/api/client/index.tslib/api/client/types.gen.tslib/api/client/utils.gen.tslib/api/core/ApiError.tslib/api/core/ApiRequestOptions.tslib/api/core/ApiResult.tslib/api/core/CancelablePromise.tslib/api/core/OpenAPI.tslib/api/core/auth.gen.tslib/api/core/bodySerializer.gen.tslib/api/core/params.gen.tslib/api/core/pathSerializer.gen.tslib/api/core/queryKeySerializer.gen.tslib/api/core/request.tslib/api/core/serverSentEvents.gen.tslib/api/core/types.gen.tslib/api/core/utils.gen.tslib/api/index.tslib/api/sdk.gen.tslib/api/types.gen.tslib/config.tslib/main.test.tslib/main.tslib/utilities/getToken.tsopenapi-ts.config.tstests/regressions.test.ts
💤 Files with no reviewable changes (7)
- lib/api/core/ApiResult.ts
- lib/api/core/ApiRequestOptions.ts
- lib/api/core/ApiError.ts
- lib/main.test.ts
- lib/api/core/OpenAPI.ts
- lib/api/core/CancelablePromise.ts
- lib/api/core/request.ts
There was a problem hiding this comment.
Pull request overview
This PR migrates the generated Management API client from @hey-api/openapi-ts 0.71.1 to 0.96.1, updating generation config, replacing the old OpenAPI singleton-based runtime with the new client runtime, and adapting library/test call sites to the new { path, query, body } request shapes.
Changes:
- Upgraded
@hey-api/openapi-tsto^0.96.0and refreshed the lockfile with new transitive dependencies/engine requirements. - Updated codegen configuration and regenerated
lib/api/**to the new client architecture (new core/client runtime files; old core removed). - Updated SDK initialization and regression tests to use the new client + new parameter shapes; maintained deprecated Callbacks method aliases via a compat layer.
Reviewed changes
Copilot reviewed 28 out of 32 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/regressions.test.ts | Updates request argument shapes for new SDK; currently weak assertions around new RequestResult return shape. |
| pnpm-lock.yaml | Locks new @hey-api/openapi-ts dependency tree (includes new Node engine requirements). |
| package.json | Bumps @hey-api/openapi-ts to ^0.96.0. |
| openapi-ts.config.ts | Migrates config to new options (postProcess, operations.strategy, includeInEntry, new fetch client plugin). |
| lib/utilities/getToken.ts | Removes OpenAPI dependency; computes audience from config domain (but should respect kindeConfig.audience). |
| lib/main.ts | Changes public exports to avoid index conflicts; now exports schemas + explicit SDK classes + compat Callbacks. |
| lib/main.test.ts | Updates expected top-level exports after removal of old OpenAPI core exports. |
| lib/config.ts | Switches initialization from OpenAPI merge to client.setConfig({ baseUrl, auth }). |
| lib/api/index.ts | Regenerated entry exports; now includes renamed exports (Applications2, etc.) due to name conflicts. |
| lib/api/core/utils.gen.ts | New generated runtime utilities (URL/path serialization, request body normalization). |
| lib/api/core/types.gen.ts | New generated core types (client/config primitives). |
| lib/api/core/serverSentEvents.gen.ts | New generated SSE client support. |
| lib/api/core/request.ts | Old generated request pipeline removed. |
| lib/api/core/queryKeySerializer.gen.ts | New generated query-key serialization helpers. |
| lib/api/core/pathSerializer.gen.ts | New generated path/query serialization utilities. |
| lib/api/core/params.gen.ts | New generated args→{body,query,path,headers} mapping utilities. |
| lib/api/core/bodySerializer.gen.ts | New generated body/query serializer implementations. |
| lib/api/core/auth.gen.ts | New generated auth token helper. |
| lib/api/core/OpenAPI.ts | Old OpenAPI singleton removed. |
| lib/api/core/CancelablePromise.ts | Old cancelable promise runtime removed. |
| lib/api/core/ApiResult.ts | Old API result type removed. |
| lib/api/core/ApiRequestOptions.ts | Old request options type removed. |
| lib/api/core/ApiError.ts | Old API error type removed. |
| lib/api/client/utils.gen.ts | New generated fetch-client helpers (auth injection, header merge, interceptors, config creation). |
| lib/api/client/types.gen.ts | New generated client request/response typings (RequestResult, Options, etc.). |
| lib/api/client/index.ts | New generated client barrel exports. |
| lib/api/client/client.gen.ts | New generated fetch client implementation (request pipeline, parsing, interceptors, throwOnError support). |
| lib/api/client.gen.ts | New generated singleton client instance. |
| lib/api/callbacks-compat.ts | Updates compat layer to new Options<..., ThrowOnError> signatures and new return types. |
| lib/api/callbacks-compat.d.ts | Updates type augmentation for deprecated Callbacks method aliases under the new client types. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Use kindeConfig.audience as primary audience source in generateM2MToken, falling back to kindeDomain + "/api" (guards against external mutation drift) - Add export type * from ./api/types.gen to lib/main.ts to restore the full request/response type surface in the public API entry point - Set responseStyle: "data" and throwOnError: true in client.setConfig() to preserve backwards-compatible call semantics from the old OpenAPI client - Fix dead billing-expand test assertions: replace double inline casts with local type aliases so assertions actually execute under the new client shape - Format lib/api/client/types.gen.ts and lib/api/core/pathSerializer.gen.ts to unblock the Prettier CI gate - Bump CI node-version to 22.x and add engines.node >=22.13.0 to package.json to match @hey-api/openapi-ts@0.96.x runtime requirement
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/regressions.test.ts`:
- Around line 459-464: The test currently guards core assertions with "if
(users?.length)" which can silently skip checks; change the test to explicitly
assert that "users" is defined and non-empty (for example assert users is
defined and expect(users.length).toBeGreaterThan(0)) before accessing users[0];
then remove the conditional and run the existing assertions on users[0].billing
and users[0].billing?.customer_id so failures are deterministic. Ensure you
update both occurrences that use the same pattern around the "users" variable
and the BillingUser type check.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 55e3a67d-b3d4-4662-9f9d-e00f74a32730
⛔ Files ignored due to path filters (2)
.github/workflows/build-test-ci.ymlis excluded by!**/*.ymlpackage.jsonis excluded by!**/*.json
📒 Files selected for processing (7)
lib/api/client/types.gen.tslib/api/core/pathSerializer.gen.tslib/config.tslib/main.tslib/utilities/getToken.tsopenapi-ts.config.tstests/regressions.test.ts
🚧 Files skipped from review as they are similar to previous changes (6)
- lib/config.ts
- lib/utilities/getToken.ts
- lib/main.ts
- openapi-ts.config.ts
- lib/api/core/pathSerializer.gen.ts
- lib/api/client/types.gen.ts
- Replace if (users?.length) guards with explicit expect(users).toBeDefined() and expect(users!.length).toBeGreaterThan(0) so billing assertion failures are deterministic rather than silently skipped - Add parseAs: 'json' to client.setConfig() so responses are always parsed as JSON; fixes test environment where vitest-fetch-mock does not set Content-Type header, causing parseAs: auto to fall back to stream mode
- Merge origin/main (commits up to 899f5a6) into feat/migrate/openapi-ts-0.96 - Take updated kinde-mgmt-api-specs.yaml (+977 lines) from main - Regenerate lib/api/{sdk,types,schemas,index}.gen.ts with openapi-ts 0.96.1 against the updated spec (adds Directories class and new endpoints) - Add Directories to lib/main.ts SDK class exports - Add ApiError class (lib/utilities/ApiError.ts) with error interceptor in config.ts so non-2xx responses throw ApiError instances with .status property - Add ApiError to lib/main.ts exports and lib/main.test.ts expected list - Take pnpm@10.33.4 packageManager from main; retain engines node>=22.13.0 - Upgrade @hey-api/client-fetch to ^0.13.0 from main; retain openapi-ts ^0.96.0 Tests: 68/68 passing, lint clean, tsc --noEmit clean
|
Hi @dtoxvanilla1991, I found a issue of typescript and runtime mismatch happening in the returned response from the sdk methods. Root Cause
Without it, the generated types default to the FixAdd {
name: "@hey-api/sdk",
operations: { strategy: "byTags" },
responseStyle: "data", // restores correct types
}This makes the generated types correctly reflect the runtime shape. Any wrong access pattern (e.g. destructuring |
Summary
Full migration of
@hey-api/openapi-tsfrom0.71.1→0.96.1.Closes #121.
Breaking changes in @hey-api/openapi-ts 0.96
Plugin system overhaul
legacy/fetchplugin removed entirely — replaced by bundled@hey-api/client-fetchformat: "prettier"→postProcess: ["prettier"]asClass: true/classNameBuilder→operations: { strategy: "byTags" }exportFromIndex: true→includeInEntry: trueresponseStyle: "data"removed from SDK plugin (now a client-level config)New client architecture
OpenAPIsingleton fromcore/OpenAPI.tsconfigured withBASEandTOKENclientsingleton fromclient.gen.tsconfigured withbaseUrlandauthcallbackApiError.ts,ApiRequestOptions.ts,ApiResult.ts,CancelablePromise.ts,OpenAPI.ts,request.tsclient.gen.ts,client/directory,core/auth.gen.ts,core/bodySerializer.gen.ts,core/pathSerializer.gen.ts,core/utils.gen.ts, etc.Method signature changes
static getCallbackUrls(data: GetCallbackUrlsData): CancelablePromise<GetCallbackUrlsResponse>static getCallbackUrls<ThrowOnError>(options: Options<GetCallbackUrlsData, ThrowOnError>)CancelablePromise<T>→RequestResult<TResponses, TErrors, ThrowOnError>Data type shape changes
{ appId: "123", requestBody: { urls: [...] } }{ path: { app_id: "123" }, body: { urls: [...] } }querysub-object:{ query: { phone: "..." } }Changes made
openapi-ts.config.tslib/api/(generated)pnpm exec openapi-tsCancelablePromise,OpenAPI,ApiError, etc.) removedlib/api/callbacks-compat.ts&callbacks-compat.d.tsCancelablePromisedependency (file no longer exists)Options<Data, ThrowOnError>signaturesgetCallbackUrLs,addRedirectCallbackUrLs, etc.)lib/config.tsimport { OpenAPI } from "./api/index"withimport { client } from "./api/client.gen"_merge(OpenAPI, { BASE, TOKEN })withclient.setConfig({ baseUrl, auth })lib/utilities/getToken.tsimport { OpenAPI } from "../api"(file deleted)OpenAPI.BASE + "/api"withkindeConfig.kindeDomain + "/api"lib/main.tsexport * from "./api/index"→export * from "./api/schemas.gen"(avoidsApplications2/Permissions2/etc. naming pollution from index.ts conflicts)./api/sdk.gen(avoidingCallbacksconflict with compat layer)Tests
lib/main.test.ts: RemovedApiError,CancelablePromise,CancelError,OpenAPIfrom expected exportstests/regressions.test.ts: Updated all call sites to use newpath/query/bodyarg shapesVerification