@kubb/plugin-faker 3.0.0-alpha.2 → 3.0.0-alpha.21
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-4AVWJQH5.js +113 -0
- package/dist/chunk-4AVWJQH5.js.map +1 -0
- package/dist/chunk-4I5F76DK.cjs +310 -0
- package/dist/chunk-4I5F76DK.cjs.map +1 -0
- package/dist/chunk-JVUPDWN2.js +304 -0
- package/dist/chunk-JVUPDWN2.js.map +1 -0
- package/dist/chunk-WYCU2YG6.cjs +115 -0
- package/dist/chunk-WYCU2YG6.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 +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 +24 -14
- 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.js
CHANGED
|
@@ -1,462 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { pluginTsName
|
|
1
|
+
import { fakerGenerator } from './chunk-4AVWJQH5.js';
|
|
2
|
+
import './chunk-JVUPDWN2.js';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { createPlugin, FileManager, PluginManager } from '@kubb/core';
|
|
5
|
+
import { camelCase } from '@kubb/core/transformers';
|
|
6
|
+
import { renderTemplate } from '@kubb/core/utils';
|
|
7
|
+
import { pluginOasName, SchemaGenerator, OperationGenerator } from '@kubb/plugin-oas';
|
|
8
|
+
import { pluginTsName } from '@kubb/plugin-ts';
|
|
9
9
|
|
|
10
|
-
// src/OperationGenerator.tsx
|
|
11
|
-
import { OperationGenerator as Generator2 } from "@kubb/plugin-oas";
|
|
12
|
-
import { Oas as Oas4 } from "@kubb/plugin-oas/components";
|
|
13
|
-
import { App as App2, createRoot as createRoot2 } from "@kubb/react";
|
|
14
|
-
|
|
15
|
-
// src/components/OperationSchema.tsx
|
|
16
|
-
import { Oas as Oas3 } from "@kubb/plugin-oas/components";
|
|
17
|
-
import { useOas, useOperation, useOperationManager } from "@kubb/plugin-oas/hooks";
|
|
18
|
-
import { File as File2, Parser, useApp as useApp2 } from "@kubb/react";
|
|
19
|
-
import { pluginTsName as pluginTsName2 } from "@kubb/plugin-ts";
|
|
20
|
-
|
|
21
|
-
// src/SchemaGenerator.tsx
|
|
22
|
-
import { SchemaGenerator as Generator } from "@kubb/plugin-oas";
|
|
23
|
-
import { Oas as Oas2 } from "@kubb/plugin-oas/components";
|
|
24
|
-
import { App, createRoot } from "@kubb/react";
|
|
25
|
-
|
|
26
|
-
// src/components/Schema.tsx
|
|
27
|
-
import { Oas } from "@kubb/plugin-oas/components";
|
|
28
|
-
import { File, Function, useApp, useFile } from "@kubb/react";
|
|
29
|
-
import { pluginTsName } from "@kubb/plugin-ts";
|
|
30
|
-
import transformers2 from "@kubb/core/transformers";
|
|
31
|
-
import { schemaKeywords as schemaKeywords2 } from "@kubb/plugin-oas";
|
|
32
|
-
import { useSchema } from "@kubb/plugin-oas/hooks";
|
|
33
|
-
|
|
34
|
-
// src/parser/index.ts
|
|
35
|
-
import transformers from "@kubb/core/transformers";
|
|
36
|
-
import { SchemaGenerator, isKeyword, schemaKeywords } from "@kubb/plugin-oas";
|
|
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 `${transformers.toRegExpString(value, "RandExp")}.gen()`;
|
|
123
|
-
}
|
|
124
|
-
return `faker.helpers.fromRegExp(${transformers.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) => 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 (isKeyword(current, schemaKeywords.union)) {
|
|
170
|
-
return fakerKeywordMapper.union(current.args.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean));
|
|
171
|
-
}
|
|
172
|
-
if (isKeyword(current, schemaKeywords.and)) {
|
|
173
|
-
return fakerKeywordMapper.and(current.args.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean));
|
|
174
|
-
}
|
|
175
|
-
if (isKeyword(current, schemaKeywords.array)) {
|
|
176
|
-
return fakerKeywordMapper.array(current.args.items.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean));
|
|
177
|
-
}
|
|
178
|
-
if (isKeyword(current, schemaKeywords.enum)) {
|
|
179
|
-
return fakerKeywordMapper.enum(
|
|
180
|
-
current.args.items.map((schema) => {
|
|
181
|
-
if (schema.format === "number") {
|
|
182
|
-
return schema.name;
|
|
183
|
-
}
|
|
184
|
-
return transformers.stringify(schema.name);
|
|
185
|
-
})
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
if (isKeyword(current, schemaKeywords.ref)) {
|
|
189
|
-
if (!current.args?.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 (isKeyword(current, schemaKeywords.object)) {
|
|
198
|
-
const argsObject = Object.entries(current.args?.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 === schemaKeywords.name);
|
|
203
|
-
const mappedName = nameSchema?.args || name;
|
|
204
|
-
if (options.mapper?.[mappedName]) {
|
|
205
|
-
return `"${name}": ${options.mapper?.[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 (isKeyword(current, 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 (isKeyword(current, schemaKeywords.const)) {
|
|
220
|
-
if (current.args.format === "number" && current.args.name !== void 0) {
|
|
221
|
-
return fakerKeywordMapper.const(current.args.name?.toString());
|
|
222
|
-
}
|
|
223
|
-
return fakerKeywordMapper.const(transformers.stringify(current.args.value));
|
|
224
|
-
}
|
|
225
|
-
if (isKeyword(current, schemaKeywords.matches) && current.args) {
|
|
226
|
-
return fakerKeywordMapper.matches(current.args, options.regexGenerator);
|
|
227
|
-
}
|
|
228
|
-
if (isKeyword(current, schemaKeywords.null) || isKeyword(current, schemaKeywords.undefined) || isKeyword(current, schemaKeywords.any)) {
|
|
229
|
-
return value() || "";
|
|
230
|
-
}
|
|
231
|
-
if (isKeyword(current, schemaKeywords.string)) {
|
|
232
|
-
if (parent) {
|
|
233
|
-
const minSchema = SchemaGenerator.find([parent], schemaKeywords.min);
|
|
234
|
-
const maxSchema = SchemaGenerator.find([parent], schemaKeywords.max);
|
|
235
|
-
return fakerKeywordMapper.string(minSchema?.args, maxSchema?.args);
|
|
236
|
-
}
|
|
237
|
-
return fakerKeywordMapper.string();
|
|
238
|
-
}
|
|
239
|
-
if (isKeyword(current, schemaKeywords.number)) {
|
|
240
|
-
if (parent) {
|
|
241
|
-
const minSchema = SchemaGenerator.find([parent], schemaKeywords.min);
|
|
242
|
-
const maxSchema = SchemaGenerator.find([parent], schemaKeywords.max);
|
|
243
|
-
return fakerKeywordMapper.number(minSchema?.args, maxSchema?.args);
|
|
244
|
-
}
|
|
245
|
-
return fakerKeywordMapper.number();
|
|
246
|
-
}
|
|
247
|
-
if (isKeyword(current, schemaKeywords.integer)) {
|
|
248
|
-
if (parent) {
|
|
249
|
-
const minSchema = SchemaGenerator.find([parent], schemaKeywords.min);
|
|
250
|
-
const maxSchema = SchemaGenerator.find([parent], schemaKeywords.max);
|
|
251
|
-
return fakerKeywordMapper.integer(minSchema?.args, maxSchema?.args);
|
|
252
|
-
}
|
|
253
|
-
return fakerKeywordMapper.integer();
|
|
254
|
-
}
|
|
255
|
-
if (isKeyword(current, schemaKeywords.datetime)) {
|
|
256
|
-
return fakerKeywordMapper.datetime();
|
|
257
|
-
}
|
|
258
|
-
if (isKeyword(current, schemaKeywords.date)) {
|
|
259
|
-
return fakerKeywordMapper.date(current.args.type, options.dateParser);
|
|
260
|
-
}
|
|
261
|
-
if (isKeyword(current, 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
|
-
import { Fragment, jsx, jsxs } from "@kubb/react/jsx-runtime";
|
|
277
|
-
function Schema(props) {
|
|
278
|
-
const { withData, description } = props;
|
|
279
|
-
const { tree, name } = useSchema();
|
|
280
|
-
const {
|
|
281
|
-
pluginManager,
|
|
282
|
-
plugin: {
|
|
283
|
-
options: { dateParser, regexGenerator, mapper, seed }
|
|
284
|
-
}
|
|
285
|
-
} = useApp();
|
|
286
|
-
const resolvedName = pluginManager.resolveName({
|
|
287
|
-
name,
|
|
288
|
-
pluginKey: [pluginFakerName],
|
|
289
|
-
type: "function"
|
|
290
|
-
});
|
|
291
|
-
const typeName = pluginManager.resolveName({
|
|
292
|
-
name,
|
|
293
|
-
pluginKey: [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__ */ jsxs(Fragment, { children: [
|
|
317
|
-
/* @__PURE__ */ jsxs(
|
|
318
|
-
Function,
|
|
319
|
-
{
|
|
320
|
-
export: true,
|
|
321
|
-
name: resolvedName,
|
|
322
|
-
JSDoc: { comments: [description ? `@description ${transformers2.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__ */ jsx("br", {}),
|
|
328
|
-
/* @__PURE__ */ jsx(Function.Return, { children: fakerTextWithOverride })
|
|
329
|
-
]
|
|
330
|
-
}
|
|
331
|
-
),
|
|
332
|
-
/* @__PURE__ */ jsx("br", {})
|
|
333
|
-
] });
|
|
334
|
-
}
|
|
335
|
-
Schema.File = function({}) {
|
|
336
|
-
const { pluginManager } = useApp();
|
|
337
|
-
const { tree, schema } = useSchema();
|
|
338
|
-
const withData = tree.some(
|
|
339
|
-
(schema2) => schema2.keyword === schemaKeywords2.array || schema2.keyword === schemaKeywords2.and || schema2.keyword === schemaKeywords2.object || schema2.keyword === schemaKeywords2.union || schema2.keyword === schemaKeywords2.tuple
|
|
340
|
-
);
|
|
341
|
-
return /* @__PURE__ */ jsxs(Oas.Schema.File, { output: pluginManager.config.output.path, children: [
|
|
342
|
-
/* @__PURE__ */ jsx(Schema.Imports, {}),
|
|
343
|
-
/* @__PURE__ */ jsx(File.Source, { children: /* @__PURE__ */ jsx(Schema, { description: schema?.description, withData }) })
|
|
344
|
-
] });
|
|
345
|
-
};
|
|
346
|
-
Schema.Imports = () => {
|
|
347
|
-
const {
|
|
348
|
-
pluginManager,
|
|
349
|
-
plugin: {
|
|
350
|
-
options: { extName, dateParser, regexGenerator }
|
|
351
|
-
}
|
|
352
|
-
} = useApp();
|
|
353
|
-
const { path: root } = useFile();
|
|
354
|
-
const { name, tree, schema } = useSchema();
|
|
355
|
-
const typeName = pluginManager.resolveName({
|
|
356
|
-
name,
|
|
357
|
-
pluginKey: [pluginTsName],
|
|
358
|
-
type: "type"
|
|
359
|
-
});
|
|
360
|
-
const typeFileName = pluginManager.resolveName({
|
|
361
|
-
name,
|
|
362
|
-
pluginKey: [pluginTsName],
|
|
363
|
-
type: "file"
|
|
364
|
-
});
|
|
365
|
-
const typePath = pluginManager.resolvePath({
|
|
366
|
-
baseName: typeFileName,
|
|
367
|
-
pluginKey: [pluginTsName]
|
|
368
|
-
});
|
|
369
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
370
|
-
/* @__PURE__ */ jsx(File.Import, { name: ["faker"], path: "@faker-js/faker" }),
|
|
371
|
-
regexGenerator === "randexp" && /* @__PURE__ */ jsx(File.Import, { name: "RandExp", path: "randexp" }),
|
|
372
|
-
dateParser && /* @__PURE__ */ jsx(File.Import, { path: dateParser, name: dateParser }),
|
|
373
|
-
typeName && typePath && /* @__PURE__ */ jsx(File.Import, { extName, isTypeOnly: true, root, path: typePath, name: [typeName] })
|
|
374
|
-
] });
|
|
375
|
-
};
|
|
376
|
-
|
|
377
|
-
// src/SchemaGenerator.tsx
|
|
378
|
-
import { jsx as jsx2 } from "@kubb/react/jsx-runtime";
|
|
379
|
-
var SchemaGenerator2 = class extends Generator {
|
|
380
|
-
async schema(name, schema, options) {
|
|
381
|
-
const { oas, pluginManager, plugin, mode, output } = this.context;
|
|
382
|
-
const root = createRoot({
|
|
383
|
-
logger: pluginManager.logger
|
|
384
|
-
});
|
|
385
|
-
const tree = this.parse({ schema, name });
|
|
386
|
-
root.render(
|
|
387
|
-
/* @__PURE__ */ jsx2(App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx2(Oas2, { oas, children: /* @__PURE__ */ jsx2(Oas2.Schema, { name, value: schema, tree, children: /* @__PURE__ */ jsx2(Schema.File, {}) }) }) })
|
|
388
|
-
);
|
|
389
|
-
return root.files;
|
|
390
|
-
}
|
|
391
|
-
};
|
|
392
|
-
|
|
393
|
-
// src/components/OperationSchema.tsx
|
|
394
|
-
import { jsx as jsx3, jsxs as jsxs2 } from "@kubb/react/jsx-runtime";
|
|
395
|
-
function OperationSchema({ description }) {
|
|
396
|
-
return /* @__PURE__ */ jsx3(Schema, { withData: false, description });
|
|
397
|
-
}
|
|
398
|
-
OperationSchema.File = function({}) {
|
|
399
|
-
const { plugin, pluginManager, mode } = useApp2();
|
|
400
|
-
const oas = useOas();
|
|
401
|
-
const { getSchemas, getFile } = useOperationManager();
|
|
402
|
-
const operation = useOperation();
|
|
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: [pluginTsName2],
|
|
417
|
-
type: "type"
|
|
418
|
-
});
|
|
419
|
-
const typeFileName = pluginManager.resolveName({
|
|
420
|
-
name: options.operationName || name,
|
|
421
|
-
pluginKey: [pluginTsName2],
|
|
422
|
-
type: "file"
|
|
423
|
-
});
|
|
424
|
-
const typePath = pluginManager.resolvePath({
|
|
425
|
-
baseName: typeFileName,
|
|
426
|
-
pluginKey: [pluginTsName2],
|
|
427
|
-
options: { tag: options.operation?.getTags()[0]?.name }
|
|
428
|
-
});
|
|
429
|
-
const tree = generator.parse({ schema, name });
|
|
430
|
-
return /* @__PURE__ */ jsxs2(Oas3.Schema, { name, value: schema, tree, children: [
|
|
431
|
-
typeName && typePath && /* @__PURE__ */ jsx3(File2.Import, { extName: plugin.options.extName, isTypeOnly: true, root: file.path, path: typePath, name: [typeName] }),
|
|
432
|
-
plugin.options.dateParser && /* @__PURE__ */ jsx3(File2.Import, { path: plugin.options.dateParser, name: plugin.options.dateParser }),
|
|
433
|
-
mode === "split" && /* @__PURE__ */ jsx3(Oas3.Schema.Imports, { extName: plugin.options.extName }),
|
|
434
|
-
/* @__PURE__ */ jsx3(File2.Source, { children: /* @__PURE__ */ jsx3(OperationSchema, { description }) })
|
|
435
|
-
] }, i);
|
|
436
|
-
};
|
|
437
|
-
return /* @__PURE__ */ jsx3(Parser, { language: "typescript", children: /* @__PURE__ */ jsxs2(File2, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
438
|
-
/* @__PURE__ */ jsx3(File2.Import, { name: ["faker"], path: "@faker-js/faker" }),
|
|
439
|
-
plugin.options.regexGenerator === "randexp" && /* @__PURE__ */ jsx3(File2.Import, { name: "RandExp", path: "randexp" }),
|
|
440
|
-
items.map(mapItem)
|
|
441
|
-
] }) });
|
|
442
|
-
};
|
|
443
|
-
|
|
444
|
-
// src/OperationGenerator.tsx
|
|
445
|
-
import { jsx as jsx4 } from "@kubb/react/jsx-runtime";
|
|
446
|
-
var OperationGenerator = class extends Generator2 {
|
|
447
|
-
async operation(operation, options) {
|
|
448
|
-
const { oas, pluginManager, plugin, mode } = this.context;
|
|
449
|
-
const root = createRoot2({
|
|
450
|
-
logger: pluginManager.logger
|
|
451
|
-
});
|
|
452
|
-
root.render(
|
|
453
|
-
/* @__PURE__ */ jsx4(App2, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx4(Oas4, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsx4(Oas4.Operation, { operation, children: /* @__PURE__ */ jsx4(OperationSchema.File, {}) }) }) })
|
|
454
|
-
);
|
|
455
|
-
return root.files;
|
|
456
|
-
}
|
|
457
|
-
};
|
|
458
|
-
|
|
459
|
-
// src/plugin.ts
|
|
460
10
|
var pluginFakerName = "plugin-faker";
|
|
461
11
|
var pluginFaker = createPlugin((options) => {
|
|
462
12
|
const {
|
|
@@ -466,28 +16,31 @@ var pluginFaker = createPlugin((options) => {
|
|
|
466
16
|
exclude = [],
|
|
467
17
|
include,
|
|
468
18
|
override = [],
|
|
469
|
-
transformers
|
|
19
|
+
transformers = {},
|
|
470
20
|
mapper = {},
|
|
471
|
-
dateType = "string",
|
|
472
21
|
unknownType = "any",
|
|
473
|
-
|
|
22
|
+
dateType = "string",
|
|
23
|
+
dateParser = "faker",
|
|
474
24
|
regexGenerator = "faker"
|
|
475
25
|
} = options;
|
|
476
26
|
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
477
27
|
return {
|
|
478
28
|
name: pluginFakerName,
|
|
479
29
|
options: {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
30
|
+
output: {
|
|
31
|
+
exportType: "barrelNamed",
|
|
32
|
+
...output
|
|
33
|
+
},
|
|
34
|
+
transformers,
|
|
483
35
|
seed,
|
|
36
|
+
dateType,
|
|
484
37
|
unknownType,
|
|
485
38
|
dateParser,
|
|
486
39
|
mapper,
|
|
487
40
|
override,
|
|
488
41
|
regexGenerator
|
|
489
42
|
},
|
|
490
|
-
pre: [pluginOasName,
|
|
43
|
+
pre: [pluginOasName, pluginTsName],
|
|
491
44
|
resolvePath(baseName, pathMode, options2) {
|
|
492
45
|
const root = path.resolve(this.config.root, this.config.output.path);
|
|
493
46
|
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
@@ -506,7 +59,7 @@ var pluginFaker = createPlugin((options) => {
|
|
|
506
59
|
isFile: type === "file"
|
|
507
60
|
});
|
|
508
61
|
if (type) {
|
|
509
|
-
return
|
|
62
|
+
return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
510
63
|
}
|
|
511
64
|
return resolvedName;
|
|
512
65
|
},
|
|
@@ -515,7 +68,7 @@ var pluginFaker = createPlugin((options) => {
|
|
|
515
68
|
const oas = await swaggerPlugin.context.getOas();
|
|
516
69
|
const root = path.resolve(this.config.root, this.config.output.path);
|
|
517
70
|
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
518
|
-
const schemaGenerator = new
|
|
71
|
+
const schemaGenerator = new SchemaGenerator(this.plugin.options, {
|
|
519
72
|
oas,
|
|
520
73
|
pluginManager: this.pluginManager,
|
|
521
74
|
plugin: this.plugin,
|
|
@@ -525,7 +78,7 @@ var pluginFaker = createPlugin((options) => {
|
|
|
525
78
|
mode,
|
|
526
79
|
output: output.path
|
|
527
80
|
});
|
|
528
|
-
const schemaFiles = await schemaGenerator.build();
|
|
81
|
+
const schemaFiles = await schemaGenerator.build(fakerGenerator);
|
|
529
82
|
await this.addFile(...schemaFiles);
|
|
530
83
|
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
531
84
|
oas,
|
|
@@ -537,37 +90,24 @@ var pluginFaker = createPlugin((options) => {
|
|
|
537
90
|
override,
|
|
538
91
|
mode
|
|
539
92
|
});
|
|
540
|
-
const operationFiles = await operationGenerator.build();
|
|
93
|
+
const operationFiles = await operationGenerator.build(fakerGenerator);
|
|
541
94
|
await this.addFile(...operationFiles);
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
if (this.config.output.write === false) {
|
|
545
|
-
return;
|
|
546
|
-
}
|
|
547
|
-
const root = path.resolve(this.config.root, this.config.output.path);
|
|
548
|
-
if (group?.type === "tag") {
|
|
549
|
-
const rootFiles = await getGroupedByTagFiles({
|
|
550
|
-
logger: this.logger,
|
|
551
|
-
files: this.fileManager.files,
|
|
552
|
-
plugin: this.plugin,
|
|
553
|
-
template,
|
|
554
|
-
exportAs: group.exportAs || "{{tag}}Mocks",
|
|
95
|
+
if (this.config.output.exportType) {
|
|
96
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
555
97
|
root,
|
|
556
|
-
output
|
|
98
|
+
output,
|
|
99
|
+
files: this.fileManager.files,
|
|
100
|
+
meta: {
|
|
101
|
+
pluginKey: this.plugin.key
|
|
102
|
+
},
|
|
103
|
+
logger: this.logger
|
|
557
104
|
});
|
|
558
|
-
await this.addFile(...
|
|
105
|
+
await this.addFile(...barrelFiles);
|
|
559
106
|
}
|
|
560
|
-
await this.fileManager.addIndexes({
|
|
561
|
-
root,
|
|
562
|
-
output,
|
|
563
|
-
meta: { pluginKey: this.plugin.key },
|
|
564
|
-
logger: this.logger
|
|
565
|
-
});
|
|
566
107
|
}
|
|
567
108
|
};
|
|
568
109
|
});
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
};
|
|
110
|
+
|
|
111
|
+
export { pluginFaker, pluginFakerName };
|
|
112
|
+
//# sourceMappingURL=index.js.map
|
|
573
113
|
//# sourceMappingURL=index.js.map
|