Skip to content

feat(deps): migrate @hey-api/openapi-ts from 0.71.1 to 0.96.1 - #143

Merged
Koosha-Owji merged 8 commits into
mainfrom
feat/migrate/openapi-ts-0.96
Aug 12, 2026
Merged

feat(deps): migrate @hey-api/openapi-ts from 0.71.1 to 0.96.1#143
Koosha-Owji merged 8 commits into
mainfrom
feat/migrate/openapi-ts-0.96

Conversation

@dtoxvanilla1991

Copy link
Copy Markdown
Contributor

Summary

Full migration of @hey-api/openapi-ts from 0.71.10.96.1.

Closes #121.


Breaking changes in @hey-api/openapi-ts 0.96

Plugin system overhaul

  • legacy/fetch plugin removed entirely — replaced by bundled @hey-api/client-fetch
  • Config option format: "prettier"postProcess: ["prettier"]
  • Config option asClass: true / classNameBuilderoperations: { strategy: "byTags" }
  • Config option exportFromIndex: trueincludeInEntry: true
  • Config option responseStyle: "data" removed from SDK plugin (now a client-level config)

New client architecture

  • Old: OpenAPI singleton from core/OpenAPI.ts configured with BASE and TOKEN
  • New: client singleton from client.gen.ts configured with baseUrl and auth callback
  • Old core files deleted: ApiError.ts, ApiRequestOptions.ts, ApiResult.ts, CancelablePromise.ts, OpenAPI.ts, request.ts
  • New generated files: client.gen.ts, client/ directory, core/auth.gen.ts, core/bodySerializer.gen.ts, core/pathSerializer.gen.ts, core/utils.gen.ts, etc.

Method signature changes

  • Old: static getCallbackUrls(data: GetCallbackUrlsData): CancelablePromise<GetCallbackUrlsResponse>
  • New: static getCallbackUrls<ThrowOnError>(options: Options<GetCallbackUrlsData, ThrowOnError>)
  • Return type: CancelablePromise<T>RequestResult<TResponses, TErrors, ThrowOnError>

Data type shape changes

  • Old flat shape: { appId: "123", requestBody: { urls: [...] } }
  • New structured shape: { path: { app_id: "123" }, body: { urls: [...] } }
  • Query params now under query sub-object: { query: { phone: "..." } }

Changes made

openapi-ts.config.ts

  • Migrated all deprecated config options to new equivalents

lib/api/ (generated)

  • Regenerated all files via pnpm exec openapi-ts
  • Old core (CancelablePromise, OpenAPI, ApiError, etc.) removed
  • New client architecture files added

lib/api/callbacks-compat.ts & callbacks-compat.d.ts

  • Removed CancelablePromise dependency (file no longer exists)
  • Updated deprecated method aliases to use new Options<Data, ThrowOnError> signatures
  • Compat layer still provides backward-compatible method name aliases (getCallbackUrLs, addRedirectCallbackUrLs, etc.)

lib/config.ts

  • Replaced import { OpenAPI } from "./api/index" with import { client } from "./api/client.gen"
  • Replaced _merge(OpenAPI, { BASE, TOKEN }) with client.setConfig({ baseUrl, auth })

lib/utilities/getToken.ts

  • Removed import { OpenAPI } from "../api" (file deleted)
  • Replaced OpenAPI.BASE + "/api" with kindeConfig.kindeDomain + "/api"

lib/main.ts

  • Changed export * from "./api/index"export * from "./api/schemas.gen" (avoids Applications2/Permissions2/etc. naming pollution from index.ts conflicts)
  • Explicitly exports all SDK classes from ./api/sdk.gen (avoiding Callbacks conflict with compat layer)

Tests

  • lib/main.test.ts: Removed ApiError, CancelablePromise, CancelError, OpenAPI from expected exports
  • tests/regressions.test.ts: Updated all call sites to use new path/query/body arg shapes

Verification

tsc --noEmit  → 0 errors
pnpm build    → ✓ built in 1.82s (177.59 kB mjs + 101.30 kB cjs)
pnpm test     → 51/51 tests passed

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
@dtoxvanilla1991
dtoxvanilla1991 requested review from a team as code owners April 27, 2026 23:41
@coderabbitai

coderabbitai Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Replaces the legacy OpenAPI runtime with a generated client. Adds typed request contracts, serialization, response handling, explicit exports, runtime configuration, and updated regression fixtures.

Changes

Generated client migration

