@kubb/plugin-msw 5.0.11 → 5.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/docs/options.md +2 -2
- package/docs/overview.md +9 -11
- package/kubb-extension.json +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
package/dist/index.js
CHANGED
package/docs/options.md
CHANGED
|
@@ -62,7 +62,7 @@ Default value. Returns the data you pass to the handler, typed with the `@kubb/p
|
|
|
62
62
|
:::
|
|
63
63
|
|
|
64
64
|
:::field{name="'faker'"}
|
|
65
|
-
Falls back to a value generated by `@kubb/plugin-faker` when `data` is
|
|
65
|
+
Falls back to a value generated by `@kubb/plugin-faker` when `data` is `undefined` or `null`. Other falsy values, such as `0`, `false`, or `''`, are sent as the response body. Register `pluginFaker()` alongside this plugin.
|
|
66
66
|
:::
|
|
67
67
|
|
|
68
68
|
::
|
|
@@ -72,7 +72,7 @@ export function getPetHandler(data?: GetPetQueryResponse | ((info: Parameters<Pa
|
|
|
72
72
|
return http.get('/pet/:petId', function handler(info) {
|
|
73
73
|
if (typeof data === 'function') return data(info)
|
|
74
74
|
|
|
75
|
-
return new Response(JSON.stringify(data
|
|
75
|
+
return new Response(JSON.stringify(data ?? createGetPetQueryResponse(data)), {
|
|
76
76
|
status: 200,
|
|
77
77
|
headers: { 'Content-Type': 'application/json' },
|
|
78
78
|
})
|
package/docs/overview.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# MSW
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The MSW plugin generates a typed MSW request handler for each operation in your OpenAPI spec.
|
|
4
4
|
|
|
5
|
-
Each handler returns the data you pass to it. With `parser: 'faker'`,
|
|
5
|
+
Each handler returns the data you pass to it. With `parser: 'faker'`, a handler called without data returns mock data from `@kubb/plugin-faker`. Only operations with a success response schema get mock data.
|
|
6
6
|
|
|
7
7
|
## Setup
|
|
8
8
|
|
|
9
|
-
- Add `@kubb/plugin-ts
|
|
10
|
-
- Add `@kubb/plugin-faker` when you set `parser: 'faker'
|
|
11
|
-
- Install
|
|
9
|
+
- Add `@kubb/plugin-ts` for the request and response types.
|
|
10
|
+
- Add `@kubb/plugin-faker` when you set `parser: 'faker'`, and install `@faker-js/faker` v10. The default `data` parser does not need it.
|
|
11
|
+
- Install `msw` v2 in the app that uses the generated code.
|
|
12
12
|
|
|
13
13
|
## Options worth knowing
|
|
14
14
|
|
|
@@ -16,8 +16,12 @@ Each handler returns the data you pass to it. With `parser: 'faker'`, it falls b
|
|
|
16
16
|
- `handlers` writes a `handlers.ts` file that exports every handler, ready to spread into `setupServer` or `setupWorker`.
|
|
17
17
|
- `baseURL` is prepended to the path each handler matches.
|
|
18
18
|
|
|
19
|
+
See [Options](https://kubb.dev/extensions/kubb-labs/plugin-msw/options) for every option and its default.
|
|
20
|
+
|
|
19
21
|
## Example
|
|
20
22
|
|
|
23
|
+
The config below generates one handler per operation and a `handlers.ts` file that exports them all.
|
|
24
|
+
|
|
21
25
|
```typescript [kubb.config.ts]
|
|
22
26
|
import { defineConfig } from 'kubb/config'
|
|
23
27
|
import { pluginTs } from '@kubb/plugin-ts'
|
|
@@ -32,9 +36,3 @@ export default defineConfig({
|
|
|
32
36
|
],
|
|
33
37
|
})
|
|
34
38
|
```
|
|
35
|
-
|
|
36
|
-
## See also
|
|
37
|
-
|
|
38
|
-
- [MSW](https://mswjs.io/)
|
|
39
|
-
- [@kubb/plugin-ts](https://kubb.dev/extensions/kubb-labs/plugin-ts)
|
|
40
|
-
- [@kubb/plugin-faker](https://kubb.dev/extensions/kubb-labs/plugin-faker)
|
package/kubb-extension.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-msw",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.12",
|
|
4
4
|
"description": "Generate Mock Service Worker (MSW) request handlers with Kubb. Intercept HTTP requests in the browser or Node.js for frontend development and testing.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api-mocking",
|
|
@@ -80,8 +80,8 @@
|
|
|
80
80
|
"registry": "https://registry.npmjs.org/"
|
|
81
81
|
},
|
|
82
82
|
"dependencies": {
|
|
83
|
-
"@kubb/plugin-faker": "^5.1.
|
|
84
|
-
"@kubb/plugin-ts": "^5.0.
|
|
83
|
+
"@kubb/plugin-faker": "^5.1.5",
|
|
84
|
+
"@kubb/plugin-ts": "^5.0.10"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@internals/shared": "0.0.0",
|