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