Skip to content

feat(plugin-axios,plugin-fetch): add returnType option to unwrap the resolved data - #818

Open
stijnvanhulle wants to merge 5 commits into
mainfrom
claude/unwrap-alternative-research-ga21xw
Open

feat(plugin-axios,plugin-fetch): add returnType option to unwrap the resolved data#818
stijnvanhulle wants to merge 5 commits into
mainfrom
claude/unwrap-alternative-research-ga21xw

Conversation

@stijnvanhulle

@stijnvanhulle stijnvanhulle commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🎯 Changes

Adds returnType: 'full' | 'data' (default 'full') to @kubb/plugin-axios and @kubb/plugin-fetch, requested in kubb-labs/discussions#3952.

'data' unwraps a generated call down to the bare success body once throwOnError (on by default) rules out the error branch. It falls back to the full { status, data, error, contentType, request, response } result for a call that sets throwOnError: false, since that path still needs error to tell success from failure.

pluginAxios({ returnType: 'data' })
// const pet = await getPetById({ path: { petId: 1 } }) // Pet, not { status, data, ... }

Applies to both the standalone functions and the class-based SDK. It doesn't change @kubb/plugin-react-query, @kubb/plugin-vue-query, or @kubb/plugin-swr, which call the client directly and expect the full result, and the docs note that limitation explicitly.

