fix(plugin-msw): stop calling zero-parameter Faker factories with data - #837
fix(plugin-msw): stop calling zero-parameter Faker factories with data#837stijnvanhulle wants to merge 4 commits into
Conversation
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
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
◈ PR Lens
Architecture 6 components touched across 4 lanes. Inside the changed components — 1 viewComponent view — MSW Generator Internals Internal modules and JSX components within @kubb/plugin-msw executing schema validation, response formatting, and Faker mock integration. Data flow
Drill down
|
🦋 Changeset detectedLatest commit: b370223 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
|
Size Change: +69 B (+0.02%) Total Size: 312 kB 📦 View Changed
ℹ️ View Unchanged
|
More templates
@kubb/plugin-axios
@kubb/plugin-cypress
@kubb/plugin-faker
@kubb/plugin-fetch
@kubb/plugin-mcp
@kubb/plugin-msw
@kubb/plugin-react-query
@kubb/plugin-redoc
@kubb/plugin-swr
@kubb/plugin-ts
@kubb/plugin-vue-query
@kubb/plugin-zod
commit: |
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
🎯 Changes
A response with no declared content (or a
voidschema) parses to a placeholder schema of typeunknown.mswGeneratordecided 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 failsTS2554: Expected 0 arguments, but got 1. The handler also emitted an unused Faker import and inferred anapplication/jsonContent-Typeheader for a response with no content.hasResponseSchemainpackages/plugin-msw/src/utils.tsalready existed for exactly this purpose (used forContent-Typeinference and theResponse.tsxcomponent), but excluded onlyvoidandany, notunknown. This change:unknownto the schemashasResponseSchematreats as "no body"mswGenerator.tsxreusehasResponseSchemainstead of its own weaker check, for both the Faker mock path and the Faker importcreatePetFakersnapshot, which had the samevoid-response bug baked inFixes #834
✅ Checklist
pnpm run test.🚀 Release Impact
🤖 Generated with Claude Code
https://claude.ai/code/session_01A53QRXimcQx3YRBbdkZ3TH
Generated by Claude Code