Layer / File(s) Summary
Client contracts and request options
lib/api/core/types.gen.ts, lib/api/client/types.gen.ts
Adds client configuration, request options, conditional results, client composition, endpoint options, and HTTP types.
Request execution runtime
lib/api/client/client.gen.ts
Adds authentication, request preparation, fetch execution, response parsing, error handling, HTTP methods, and SSE wiring.
Request and query serialization
lib/api/core/pathSerializer.gen.ts, lib/api/core/queryKeySerializer.gen.ts
Adds OpenAPI path serialization and deterministic query-key normalization.
Runtime configuration and public exports
lib/config.ts, lib/utilities/*, lib/api/index.ts, lib/main.ts, lib/main.test.ts
Configures the generated client, adds ApiError, updates token audience resolution, and replaces legacy exports.
Code generation and regression updates
openapi-ts.config.ts, tests/regressions.test.ts
Updates generator settings and changes request fixtures to use nested path, body, and query parameters.

Estimated code review effort: 4 (Complex) | ~75 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SDK
  participant Client
  participant Fetch
  participant Response
  SDK->>Client: configure and submit typed request
  Client->>Fetch: build URL, authenticate, and execute request
  Fetch->>Response: return HTTP response
  Response->>Client: parse data or structured error
  Client->>SDK: return result or throw error
Loading

Possibly related PRs

Suggested reviewers: koosha-owji

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR migrates to 0.96.1, but issue #121 requires @hey-api/openapi-ts ^0.97.0 and its associated breaking-change updates. Upgrade to ^0.97.0, regenerate the client, and verify the Node, runtimeConfigPath, response/error, Ky, and ESM requirements from #121.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the dependency migration and matches the primary changeset.
Description check ✅ Passed The description directly explains the dependency migration, breaking changes, implementation updates, and verification results.
Out of Scope Changes check ✅ Passed The changes remain focused on the OpenAPI generator migration, generated client updates, compatibility aliases, runtime configuration, exports, and regression tests.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/migrate/openapi-ts-0.96

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 | 🔴 Critical

Add Node.js engine constraint and update CI to version >=22.13.

The migration to @hey-api/openapi-ts requires Node >= 22.13, but the repository has no enforcement:

  • package.json is missing engines.node
  • GitHub CI workflows are set to Node 20.x (incompatible)

Add "engines": { "node": ">=22.13" } to package.json and update .github/workflows to 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

📥 Commits

Reviewing files that changed from the base of the PR and between c621a99 and 3e89aa4.

⛔ Files ignored due to path filters (2)
  • package.json is excluded by !**/*.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !**/*.yaml
📒 Files selected for processing (30)
  • lib/api/callbacks-compat.d.ts
  • lib/api/callbacks-compat.ts
  • lib/api/client.gen.ts
  • lib/api/client/client.gen.ts
  • lib/api/client/index.ts
  • lib/api/client/types.gen.ts
  • lib/api/client/utils.gen.ts
  • lib/api/core/ApiError.ts
  • lib/api/core/ApiRequestOptions.ts
  • lib/api/core/ApiResult.ts
  • lib/api/core/CancelablePromise.ts
  • lib/api/core/OpenAPI.ts
  • lib/api/core/auth.gen.ts
  • lib/api/core/bodySerializer.gen.ts
  • lib/api/core/params.gen.ts
  • lib/api/core/pathSerializer.gen.ts
  • lib/api/core/queryKeySerializer.gen.ts
  • lib/api/core/request.ts
  • lib/api/core/serverSentEvents.gen.ts
  • lib/api/core/types.gen.ts
  • lib/api/core/utils.gen.ts
  • lib/api/index.ts
  • lib/api/sdk.gen.ts
  • lib/api/types.gen.ts
  • lib/config.ts
  • lib/main.test.ts
  • lib/main.ts
  • lib/utilities/getToken.ts
  • openapi-ts.config.ts
  • tests/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

Comment thread lib/api/client/types.gen.ts
Comment thread lib/api/client/utils.gen.ts
Comment thread lib/api/core/bodySerializer.gen.ts
Comment thread lib/api/core/bodySerializer.gen.ts
Comment thread lib/api/core/serverSentEvents.gen.ts
Comment thread lib/utilities/getToken.ts Outdated
Comment thread tests/regressions.test.ts Outdated

Copilot AI 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.

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-ts to ^0.96.0 and 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.

Comment thread tests/regressions.test.ts Outdated
Comment thread tests/regressions.test.ts Outdated
Comment thread lib/main.ts
Comment thread package.json
Comment thread lib/config.ts
Comment thread lib/utilities/getToken.ts
- 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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3e89aa4 and ff4a7a0.

⛔ Files ignored due to path filters (2)
  • .github/workflows/build-test-ci.yml is excluded by !**/*.yml
  • package.json is excluded by !**/*.json
📒 Files selected for processing (7)
  • lib/api/client/types.gen.ts
  • lib/api/core/pathSerializer.gen.ts
  • lib/config.ts
  • lib/main.ts
  • lib/utilities/getToken.ts
  • openapi-ts.config.ts
  • tests/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

Comment thread tests/regressions.test.ts Outdated
- 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
@shafaladhikari

Copy link
Copy Markdown
Contributor

Hi @dtoxvanilla1991, I found a issue of typescript and runtime mismatch happening in the returned response from the sdk methods.

Root Cause

responseStyle: "data" was present in the @hey-api/sdk plugin config before the 0.96.1 migration (55f5b93) but was dropped in the migration commit (3e89aa4) when switching from legacy/fetch + asClass: true to @hey-api/client-fetch + strategy: "byTags".

Without it, the generated types default to the "fields" shape — methods typed as returning { data: T, request, response } — while responseStyle: "data" in client.setConfig() makes the runtime return T directly. TypeScript and runtime disagree.

Fix

Add responseStyle: "data" back to the @hey-api/sdk plugin in openapi-ts.config.ts:

{
  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 { data } from the result) will then be caught by TypeScript rather than silently failing at runtime.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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 `@lib/config.ts`:
- Around line 74-76: Update the interceptor setup in init so repeated
initialization does not accumulate error handlers: retain the registered handler
identifier and eject it before registering a replacement, or otherwise register
only once. In the handler, guard the response before accessing status so
transport failures with an undefined response still produce an ApiError safely.
- Around line 66-71: Update the `@hey-api/sdk` plugin configuration in
openapi-ts.config.ts to set responseStyle to "data", matching the runtime client
configuration in setConfig. Regenerate the generated API files under lib/api/ so
their response types align with the data response shape.
🪄 Autofix

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 Plus

Run ID: 43f19aba-d067-4402-8086-771acd869d5d

📥 Commits

Reviewing files that changed from the base of the PR and between ff4a7a0 and c7c98a3.

⛔ Files ignored due to path filters (3)
  • .github/workflows/build-test-ci.yml is excluded by !**/*.yml
  • package.json is excluded by !**/*.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !**/*.yaml
