Skip to content

fix(fetch): type SDK responses from parseAs option#4075

Draft
Dexter2099 wants to merge 5 commits into
hey-api:mainfrom
Dexter2099:fix/parseas-response-type
Draft

fix(fetch): type SDK responses from parseAs option#4075
Dexter2099 wants to merge 5 commits into
hey-api:mainfrom
Dexter2099:fix/parseas-response-type

Conversation

@Dexter2099

@Dexter2099 Dexter2099 commented Jun 16, 2026

Copy link
Copy Markdown

Summary

Fixes #3835.

Threads the fetch client's request-level parseAs option through generated SDK function types so callers get the runtime response shape in data.

For example, parseAs: 'blob' now produces Blob data instead of the OpenAPI schema response type. The default parseAs: 'auto' behavior keeps the existing schema-derived response type.

Most of the diff is generated fixture output from the client, plugin, and example matrices.

Cause

The fetch client runtime already parses responses according to parseAs, but generated SDK functions only passed schema-derived response types into RequestResult. The request-level parse mode was not part of the SDK function generic, client method call, or return type.

Fix

  • Add an internal parse-mode generic to fetch client request/result types.
  • Map explicit parse modes to their runtime data types.
  • Thread TParseAs through fetch SDK options, return types, and client method calls.
  • Add compile-time regression coverage and update generated snapshots/examples.

Tests

  • corepack pnpm ty @hey-api/openapi-ts
  • corepack pnpm ty @test/openapi-ts
  • corepack pnpm exec vitest run --project @hey-api/openapi-ts packages/openapi-ts/src/plugins/@hey-api/client-fetch/__tests__
  • corepack pnpm exec vitest run --project @test/openapi-ts packages/openapi-ts-tests/main/test/clients.test.ts
  • corepack pnpm exec vitest run --project @test/openapi-ts packages/openapi-ts-tests/main/test/plugins.test.ts
  • sh ./scripts/examples-check.sh
  • targeted eslint on touched source/test files
  • targeted oxfmt --check on package diff files

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown

@Dexter2099 is attempting to deploy a commit to the Hey API Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: c1f7775

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes — threads parseAs through the fetch client's RequestResult and SDK function generics so callers get the right data type for each parse mode.

  • Add ParsedResponse<TData, TParseAs> conditional type — maps each parseAs literal to its runtime data type (Blob, string, ArrayBuffer, FormData, ReadableStream<Uint8Array> | null for stream, or TData[keyof TData] for json/auto).
  • Thread TParseAs through RequestResult, MethodFn, RequestFn, RequestOptions, ResolvedRequestOptions, Client — all the fetch client surface types gain a TParseAs generic defaulting to 'auto'.
  • Gate SDK emission behind isFetchClient and !isSseoperationStatements(), operationReturnType(), operationOptionsType(), createTypeOptions(), and v1/node.ts all use $if(isFetchClient, ...) and supportsParseAs = isFetchClient && !isSse so non-fetch clients and SSE operations are untouched.
  • Add Config to SDK imports — the generated Options type uses NonNullable<Config['parseAs']> as the TParseAs constraint.
  • Add compile-time type assertionstypes.test.ts verifies RequestResult produces Blob, string, ArrayBuffer, and the JSON-shaped response type for the corresponding parseAs values.
  • Update 30 snapshot files — all mechanical propagation of the new generic across 10 client-fetch snapshot variants.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 38.73%. Comparing base (795a33d) to head (c1f7775).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4075      +/-   ##
==========================================
+ Coverage   38.68%   38.73%   +0.05%     
==========================================
  Files         626      626              
  Lines       21864    21894      +30     
  Branches     6406     6431      +25     
==========================================
+ Hits         8458     8481      +23     
- Misses      10922    10928       +6     
- Partials     2484     2485       +1     
Flag Coverage Δ
unittests 38.73% <ø> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Dexter2099 Dexter2099 force-pushed the fix/parseas-response-type branch from e9ae2d5 to c1f7775 Compare June 16, 2026 05:32
@pkg-pr-new

pkg-pr-new Bot commented Jun 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

@hey-api/codegen-core

npm i https://pkg.pr.new/@hey-api/codegen-core@4075

@hey-api/json-schema-ref-parser

npm i https://pkg.pr.new/@hey-api/json-schema-ref-parser@4075

@hey-api/nuxt

npm i https://pkg.pr.new/@hey-api/nuxt@4075

@hey-api/openapi-ts

npm i https://pkg.pr.new/@hey-api/openapi-ts@4075

@hey-api/shared

npm i https://pkg.pr.new/@hey-api/shared@4075

@hey-api/spec-types

npm i https://pkg.pr.new/@hey-api/spec-types@4075

@hey-api/types

npm i https://pkg.pr.new/@hey-api/types@4075

@hey-api/vite-plugin

npm i https://pkg.pr.new/@hey-api/vite-plugin@4075

commit: c1f7775

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.

When using parseAs the return type is type wrongly.

1 participant