@kubb/plugin-faker 3.0.0-alpha.2 → 3.0.0-alpha.20

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 (55) hide show
  1. package/README.md +13 -4
  2. package/dist/chunk-4RI7I4U6.cjs +115 -0
  3. package/dist/chunk-4RI7I4U6.cjs.map +1 -0
  4. package/dist/chunk-ORCMQTO5.js +304 -0
  5. package/dist/chunk-ORCMQTO5.js.map +1 -0
  6. package/dist/chunk-RKYLMZMT.js +113 -0
  7. package/dist/chunk-RKYLMZMT.js.map +1 -0
  8. package/dist/chunk-XCZY3DPW.cjs +310 -0
  9. package/dist/chunk-XCZY3DPW.cjs.map +1 -0
  10. package/dist/components.cjs +6 -565
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +15 -18
  13. package/dist/components.d.ts +15 -18
  14. package/dist/components.js +2 -570
  15. package/dist/components.js.map +1 -1
  16. package/dist/generators.cjs +13 -0
  17. package/dist/generators.cjs.map +1 -0
  18. package/dist/generators.d.cts +8 -0
  19. package/dist/generators.d.ts +8 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +51 -504
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +4 -125
  25. package/dist/index.d.ts +4 -125
  26. package/dist/index.js +34 -494
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-dutOIgtG.d.cts +108 -0
  29. package/dist/types-dutOIgtG.d.ts +108 -0
  30. package/package.json +19 -15
  31. package/src/components/Faker.tsx +80 -0
  32. package/src/components/index.ts +1 -2
  33. package/src/generators/__snapshots__/createPet.ts +26 -0
  34. package/src/generators/__snapshots__/createPetSeed.ts +30 -0
  35. package/src/generators/__snapshots__/createPetUnknownTypeAny.ts +26 -0
  36. package/src/generators/__snapshots__/deletePet.ts +3 -0
  37. package/src/generators/__snapshots__/enumNames.ts +5 -0
  38. package/src/generators/__snapshots__/enumVarNames.ts +5 -0
  39. package/src/generators/__snapshots__/getPets.ts +29 -0
  40. package/src/generators/__snapshots__/pet.ts +8 -0
  41. package/src/generators/__snapshots__/petWithDateString.ts +8 -0
  42. package/src/generators/__snapshots__/petWithDayjs.ts +9 -0
  43. package/src/generators/__snapshots__/petWithMapper.ts +8 -0
  44. package/src/generators/__snapshots__/petWithRandExp.ts +9 -0
  45. package/src/generators/__snapshots__/pets.ts +8 -0
  46. package/src/generators/__snapshots__/showPetById.ts +29 -0
  47. package/src/generators/fakerGenerator.tsx +140 -0
  48. package/src/generators/index.ts +1 -0
  49. package/src/parser/index.ts +23 -13
  50. package/src/plugin.ts +20 -33
  51. package/src/types.ts +22 -47
  52. package/src/OperationGenerator.tsx +0 -30
  53. package/src/SchemaGenerator.tsx +0 -31
  54. package/src/components/OperationSchema.tsx +0 -84
  55. package/src/components/Schema.tsx +0 -146
@@ -1,23 +1,20 @@
1
- import { ReactNode } from 'react';
2
-
3
- type Props$1 = {
4
- description?: string;
5
- };
6
- declare function OperationSchema({ description }: Props$1): ReactNode;
7
- declare namespace OperationSchema {
8
- var File: ({}: FileProps$1) => ReactNode;
9
- }
10
- type FileProps$1 = {};
1
+ import { Schema } from '@kubb/plugin-oas';
2
+ import { KubbNode } from '@kubb/react/types';
3
+ import { P as PluginFaker } from './types-dutOIgtG.cjs';
4
+ import '@kubb/core';
5
+ import '@kubb/oas';
11
6
 