📒 Files selected for processing (8)
  • lib/api/index.ts
  • lib/api/sdk.gen.ts
  • lib/api/types.gen.ts
  • lib/config.ts
  • lib/main.test.ts
  • lib/main.ts
  • lib/utilities/ApiError.ts
  • tests/regressions.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • lib/main.test.ts
  • lib/api/index.ts
  • tests/regressions.test.ts

Comment thread lib/config.ts
Comment thread lib/config.ts Outdated
@dtoxvanilla1991

Copy link
Copy Markdown
Contributor Author

@Koosha-Owji thanks for the patch commit on feedback. I checked just now. Should be good to merge.

The openapi-ts config already set responseStyle: "data", but sdk.gen.ts was
not regenerated, so TypeScript still typed methods as fields-shaped while
init() returned data at runtime. Regenerating also applies the committed
definitions.case preserve setting.

Co-authored-by: Cursor <cursoragent@cursor.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 `@lib/api/client/types.gen.ts`:
- Around line 125-126: Update the RequestResult generator template to include a
transport-error variant for fetch rejections with throwOnError: false and
responseStyle: "fields", allowing response to be undefined and error to
represent the rejected value rather than only TError. Add a regression test
covering this createClient behavior, then regenerate lib/api/client/types.gen.ts
so the generated types match the template.
🪄 Autofix

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 Plus

Run ID: bda48db0-d58e-479f-8b0e-8e9c9a526407

📥 Commits

Reviewing files that changed from the base of the PR and between c7c98a3 and ab413b3.

📒 Files selected for processing (9)
  • lib/api/client/client.gen.ts
  • lib/api/client/types.gen.ts
  • lib/api/core/queryKeySerializer.gen.ts
  • lib/api/core/types.gen.ts
  • lib/api/index.ts
  • lib/api/sdk.gen.ts
  • lib/api/types.gen.ts
  • lib/config.ts
  • openapi-ts.config.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • openapi-ts.config.ts
  • lib/api/index.ts
  • lib/config.ts
  • lib/api/core/queryKeySerializer.gen.ts
  • lib/api/client/client.gen.ts
  • lib/api/core/types.gen.ts

Comment thread lib/api/client/types.gen.ts
@shafaladhikari

Copy link
Copy Markdown
Contributor

Regenerated SDK (ab413b3)

The config already had responseStyle: "data", but sdk.gen.ts wasn’t regenerated, so types still used the "fields" shape while runtime returned data.

Ran openapi-ts and committed the output. Methods now include responseStyle: "data" and the "data" generic. Lint/build/tests pass (68/68).

Casing: schema types stay snake_case (success_response, etc.) — same as current main, from definitions.case: "preserve". Operation types stay PascalCase (GetUsersData, etc.). That’s expected, not a break vs the published package.

@Koosha-Owji
Koosha-Owji merged commit 1fe2b97 into main Aug 12, 2026
4 checks passed
@Koosha-Owji
Koosha-Owji deleted the feat/migrate/openapi-ts-0.96 branch August 12, 2026 02:43
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.

5 participants