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