Skip to content

fix(plugin-msw): stop calling zero-parameter Faker factories with data - #837

Open
stijnvanhulle wants to merge 4 commits into
mainfrom
claude/github-issue-834-snt57d
Open

fix(plugin-msw): stop calling zero-parameter Faker factories with data#837
stijnvanhulle wants to merge 4 commits into
mainfrom
claude/github-issue-834-snt57d

Conversation

@stijnvanhulle

Copy link
Copy Markdown
Contributor

🎯 Changes

A response with no declared content (or a void schema) parses to a placeholder schema of type unknown. mswGenerator decided whether to wire up the Faker mock path with a raw truthy check on the schema (!!response.content?.[0]?.schema), which is true even for these placeholder schemas. That made the generated handler call a zero-parameter Faker factory with an argument (createPingResponse(data)), which fails TS2554: Expected 0 arguments, but got 1. The handler also emitted an unused Faker import and inferred an application/json Content-Type header for a response with no content.

hasResponseSchema in packages/plugin-msw/src/utils.ts already existed for exactly this purpose (used for Content-Type inference and the Response.tsx component), but excluded only void and any, not unknown. This change:

  • Adds unknown to the schemas hasResponseSchema treats as "no body"
  • Makes mswGenerator.tsx reuse hasResponseSchema instead of its own weaker check, for both the Faker mock path and the Faker import
  • Updates the createPetFaker snapshot, which had the same void-response bug baked in

Fixes #834

✅ 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_01A53QRXimcQx3YRBbdkZ3TH


Generated by Claude Code

Bodyless responses parse to a schema of type "unknown", but mswGenerator
only checked schema truthiness to decide whether to wire up the Faker
mock path. That made handlers call a zero-parameter Faker factory with
an argument, failing TS2554, and add an unused Faker import plus an
incorrect application/json Content-Type header.

hasResponseSchema (already used for Content-Type inference) now also
treats "unknown" as no-schema, and mswGenerator reuses it instead of
its own weaker check.

Fixes #834

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

codesandbox Bot commented Sep 3, 2026

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@coldtea-pr-lens

coldtea-pr-lens Bot commented Sep 3, 2026

Copy link
Copy Markdown

◈ PR Lens

🟢 +0 new · 🟠 ~6 changed · 🔴 -0 removed · 1 flow · 10 files · commit b370223


Architecture

Architecture diagram for kubb-labs/plugins at b370223

6 components touched across 4 lanes.

Open full size


Inside the changed components — 1 view

Component view — MSW Generator Internals

Internal modules and JSX components within @⁠kubb/plugin-msw executing schema validation, response formatting, and Faker mock integration.

Architecture view of Component view — MSW Generator Internals in kubb-labs/plugins

Data flow

Data flow diagram for kubb-labs/plugins at b370223

Generating MSW handlers for bodyless operations

Open full size


Drill down
Testing & Mocking — 3 components
🟡 CHANGED @⁠kubb/plugin-msw

Generates Mock Service Worker (MSW) route handlers and response helpers from OpenAPI operations.

🟡 CHANGED MSW Generator

Builds MSW handler files, conditionally importing Faker mock factories only when valid success schemas exist.

🟡 CHANGED Schema & Header Utils

Determines valid response schemas and content types, filtering out void, any, and unknown placeholder schemas.

Examples & Suites — 3 components
🟡 CHANGED Advanced PetStore Pipeline

Advanced example containing updated MSW handler snapshots for PetStore operations.

🟡 CHANGED MSW Mocking Example

Example application verifying MSW handler output for bodyless error and status responses.

🟡 CHANGED OpenAPI 3.0 Integration Tests

Integration snapshot test suite covering MSW generation across baseURL, tag grouping, and parser variants.


View

  • Architecture lens
  • Data flow lens
  • Expand every detail
  • Show unchanged neighbours

Tip

The boxes under View are live. Tick Architecture lens or Data flow lens to choose which diagrams appear, or Expand every detail to open every drill-down at once. The comment redraws in place a few seconds later.

🪧 More tips
  • Run PR Lens on your own machine: npx skills add coldteadotai/pr-lens installs the agent skill. Then tell your coding agent: "Diagram the change you just made with PR Lens and attach it to the pull request."
  • Draw a diff before it is even a pull request: npx @coldtea/pr-lens-cli analyze --base origin/main reads the diff with your own model key, and npx @coldtea/pr-lens-cli render .pr-lens/graph.json draws the same lenses on your machine.
  • Show unchanged neighbours lists the components this change did not touch alongside the ones it did, so the drill-down shows what the changed code sits next to.
  • GitHub will not let you zoom an image in a comment. The link under each diagram opens it full size on a page of its own, where you can.
  • The CLI's render picks up .github/pr-lens.yml automatically and applies your corrections (renames, exclusions, lane pins) at draw time.
  • Would you rather run it from CI on a key of your own? Add .github/workflows/pr-lens.yml with coldteadotai/pr-lens/packages/action@v0 and a model key in your repository secrets, say GEMINI_API_KEY. The Action asks Gemini by default, or OpenAI and any endpoint speaking /chat/completions through its provider input.
  • PR Lens is free for open source. A star on the repository is what keeps it going.
  • Push a new commit and the whole comment re-renders for the new head. An older run never overwrites a newer one, so a slow render cannot put a stale diagram back.
  • The diagrams follow your GitHub theme, so dark mode gets the dark render and light mode the light one, and the moving dots show this pull request's data in motion.

◈ Rendered by PR Lens · crafted with ❤️ by the Coldtea team · Something drawn wrong?

@changeset-bot

changeset-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b370223

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

This PR includes changesets to release 1 package
Name Type
@kubb/plugin-msw Patch

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

@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 64eec64a-e0fd-4565-91b6-27c8d361c442

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Size Change: +69 B (+0.02%)

Total Size: 312 kB

📦 View Changed
Filename Size Change
packages/plugin-msw/dist/index.cjs 5.85 kB +35 B (+0.6%)
packages/plugin-msw/dist/index.js 5.75 kB +34 B (+0.59%)
ℹ️ View Unchanged
Filename Size
packages/plugin-axios/dist/index.cjs 15.5 kB
packages/plugin-axios/dist/index.js 15 kB
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/index.cjs 15.5 kB
packages/plugin-fetch/dist/index.js 15 kB
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/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

@pkg-pr-new

pkg-pr-new Bot commented Sep 3, 2026

Copy link
Copy Markdown
More templates

@kubb/plugin-axios

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

@kubb/plugin-cypress

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

@kubb/plugin-faker

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

@kubb/plugin-fetch

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

@kubb/plugin-mcp

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

@kubb/plugin-msw

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

@kubb/plugin-react-query

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

@kubb/plugin-redoc

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

@kubb/plugin-swr

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

@kubb/plugin-ts

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

@kubb/plugin-vue-query

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

@kubb/plugin-zod

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

commit: b370223

stijnvanhulle and others added 3 commits September 3, 2026 15:59
The petStore fixture's 400/404/405 responses declare no content, so
they hit the same bug as issue #834. Update their snapshots to drop
the Content-Type header and make the data parameter optional, matching
the fixed hasResponseSchema check.

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

plugin-msw: bodyless response handler passes data to a zero-parameter Faker factory

2 participants