12
7
  type Props = {
8
+ name: string;
9
+ typeName: string;
10
+ tree: Array<Schema>;
11
+ seed?: PluginFaker['options']['seed'];
13
12
  description?: string;
14
- withData?: boolean;
13
+ regexGenerator?: PluginFaker['options']['regexGenerator'];
14
+ mapper?: PluginFaker['options']['mapper'];
15
+ dateParser?: PluginFaker['options']['dateParser'];
16
+ canOverride: boolean;
15
17
  };
16
- declare function Schema(props: Props): ReactNode;
17
- declare namespace Schema {
18
- var File: ({}: FileProps) => ReactNode;
19
- var Imports: () => ReactNode;
20
- }
21
- type FileProps = {};
18
+ declare function Faker({ tree, description, name, typeName, seed, regexGenerator, canOverride, mapper, dateParser }: Props): KubbNode;
22
19
 
23
- export { OperationSchema, Schema };
20
+ export { Faker };
@@ -1,23 +1,20 @@
1
- import { ReactNode } from 'react';
2
-
3
- type Props$1 = {
4
- description?: string;
5
- };
6
- declare function OperationSchema({ description }: Props$1): ReactNode;
7
- declare namespace OperationSchema {
8
- var File: ({}: FileProps$1) => ReactNode;
9
- }
10
- type FileProps$1 = {};
1
+ import { Schema } from '@kubb/plugin-oas';
2
+ import { KubbNode } from '@kubb/react/types';
3
+ import { P as PluginFaker } from './types-dutOIgtG.js';
4
+ import '@kubb/core';
5
+ import '@kubb/oas';
11
6
 
12
7
  type Props = {
8
+ name: string;
9
+ typeName: string;
10
+ tree: Array<Schema>;
11
+ seed?: PluginFaker['options']['seed'];
13
12
  description?: string;
14
- withData?: boolean;
13
+ regexGenerator?: PluginFaker['options']['regexGenerator'];
14
+ mapper?: PluginFaker['options']['mapper'];
15
+ dateParser?: PluginFaker['options']['dateParser'];
16
+ canOverride: boolean;
15
17
  };
16
- declare function Schema(props: Props): ReactNode;
17
- declare namespace Schema {
18
- var File: ({}: FileProps) => ReactNode;
19
- var Imports: () => ReactNode;
20
- }
21
- type FileProps = {};
18
+ declare function Faker({ tree, description, name, typeName, seed, regexGenerator, canOverride, mapper, dateParser }: Props): KubbNode;
22
19
 
