@kubb/plugin-faker 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 +364 -0
  2. package/package.json +6 -6
package/extension.yaml ADDED
@@ -0,0 +1,364 @@
1
+ $schema: https://kubb.dev/schemas/extension.json
2
+ kind: plugin
3
+ id: plugin-faker
4
+ name: Faker
5
+ description: Generate realistic mock data using Faker.js from OpenAPI specifications.
6
+ category: mocks
7
+ type: official
8
+ npmPackage: "@kubb/plugin-faker"
9
+ docsPath: /plugins/plugin-faker
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
+ - faker
19
+ - mock-data
20
+ - mocks
21
+ - fixtures
22
+ - testing
23
+ - codegen
24
+ - openapi
25
+ dependencies:
26
+ - plugin-ts
27
+ resources:
28
+ documentation: https://kubb.dev/plugins/plugin-faker
29
+ repository: https://github.com/kubb-labs/plugins
30
+ issues: https://github.com/kubb-labs/plugins/issues
31
+ changelog: https://github.com/kubb-labs/plugins/blob/main/packages/plugin-faker/CHANGELOG.md
32
+ codesandbox: https://codesandbox.io/p/github/kubb-labs/plugins/main/examples/faker
33
+ featured: false
34
+ icon:
35
+ light: https://kubb.dev/feature/faker.svg
36
+ intro: |
37
+ # @kubb/plugin-faker
38
+
39
+ Generate mock data factories from your OpenAPI schema using [Faker.js](https://fakerjs.dev/). Create realistic test data that matches your API's types.
40
+ options:
41
+ - name: output
42
+ type: Output
43
+ required: false
44
+ default: "{ path: 'mocks', barrelType: 'named' }"
45
+ description: Specify the export location for the files and define the behavior of the output.
46
+ properties:
47
+ - name: path
48
+ type: string
49
+ required: true
50
+ description: Output directory or file for the generated code, relative to the global `output.path`.
51
+ tip: |
52
+ if `output.path` is a file, `group` cannot be used.
53
+ default: "'mocks'"
54
+ - name: barrelType
55
+ type: "'all' | 'named' | 'propagate' | false"
56
+ required: false
57
+ default: "'named'"
58
+ description: Specify what to export and optionally disable barrel-file generation.
59
+ tip: |
60
+ 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.
61
+ examples:
62
+ - name: all
63
+ files:
64
+ - lang: typescript
65
+ code: |
66
+ export * from './gen/petService.ts'
67
+ twoslash: false
68
+ - name: named
69
+ files:
70
+ - lang: typescript
71
+ code: |
72
+ export { PetService } from './gen/petService.ts'
73
+ twoslash: false
74
+ - name: propagate
75
+ files:
76
+ - lang: typescript
77
+ code: ""
78
+ twoslash: false
79
+ - name: "false"
80
+ files:
81
+ - lang: typescript
82
+ code: ""
83
+ twoslash: false
84
+ - name: banner
85
+ type: "string | ((node: RootNode) => string)"
86
+ required: false
87
+ 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.
88
+ - name: footer
89
+ type: "string | ((node: RootNode) => string)"
90
+ required: false
91
+ 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.
92
+ - name: override
93
+ type: boolean
94
+ required: false
95
+ default: "false"
96
+ description: Whether Kubb overrides existing external files that can be generated if they already exist.
97
+ - name: group
98
+ type: Group
99
+ required: false
100
+ description: |
101
+ Grouping combines files in a folder based on a specific `type`.
102
+ examples:
103
+ - name: kubb.config.ts
104
+ files:
105
+ - lang: typescript
106
+ code: |
107
+ group: {
108
+ type: 'tag',
109
+ name({ group }) {
110
+ return `${group}Controller`
111
+ }
112
+ }
113
+ twoslash: false
114
+ body: |
115
+ With the configuration above, the generator emits:
116
+
117
+ ```text
118
+ .
119
+ ├── src/
120
+ │ └── petController/
121
+ │ │ ├── addPet.ts
122
+ │ │ └── getPet.ts
123
+ │ └── storeController/
124
+ │ ├── createStore.ts
125
+ │ └── getStoreById.ts
126
+ ├── petStore.yaml
127
+ ├── kubb.config.ts
128
+ └── package.json
129
+ ```
130
+ properties:
131
+ - name: type
132
+ type: "'tag'"
133
+ required: true
134
+ description: Specify the property to group files by. Required when `group` is defined.
135
+ note: |
136
+ `Required: true*` means this is required only when the `group` option is used. The `group` option itself is optional.
137
+ body: |
138
+ - `'tag'`: Uses the first tag from `operation.getTags().at(0)?.name`
139
+ - name: name
140
+ type: "(context: GroupContext) => string"
141
+ required: false
142
+ default: (ctx) => `${ctx.group}Controller`
143
+ description: Return the name of a group based on the group name. This is used for file and helper name generation.
144
+ - name: dateParser
145
+ type: "'faker' | 'dayjs' | 'moment' | string"
146
+ required: false
147
+ default: "'faker'"
148
+ description: Choose which formatter to use for `date`, `time`, or `datetime` fields represented as strings.
149
+ tip: |
150
+ You can use another library that exposes a default export. Kubb adds the import automatically.
151
+ examples:
152
+ - name: "'faker'"
153
+ files:
154
+ - lang: ts
155
+ code: |
156
+ faker.date.anytime().toISOString().substring(0, 10)
157
+ - name: "'dayjs'"
158
+ files:
159
+ - lang: ts
160
+ code: |
161
+ dayjs(faker.date.anytime()).format('YYYY-MM-DD')
162
+ - name: "'moment'"
163
+ files:
164
+ - lang: ts
165
+ code: |
166
+ moment(faker.date.anytime()).format('YYYY-MM-DD')
167
+ - name: mapper
168
+ type: Record<string, string>
169
+ required: false
170
+ description: Override individual properties with custom Faker expressions.
171
+ - name: paramsCasing
172
+ type: "'camelcase'"
173
+ required: false
174
+ description: Transform parameter property names in generated mocks for path, query, and headers.
175
+ important: |
176
+ Use the same `paramsCasing` value in `@kubb/plugin-ts` so the generated mock objects stay compatible with the generated types.
177
+ - name: regexGenerator
178
+ type: "'faker' | 'randexp'"
179
+ required: false
180
+ default: "'faker'"
181
+ description: Generate strings from regex patterns using Faker or randexp.
182
+ examples:
183
+ - name: "'faker'"
184
+ files:
185
+ - lang: ts
186
+ code: |
187
+ faker.helpers.fromRegExp('^[A-Z]+$')
188
+ - name: "'randexp'"
189
+ files:
190
+ - lang: ts
191
+ code: |
192
+ new RandExp(/^[A-Z]+$/).gen()
193
+ - name: seed
194
+ type: number | number[]
195
+ required: false
196
+ description: Seed faker for deterministic output.
197
+ - name: locale
198
+ type: string
199
+ required: false
200
+ default: "'en'"
201
+ description: Generate mock data using a locale-specific Faker instance.
202
+ tip: |
203
+ See the [Faker.js localization docs](https://fakerjs.dev/api/localization.html) for the full list of supported locales.
204
+ examples:
205
+ - name: "'de'"
206
+ files:
207
+ - lang: ts
208
+ code: |
209
+ import { fakerDE as faker } from '@faker-js/faker'
210
+ - name: "'de_AT'"
211
+ files:
212
+ - lang: ts
213
+ code: |
214
+ import { fakerDE_AT as faker } from '@faker-js/faker'
215
+ - name: include
216
+ type: Array<Include>
217
+ required: false
218
+ description: Array containing include parameters to include tags, operations, methods, paths, or content types.
219
+ codeBlock:
220
+ lang: typescript
221
+ title: Include
222
+ code: |
223
+ export type Include = {
224
+ type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
225
+ pattern: string | RegExp
226
+ }
227
+ - name: exclude
228
+ type: Array<Exclude>
229
+ required: false
230
+ description: Array containing exclude parameters to exclude or skip tags, operations, methods, paths, or content types.
231
+ codeBlock:
232
+ lang: typescript
233
+ title: Exclude
234
+ code: |
235
+ export type Exclude = {
236
+ type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
237
+ pattern: string | RegExp
238
+ }
239
+ - name: override
240
+ type: Array<Override>
241
+ required: false
242
+ description: Array containing override parameters to override `options` based on tags, operations, methods, paths, or content types.
243
+ codeBlock:
244
+ lang: typescript
245
+ title: Override
246
+ code: |
247
+ export type Override = {
248
+ type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
249
+ pattern: string | RegExp
250
+ options: PluginOptions
251
+ }
252
+ - name: generators
253
+ type: Array<Generator<PluginFaker>>
254
+ required: false
255
+ experimental: true
256
+ description: |
257
+ Define additional generators next to the built-in generators.
258
+
259
+ See [Generators](https://kubb.dev/docs/5.x/guides/creating-plugins) for more information on how to use generators.
260
+ - name: resolver
261
+ type: Partial<ResolverFaker>
262
+ required: false
263
+ description: Customize helper naming on top of the active compatibility preset.
264
+ codeBlock:
265
+ lang: typescript
266
+ code: |
267
+ pluginFaker({
268
+ resolver: {
269
+ resolveName(name) {
270
+ return `${this.default(name)}Mock`
271
+ },
272
+ },
273
+ })
274
+ - name: transformer
275
+ type: ast.Visitor
276
+ required: false
277
+ description: Apply a single AST visitor before the faker helpers are rendered.
278
+ codeBlock:
279
+ lang: typescript
280
+ code: |
281
+ pluginFaker({
282
+ transformer: {
283
+ schema(node) {
284
+ return { ...node, description: undefined }
285
+ },
286
+ },
287
+ })
288
+ - name: printer
289
+ type: "{ nodes?: PrinterFakerNodes }"
290
+ required: false
291
+ description: |
292
+ Override individual printer node handlers to customize how specific schema types are rendered.
293
+
294
+ Each key is a `SchemaType` (for example `'integer'`, `'date'`, or `'ref'`). The function you provide replaces the built-in handler for that type. Use `this.transform` to recurse into nested schema nodes and `this.options` to read printer options.
295
+ examples:
296
+ - name: Override integer to float()
297
+ files:
298
+ - lang: typescript
299
+ code: |
300
+ import { pluginFaker } from '@kubb/plugin-faker'
301
+
302
+ pluginFaker({
303
+ printer: {
304
+ nodes: {
305
+ integer() {
306
+ return 'faker.number.float()'
307
+ },
308
+ },
309
+ },
310
+ })
311
+ twoslash: false
312
+ - name: Override date strings
313
+ files:
314
+ - lang: typescript
315
+ code: |
316
+ import { pluginFaker } from '@kubb/plugin-faker'
317
+
318
+ pluginFaker({
319
+ printer: {
320
+ nodes: {
321
+ date(node) {
322
+ if (node.representation === 'string') {
323
+ return 'new Date().toISOString().substring(0, 10)'
324
+ }
325
+
326
+ return 'new Date()'
327
+ },
328
+ },
329
+ },
330
+ })
331
+ twoslash: false
332
+ examples:
333
+ - name: kubb.config.ts
334
+ files:
335
+ - lang: typescript
336
+ code: |
337
+ import { defineConfig } from 'kubb'
338
+ import { pluginFaker } from '@kubb/plugin-faker'
339
+ import { pluginTs } from '@kubb/plugin-ts'
340
+
341
+ export default defineConfig({
342
+ input: {
343
+ path: './petStore.yaml',
344
+ },
345
+ output: {
346
+ path: './src/gen',
347
+ },
348
+ plugins: [
349
+ pluginTs({
350
+ output: {
351
+ path: './types',
352
+ },
353
+ }),
354
+ pluginFaker({
355
+ output: {
356
+ path: './mocks',
357
+ barrelType: 'named',
358
+ },
359
+ seed: [100],
360
+ paramsCasing: 'camelcase',
361
+ }),
362
+ ],
363
+ })
364
+ twoslash: false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-faker",
3
- "version": "5.0.0-beta.3",
3
+ "version": "5.0.0-beta.4",
4
4
  "description": "Faker.js data generator plugin for Kubb, creating realistic mock data from OpenAPI specifications for development and testing.",
5
5
  "keywords": [
6
6
  "code-generator",
@@ -31,7 +31,7 @@
31
31
  "files": [
32
32
  "src",
33
33
  "dist",
34
- "plugin.json",
34
+ "extension.yaml",
35
35
  "!/**/**.test.**",
36
36
  "!/**/__tests__/**",
37
37
  "!/**/__snapshots__/**"
@@ -71,15 +71,15 @@
71
71
  "registry": "https://registry.npmjs.org/"
72
72
  },
73
73
  "dependencies": {
74
- "@kubb/core": "5.0.0-beta.3",
75
- "@kubb/renderer-jsx": "5.0.0-beta.3",
76
- "@kubb/plugin-ts": "5.0.0-beta.3"
74
+ "@kubb/core": "5.0.0-beta.4",
75
+ "@kubb/renderer-jsx": "5.0.0-beta.4",
76
+ "@kubb/plugin-ts": "5.0.0-beta.4"
77
77
  },
78
78
  "devDependencies": {
79
79
  "@internals/utils": "0.0.0"
80
80
  },
81
81
  "peerDependencies": {
82
- "@kubb/renderer-jsx": "5.0.0-beta.3"
82
+ "@kubb/renderer-jsx": "5.0.0-beta.4"
83
83
  },
84
84
  "size-limit": [
85
85
  {