How it works

  • internals/client: new ReturnTypeOption on Options/ResolvedOptions, threaded through the shared Operation and SdkClient builders. buildResultType picks RequestResult or the runtime's new UnwrappedResult type, and buildReturnStatement adds a .then((result) => (config.throwOnError ?? true ? result.data : result)) step for 'data'.
  • plugin-axios/plugin-fetch: default returnType = 'full', plus the matching UnwrappedResult runtime type in each templates/*.ts.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is for the docs (no release).

🤖 Generated with Claude Code

https://claude.ai/code/session_012DSVW79h2FdFDkoWWr6PwN

…resolved data

Discussion kubb-labs/discussions#3952 asked for a way to get the bare
success body back from a generated call instead of the full
{ status, data, error, contentType, request, response } result. Add
returnType: 'full' | 'data' (default 'full') to plugin-axios and
plugin-fetch, applying to both the standalone functions and the
class-based SDK.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012DSVW79h2FdFDkoWWr6PwN
@codesandbox

codesandbox Bot commented Sep 1, 2026

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@changeset-bot

changeset-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f2bf4a4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@kubb/plugin-axios Minor
@kubb/plugin-fetch Minor

Not sure what this means? Click here to learn what changesets are.

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

@pkg-pr-new

pkg-pr-new Bot commented Sep 1, 2026

Copy link
Copy Markdown
More templates

@kubb/plugin-axios

npm i https://pkg.pr.new/@kubb/plugin-axios@818

@kubb/plugin-cypress

npm i https://pkg.pr.new/@kubb/plugin-cypress@818

@kubb/plugin-faker

npm i https://pkg.pr.new/@kubb/plugin-faker@818

@kubb/plugin-fetch

npm i https://pkg.pr.new/@kubb/plugin-fetch@818

@kubb/plugin-mcp

npm i https://pkg.pr.new/@kubb/plugin-mcp@818

@kubb/plugin-msw

npm i https://pkg.pr.new/@kubb/plugin-msw@818

@kubb/plugin-react-query

npm i https://pkg.pr.new/@kubb/plugin-react-query@818

@kubb/plugin-redoc

npm i https://pkg.pr.new/@kubb/plugin-redoc@818

@kubb/plugin-swr

npm i https://pkg.pr.new/@kubb/plugin-swr@818

@kubb/plugin-ts

npm i https://pkg.pr.new/@kubb/plugin-ts@818

@kubb/plugin-vue-query

npm i https://pkg.pr.new/@kubb/plugin-vue-query@818

@kubb/plugin-zod

npm i https://pkg.pr.new/@kubb/plugin-zod@818

commit: f2bf4a4

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Size Change: +1.37 kB (+0.44%)

Total Size: 313 kB

📦 View Changed
Filename Size Change
packages/plugin-axios/dist/index.cjs 15.6 kB +335 B (+2.19%)
packages/plugin-axios/dist/index.js 15.2 kB +348 B (+2.35%)
packages/plugin-fetch/dist/index.cjs 15.6 kB +335 B (+2.19%)
packages/plugin-fetch/dist/index.js 15.2 kB +350 B (+2.36%)
ℹ️ View Unchanged
Filename Size
packages/plugin-axios/dist/rolldown-runtime-C0LytTxp.js 168 B
packages/plugin-cypress/dist/index.cjs 5.71 kB
packages/plugin-cypress/dist/index.js 5.62 kB
packages/plugin-cypress/dist/rolldown-runtime-C0LytTxp.js 168 B
packages/plugin-faker/dist/index.cjs 14.5 kB
packages/plugin-faker/dist/index.js 14.4 kB
packages/plugin-faker/dist/rolldown-runtime-C0LytTxp.js 168 B
packages/plugin-fetch/dist/rolldown-runtime-C0LytTxp.js 168 B
packages/plugin-mcp/dist/index.cjs 10 kB
packages/plugin-mcp/dist/index.js 9.54 kB
packages/plugin-mcp/dist/rolldown-runtime-C0LytTxp.js 168 B
packages/plugin-msw/dist/index.cjs 5.81 kB
packages/plugin-msw/dist/index.js 5.72 kB
packages/plugin-msw/dist/rolldown-runtime-C0LytTxp.js 168 B
packages/plugin-react-query/dist/index.cjs 17.8 kB
packages/plugin-react-query/dist/index.js 17.2 kB
packages/plugin-react-query/dist/rolldown-runtime-C0LytTxp.js 168 B
packages/plugin-redoc/dist/index.cjs 2.21 kB
packages/plugin-redoc/dist/index.js 1.74 kB
packages/plugin-redoc/dist/rolldown-runtime-C0LytTxp.js 168 B
packages/plugin-swr/dist/index.cjs 12 kB
packages/plugin-swr/dist/index.js 11.4 kB
packages/plugin-swr/dist/rolldown-runtime-C0LytTxp.js 168 B
packages/plugin-ts/dist/index.cjs 23.8 kB
packages/plugin-ts/dist/index.js 23.1 kB
packages/plugin-ts/dist/rolldown-runtime-CNktS9qV.js 291 B
packages/plugin-vue-query/dist/index.cjs 14.8 kB
packages/plugin-vue-query/dist/index.js 14.3 kB
packages/plugin-vue-query/dist/rolldown-runtime-C0LytTxp.js 168 B
packages/plugin-zod/dist/index.cjs 19.7 kB
packages/plugin-zod/dist/index.js 19.6 kB
packages/plugin-zod/dist/rolldown-runtime-C0LytTxp.js 168 B

compressed-size-action

…type

The plugin-axios and plugin-fetch runtime templates gained an
UnwrappedResult type for returnType: 'data' (PR #818). The tests/3.0.x
suite snapshots the generated .kubb/client.ts verbatim, so every
consumer's snapshot (axios, fetch, mcp, react-query, swr, vue-query)
needed the same addition.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012DSVW79h2FdFDkoWWr6PwN
…a shared runtime helper

/simplify's reuse, simplification, and altitude passes all converged
on the same finding: the generated return statement inlined
`config.throwOnError ?? true ? result.data : result` as a literal
string, restating a default the runtime already applies internally,
once per operation across every spec. The sibling `text/event-stream`
path already centralizes its post-processing in a runtime function
(toEventStream); this does the same for returnType: 'data' with a new
unwrapResult(promise, throwOnError) exported from both templates.

Verified with a real `pnpm generate` against a built plugin-axios,
covering the no-2xx-response edge case that broke CI on PR #820.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012DSVW79h2FdFDkoWWr6PwN
unwrapResult is a pure function over a promise, so it doesn't need
the axios/fetch client mocking machinery. Call it directly with a
resolved promise instead.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012DSVW79h2FdFDkoWWr6PwN
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