@kubb/plugin-msw 5.0.0-beta.3 → 5.0.0-beta.4

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.
Files changed (2) hide show
  1. package/extension.yaml +260 -0
  2. package/package.json +7 -7
package/extension.yaml ADDED
@@ -0,0 +1,260 @@
1
+ $schema: https://kubb.dev/schemas/extension.json
2
+ kind: plugin
3
+ id: plugin-msw
4
+ name: MSW
5
+ description: Generate Mock Service Worker (MSW) handlers from OpenAPI specifications.
6
+ category: mocks
7
+ type: official
8
+ npmPackage: "@kubb/plugin-msw"
9
+ docsPath: /plugins/plugin-msw
10
+ repo: https://github.com/kubb-labs/plugins
11
+ maintainers:
12
+ - name: Stijn Van Hulle
13
+ github: stijnvanhulle
14
+ compatibility:
15
+ kubb: ">=5.0.0"
16
+ node: ">=22"
17
+ tags:
18
+ - msw
19
+ - mock-service-worker
20
+ - api-mocking
21
+ - mocks
22
+ - testing
23
+ - codegen
24
+ - openapi
25
+ dependencies:
26
+ - plugin-ts
27
+ - plugin-faker
28
+ resources:
29
+ documentation: https://kubb.dev/plugins/plugin-msw
30
+ repository: https://github.com/kubb-labs/plugins
31
+ issues: https://github.com/kubb-labs/plugins/issues
32
+ changelog: https://github.com/kubb-labs/plugins/blob/main/packages/plugin-msw/CHANGELOG.md
33
+ codesandbox: https://codesandbox.io/p/github/kubb-labs/plugins/main/examples/msw
34
+ featured: false
35
+ icon:
36
+ light: https://kubb.dev/feature/msw.svg
37
+ intro: |
38
+ # @kubb/plugin-msw
39
+
40
+ Generate [MSW](https://mswjs.io/) API mock handlers from your OpenAPI schema. Mock API requests in development and tests with type-safe handlers.
41
+ options:
42
+ - name: output
43
+ type: Output
44
+ required: false
45
+ default: "{ path: 'handlers', barrelType: 'named' }"
46
+ description: Specify the export location for the files and define the behavior of the output.
47
+ properties:
48
+ - name: path
49
+ type: string
50
+ required: true
51
+ description: Output directory or file for the generated code, relative to the global `output.path`.
52
+ tip: |
53
+ if `output.path` is a file, `group` cannot be used.
54
+ default: "'handlers'"
55
+ - name: barrelType
56
+ type: "'all' | 'named' | 'propagate' | false"
57
+ required: false
58
+ default: "'named'"
59
+ description: Specify what to export and optionally disable barrel-file generation.
60
+ tip: |
61
+ Using `propagate` will prevent a plugin from creating a barrel file, but it will still propagate, allowing [`output.barrelType`](https://kubb.dev/docs/5.x/configuration#output-barreltype) to export the specific function or type.
62
+ examples:
63
+ - name: all
64
+ files:
65
+ - lang: typescript
66
+ code: |
67
+ export * from './gen/petService.ts'
68
+ twoslash: false
69
+ - name: named
70
+ files:
71
+ - lang: typescript
72
+ code: |
73
+ export { PetService } from './gen/petService.ts'
74
+ twoslash: false
75
+ - name: propagate
76
+ files:
77
+ - lang: typescript
78
+ code: ""
79
+ twoslash: false
80
+ - name: "false"
81
+ files:
82
+ - lang: typescript
83
+ code: ""
84
+ twoslash: false
85
+ - name: banner
86
+ type: "string | ((node: RootNode) => string)"
87
+ required: false
88
+ description: Add a banner comment at the top of every generated file. Accepts a static string or a function that receives the `RootNode` and returns a string.
89
+ - name: footer
90
+ type: "string | ((node: RootNode) => string)"
91
+ required: false
92
+ description: Add a footer comment at the end of every generated file. Accepts a static string or a function that receives the `RootNode` and returns a string.
93
+ - name: override
94
+ type: boolean
95
+ required: false
96
+ default: "false"
97
+ description: Whether Kubb overrides existing external files that can be generated if they already exist.
98
+ - name: handlers
99
+ type: boolean
100
+ required: false
101
+ default: "false"
102
+ description: Create a `handlers.ts` file with all handlers grouped by methods.
103
+ - name: contentType
104
+ type: "'application/json' | (string & {})"
105
+ required: false
106
+ description: |
107
+ Define which content type to use.
108
+
109
+ By default, Kubb uses the first JSON-valid media type.
110
+ - name: baseURL
111
+ type: string
112
+ required: false
113
+ description: Sets a custom base URL for all generated calls. When not set, the base URL is automatically taken from the OAS spec via the adapter (e.g. the `servers[0].url` field).
114
+ - name: group
115
+ type: Group
116
+ required: false
117
+ description: |
118
+ Grouping combines files in a folder based on a specific `type`.
119
+ examples:
120
+ - name: kubb.config.ts
121
+ files:
122
+ - lang: typescript
123
+ code: |
124
+ group: {
125
+ type: 'tag',
126
+ name({ group }) {
127
+ return `${group}Controller`
128
+ }
129
+ }
130
+ twoslash: false
131
+ body: |
132
+ With the configuration above, the generator emits:
133
+
134
+ ```text
135
+ .
136
+ ├── src/
137
+ │ └── petController/
138
+ │ │ ├── addPet.ts
139
+ │ │ └── getPet.ts
140
+ │ └── storeController/
141
+ │ ├── createStore.ts
142
+ │ └── getStoreById.ts
143
+ ├── petStore.yaml
144
+ ├── kubb.config.ts
145
+ └── package.json
146
+ ```
147
+ properties:
148
+ - name: type
149
+ type: "'tag'"
150
+ required: true
151
+ description: Specify the property to group files by. Required when `group` is defined.
152
+ note: |
153
+ `Required: true*` means this is required only when the `group` option is used. The `group` option itself is optional.
154
+ body: |
155
+ - `'tag'`: Uses the first tag from `operation.getTags().at(0)?.name`
156
+ - name: name
157
+ type: "(context: GroupContext) => string"
158
+ required: false
159
+ default: (ctx) => `${ctx.group}Controller`
160
+ description: Return the name of a group based on the group name. This is used for file and identifier generation.
161
+ - name: parser
162
+ type: "'data' | 'faker'"
163
+ required: false
164
+ default: "'data'"
165
+ description: Choose which parser to use when generating response data.
166
+ body: |
167
+ - `'faker'` will use `@kubb/plugin-faker` to generate the data for the response.
168
+ - `'data'` will use your custom data to generate the data for the response.
169
+ - name: include
170
+ type: Array<Include>
171
+ required: false
172
+ description: Array containing include parameters to include tags, operations, methods, paths, or content types.
173
+ codeBlock:
174
+ lang: typescript
175
+ title: Include
176
+ code: |
177
+ export type Include = {
178
+ type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
179
+ pattern: string | RegExp
180
+ }
181
+ - name: exclude
182
+ type: Array<Exclude>
183
+ required: false
184
+ description: Array containing exclude parameters to exclude or skip tags, operations, methods, paths, or content types.
185
+ codeBlock:
186
+ lang: typescript
187
+ title: Exclude
188
+ code: |
189
+ export type Exclude = {
190
+ type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
191
+ pattern: string | RegExp
192
+ }
193
+ - name: override
194
+ type: Array<Override>
195
+ required: false
196
+ description: Array containing override parameters to override `options` based on tags, operations, methods, paths, or content types.
197
+ codeBlock:
198
+ lang: typescript
199
+ title: Override
200
+ code: |
201
+ export type Override = {
202
+ type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
203
+ pattern: string | RegExp
204
+ options: PluginOptions
205
+ }
206
+ - name: generators
207
+ type: Array<Generator<PluginMsw>>
208
+ required: false
209
+ experimental: true
210
+ description: |
211
+ Define additional generators next to the built-in generators.
212
+
213
+ See [Generators](https://kubb.dev/docs/5.x/guides/creating-plugins) for more information on how to use generators.
214
+ - name: transformers
215
+ type: object
216
+ required: false
217
+ description: Customize the generated names based on the type provided by the plugin.
218
+ properties:
219
+ - name: name
220
+ type: "(name: string, type?: ResolveType) => string"
221
+ required: false
222
+ description: Customize the names based on the type that is provided by the plugin.
223
+ codeBlock:
224
+ lang: typescript
225
+ code: |
226
+ type ResolveType = 'file' | 'function' | 'type' | 'const'
227
+ examples:
228
+ - name: kubb.config.ts
229
+ files:
230
+ - lang: typescript
231
+ code: |
232
+ import { defineConfig } from 'kubb'
233
+ import { pluginMsw } from '@kubb/plugin-msw'
234
+ import { pluginTs } from '@kubb/plugin-ts'
235
+
236
+ export default defineConfig({
237
+ input: {
238
+ path: './petStore.yaml',
239
+ },
240
+ output: {
241
+ path: './src/gen',
242
+ },
243
+ plugins: [
244
+ pluginTs(),
245
+ pluginMsw({
246
+ output: {
247
+ path: './mocks',
248
+ barrelType: 'named',
249
+ banner: '/* eslint-disable no-alert, no-console */',
250
+ footer: '',
251
+ },
252
+ group: {
253
+ type: 'tag',
254
+ name: ({ group }) => `${group}Service`,
255
+ },
256
+ handlers: true,
257
+ }),
258
+ ],
259
+ })
260
+ twoslash: false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-msw",
3
- "version": "5.0.0-beta.3",
3
+ "version": "5.0.0-beta.4",
4
4
  "description": "Mock Service Worker (MSW) handlers generator plugin for Kubb, creating API mocks from OpenAPI specifications for frontend development and testing.",
5
5
  "keywords": [
6
6
  "api-mocking",
@@ -30,7 +30,7 @@
30
30
  "files": [
31
31
  "src",
32
32
  "dist",
33
- "plugin.json",
33
+ "extension.yaml",
34
34
  "!/**/**.test.**",
35
35
  "!/**/__tests__/**",
36
36
  "!/**/__snapshots__/**"
@@ -76,16 +76,16 @@
76
76
  "registry": "https://registry.npmjs.org/"
77
77
  },
78
78
  "dependencies": {
79
- "@kubb/core": "5.0.0-beta.3",
80
- "@kubb/renderer-jsx": "5.0.0-beta.3",
81
- "@kubb/plugin-faker": "5.0.0-beta.3",
82
- "@kubb/plugin-ts": "5.0.0-beta.3"
79
+ "@kubb/core": "5.0.0-beta.4",
80
+ "@kubb/renderer-jsx": "5.0.0-beta.4",
81
+ "@kubb/plugin-faker": "5.0.0-beta.4",
82
+ "@kubb/plugin-ts": "5.0.0-beta.4"
83
83
  },
84
84
  "devDependencies": {
85
85
  "@internals/utils": "0.0.0"
86
86
  },
87
87
  "peerDependencies": {
88
- "@kubb/renderer-jsx": "5.0.0-beta.3"
88
+ "@kubb/renderer-jsx": "5.0.0-beta.4"
89
89
  },
90
90
  "size-limit": [
91
91
  {