You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(core): allow mock data generators only (#3398)
* feat(mock): add generateHandlers option to suppress MSW handler output
When `generateHandlers: false` is set in mock options, only faker data
generator functions are produced — no MSW request handlers, no aggregated
handler array, and no `msw` dependency in imports. This allows users who
only need mock data factories to avoid the MSW dependency entirely.
* fix(core): handle empty handlerName in writers when generateHandlers is false
Guard handlerName accumulation in target and target-tags writers to avoid
producing junk `()` entries when handlers are disabled. Also update the
split-tags index file to use barrel exports when there is no aggregated
handler function to reference.
* test(mock): add coverage for generateHandlers: false option
Verify that handler and handlerName are empty, mock data function is
still generated, msw imports are excluded, and faker locale imports
work correctly when generateHandlers is disabled.
* docs(mock): document generateHandlers option
Add generateHandlers to the configuration reference table and a new
"Data Generators Only" section to the MSW guide explaining the use case
and output differences.
* fix(core): avoid leading comma when accumulating handlerNames in target-tags
Copy file name to clipboardExpand all lines: docs/content/docs/guides/msw.mdx
+25Lines changed: 25 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -245,6 +245,31 @@ const server = setupServer(...handlers);
245
245
export { server };
246
246
```
247
247
248
+
## Data Generators Only
249
+
250
+
If you only need mock data factories without MSW request handlers, set `generateHandlers` to `false`:
251
+
252
+
```ts title="orval.config.ts"
253
+
exportdefaultdefineConfig({
254
+
petstore: {
255
+
output: {
256
+
mock: {
257
+
type: 'msw',
258
+
generateHandlers: false,
259
+
},
260
+
},
261
+
},
262
+
});
263
+
```
264
+
265
+
This generates only the `get<OperationId>ResponseMock` functions (powered by Faker.js) — no MSW handlers, no aggregated handler array, and no `msw` dependency in the output. Your project only needs `@faker-js/faker` as a dependency.
266
+
267
+
This is useful when you want mock data for:
268
+
- Unit tests with custom assertion libraries
269
+
- Storybook stories
270
+
- Seed scripts
271
+
- Any test setup that doesn't use MSW
272
+
248
273
## MSW Best Practices
249
274
250
275
The generated code follows [MSW best practices](https://mswjs.io/docs/best-practices):
0 commit comments