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