23
- export { OperationSchema, Schema };
20
+ export { Faker };
@@ -1,571 +1,3 @@
1
- // src/components/OperationSchema.tsx
2
- import { Oas as Oas4 } from "@kubb/plugin-oas/components";
3
- import { useOas, useOperation, useOperationManager } from "@kubb/plugin-oas/hooks";
4
- import { File as File2, Parser, useApp as useApp2 } from "@kubb/react";
5
- import { pluginTsName as pluginTsName3 } from "@kubb/plugin-ts";
6
-
7
- // src/SchemaGenerator.tsx
8
- import { SchemaGenerator as Generator2 } from "@kubb/plugin-oas";
9
- import { Oas as Oas3 } from "@kubb/plugin-oas/components";
10
- import { App as App2, createRoot as createRoot2 } from "@kubb/react";
11
-
12
- // src/components/Schema.tsx
13
- import { Oas as Oas2 } from "@kubb/plugin-oas/components";
14
- import { File, Function, useApp, useFile } from "@kubb/react";
15
- import { pluginTsName as pluginTsName2 } from "@kubb/plugin-ts";
16
- import transformers2 from "@kubb/core/transformers";
17
- import { schemaKeywords as schemaKeywords2 } from "@kubb/plugin-oas";
18
- import { useSchema } from "@kubb/plugin-oas/hooks";
19
-
20
- // src/parser/index.ts
21
- import transformers from "@kubb/core/transformers";
22
- import { SchemaGenerator, isKeyword, schemaKeywords } from "@kubb/plugin-oas";
23
- var fakerKeywordMapper = {
24
- any: () => "undefined",
25
- unknown: () => "unknown",
26
- number: (min, max) => {
27
- if (max !== void 0 && min !== void 0) {
28
- return `faker.number.float({ min: ${min}, max: ${max} })`;
29
- }
30
- if (min !== void 0) {
31
- return `faker.number.float({ min: ${min} })`;
32
- }
33
- if (max !== void 0) {
34
- return `faker.number.float({ max: ${max} })`;
35
- }
36
- return "faker.number.float()";
37
- },
38
- integer: (min, max) => {
39
- if (max !== void 0 && min !== void 0) {
40
- return `faker.number.int({ min: ${min}, max: ${max} })`;
41
- }
42
- if (min !== void 0) {
43
- return `faker.number.int({ min: ${min} })`;
44
- }
45
- if (max !== void 0) {
46
- return `faker.number.int({ max: ${max} })`;
47
- }
48
- return "faker.number.int()";
49
- },
50
- string: (min, max) => {
51
- if (max !== void 0 && min !== void 0) {
52
- return `faker.string.alpha({ length: { min: ${min}, max: ${max} } })`;
53
- }
54
- if (min !== void 0) {
55
- return `faker.string.alpha({ length: { min: ${min} } })`;
56
- }
57
- if (max !== void 0) {
58
- return `faker.string.alpha({ length: { max: ${max} } })`;
59
- }
60
- return "faker.string.alpha()";
61
- },
62
- boolean: () => "faker.datatype.boolean()",
63
- undefined: () => "undefined",
64
- null: () => "null",
65
- array: (items = []) => `faker.helpers.arrayElements([${items.join(", ")}]) as any`,
66
- tuple: (items = []) => `faker.helpers.arrayElements([${items.join(", ")}]) as any`,
67
- enum: (items = []) => `faker.helpers.arrayElement<any>([${items.join(", ")}])`,
68
- union: (items = []) => `faker.helpers.arrayElement<any>([${items.join(", ")}])`,
69
- /**
70
- * ISO 8601
71
- */
72
- datetime: () => "faker.date.anytime().toISOString()",
73
- /**
74
- * Type `'date'` Date
75
- * Type `'string'` ISO date format (YYYY-MM-DD)
76
- * @default ISO date format (YYYY-MM-DD)
77
- */
78
- date: (type = "string", parser) => {
79
- if (type === "string") {
80
- if (parser) {
81
- return `${parser}(faker.date.anytime()).format("YYYY-MM-DD")`;
82
- }
83
- return "faker.date.anytime().toString()";
84
- }
85
- return "faker.date.anytime()";
86
- },
87
- /**
88
- * Type `'date'` Date
89
- * Type `'string'` ISO time format (HH:mm:ss[.SSSSSS])
90
- * @default ISO time format (HH:mm:ss[.SSSSSS])
91
- */
92
- time: (type = "string", parser) => {
93
- if (type === "string") {
94
- if (parser) {
95
- return `${parser}(faker.date.anytime()).format("HH:mm:ss")`;
96
- }
97
- return "faker.date.anytime().toString()";
98
- }
99
- return "faker.date.anytime()";
100
- },
101
- uuid: () => "faker.string.uuid()",
102
- url: () => "faker.internet.url()",
103
- and: (items = []) => `Object.assign({}, ${items.join(", ")})`,
104
- object: () => "object",
105
- ref: () => "ref",
106
- matches: (value = "", regexGenerator = "faker") => {
107
- if (regexGenerator === "randexp") {
108
- return `${transformers.toRegExpString(value, "RandExp")}.gen()`;
109
- }
110
- return `faker.helpers.fromRegExp(${transformers.toRegExpString(value)})`;
111
- },
112
- email: () => "faker.internet.email()",
113
- firstName: () => "faker.person.firstName()",
114
- lastName: () => "faker.person.lastName()",
115
- password: () => "faker.internet.password()",
116
- phone: () => "faker.phone.number()",
117
- blob: () => "faker.image.imageUrl() as unknown as Blob",
118
- default: void 0,
119
- describe: void 0,
120
- const: (value) => value ?? "",
121
- max: void 0,
122
- min: void 0,
123
- nullable: void 0,
124
- nullish: void 0,
125
- optional: void 0,
126
- readOnly: void 0,
127
- strict: void 0,
128
- deprecated: void 0,
129
- example: void 0,
130
- schema: void 0,
131
- catchall: void 0,
132
- name: void 0
133
- };
134
- function schemaKeywordsorter(a, b) {
135
- if (b.keyword === "null") {
136
- return -1;
137
- }
138
- return 0;
139
- }
140
- function joinItems(items) {
141
- switch (items.length) {
142
- case 0:
143
- return "undefined";
144
- case 1:
145
- return items[0];
146
- default:
147
- return fakerKeywordMapper.union(items);
148
- }
149
- }
150
- function parse(parent, current, options) {
151
- const value = fakerKeywordMapper[current.keyword];
152
- if (!value) {
153
- return void 0;
154
- }
155
- if (isKeyword(current, schemaKeywords.union)) {
156
- return fakerKeywordMapper.union(current.args.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean));
157
- }
158
- if (isKeyword(current, schemaKeywords.and)) {
159
- return fakerKeywordMapper.and(current.args.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean));
160
- }
161
- if (isKeyword(current, schemaKeywords.array)) {
162
- return fakerKeywordMapper.array(current.args.items.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean));
163
- }
164
- if (isKeyword(current, schemaKeywords.enum)) {
165
- return fakerKeywordMapper.enum(
166
- current.args.items.map((schema) => {
167
- if (schema.format === "number") {
168
- return schema.name;
169
- }
170
- return transformers.stringify(schema.name);
171
- })
172
- );
173
- }
174
- if (isKeyword(current, schemaKeywords.ref)) {
175
- if (!current.args?.name) {
176
- throw new Error(`Name not defined for keyword ${current.keyword}`);
177
- }
178
- if (options.withData) {
179
- return `${current.args.name}(data)`;
180
- }
181
- return `${current.args.name}()`;
182
- }
183
- if (isKeyword(current, schemaKeywords.object)) {
184
- const argsObject = Object.entries(current.args?.properties || {}).filter((item) => {
185
- const schema = item[1];
186
- return schema && typeof schema.map === "function";
187
- }).map(([name, schemas]) => {
188
- const nameSchema = schemas.find((schema) => schema.keyword === schemaKeywords.name);
189
- const mappedName = nameSchema?.args || name;
190
- if (options.mapper?.[mappedName]) {
191
- return `"${name}": ${options.mapper?.[mappedName]}`;
192
- }
193
- return `"${name}": ${joinItems(
194
- schemas.sort(schemaKeywordsorter).map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean)
195
- )}`;
196
- }).join(",");
197
- return `{${argsObject}}`;
198
- }
199
- if (isKeyword(current, schemaKeywords.tuple)) {
200
- if (Array.isArray(current.args.items)) {
201
- return fakerKeywordMapper.tuple(current.args.items.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean));
202
- }
203
- return parse(current, current.args.items, { ...options, withData: false });
204
- }
205
- if (isKeyword(current, schemaKeywords.const)) {
206
- if (current.args.format === "number" && current.args.name !== void 0) {
207
- return fakerKeywordMapper.const(current.args.name?.toString());
208
- }
209
- return fakerKeywordMapper.const(transformers.stringify(current.args.value));
210
- }
211
- if (isKeyword(current, schemaKeywords.matches) && current.args) {
212
- return fakerKeywordMapper.matches(current.args, options.regexGenerator);
213
- }
214
- if (isKeyword(current, schemaKeywords.null) || isKeyword(current, schemaKeywords.undefined) || isKeyword(current, schemaKeywords.any)) {
215
- return value() || "";
216
- }
217
- if (isKeyword(current, schemaKeywords.string)) {
218
- if (parent) {
219
- const minSchema = SchemaGenerator.find([parent], schemaKeywords.min);
220
- const maxSchema = SchemaGenerator.find([parent], schemaKeywords.max);
221
- return fakerKeywordMapper.string(minSchema?.args, maxSchema?.args);
222
- }
223
- return fakerKeywordMapper.string();
224
- }
225
- if (isKeyword(current, schemaKeywords.number)) {
226
- if (parent) {
227
- const minSchema = SchemaGenerator.find([parent], schemaKeywords.min);
228
- const maxSchema = SchemaGenerator.find([parent], schemaKeywords.max);
229
- return fakerKeywordMapper.number(minSchema?.args, maxSchema?.args);
230
- }
231
- return fakerKeywordMapper.number();
232
- }
233
- if (isKeyword(current, schemaKeywords.integer)) {
234
- if (parent) {
235
- const minSchema = SchemaGenerator.find([parent], schemaKeywords.min);
236
- const maxSchema = SchemaGenerator.find([parent], schemaKeywords.max);
237
- return fakerKeywordMapper.integer(minSchema?.args, maxSchema?.args);
238
- }
239
- return fakerKeywordMapper.integer();
240
- }
241
- if (isKeyword(current, schemaKeywords.datetime)) {
242
- return fakerKeywordMapper.datetime();
243
- }
244
- if (isKeyword(current, schemaKeywords.date)) {
245
- return fakerKeywordMapper.date(current.args.type, options.dateParser);
246
- }
247
- if (isKeyword(current, schemaKeywords.time)) {
248
- return fakerKeywordMapper.time(current.args.type, options.dateParser);
249
- }
250
- if (current.keyword in fakerKeywordMapper && "args" in current) {
251
- const value2 = fakerKeywordMapper[current.keyword];
252
- const options2 = JSON.stringify(current.args);
253
- return value2(options2);
254
- }
255
- if (current.keyword in fakerKeywordMapper) {
256
- return value();
257
- }
258
- return void 0;
259
- }
260
-
261
- // src/plugin.ts
262
- import path from "path";
263
- import { FileManager, PluginManager, createPlugin } from "@kubb/core";
264
- import { camelCase } from "@kubb/core/transformers";
265
- import { renderTemplate } from "@kubb/core/utils";
266
- import { pluginOasName } from "@kubb/plugin-oas";
267
- import { getGroupedByTagFiles } from "@kubb/plugin-oas/utils";
268
- import { pluginTsName } from "@kubb/plugin-ts";
269
-
270
- // src/OperationGenerator.tsx
271
- import { OperationGenerator as Generator } from "@kubb/plugin-oas";
272
- import { Oas } from "@kubb/plugin-oas/components";
273
- import { App, createRoot } from "@kubb/react";
274
- import { jsx } from "@kubb/react/jsx-runtime";
275
- var OperationGenerator = class extends Generator {
276
- async operation(operation, options) {
277
- const { oas, pluginManager, plugin, mode } = this.context;
278
- const root = createRoot({
279
- logger: pluginManager.logger
280
- });
281
- root.render(
282
- /* @__PURE__ */ jsx(App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx(Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsx(Oas.Operation, { operation, children: /* @__PURE__ */ jsx(OperationSchema.File, {}) }) }) })
283
- );
284
- return root.files;
285
- }
286
- };
287
-
288
- // src/plugin.ts
289
- var pluginFakerName = "plugin-faker";
290
- var pluginFaker = createPlugin((options) => {
291
- const {
292
- output = { path: "mocks" },
293
- seed,
294
- group,
295
- exclude = [],
296
- include,
297
- override = [],
298
- transformers: transformers3 = {},
299
- mapper = {},
300
- dateType = "string",
301
- unknownType = "any",
302
- dateParser,
303
- regexGenerator = "faker"
304
- } = options;
305
- const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
306
- return {
307
- name: pluginFakerName,
308
- options: {
309
- extName: output.extName,
310
- transformers: transformers3,
311
- dateType,
312
- seed,
313
- unknownType,
314
- dateParser,
315
- mapper,
316
- override,
317
- regexGenerator
318
- },
319
- pre: [pluginOasName, pluginTsName],
320
- resolvePath(baseName, pathMode, options2) {
321
- const root = path.resolve(this.config.root, this.config.output.path);
322
- const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
323
- if (mode === "single") {
324
- return path.resolve(root, output.path);
325
- }
326
- if (options2?.tag && group?.type === "tag") {
327
- const tag = camelCase(options2.tag);
328
- return path.resolve(root, renderTemplate(template, { tag }), baseName);
329
- }
330
- return path.resolve(root, output.path, baseName);
331
- },
332
- resolveName(name, type) {
333
- const resolvedName = camelCase(name, {
334
- prefix: type ? "create" : void 0,
335
- isFile: type === "file"
336
- });
337
- if (type) {
338
- return transformers3?.name?.(resolvedName, type) || resolvedName;
339
- }
340
- return resolvedName;
341
- },
342
- async buildStart() {
343
- const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
344
- const oas = await swaggerPlugin.context.getOas();
345
- const root = path.resolve(this.config.root, this.config.output.path);
346
- const mode = FileManager.getMode(path.resolve(root, output.path));
347
- const schemaGenerator = new SchemaGenerator2(this.plugin.options, {
348
- oas,
349
- pluginManager: this.pluginManager,
350
- plugin: this.plugin,
351
- contentType: swaggerPlugin.context.contentType,
352
- include: void 0,
353
- override,
354
- mode,
355
- output: output.path
356
- });
357
- const schemaFiles = await schemaGenerator.build();
358
- await this.addFile(...schemaFiles);
359
- const operationGenerator = new OperationGenerator(this.plugin.options, {
360
- oas,
361
- pluginManager: this.pluginManager,
362
- plugin: this.plugin,
363
- contentType: swaggerPlugin.context.contentType,
364
- exclude,
365
- include,
366
- override,
367
- mode
368
- });
369
- const operationFiles = await operationGenerator.build();
370
- await this.addFile(...operationFiles);
371
- },
372
- async buildEnd() {
373
- if (this.config.output.write === false) {
374
- return;
375
- }
376
- const root = path.resolve(this.config.root, this.config.output.path);
377
- if (group?.type === "tag") {
378
- const rootFiles = await getGroupedByTagFiles({
379
- logger: this.logger,
380
- files: this.fileManager.files,
381
- plugin: this.plugin,
382
- template,
383
- exportAs: group.exportAs || "{{tag}}Mocks",
384
- root,
385
- output
386
- });
387
- await this.addFile(...rootFiles);
388
- }
389
- await this.fileManager.addIndexes({
390
- root,
391
- output,
392
- meta: { pluginKey: this.plugin.key },
393
- logger: this.logger
394
- });
395
- }
396
- };
397
- });
398
-
399
- // src/components/Schema.tsx
400
- import { Fragment, jsx as jsx2, jsxs } from "@kubb/react/jsx-runtime";
401
- function Schema(props) {
402
- const { withData, description } = props;
403
- const { tree, name } = useSchema();
404
- const {
405
- pluginManager,
406
- plugin: {
407
- options: { dateParser, regexGenerator, mapper, seed }
408
- }
409
- } = useApp();
410
- const resolvedName = pluginManager.resolveName({
411
- name,
412
- pluginKey: [pluginFakerName],
413
- type: "function"
414
- });
415
- const typeName = pluginManager.resolveName({
416
- name,
417
- pluginKey: [pluginTsName2],
418
- type: "type"
419
- });
420
- const fakerText = joinItems(
421
- tree.map((schema) => parse(void 0, schema, { name: resolvedName, typeName, seed, regexGenerator, mapper, withData, dateParser })).filter(Boolean)
422
- );
423
- let fakerDefaultOverride = void 0;
424
- let fakerTextWithOverride = fakerText;
425
- if (withData && fakerText.startsWith("{")) {
426
- fakerDefaultOverride = "{}";
427
- fakerTextWithOverride = `{
428
- ...${fakerText},
429
- ...data
430
- }`;
431
- }
432
- if (withData && fakerText.startsWith("faker.helpers.arrayElements")) {
433
- fakerDefaultOverride = "[]";
434
- fakerTextWithOverride = `[
435
- ...${fakerText},
436
- ...data
437
- ]`;
438
- }
439
- const params = fakerDefaultOverride ? `data: NonNullable<Partial<${typeName}>> = ${fakerDefaultOverride}` : `data?: NonNullable<Partial<${typeName}>>`;
440
- return /* @__PURE__ */ jsxs(Fragment, { children: [
441
- /* @__PURE__ */ jsxs(
442
- Function,
443
- {
444
- export: true,
445
- name: resolvedName,
446
- JSDoc: { comments: [description ? `@description ${transformers2.jsStringEscape(description)}` : void 0].filter(Boolean) },
447
- params: withData ? params : "",
448
- returnType: typeName ? `NonNullable<${typeName}>` : "",
449
- children: [
450
- seed ? `faker.seed(${JSON.stringify(seed)})` : "",
451
- /* @__PURE__ */ jsx2("br", {}),
452
- /* @__PURE__ */ jsx2(Function.Return, { children: fakerTextWithOverride })
453
- ]
454
- }
455
- ),
456
- /* @__PURE__ */ jsx2("br", {})
457
- ] });
458
- }
459
- Schema.File = function({}) {
460
- const { pluginManager } = useApp();
461
- const { tree, schema } = useSchema();
462
- const withData = tree.some(
463
- (schema2) => schema2.keyword === schemaKeywords2.array || schema2.keyword === schemaKeywords2.and || schema2.keyword === schemaKeywords2.object || schema2.keyword === schemaKeywords2.union || schema2.keyword === schemaKeywords2.tuple
464
- );
465
- return /* @__PURE__ */ jsxs(Oas2.Schema.File, { output: pluginManager.config.output.path, children: [
466
- /* @__PURE__ */ jsx2(Schema.Imports, {}),
467
- /* @__PURE__ */ jsx2(File.Source, { children: /* @__PURE__ */ jsx2(Schema, { description: schema?.description, withData }) })
468
- ] });
469
- };
470
- Schema.Imports = () => {
471
- const {
472
- pluginManager,
473
- plugin: {
474
- options: { extName, dateParser, regexGenerator }
475
- }
476
- } = useApp();
477
- const { path: root } = useFile();
478
- const { name, tree, schema } = useSchema();
479
- const typeName = pluginManager.resolveName({
480
- name,
481
- pluginKey: [pluginTsName2],
482
- type: "type"
483
- });
484
- const typeFileName = pluginManager.resolveName({
485
- name,
486
- pluginKey: [pluginTsName2],
487
- type: "file"
488
- });
489
- const typePath = pluginManager.resolvePath({
490
- baseName: typeFileName,
491
- pluginKey: [pluginTsName2]
492
- });
493
- return /* @__PURE__ */ jsxs(Fragment, { children: [
494
- /* @__PURE__ */ jsx2(File.Import, { name: ["faker"], path: "@faker-js/faker" }),
495
- regexGenerator === "randexp" && /* @__PURE__ */ jsx2(File.Import, { name: "RandExp", path: "randexp" }),
496
- dateParser && /* @__PURE__ */ jsx2(File.Import, { path: dateParser, name: dateParser }),
497
- typeName && typePath && /* @__PURE__ */ jsx2(File.Import, { extName, isTypeOnly: true, root, path: typePath, name: [typeName] })
498
- ] });
499
- };
500
-
501
- // src/SchemaGenerator.tsx
502
- import { jsx as jsx3 } from "@kubb/react/jsx-runtime";
503
- var SchemaGenerator2 = class extends Generator2 {
504
- async schema(name, schema, options) {
505
- const { oas, pluginManager, plugin, mode, output } = this.context;
506
- const root = createRoot2({
507
- logger: pluginManager.logger
508
- });
509
- const tree = this.parse({ schema, name });
510
- root.render(
511
- /* @__PURE__ */ jsx3(App2, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx3(Oas3, { oas, children: /* @__PURE__ */ jsx3(Oas3.Schema, { name, value: schema, tree, children: /* @__PURE__ */ jsx3(Schema.File, {}) }) }) })
512
- );
513
- return root.files;
514
- }
515
- };
516
-
517
- // src/components/OperationSchema.tsx
518
- import { jsx as jsx4, jsxs as jsxs2 } from "@kubb/react/jsx-runtime";
519
- function OperationSchema({ description }) {
520
- return /* @__PURE__ */ jsx4(Schema, { withData: false, description });
521
- }
522
- OperationSchema.File = function({}) {
523
- const { plugin, pluginManager, mode } = useApp2();
524
- const oas = useOas();
525
- const { getSchemas, getFile } = useOperationManager();
526
- const operation = useOperation();
527
- const file = getFile(operation);
528
- const schemas = getSchemas(operation);
529
- const generator = new SchemaGenerator2(plugin.options, {
530
- oas,
531
- plugin,
532
- pluginManager,
533
- mode,
534
- override: plugin.options.override
535
- });
536
- const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
537
- const mapItem = ({ name, schema, description, ...options }, i) => {
538
- const typeName = pluginManager.resolveName({
539
- name,
540
- pluginKey: [pluginTsName3],
541
- type: "type"
542
- });
543
- const typeFileName = pluginManager.resolveName({
544
- name: options.operationName || name,
545
- pluginKey: [pluginTsName3],
546
- type: "file"
547
- });
548
- const typePath = pluginManager.resolvePath({
549
- baseName: typeFileName,
550
- pluginKey: [pluginTsName3],
551
- options: { tag: options.operation?.getTags()[0]?.name }
552
- });
553
- const tree = generator.parse({ schema, name });
554
- return /* @__PURE__ */ jsxs2(Oas4.Schema, { name, value: schema, tree, children: [
555
- typeName && typePath && /* @__PURE__ */ jsx4(File2.Import, { extName: plugin.options.extName, isTypeOnly: true, root: file.path, path: typePath, name: [typeName] }),
556
- plugin.options.dateParser && /* @__PURE__ */ jsx4(File2.Import, { path: plugin.options.dateParser, name: plugin.options.dateParser }),
557
- mode === "split" && /* @__PURE__ */ jsx4(Oas4.Schema.Imports, { extName: plugin.options.extName }),
558
- /* @__PURE__ */ jsx4(File2.Source, { children: /* @__PURE__ */ jsx4(OperationSchema, { description }) })
559
- ] }, i);
560
- };
561
- return /* @__PURE__ */ jsx4(Parser, { language: "typescript", children: /* @__PURE__ */ jsxs2(File2, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
562
- /* @__PURE__ */ jsx4(File2.Import, { name: ["faker"], path: "@faker-js/faker" }),
563
- plugin.options.regexGenerator === "randexp" && /* @__PURE__ */ jsx4(File2.Import, { name: "RandExp", path: "randexp" }),
564
- items.map(mapItem)
565
- ] }) });
566
- };
567
- export {
568
- OperationSchema,
569
- Schema
570
- };
1
+ export { Faker } from './chunk-ORCMQTO5.js';
2
+ //# sourceMappingURL=components.js.map
571
3
  //# sourceMappingURL=components.js.map