@kubb/plugin-faker 5.0.0-beta.3 → 5.0.0-beta.31
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/README.md +26 -5
- package/dist/{Faker-CdyPfOPg.d.ts → Faker-BaLJxPyl.d.ts} +2 -2
- package/dist/{Faker-fcQEB9i5.js → Faker-DwIc_lta.js} +38 -100
- package/dist/Faker-DwIc_lta.js.map +1 -0
- package/dist/{Faker-BgleOzVN.cjs → Faker-XuyEQflW.cjs} +37 -123
- package/dist/Faker-XuyEQflW.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/components.js +1 -1
- package/dist/{fakerGenerator-VJEVzLjc.cjs → fakerGenerator-BBr2WsG8.cjs} +236 -60
- package/dist/fakerGenerator-BBr2WsG8.cjs.map +1 -0
- package/dist/{fakerGenerator-D7daHCh6.js → fakerGenerator-BDNxA7KY.js} +235 -59
- package/dist/fakerGenerator-BDNxA7KY.js.map +1 -0
- package/dist/fakerGenerator-DSvAJTq3.d.ts +15 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +213 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +33 -12
- package/dist/index.js +214 -43
- package/dist/index.js.map +1 -1
- package/dist/{printerFaker-CJiwzoto.d.ts → printerFaker-Bhwq62d1.d.ts} +63 -26
- package/extension.yaml +817 -0
- package/package.json +9 -13
- package/src/components/Faker.tsx +50 -64
- package/src/generators/fakerGenerator.tsx +107 -67
- package/src/plugin.ts +25 -21
- package/src/printers/printerFaker.ts +80 -16
- package/src/resolvers/resolverFaker.ts +29 -37
- package/src/types.ts +36 -23
- package/src/utils.ts +6 -105
- package/dist/Faker-BgleOzVN.cjs.map +0 -1
- package/dist/Faker-fcQEB9i5.js.map +0 -1
- package/dist/fakerGenerator-C3Ho3BaI.d.ts +0 -9
- package/dist/fakerGenerator-D7daHCh6.js.map +0 -1
- package/dist/fakerGenerator-VJEVzLjc.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -2,8 +2,8 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
const require_Faker = require("./Faker-
|
|
6
|
-
const require_fakerGenerator = require("./fakerGenerator-
|
|
5
|
+
const require_Faker = require("./Faker-XuyEQflW.cjs");
|
|
6
|
+
const require_fakerGenerator = require("./fakerGenerator-BBr2WsG8.cjs");
|
|
7
7
|
let node_path = require("node:path");
|
|
8
8
|
node_path = require_Faker.__toESM(node_path, 1);
|
|
9
9
|
let _kubb_core = require("@kubb/core");
|
|
@@ -52,42 +52,196 @@ function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
|
52
52
|
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
53
53
|
}
|
|
54
54
|
//#endregion
|
|
55
|
-
//#region src/
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
//#region ../../internals/utils/src/reserved.ts
|
|
56
|
+
/**
|
|
57
|
+
* JavaScript and Java reserved words.
|
|
58
|
+
* @link https://github.com/jonschlinkert/reserved/blob/master/index.js
|
|
59
|
+
*/
|
|
60
|
+
const reservedWords = new Set([
|
|
61
|
+
"abstract",
|
|
62
|
+
"arguments",
|
|
63
|
+
"boolean",
|
|
64
|
+
"break",
|
|
65
|
+
"byte",
|
|
66
|
+
"case",
|
|
67
|
+
"catch",
|
|
68
|
+
"char",
|
|
69
|
+
"class",
|
|
70
|
+
"const",
|
|
71
|
+
"continue",
|
|
72
|
+
"debugger",
|
|
73
|
+
"default",
|
|
74
|
+
"delete",
|
|
75
|
+
"do",
|
|
76
|
+
"double",
|
|
77
|
+
"else",
|
|
78
|
+
"enum",
|
|
79
|
+
"eval",
|
|
80
|
+
"export",
|
|
81
|
+
"extends",
|
|
82
|
+
"false",
|
|
83
|
+
"final",
|
|
84
|
+
"finally",
|
|
85
|
+
"float",
|
|
86
|
+
"for",
|
|
87
|
+
"function",
|
|
88
|
+
"goto",
|
|
89
|
+
"if",
|
|
90
|
+
"implements",
|
|
91
|
+
"import",
|
|
92
|
+
"in",
|
|
93
|
+
"instanceof",
|
|
94
|
+
"int",
|
|
95
|
+
"interface",
|
|
96
|
+
"let",
|
|
97
|
+
"long",
|
|
98
|
+
"native",
|
|
99
|
+
"new",
|
|
100
|
+
"null",
|
|
101
|
+
"package",
|
|
102
|
+
"private",
|
|
103
|
+
"protected",
|
|
104
|
+
"public",
|
|
105
|
+
"return",
|
|
106
|
+
"short",
|
|
107
|
+
"static",
|
|
108
|
+
"super",
|
|
109
|
+
"switch",
|
|
110
|
+
"synchronized",
|
|
111
|
+
"this",
|
|
112
|
+
"throw",
|
|
113
|
+
"throws",
|
|
114
|
+
"transient",
|
|
115
|
+
"true",
|
|
116
|
+
"try",
|
|
117
|
+
"typeof",
|
|
118
|
+
"var",
|
|
119
|
+
"void",
|
|
120
|
+
"volatile",
|
|
121
|
+
"while",
|
|
122
|
+
"with",
|
|
123
|
+
"yield",
|
|
124
|
+
"Array",
|
|
125
|
+
"Date",
|
|
126
|
+
"hasOwnProperty",
|
|
127
|
+
"Infinity",
|
|
128
|
+
"isFinite",
|
|
129
|
+
"isNaN",
|
|
130
|
+
"isPrototypeOf",
|
|
131
|
+
"length",
|
|
132
|
+
"Math",
|
|
133
|
+
"name",
|
|
134
|
+
"NaN",
|
|
135
|
+
"Number",
|
|
136
|
+
"Object",
|
|
137
|
+
"prototype",
|
|
138
|
+
"String",
|
|
139
|
+
"toString",
|
|
140
|
+
"undefined",
|
|
141
|
+
"valueOf"
|
|
142
|
+
]);
|
|
143
|
+
/**
|
|
144
|
+
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* isValidVarName('status') // true
|
|
149
|
+
* isValidVarName('class') // false (reserved word)
|
|
150
|
+
* isValidVarName('42foo') // false (starts with digit)
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
function isValidVarName(name) {
|
|
154
|
+
if (!name || reservedWords.has(name)) return false;
|
|
155
|
+
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
63
156
|
}
|
|
64
157
|
/**
|
|
65
|
-
*
|
|
158
|
+
* Returns `name` when it's a syntactically valid JavaScript variable name,
|
|
159
|
+
* otherwise prefixes it with `_` so the result is a valid identifier.
|
|
66
160
|
*
|
|
67
|
-
*
|
|
161
|
+
* Useful for sanitizing OpenAPI schema names or operation IDs that start with
|
|
162
|
+
* a digit (e.g. `409`, `504AccountCancel`) before using them as exported
|
|
163
|
+
* variable, type, or function names.
|
|
68
164
|
*
|
|
69
165
|
* @example
|
|
70
|
-
*
|
|
166
|
+
* ```ts
|
|
167
|
+
* ensureValidVarName('409') // '_409'
|
|
168
|
+
* ensureValidVarName('504AccountCancel') // '_504AccountCancel'
|
|
169
|
+
* ensureValidVarName('Pet') // 'Pet'
|
|
170
|
+
* ensureValidVarName('class') // '_class'
|
|
171
|
+
* ```
|
|
71
172
|
*/
|
|
72
|
-
|
|
173
|
+
function ensureValidVarName(name) {
|
|
174
|
+
if (!name || isValidVarName(name)) return name;
|
|
175
|
+
return `_${name}`;
|
|
176
|
+
}
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region ../../internals/shared/src/group.ts
|
|
179
|
+
/**
|
|
180
|
+
* Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
|
|
181
|
+
* shared default naming so every plugin groups output consistently:
|
|
182
|
+
*
|
|
183
|
+
* - `path` groups use the second path segment (`/pet/findByStatus` → `pet`).
|
|
184
|
+
* - other groups use `${camelCase(group)}${suffix}` (e.g. `petController`).
|
|
185
|
+
*
|
|
186
|
+
* Returns `null` when grouping is disabled, matching the per-plugin convention.
|
|
187
|
+
*
|
|
188
|
+
* @param group - The user-supplied group option, or `undefined` to disable grouping.
|
|
189
|
+
* @param options.suffix - Appended to non-`path` group names, e.g. `'Controller'` or `'Requests'`.
|
|
190
|
+
* @param options.honorName - When `true`, a user-provided `group.name` overrides the default namer.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```ts
|
|
194
|
+
* createGroupConfig(group, { suffix: 'Controller' }) // plugin-ts, plugin-zod
|
|
195
|
+
* createGroupConfig(group, { suffix: 'Controller', honorName: true }) // plugin-faker, plugin-client, …
|
|
196
|
+
* createGroupConfig(group, { suffix: 'Requests', honorName: true }) // plugin-cypress, plugin-mcp
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
function createGroupConfig(group, options) {
|
|
200
|
+
if (!group) return null;
|
|
201
|
+
const defaultName = (ctx) => {
|
|
202
|
+
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
203
|
+
return `${camelCase(ctx.group)}${options.suffix}`;
|
|
204
|
+
};
|
|
205
|
+
return {
|
|
206
|
+
...group,
|
|
207
|
+
name: options.honorName && group.name ? group.name : defaultName
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/resolvers/resolverFaker.ts
|
|
212
|
+
/**
|
|
213
|
+
* Default resolver used by `@kubb/plugin-faker`. Decides the names and file
|
|
214
|
+
* paths for every generated mock factory. Functions and files are prefixed
|
|
215
|
+
* with `create` so `Pet` becomes `createPet`.
|
|
216
|
+
*
|
|
217
|
+
* @example Resolve a factory name
|
|
218
|
+
* ```ts
|
|
219
|
+
* import { resolverFaker } from '@kubb/plugin-faker'
|
|
220
|
+
*
|
|
221
|
+
* resolverFaker.default('list pets', 'function') // 'createListPets'
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
const resolverFaker = (0, _kubb_core.defineResolver)(() => {
|
|
73
225
|
return {
|
|
74
226
|
name: "default",
|
|
75
227
|
pluginName: "plugin-faker",
|
|
76
228
|
default(name, type) {
|
|
77
|
-
const resolvedName = camelCase(name, {
|
|
78
|
-
|
|
79
|
-
|
|
229
|
+
const resolvedName = camelCase(name, {
|
|
230
|
+
isFile: type === "file",
|
|
231
|
+
prefix: "create"
|
|
232
|
+
});
|
|
233
|
+
return type === "file" ? resolvedName : ensureValidVarName(resolvedName);
|
|
80
234
|
},
|
|
81
235
|
resolveName(name, type) {
|
|
82
|
-
return
|
|
236
|
+
return this.default(name, type);
|
|
83
237
|
},
|
|
84
238
|
resolvePathName(name, type) {
|
|
85
|
-
return
|
|
239
|
+
return this.default(name, type);
|
|
86
240
|
},
|
|
87
241
|
resolveFile({ name, extname, tag, path: groupPath }, context) {
|
|
88
|
-
const pathMode = _kubb_core.
|
|
89
|
-
const baseName = `${pathMode === "single" ? "" :
|
|
90
|
-
const filePath =
|
|
242
|
+
const pathMode = _kubb_core.KubbDriver.getMode(node_path.default.resolve(context.root, context.output.path));
|
|
243
|
+
const baseName = `${pathMode === "single" ? "" : this.resolveName(name, "file")}${extname}`;
|
|
244
|
+
const filePath = this.resolvePath({
|
|
91
245
|
baseName,
|
|
92
246
|
pathMode,
|
|
93
247
|
tag,
|
|
@@ -100,61 +254,78 @@ const resolverFaker = (0, _kubb_core.defineResolver)((ctx) => {
|
|
|
100
254
|
path: filePath,
|
|
101
255
|
baseName,
|
|
102
256
|
extname,
|
|
103
|
-
meta: { pluginName:
|
|
257
|
+
meta: { pluginName: this.pluginName },
|
|
104
258
|
sources: [],
|
|
105
259
|
imports: [],
|
|
106
260
|
exports: []
|
|
107
261
|
};
|
|
108
262
|
},
|
|
109
263
|
resolveParamName(node, param) {
|
|
110
|
-
return
|
|
264
|
+
return this.resolveName(`${node.operationId} ${param.in} ${param.name}`);
|
|
111
265
|
},
|
|
112
266
|
resolveDataName(node) {
|
|
113
|
-
return
|
|
267
|
+
return this.resolveName(`${node.operationId} Data`);
|
|
114
268
|
},
|
|
115
269
|
resolveResponseStatusName(node, statusCode) {
|
|
116
|
-
return
|
|
270
|
+
return this.resolveName(`${node.operationId} Status ${statusCode}`);
|
|
117
271
|
},
|
|
118
272
|
resolveResponseName(node) {
|
|
119
|
-
return
|
|
273
|
+
return this.resolveName(`${node.operationId} Response`);
|
|
274
|
+
},
|
|
275
|
+
resolveResponsesName(node) {
|
|
276
|
+
return this.resolveName(`${node.operationId} Responses`);
|
|
120
277
|
},
|
|
121
278
|
resolvePathParamsName(node, param) {
|
|
122
|
-
return
|
|
279
|
+
return this.resolveParamName(node, param);
|
|
123
280
|
},
|
|
124
281
|
resolveQueryParamsName(node, param) {
|
|
125
|
-
return
|
|
282
|
+
return this.resolveParamName(node, param);
|
|
126
283
|
},
|
|
127
284
|
resolveHeaderParamsName(node, param) {
|
|
128
|
-
return
|
|
285
|
+
return this.resolveParamName(node, param);
|
|
129
286
|
}
|
|
130
287
|
};
|
|
131
288
|
});
|
|
132
289
|
//#endregion
|
|
133
290
|
//#region src/plugin.ts
|
|
134
291
|
/**
|
|
135
|
-
* Canonical plugin name for `@kubb/plugin-faker
|
|
292
|
+
* Canonical plugin name for `@kubb/plugin-faker`. Used for driver lookups and
|
|
293
|
+
* cross-plugin dependency references.
|
|
136
294
|
*/
|
|
137
295
|
const pluginFakerName = "plugin-faker";
|
|
138
296
|
/**
|
|
139
|
-
* Generates
|
|
140
|
-
*
|
|
141
|
-
*
|
|
297
|
+
* Generates one mock-data factory per OpenAPI schema using Faker.js. Call
|
|
298
|
+
* `createPet()` to get a realistic `Pet` object. Useful for tests, Storybook,
|
|
299
|
+
* and local development without a running backend.
|
|
142
300
|
*
|
|
143
301
|
* @example
|
|
144
|
-
*
|
|
302
|
+
* ```ts
|
|
303
|
+
* import { defineConfig } from 'kubb'
|
|
304
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
305
|
+
* import { pluginFaker } from '@kubb/plugin-faker'
|
|
306
|
+
*
|
|
307
|
+
* export default defineConfig({
|
|
308
|
+
* input: { path: './petStore.yaml' },
|
|
309
|
+
* output: { path: './src/gen' },
|
|
310
|
+
* plugins: [
|
|
311
|
+
* pluginTs(),
|
|
312
|
+
* pluginFaker({
|
|
313
|
+
* output: { path: './mocks' },
|
|
314
|
+
* seed: [100],
|
|
315
|
+
* }),
|
|
316
|
+
* ],
|
|
317
|
+
* })
|
|
318
|
+
* ```
|
|
145
319
|
*/
|
|
146
320
|
const pluginFaker = (0, _kubb_core.definePlugin)((options) => {
|
|
147
321
|
const { output = {
|
|
148
322
|
path: "mocks",
|
|
149
323
|
barrelType: "named"
|
|
150
324
|
}, seed, locale, group, exclude = [], include, override = [], mapper = {}, dateParser = "faker", generators: userGenerators = [], regexGenerator = "faker", paramsCasing, printer, resolver: userResolver, transformer: userTransformer } = options;
|
|
151
|
-
const groupConfig = group
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return `${camelCase(ctx.group)}Controller`;
|
|
156
|
-
}
|
|
157
|
-
} : void 0;
|
|
325
|
+
const groupConfig = createGroupConfig(group, {
|
|
326
|
+
suffix: "Controller",
|
|
327
|
+
honorName: true
|
|
328
|
+
});
|
|
158
329
|
return {
|
|
159
330
|
name: pluginFakerName,
|
|
160
331
|
options,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["PluginDriver","path","pluginTsName","fakerGenerator"],"sources":["../../../internals/utils/src/casing.ts","../src/resolvers/resolverFaker.ts","../src/plugin.ts"],"sourcesContent":["type Options = {\n /**\n * When `true`, dot-separated segments are split on `.` and joined with `/` after casing.\n */\n isFile?: boolean\n /**\n * Text prepended before casing is applied.\n */\n prefix?: string\n /**\n * Text appended before casing is applied.\n */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n *\n * Only splits on dots followed by a letter so that version numbers\n * embedded in operationIds (e.g. `v2025.0`) are kept intact.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split(/\\.(?=[a-zA-Z])/)\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","import { createHash } from 'node:crypto'\nimport path from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport { defineResolver, PluginDriver } from '@kubb/core'\nimport type { PluginFaker } from '../types.ts'\n\nfunction isValidStrictIdentifier(name: string): boolean {\n try {\n new Function(`\"use strict\"; const ${name} = 1;`)\n } catch {\n return false\n }\n\n return true\n}\n\n/**\n * Naming convention resolver for Faker plugin.\n *\n * Provides default naming helpers using camelCase. Prefixes invalid identifiers with `_`.\n *\n * @example\n * `resolverFaker.default('list pets', 'function') // → 'listPets'`\n */\nexport const resolverFaker = defineResolver<PluginFaker>((ctx) => {\n return {\n name: 'default',\n pluginName: 'plugin-faker',\n default(name, type) {\n const resolvedName = camelCase(name, { isFile: type === 'file' })\n\n if (type === 'file' || isValidStrictIdentifier(resolvedName)) {\n return resolvedName\n }\n\n return `_${resolvedName}`\n },\n resolveName(name, type) {\n return ctx.default(name, type)\n },\n resolvePathName(name, type) {\n return ctx.default(name, type)\n },\n resolveFile({ name, extname, tag, path: groupPath }, context) {\n const pathMode = PluginDriver.getMode(path.resolve(context.root, context.output.path))\n const baseName = `${pathMode === 'single' ? '' : ctx.resolveName(name, 'file')}${extname}` as `${string}.${string}`\n const filePath = ctx.resolvePath(\n {\n baseName,\n pathMode,\n tag,\n path: groupPath,\n },\n context,\n )\n\n return {\n kind: 'File',\n id: createHash('sha256').update(filePath).digest('hex'),\n name: path.basename(filePath, extname),\n path: filePath,\n baseName,\n extname,\n meta: { pluginName: ctx.pluginName },\n sources: [],\n imports: [],\n exports: [],\n }\n },\n resolveParamName(node, param) {\n return ctx.resolveName(`${node.operationId} ${param.in} ${param.name}`)\n },\n resolveDataName(node) {\n return ctx.resolveName(`${node.operationId} Data`)\n },\n resolveResponseStatusName(node, statusCode) {\n return ctx.resolveName(`${node.operationId} Status ${statusCode}`)\n },\n resolveResponseName(node) {\n return ctx.resolveName(`${node.operationId} Response`)\n },\n resolvePathParamsName(node, param) {\n return ctx.resolveParamName(node, param)\n },\n resolveQueryParamsName(node, param) {\n return ctx.resolveParamName(node, param)\n },\n resolveHeaderParamsName(node, param) {\n return ctx.resolveParamName(node, param)\n },\n }\n})\n","import { camelCase } from '@internals/utils'\nimport { definePlugin, type Group } from '@kubb/core'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { fakerGenerator } from './generators/fakerGenerator.tsx'\nimport { resolverFaker } from './resolvers/resolverFaker.ts'\nimport type { PluginFaker } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-faker`, used in driver lookups and warnings.\n */\nexport const pluginFakerName = 'plugin-faker' satisfies PluginFaker['name']\n\n/**\n * Generates Faker mock data factories from OpenAPI/AST specification.\n *\n * Creates randomized test data and mock helpers from schema definitions.\n *\n * @example\n * `import pluginFaker from '@kubb/plugin-faker'; export default defineConfig({ plugins: [pluginFaker({ output: { path: 'mocks' } })], })`\n */\nexport const pluginFaker = definePlugin<PluginFaker>((options) => {\n const {\n output = { path: 'mocks', barrelType: 'named' },\n seed,\n locale,\n group,\n exclude = [],\n include,\n override = [],\n mapper = {},\n dateParser = 'faker',\n generators: userGenerators = [],\n regexGenerator = 'faker',\n paramsCasing,\n printer,\n resolver: userResolver,\n transformer: userTransformer,\n } = options\n\n const groupConfig = group\n ? ({\n ...group,\n name: group.name\n ? group.name\n : (ctx: { group: string }) => {\n if (group.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n\n return `${camelCase(ctx.group)}Controller`\n },\n } satisfies Group)\n : undefined\n\n return {\n name: pluginFakerName,\n options,\n dependencies: [pluginTsName],\n hooks: {\n 'kubb:plugin:setup'(ctx) {\n ctx.setOptions({\n output,\n seed,\n locale,\n exclude,\n include,\n override,\n group: groupConfig,\n mapper,\n dateParser,\n regexGenerator,\n paramsCasing,\n printer,\n })\n ctx.setResolver(userResolver ? { ...resolverFaker, ...userResolver } : resolverFaker)\n if (userTransformer) {\n ctx.setTransformer(userTransformer)\n }\n ctx.addGenerator(fakerGenerator)\n for (const generator of userGenerators) {\n ctx.addGenerator(generator)\n }\n },\n },\n }\n})\n\nexport default pluginFaker\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsBA,SAAS,gBAAgB,MAAc,QAAyB;AAS9D,QARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,gBAAgB,QAEH,CAAC,MAAM,gBAAgB,CAAC,OAAO,QAE3C,CACT,KAAK,MAAM,MAAM;AAEhB,MADiB,KAAK,SAAS,KAAK,SAAS,KAAK,aAAa,CACjD,QAAO;AACrB,MAAI,MAAM,KAAK,CAAC,OAAQ,QAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;AAC3E,SAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;GACnD,CACD,KAAK,GAAG,CACR,QAAQ,iBAAiB,GAAG;;;;;;;;;;AAWjC,SAAS,iBAAiB,MAAc,eAAkE;CACxG,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I,MAAM,CAAC;;EAEtC,GACD,KAAA;AAEJ,QAAO;EACL,MAAM;EACN;EACA,cAAc,CAACC,gBAAAA,aAAa;EAC5B,OAAO,EACL,oBAAoB,KAAK;AACvB,OAAI,WAAW;IACb;IACA;IACA;IACA;IACA;IACA;IACA,OAAO;IACP;IACA;IACA;IACA;IACA;IACD,CAAC;AACF,OAAI,YAAY,eAAe;IAAE,GAAG;IAAe,GAAG;IAAc,GAAG,cAAc;AACrF,OAAI,gBACF,KAAI,eAAe,gBAAgB;AAErC,OAAI,aAAaC,uBAAAA,eAAe;AAChC,QAAK,MAAM,aAAa,eACtB,KAAI,aAAa,UAAU;KAGhC;EACF;EACD"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["KubbDriver","path","pluginTsName","fakerGenerator"],"sources":["../../../internals/utils/src/casing.ts","../../../internals/utils/src/reserved.ts","../../../internals/shared/src/group.ts","../src/resolvers/resolverFaker.ts","../src/plugin.ts"],"sourcesContent":["type Options = {\n /**\n * When `true`, dot-separated segments are split on `.` and joined with `/` after casing.\n */\n isFile?: boolean\n /**\n * Text prepended before casing is applied.\n */\n prefix?: string\n /**\n * Text appended before casing is applied.\n */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n *\n * Only splits on dots followed by a letter so that version numbers\n * embedded in operationIds (e.g. `v2025.0`) are kept intact.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split(/\\.(?=[a-zA-Z])/)\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","/**\n * JavaScript and Java reserved words.\n * @link https://github.com/jonschlinkert/reserved/blob/master/index.js\n */\nconst reservedWords = new Set([\n 'abstract',\n 'arguments',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n 'Array',\n 'Date',\n 'hasOwnProperty',\n 'Infinity',\n 'isFinite',\n 'isNaN',\n 'isPrototypeOf',\n 'length',\n 'Math',\n 'name',\n 'NaN',\n 'Number',\n 'Object',\n 'prototype',\n 'String',\n 'toString',\n 'undefined',\n 'valueOf',\n] as const)\n\n/**\n * Returns `true` when `name` is a syntactically valid JavaScript variable name.\n *\n * @example\n * ```ts\n * isValidVarName('status') // true\n * isValidVarName('class') // false (reserved word)\n * isValidVarName('42foo') // false (starts with digit)\n * ```\n */\nexport function isValidVarName(name: string): boolean {\n if (!name || reservedWords.has(name as 'valueOf')) {\n return false\n }\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name)\n}\n\n/**\n * Returns `name` when it's a syntactically valid JavaScript variable name,\n * otherwise prefixes it with `_` so the result is a valid identifier.\n *\n * Useful for sanitizing OpenAPI schema names or operation IDs that start with\n * a digit (e.g. `409`, `504AccountCancel`) before using them as exported\n * variable, type, or function names.\n *\n * @example\n * ```ts\n * ensureValidVarName('409') // '_409'\n * ensureValidVarName('504AccountCancel') // '_504AccountCancel'\n * ensureValidVarName('Pet') // 'Pet'\n * ensureValidVarName('class') // '_class'\n * ```\n */\nexport function ensureValidVarName(name: string): string {\n if (!name || isValidVarName(name)) {\n return name\n }\n return `_${name}`\n}\n","import { camelCase } from '@internals/utils'\nimport type { Group } from '@kubb/core'\n\n/**\n * Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the\n * shared default naming so every plugin groups output consistently:\n *\n * - `path` groups use the second path segment (`/pet/findByStatus` → `pet`).\n * - other groups use `${camelCase(group)}${suffix}` (e.g. `petController`).\n *\n * Returns `null` when grouping is disabled, matching the per-plugin convention.\n *\n * @param group - The user-supplied group option, or `undefined` to disable grouping.\n * @param options.suffix - Appended to non-`path` group names, e.g. `'Controller'` or `'Requests'`.\n * @param options.honorName - When `true`, a user-provided `group.name` overrides the default namer.\n *\n * @example\n * ```ts\n * createGroupConfig(group, { suffix: 'Controller' }) // plugin-ts, plugin-zod\n * createGroupConfig(group, { suffix: 'Controller', honorName: true }) // plugin-faker, plugin-client, …\n * createGroupConfig(group, { suffix: 'Requests', honorName: true }) // plugin-cypress, plugin-mcp\n * ```\n */\nexport function createGroupConfig(group: Group | undefined, options: { suffix: string; honorName?: boolean }): Group | null {\n if (!group) {\n return null\n }\n\n const defaultName = (ctx: { group: string }): string => {\n if (group.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n\n return `${camelCase(ctx.group)}${options.suffix}`\n }\n\n return {\n ...group,\n name: options.honorName && group.name ? group.name : defaultName,\n } satisfies Group\n}\n","import { createHash } from 'node:crypto'\nimport path from 'node:path'\nimport { camelCase, ensureValidVarName } from '@internals/utils'\nimport { defineResolver, KubbDriver } from '@kubb/core'\nimport type { PluginFaker } from '../types.ts'\n\n/**\n * Default resolver used by `@kubb/plugin-faker`. Decides the names and file\n * paths for every generated mock factory. Functions and files are prefixed\n * with `create` so `Pet` becomes `createPet`.\n *\n * @example Resolve a factory name\n * ```ts\n * import { resolverFaker } from '@kubb/plugin-faker'\n *\n * resolverFaker.default('list pets', 'function') // 'createListPets'\n * ```\n */\nexport const resolverFaker = defineResolver<PluginFaker>(() => {\n return {\n name: 'default',\n pluginName: 'plugin-faker',\n default(name, type) {\n const resolvedName = camelCase(name, { isFile: type === 'file', prefix: 'create' })\n return type === 'file' ? resolvedName : ensureValidVarName(resolvedName)\n },\n resolveName(name, type) {\n return this.default(name, type)\n },\n resolvePathName(name, type) {\n return this.default(name, type)\n },\n resolveFile({ name, extname, tag, path: groupPath }, context) {\n const pathMode = KubbDriver.getMode(path.resolve(context.root, context.output.path))\n const baseName = `${pathMode === 'single' ? '' : this.resolveName(name, 'file')}${extname}` as `${string}.${string}`\n const filePath = this.resolvePath(\n {\n baseName,\n pathMode,\n tag,\n path: groupPath,\n },\n context,\n )\n\n return {\n kind: 'File',\n id: createHash('sha256').update(filePath).digest('hex'),\n name: path.basename(filePath, extname),\n path: filePath,\n baseName,\n extname,\n meta: { pluginName: this.pluginName },\n sources: [],\n imports: [],\n exports: [],\n }\n },\n resolveParamName(node, param) {\n return this.resolveName(`${node.operationId} ${param.in} ${param.name}`)\n },\n resolveDataName(node) {\n return this.resolveName(`${node.operationId} Data`)\n },\n resolveResponseStatusName(node, statusCode) {\n return this.resolveName(`${node.operationId} Status ${statusCode}`)\n },\n resolveResponseName(node) {\n return this.resolveName(`${node.operationId} Response`)\n },\n resolveResponsesName(node) {\n return this.resolveName(`${node.operationId} Responses`)\n },\n resolvePathParamsName(node, param) {\n return this.resolveParamName(node, param)\n },\n resolveQueryParamsName(node, param) {\n return this.resolveParamName(node, param)\n },\n resolveHeaderParamsName(node, param) {\n return this.resolveParamName(node, param)\n },\n }\n})\n","import { createGroupConfig } from '@internals/shared'\nimport { definePlugin } from '@kubb/core'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { fakerGenerator } from './generators/fakerGenerator.tsx'\nimport { resolverFaker } from './resolvers/resolverFaker.ts'\nimport type { PluginFaker } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-faker`. Used for driver lookups and\n * cross-plugin dependency references.\n */\nexport const pluginFakerName = 'plugin-faker' satisfies PluginFaker['name']\n\n/**\n * Generates one mock-data factory per OpenAPI schema using Faker.js. Call\n * `createPet()` to get a realistic `Pet` object. Useful for tests, Storybook,\n * and local development without a running backend.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginTs } from '@kubb/plugin-ts'\n * import { pluginFaker } from '@kubb/plugin-faker'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [\n * pluginTs(),\n * pluginFaker({\n * output: { path: './mocks' },\n * seed: [100],\n * }),\n * ],\n * })\n * ```\n */\nexport const pluginFaker = definePlugin<PluginFaker>((options) => {\n const {\n output = { path: 'mocks', barrelType: 'named' },\n seed,\n locale,\n group,\n exclude = [],\n include,\n override = [],\n mapper = {},\n dateParser = 'faker',\n generators: userGenerators = [],\n regexGenerator = 'faker',\n paramsCasing,\n printer,\n resolver: userResolver,\n transformer: userTransformer,\n } = options\n\n const groupConfig = createGroupConfig(group, { suffix: 'Controller', honorName: true })\n\n return {\n name: pluginFakerName,\n options,\n dependencies: [pluginTsName],\n hooks: {\n 'kubb:plugin:setup'(ctx) {\n ctx.setOptions({\n output,\n seed,\n locale,\n exclude,\n include,\n override,\n group: groupConfig,\n mapper,\n dateParser,\n regexGenerator,\n paramsCasing,\n printer,\n })\n ctx.setResolver(userResolver ? { ...resolverFaker, ...userResolver } : resolverFaker)\n if (userTransformer) {\n ctx.setTransformer(userTransformer)\n }\n ctx.addGenerator(fakerGenerator)\n for (const generator of userGenerators) {\n ctx.addGenerator(generator)\n }\n },\n },\n }\n})\n\nexport default pluginFaker\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsBA,SAAS,gBAAgB,MAAc,QAAyB;CAS9D,OARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,gBAAgB,QAEH,CAAC,MAAM,gBAAgB,CAAC,OAAO,QAE3C,CACT,KAAK,MAAM,MAAM;EAEhB,IADiB,KAAK,SAAS,KAAK,SAAS,KAAK,aAAa,EACjD,OAAO;EACrB,IAAI,MAAM,KAAK,CAAC,QAAQ,OAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;EAC3E,OAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;GACnD,CACD,KAAK,GAAG,CACR,QAAQ,iBAAiB,GAAG;;;;;;;;;;AAWjC,SAAS,iBAAiB,MAAc,eAAkE;CACxG,MAAM,QAAQ,KAAK,MAAM,iBAAiB;CAC1C,OAAO,MAAM,KAAK,MAAM,MAAM,cAAc,MAAM,MAAM,MAAM,SAAS,EAAE,CAAC,CAAC,KAAK,IAAI;;;;;;;;;;AAWtF,SAAgB,UAAU,MAAc,EAAE,QAAQ,SAAS,IAAI,SAAS,OAAgB,EAAE,EAAU;CAClG,IAAI,QACF,OAAO,iBAAiB,OAAO,MAAM,WAAW,UAAU,MAAM,SAAS;EAAE;EAAQ;EAAQ,GAAG,EAAE,CAAC,CAAC;CAGpG,OAAO,gBAAgB,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU,MAAM;;;;;;;;AChE9D,MAAM,gBAAgB,IAAI,IAAI;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;C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;;;;;;;;AA0B/B,MAAa,eAAA,GAAA,WAAA,eAAyC,YAAY;CAChE,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;EAAS,EAC/C,MACA,QACA,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,SAAS,EAAE,EACX,aAAa,SACb,YAAY,iBAAiB,EAAE,EAC/B,iBAAiB,SACjB,cACA,SACA,UAAU,cACV,aAAa,oBACX;CAEJ,MAAM,cAAc,kBAAkB,OAAO;EAAE,QAAQ;EAAc,WAAW;EAAM,CAAC;CAEvF,OAAO;EACL,MAAM;EACN;EACA,cAAc,CAACC,gBAAAA,aAAa;EAC5B,OAAO,EACL,oBAAoB,KAAK;GACvB,IAAI,WAAW;IACb;IACA;IACA;IACA;IACA;IACA;IACA,OAAO;IACP;IACA;IACA;IACA;IACA;IACD,CAAC;GACF,IAAI,YAAY,eAAe;IAAE,GAAG;IAAe,GAAG;IAAc,GAAG,cAAc;GACrF,IAAI,iBACF,IAAI,eAAe,gBAAgB;GAErC,IAAI,aAAaC,uBAAAA,eAAe;GAChC,KAAK,MAAM,aAAa,gBACtB,IAAI,aAAa,UAAU;KAGhC;EACF;EACD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,32 +1,53 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { a as Options, i as printerFaker, n as PrinterFakerNodes, o as PluginFaker, r as PrinterFakerOptions, s as ResolverFaker, t as PrinterFakerFactory } from "./printerFaker-
|
|
3
|
-
import { t as Faker } from "./Faker-
|
|
4
|
-
import { t as fakerGenerator } from "./fakerGenerator-
|
|
2
|
+
import { a as Options, i as printerFaker, n as PrinterFakerNodes, o as PluginFaker, r as PrinterFakerOptions, s as ResolverFaker, t as PrinterFakerFactory } from "./printerFaker-Bhwq62d1.js";
|
|
3
|
+
import { t as Faker } from "./Faker-BaLJxPyl.js";
|
|
4
|
+
import { t as fakerGenerator } from "./fakerGenerator-DSvAJTq3.js";
|
|
5
5
|
import * as _$_kubb_core0 from "@kubb/core";
|
|
6
6
|
|
|
7
7
|
//#region src/plugin.d.ts
|
|
8
8
|
/**
|
|
9
|
-
* Canonical plugin name for `@kubb/plugin-faker
|
|
9
|
+
* Canonical plugin name for `@kubb/plugin-faker`. Used for driver lookups and
|
|
10
|
+
* cross-plugin dependency references.
|
|
10
11
|
*/
|
|
11
12
|
declare const pluginFakerName = "plugin-faker";
|
|
12
13
|
/**
|
|
13
|
-
* Generates
|
|
14
|
-
*
|
|
15
|
-
*
|
|
14
|
+
* Generates one mock-data factory per OpenAPI schema using Faker.js. Call
|
|
15
|
+
* `createPet()` to get a realistic `Pet` object. Useful for tests, Storybook,
|
|
16
|
+
* and local development without a running backend.
|
|
16
17
|
*
|
|
17
18
|
* @example
|
|
18
|
-
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { defineConfig } from 'kubb'
|
|
21
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
22
|
+
* import { pluginFaker } from '@kubb/plugin-faker'
|
|
23
|
+
*
|
|
24
|
+
* export default defineConfig({
|
|
25
|
+
* input: { path: './petStore.yaml' },
|
|
26
|
+
* output: { path: './src/gen' },
|
|
27
|
+
* plugins: [
|
|
28
|
+
* pluginTs(),
|
|
29
|
+
* pluginFaker({
|
|
30
|
+
* output: { path: './mocks' },
|
|
31
|
+
* seed: [100],
|
|
32
|
+
* }),
|
|
33
|
+
* ],
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
19
36
|
*/
|
|
20
37
|
declare const pluginFaker: (options?: Options | undefined) => _$_kubb_core0.Plugin<PluginFaker>;
|
|
21
38
|
//#endregion
|
|
22
39
|
//#region src/resolvers/resolverFaker.d.ts
|
|
23
40
|
/**
|
|
24
|
-
*
|
|
41
|
+
* Default resolver used by `@kubb/plugin-faker`. Decides the names and file
|
|
42
|
+
* paths for every generated mock factory. Functions and files are prefixed
|
|
43
|
+
* with `create` so `Pet` becomes `createPet`.
|
|
25
44
|
*
|
|
26
|
-
*
|
|
45
|
+
* @example Resolve a factory name
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { resolverFaker } from '@kubb/plugin-faker'
|
|
27
48
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
49
|
+
* resolverFaker.default('list pets', 'function') // 'createListPets'
|
|
50
|
+
* ```
|
|
30
51
|
*/
|
|
31
52
|
declare const resolverFaker: ResolverFaker;
|
|
32
53
|
//#endregion
|