@kubb/plugin-faker 5.0.0-alpha.9 → 5.0.0-beta.10

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