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