Generate schema-valid MSW handlers directly from your Zod schemas #2752
gonll
started this conversation in
Show and tell
Replies: 1 comment 2 replies
|
Hi @gonll. Thanks for building Zodmint. I wonder did you compare it to Data? I haven't ported back the handler generation, but that's on the roadmap. I went for full Standard Schema support instead of just Zod so devs could bring their own schema libraries for modeling. Would like to hear your thoughts on it. |
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
zodmint/msw
generate schema-valid MSW handlers directly from your Zod schemas
Hey folks 👋
I built [zodmint](https://github.com/gonll/zodmint), a fixture generator that derives mock data from Zod schemas, guaranteeing
schema.safeParse(output).success === trueon every value. It ships a first-classzodmint/mswsub-entry that wires a Zod schema directly to an MSW v2 handler.The problem it solves
When you hand-write MSW handlers, the response body is decoupled from your schema.
faker.internet.email()doesn't know about.max(10).faker.number.int()doesn't know about.positive(). Your handlers pass in tests but the shape drifts silently from what your app actually validates.How it works
Every response is generated from the schema itself, so it always satisfies the same validation your app runs on real API responses.
It supports all the options you'd expect:
Or batch with
mockHandlers():Install
MSW and Zod are peer dependencies you likely already have.
Full docs: [github.com/gonll/zodmint](https://github.com/gonll/zodmint)
Would love feedback, especially from folks with complex union/discriminated union schemas, those are the interesting edge cases. 🙏
All reactions