@kubb/plugin-faker 3.0.0-alpha.9 → 3.0.0-beta.1
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 +14 -5
- package/dist/chunk-HTZ2R6MK.js +305 -0
- package/dist/chunk-HTZ2R6MK.js.map +1 -0
- package/dist/chunk-KBSFZ5OP.cjs +311 -0
- package/dist/chunk-KBSFZ5OP.cjs.map +1 -0
- package/dist/chunk-QFJUM25Z.js +113 -0
- package/dist/chunk-QFJUM25Z.js.map +1 -0
- package/dist/chunk-U6LOSTOE.cjs +115 -0
- package/dist/chunk-U6LOSTOE.cjs.map +1 -0
- package/dist/components.cjs +6 -556
- 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 -561
- 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 +52 -500
- 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 +39 -494
- package/dist/index.js.map +1 -1
- package/dist/types-C1bqlbxh.d.cts +94 -0
- package/dist/types-C1bqlbxh.d.ts +94 -0
- package/package.json +20 -16
- 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 +25 -14
- package/src/plugin.ts +29 -36
- package/src/types.ts +28 -67
- package/src/OperationGenerator.tsx +0 -31
- package/src/SchemaGenerator.tsx +0 -31
- package/src/components/OperationSchema.tsx +0 -82
- package/src/components/Schema.tsx +0 -144
package/dist/index.cjs
CHANGED
|
@@ -1,524 +1,77 @@
|
|
|
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 _plugints = require('@kubb/plugin-ts');
|
|
1
|
+
'use strict';
|
|
8
2
|
|
|
9
|
-
|
|
3
|
+
var chunkU6LOSTOE_cjs = require('./chunk-U6LOSTOE.cjs');
|
|
4
|
+
require('./chunk-KBSFZ5OP.cjs');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var core = require('@kubb/core');
|
|
7
|
+
var transformers = require('@kubb/core/transformers');
|
|
8
|
+
require('@kubb/core/utils');
|
|
9
|
+
var pluginOas = require('@kubb/plugin-oas');
|
|
10
|
+
var pluginTs = require('@kubb/plugin-ts');
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
var _react = require('@kubb/react');
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
15
15
|
|
|
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
16
|
var pluginFakerName = "plugin-faker";
|
|
460
|
-
var pluginFaker =
|
|
17
|
+
var pluginFaker = core.createPlugin((options) => {
|
|
461
18
|
const {
|
|
462
|
-
output = { path: "mocks" },
|
|
19
|
+
output = { path: "mocks", barrelType: "named" },
|
|
463
20
|
seed,
|
|
464
21
|
group,
|
|
465
22
|
exclude = [],
|
|
466
23
|
include,
|
|
467
24
|
override = [],
|
|
468
|
-
transformers:
|
|
25
|
+
transformers: transformers$1 = {},
|
|
469
26
|
mapper = {},
|
|
470
|
-
dateType = "string",
|
|
471
27
|
unknownType = "any",
|
|
472
|
-
|
|
28
|
+
dateType = "string",
|
|
29
|
+
dateParser = "faker",
|
|
30
|
+
generators = [chunkU6LOSTOE_cjs.fakerGenerator].filter(Boolean),
|
|
473
31
|
regexGenerator = "faker"
|
|
474
32
|
} = options;
|
|
475
|
-
const template = _optionalChain([group, 'optionalAccess', _26 => _26.output]) ? group.output : `${output.path}/{{tag}}Controller`;
|
|
476
33
|
return {
|
|
477
34
|
name: pluginFakerName,
|
|
478
|
-
output: {
|
|
479
|
-
exportType: "barrelNamed",
|
|
480
|
-
...output
|
|
481
|
-
},
|
|
482
35
|
options: {
|
|
483
|
-
|
|
484
|
-
transformers:
|
|
485
|
-
dateType,
|
|
36
|
+
output,
|
|
37
|
+
transformers: transformers$1,
|
|
486
38
|
seed,
|
|
39
|
+
dateType,
|
|
487
40
|
unknownType,
|
|
488
41
|
dateParser,
|
|
489
42
|
mapper,
|
|
490
43
|
override,
|
|
491
44
|
regexGenerator
|
|
492
45
|
},
|
|
493
|
-
pre: [
|
|
46
|
+
pre: [pluginOas.pluginOasName, pluginTs.pluginTsName],
|
|
494
47
|
resolvePath(baseName, pathMode, options2) {
|
|
495
|
-
const root =
|
|
496
|
-
const mode =
|
|
497
|
-
if (
|
|
498
|
-
|
|
48
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
49
|
+
const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
50
|
+
if (options2?.tag && group?.type === "tag") {
|
|
51
|
+
const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
|
|
52
|
+
return path__default.default.resolve(root, output.path, groupName({ group: transformers.camelCase(options2.tag) }), baseName);
|
|
499
53
|
}
|
|
500
|
-
if (
|
|
501
|
-
|
|
502
|
-
return _path2.default.resolve(root, _utils.renderTemplate.call(void 0, template, { tag }), baseName);
|
|
54
|
+
if (mode === "single") {
|
|
55
|
+
return path__default.default.resolve(root, output.path);
|
|
503
56
|
}
|
|
504
|
-
return
|
|
57
|
+
return path__default.default.resolve(root, output.path, baseName);
|
|
505
58
|
},
|
|
506
59
|
resolveName(name, type) {
|
|
507
|
-
const resolvedName =
|
|
60
|
+
const resolvedName = transformers.camelCase(name, {
|
|
508
61
|
prefix: type ? "create" : void 0,
|
|
509
62
|
isFile: type === "file"
|
|
510
63
|
});
|
|
511
64
|
if (type) {
|
|
512
|
-
return
|
|
65
|
+
return transformers$1?.name?.(resolvedName, type) || resolvedName;
|
|
513
66
|
}
|
|
514
67
|
return resolvedName;
|
|
515
68
|
},
|
|
516
69
|
async buildStart() {
|
|
517
|
-
const [swaggerPlugin] =
|
|
70
|
+
const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
|
|
518
71
|
const oas = await swaggerPlugin.context.getOas();
|
|
519
|
-
const root =
|
|
520
|
-
const mode =
|
|
521
|
-
const schemaGenerator = new
|
|
72
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
73
|
+
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
74
|
+
const schemaGenerator = new pluginOas.SchemaGenerator(this.plugin.options, {
|
|
522
75
|
oas,
|
|
523
76
|
pluginManager: this.pluginManager,
|
|
524
77
|
plugin: this.plugin,
|
|
@@ -528,9 +81,9 @@ var pluginFaker = _core.createPlugin.call(void 0, (options) => {
|
|
|
528
81
|
mode,
|
|
529
82
|
output: output.path
|
|
530
83
|
});
|
|
531
|
-
const schemaFiles = await schemaGenerator.build();
|
|
84
|
+
const schemaFiles = await schemaGenerator.build(...generators);
|
|
532
85
|
await this.addFile(...schemaFiles);
|
|
533
|
-
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
86
|
+
const operationGenerator = new pluginOas.OperationGenerator(this.plugin.options, {
|
|
534
87
|
oas,
|
|
535
88
|
pluginManager: this.pluginManager,
|
|
536
89
|
plugin: this.plugin,
|
|
@@ -540,25 +93,24 @@ var pluginFaker = _core.createPlugin.call(void 0, (options) => {
|
|
|
540
93
|
override,
|
|
541
94
|
mode
|
|
542
95
|
});
|
|
543
|
-
const operationFiles = await operationGenerator.build();
|
|
96
|
+
const operationFiles = await operationGenerator.build(...generators);
|
|
544
97
|
await this.addFile(...operationFiles);
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
}
|
|
98
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
99
|
+
type: output.barrelType ?? "named",
|
|
100
|
+
root,
|
|
101
|
+
output,
|
|
102
|
+
files: this.fileManager.files,
|
|
103
|
+
meta: {
|
|
104
|
+
pluginKey: this.plugin.key
|
|
105
|
+
},
|
|
106
|
+
logger: this.logger
|
|
107
|
+
});
|
|
108
|
+
await this.addFile(...barrelFiles);
|
|
557
109
|
}
|
|
558
110
|
};
|
|
559
111
|
});
|
|
560
112
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
113
|
+
exports.pluginFaker = pluginFaker;
|
|
114
|
+
exports.pluginFakerName = pluginFakerName;
|
|
115
|
+
//# sourceMappingURL=index.cjs.map
|
|
564
116
|
//# sourceMappingURL=index.cjs.map
|