@kubb/plugin-faker 3.0.0-alpha.1 → 3.0.0-alpha.11
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/components.cjs +137 -178
- package/dist/components.cjs.map +1 -1
- package/dist/components.js +66 -115
- package/dist/components.js.map +1 -1
- package/dist/index.cjs +137 -180
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +55 -106
- package/dist/index.js.map +1 -1
- package/package.json +13 -13
- package/src/OperationGenerator.tsx +1 -0
- package/src/components/OperationSchema.tsx +11 -13
- package/src/components/Schema.tsx +5 -7
- package/src/plugin.ts +16 -33
package/dist/index.cjs
CHANGED
|
@@ -1,39 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
3
|
-
var _core = require('@kubb/core');
|
|
4
|
-
var _transformers = require('@kubb/core/transformers'); var _transformers2 = _interopRequireDefault(_transformers);
|
|
5
|
-
var _utils = require('@kubb/core/utils');
|
|
6
|
-
var _pluginoas = require('@kubb/plugin-oas');
|
|
7
|
-
var _utils3 = require('@kubb/plugin-oas/utils');
|
|
8
|
-
var _plugints = require('@kubb/plugin-ts');
|
|
1
|
+
'use strict';
|
|
9
2
|
|
|
10
|
-
|
|
3
|
+
var path = require('path');
|
|
4
|
+
var core = require('@kubb/core');
|
|
5
|
+
var transformers = require('@kubb/core/transformers');
|
|
6
|
+
var utils = require('@kubb/core/utils');
|
|
7
|
+
var pluginOas = require('@kubb/plugin-oas');
|
|
8
|
+
var pluginTs = require('@kubb/plugin-ts');
|
|
9
|
+
var components = require('@kubb/plugin-oas/components');
|
|
10
|
+
var react = require('@kubb/react');
|
|
11
|
+
var hooks = require('@kubb/plugin-oas/hooks');
|
|
12
|
+
var jsxRuntime = require('@kubb/react/jsx-runtime');
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
var _react = require('@kubb/react');
|
|
14
|
-
|
|
15
|
-
// src/components/OperationSchema.tsx
|
|
16
|
-
|
|
17
|
-
var _hooks = require('@kubb/plugin-oas/hooks');
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// src/SchemaGenerator.tsx
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// src/components/Schema.tsx
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// src/parser/index.ts
|
|
14
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
35
15
|
|
|
16
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
17
|
+
var transformers__default = /*#__PURE__*/_interopDefault(transformers);
|
|
36
18
|
|
|
19
|
+
// src/plugin.ts
|
|
37
20
|
var fakerKeywordMapper = {
|
|
38
21
|
any: () => "undefined",
|
|
39
22
|
unknown: () => "unknown",
|
|
@@ -119,9 +102,9 @@ var fakerKeywordMapper = {
|
|
|
119
102
|
ref: () => "ref",
|
|
120
103
|
matches: (value = "", regexGenerator = "faker") => {
|
|
121
104
|
if (regexGenerator === "randexp") {
|
|
122
|
-
return `${
|
|
105
|
+
return `${transformers__default.default.toRegExpString(value, "RandExp")}.gen()`;
|
|
123
106
|
}
|
|
124
|
-
return `faker.helpers.fromRegExp(${
|
|
107
|
+
return `faker.helpers.fromRegExp(${transformers__default.default.toRegExpString(value)})`;
|
|
125
108
|
},
|
|
126
109
|
email: () => "faker.internet.email()",
|
|
127
110
|
firstName: () => "faker.person.firstName()",
|
|
@@ -131,7 +114,7 @@ var fakerKeywordMapper = {
|
|
|
131
114
|
blob: () => "faker.image.imageUrl() as unknown as Blob",
|
|
132
115
|
default: void 0,
|
|
133
116
|
describe: void 0,
|
|
134
|
-
const: (value) =>
|
|
117
|
+
const: (value) => value ?? "",
|
|
135
118
|
max: void 0,
|
|
136
119
|
min: void 0,
|
|
137
120
|
nullable: void 0,
|
|
@@ -166,27 +149,27 @@ function parse(parent, current, options) {
|
|
|
166
149
|
if (!value) {
|
|
167
150
|
return void 0;
|
|
168
151
|
}
|
|
169
|
-
if (
|
|
152
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.union)) {
|
|
170
153
|
return fakerKeywordMapper.union(current.args.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean));
|
|
171
154
|
}
|
|
172
|
-
if (
|
|
155
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.and)) {
|
|
173
156
|
return fakerKeywordMapper.and(current.args.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean));
|
|
174
157
|
}
|
|
175
|
-
if (
|
|
158
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.array)) {
|
|
176
159
|
return fakerKeywordMapper.array(current.args.items.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean));
|
|
177
160
|
}
|
|
178
|
-
if (
|
|
161
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.enum)) {
|
|
179
162
|
return fakerKeywordMapper.enum(
|
|
180
163
|
current.args.items.map((schema) => {
|
|
181
164
|
if (schema.format === "number") {
|
|
182
165
|
return schema.name;
|
|
183
166
|
}
|
|
184
|
-
return
|
|
167
|
+
return transformers__default.default.stringify(schema.name);
|
|
185
168
|
})
|
|
186
169
|
);
|
|
187
170
|
}
|
|
188
|
-
if (
|
|
189
|
-
if (!
|
|
171
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.ref)) {
|
|
172
|
+
if (!current.args?.name) {
|
|
190
173
|
throw new Error(`Name not defined for keyword ${current.keyword}`);
|
|
191
174
|
}
|
|
192
175
|
if (options.withData) {
|
|
@@ -194,15 +177,15 @@ function parse(parent, current, options) {
|
|
|
194
177
|
}
|
|
195
178
|
return `${current.args.name}()`;
|
|
196
179
|
}
|
|
197
|
-
if (
|
|
198
|
-
const argsObject = Object.entries(
|
|
180
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.object)) {
|
|
181
|
+
const argsObject = Object.entries(current.args?.properties || {}).filter((item) => {
|
|
199
182
|
const schema = item[1];
|
|
200
183
|
return schema && typeof schema.map === "function";
|
|
201
184
|
}).map(([name, schemas]) => {
|
|
202
|
-
const nameSchema = schemas.find((schema) => schema.keyword ===
|
|
203
|
-
const mappedName =
|
|
204
|
-
if (
|
|
205
|
-
return `"${name}": ${
|
|
185
|
+
const nameSchema = schemas.find((schema) => schema.keyword === pluginOas.schemaKeywords.name);
|
|
186
|
+
const mappedName = nameSchema?.args || name;
|
|
187
|
+
if (options.mapper?.[mappedName]) {
|
|
188
|
+
return `"${name}": ${options.mapper?.[mappedName]}`;
|
|
206
189
|
}
|
|
207
190
|
return `"${name}": ${joinItems(
|
|
208
191
|
schemas.sort(schemaKeywordsorter).map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean)
|
|
@@ -210,55 +193,55 @@ function parse(parent, current, options) {
|
|
|
210
193
|
}).join(",");
|
|
211
194
|
return `{${argsObject}}`;
|
|
212
195
|
}
|
|
213
|
-
if (
|
|
196
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.tuple)) {
|
|
214
197
|
if (Array.isArray(current.args.items)) {
|
|
215
198
|
return fakerKeywordMapper.tuple(current.args.items.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean));
|
|
216
199
|
}
|
|
217
200
|
return parse(current, current.args.items, { ...options, withData: false });
|
|
218
201
|
}
|
|
219
|
-
if (
|
|
202
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.const)) {
|
|
220
203
|
if (current.args.format === "number" && current.args.name !== void 0) {
|
|
221
|
-
return fakerKeywordMapper.const(
|
|
204
|
+
return fakerKeywordMapper.const(current.args.name?.toString());
|
|
222
205
|
}
|
|
223
|
-
return fakerKeywordMapper.const(
|
|
206
|
+
return fakerKeywordMapper.const(transformers__default.default.stringify(current.args.value));
|
|
224
207
|
}
|
|
225
|
-
if (
|
|
208
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.matches) && current.args) {
|
|
226
209
|
return fakerKeywordMapper.matches(current.args, options.regexGenerator);
|
|
227
210
|
}
|
|
228
|
-
if (
|
|
211
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.null) || pluginOas.isKeyword(current, pluginOas.schemaKeywords.undefined) || pluginOas.isKeyword(current, pluginOas.schemaKeywords.any)) {
|
|
229
212
|
return value() || "";
|
|
230
213
|
}
|
|
231
|
-
if (
|
|
214
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.string)) {
|
|
232
215
|
if (parent) {
|
|
233
|
-
const minSchema =
|
|
234
|
-
const maxSchema =
|
|
235
|
-
return fakerKeywordMapper.string(
|
|
216
|
+
const minSchema = pluginOas.SchemaGenerator.find([parent], pluginOas.schemaKeywords.min);
|
|
217
|
+
const maxSchema = pluginOas.SchemaGenerator.find([parent], pluginOas.schemaKeywords.max);
|
|
218
|
+
return fakerKeywordMapper.string(minSchema?.args, maxSchema?.args);
|
|
236
219
|
}
|
|
237
220
|
return fakerKeywordMapper.string();
|
|
238
221
|
}
|
|
239
|
-
if (
|
|
222
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.number)) {
|
|
240
223
|
if (parent) {
|
|
241
|
-
const minSchema =
|
|
242
|
-
const maxSchema =
|
|
243
|
-
return fakerKeywordMapper.number(
|
|
224
|
+
const minSchema = pluginOas.SchemaGenerator.find([parent], pluginOas.schemaKeywords.min);
|
|
225
|
+
const maxSchema = pluginOas.SchemaGenerator.find([parent], pluginOas.schemaKeywords.max);
|
|
226
|
+
return fakerKeywordMapper.number(minSchema?.args, maxSchema?.args);
|
|
244
227
|
}
|
|
245
228
|
return fakerKeywordMapper.number();
|
|
246
229
|
}
|
|
247
|
-
if (
|
|
230
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.integer)) {
|
|
248
231
|
if (parent) {
|
|
249
|
-
const minSchema =
|
|
250
|
-
const maxSchema =
|
|
251
|
-
return fakerKeywordMapper.integer(
|
|
232
|
+
const minSchema = pluginOas.SchemaGenerator.find([parent], pluginOas.schemaKeywords.min);
|
|
233
|
+
const maxSchema = pluginOas.SchemaGenerator.find([parent], pluginOas.schemaKeywords.max);
|
|
234
|
+
return fakerKeywordMapper.integer(minSchema?.args, maxSchema?.args);
|
|
252
235
|
}
|
|
253
236
|
return fakerKeywordMapper.integer();
|
|
254
237
|
}
|
|
255
|
-
if (
|
|
238
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.datetime)) {
|
|
256
239
|
return fakerKeywordMapper.datetime();
|
|
257
240
|
}
|
|
258
|
-
if (
|
|
241
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.date)) {
|
|
259
242
|
return fakerKeywordMapper.date(current.args.type, options.dateParser);
|
|
260
243
|
}
|
|
261
|
-
if (
|
|
244
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.time)) {
|
|
262
245
|
return fakerKeywordMapper.time(current.args.type, options.dateParser);
|
|
263
246
|
}
|
|
264
247
|
if (current.keyword in fakerKeywordMapper && "args" in current) {
|
|
@@ -271,18 +254,15 @@ function parse(parent, current, options) {
|
|
|
271
254
|
}
|
|
272
255
|
return void 0;
|
|
273
256
|
}
|
|
274
|
-
|
|
275
|
-
// src/components/Schema.tsx
|
|
276
|
-
var _jsxruntime = require('@kubb/react/jsx-runtime');
|
|
277
257
|
function Schema(props) {
|
|
278
258
|
const { withData, description } = props;
|
|
279
|
-
const { tree, name } =
|
|
259
|
+
const { tree, name } = hooks.useSchema();
|
|
280
260
|
const {
|
|
281
261
|
pluginManager,
|
|
282
262
|
plugin: {
|
|
283
263
|
options: { dateParser, regexGenerator, mapper, seed }
|
|
284
264
|
}
|
|
285
|
-
} =
|
|
265
|
+
} = react.useApp();
|
|
286
266
|
const resolvedName = pluginManager.resolveName({
|
|
287
267
|
name,
|
|
288
268
|
pluginKey: [pluginFakerName],
|
|
@@ -290,7 +270,7 @@ function Schema(props) {
|
|
|
290
270
|
});
|
|
291
271
|
const typeName = pluginManager.resolveName({
|
|
292
272
|
name,
|
|
293
|
-
pluginKey: [
|
|
273
|
+
pluginKey: [pluginTs.pluginTsName],
|
|
294
274
|
type: "type"
|
|
295
275
|
});
|
|
296
276
|
const fakerText = joinItems(
|
|
@@ -313,34 +293,34 @@ function Schema(props) {
|
|
|
313
293
|
]`;
|
|
314
294
|
}
|
|
315
295
|
const params = fakerDefaultOverride ? `data: NonNullable<Partial<${typeName}>> = ${fakerDefaultOverride}` : `data?: NonNullable<Partial<${typeName}>>`;
|
|
316
|
-
return /* @__PURE__ */
|
|
317
|
-
/* @__PURE__ */
|
|
318
|
-
|
|
296
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File.Source, { name: resolvedName, isExportable: true, isIndexable: true, children: [
|
|
297
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
298
|
+
react.Function,
|
|
319
299
|
{
|
|
320
300
|
export: true,
|
|
321
301
|
name: resolvedName,
|
|
322
|
-
JSDoc: { comments: [description ? `@description ${
|
|
302
|
+
JSDoc: { comments: [description ? `@description ${transformers__default.default.jsStringEscape(description)}` : void 0].filter(Boolean) },
|
|
323
303
|
params: withData ? params : "",
|
|
324
304
|
returnType: typeName ? `NonNullable<${typeName}>` : "",
|
|
325
305
|
children: [
|
|
326
306
|
seed ? `faker.seed(${JSON.stringify(seed)})` : "",
|
|
327
|
-
/* @__PURE__ */
|
|
328
|
-
/* @__PURE__ */
|
|
307
|
+
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
|
|
308
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.Function.Return, { children: fakerTextWithOverride })
|
|
329
309
|
]
|
|
330
310
|
}
|
|
331
311
|
),
|
|
332
|
-
/* @__PURE__ */
|
|
312
|
+
/* @__PURE__ */ jsxRuntime.jsx("br", {})
|
|
333
313
|
] });
|
|
334
314
|
}
|
|
335
315
|
Schema.File = function({}) {
|
|
336
|
-
const { pluginManager } =
|
|
337
|
-
const { tree, schema } =
|
|
316
|
+
const { pluginManager } = react.useApp();
|
|
317
|
+
const { tree, schema } = hooks.useSchema();
|
|
338
318
|
const withData = tree.some(
|
|
339
|
-
(schema2) => schema2.keyword ===
|
|
319
|
+
(schema2) => schema2.keyword === pluginOas.schemaKeywords.array || schema2.keyword === pluginOas.schemaKeywords.and || schema2.keyword === pluginOas.schemaKeywords.object || schema2.keyword === pluginOas.schemaKeywords.union || schema2.keyword === pluginOas.schemaKeywords.tuple
|
|
340
320
|
);
|
|
341
|
-
return /* @__PURE__ */
|
|
342
|
-
/* @__PURE__ */
|
|
343
|
-
/* @__PURE__ */
|
|
321
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(components.Oas.Schema.File, { output: pluginManager.config.output.path, children: [
|
|
322
|
+
/* @__PURE__ */ jsxRuntime.jsx(Schema.Imports, {}),
|
|
323
|
+
/* @__PURE__ */ jsxRuntime.jsx(Schema, { description: schema?.description, withData })
|
|
344
324
|
] });
|
|
345
325
|
};
|
|
346
326
|
Schema.Imports = () => {
|
|
@@ -349,57 +329,51 @@ Schema.Imports = () => {
|
|
|
349
329
|
plugin: {
|
|
350
330
|
options: { extName, dateParser, regexGenerator }
|
|
351
331
|
}
|
|
352
|
-
} =
|
|
353
|
-
const { path: root } =
|
|
354
|
-
const { name, tree, schema } =
|
|
332
|
+
} = react.useApp();
|
|
333
|
+
const { path: root } = react.useFile();
|
|
334
|
+
const { name, tree, schema } = hooks.useSchema();
|
|
355
335
|
const typeName = pluginManager.resolveName({
|
|
356
336
|
name,
|
|
357
|
-
pluginKey: [
|
|
337
|
+
pluginKey: [pluginTs.pluginTsName],
|
|
358
338
|
type: "type"
|
|
359
339
|
});
|
|
360
340
|
const typeFileName = pluginManager.resolveName({
|
|
361
341
|
name,
|
|
362
|
-
pluginKey: [
|
|
342
|
+
pluginKey: [pluginTs.pluginTsName],
|
|
363
343
|
type: "file"
|
|
364
344
|
});
|
|
365
345
|
const typePath = pluginManager.resolvePath({
|
|
366
346
|
baseName: typeFileName,
|
|
367
|
-
pluginKey: [
|
|
347
|
+
pluginKey: [pluginTs.pluginTsName]
|
|
368
348
|
});
|
|
369
|
-
return /* @__PURE__ */
|
|
370
|
-
/* @__PURE__ */
|
|
371
|
-
regexGenerator === "randexp" && /* @__PURE__ */
|
|
372
|
-
dateParser && /* @__PURE__ */
|
|
373
|
-
typeName && typePath && /* @__PURE__ */
|
|
349
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
350
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["faker"], path: "@faker-js/faker" }),
|
|
351
|
+
regexGenerator === "randexp" && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: "RandExp", path: "randexp" }),
|
|
352
|
+
dateParser && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { path: dateParser, name: dateParser }),
|
|
353
|
+
typeName && typePath && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { isTypeOnly: true, root, path: typePath, name: [typeName] })
|
|
374
354
|
] });
|
|
375
355
|
};
|
|
376
|
-
|
|
377
|
-
// src/SchemaGenerator.tsx
|
|
378
|
-
|
|
379
|
-
var SchemaGenerator2 = class extends _pluginoas.SchemaGenerator {
|
|
356
|
+
var SchemaGenerator2 = class extends pluginOas.SchemaGenerator {
|
|
380
357
|
async schema(name, schema, options) {
|
|
381
358
|
const { oas, pluginManager, plugin, mode, output } = this.context;
|
|
382
|
-
const root =
|
|
359
|
+
const root = react.createRoot({
|
|
383
360
|
logger: pluginManager.logger
|
|
384
361
|
});
|
|
385
362
|
const tree = this.parse({ schema, name });
|
|
386
363
|
root.render(
|
|
387
|
-
/* @__PURE__ */
|
|
364
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsxRuntime.jsx(components.Oas, { oas, children: /* @__PURE__ */ jsxRuntime.jsx(components.Oas.Schema, { name, value: schema, tree, children: /* @__PURE__ */ jsxRuntime.jsx(Schema.File, {}) }) }) })
|
|
388
365
|
);
|
|
389
366
|
return root.files;
|
|
390
367
|
}
|
|
391
368
|
};
|
|
392
|
-
|
|
393
|
-
// src/components/OperationSchema.tsx
|
|
394
|
-
|
|
395
369
|
function OperationSchema({ description }) {
|
|
396
|
-
return /* @__PURE__ */
|
|
370
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Schema, { withData: false, description });
|
|
397
371
|
}
|
|
398
372
|
OperationSchema.File = function({}) {
|
|
399
|
-
const { plugin, pluginManager, mode } =
|
|
400
|
-
const oas =
|
|
401
|
-
const { getSchemas, getFile } =
|
|
402
|
-
const operation =
|
|
373
|
+
const { plugin, pluginManager, mode } = react.useApp();
|
|
374
|
+
const oas = hooks.useOas();
|
|
375
|
+
const { getSchemas, getFile } = hooks.useOperationManager();
|
|
376
|
+
const operation = hooks.useOperation();
|
|
403
377
|
const file = getFile(operation);
|
|
404
378
|
const schemas = getSchemas(operation);
|
|
405
379
|
const generator = new SchemaGenerator2(plugin.options, {
|
|
@@ -413,44 +387,41 @@ OperationSchema.File = function({}) {
|
|
|
413
387
|
const mapItem = ({ name, schema, description, ...options }, i) => {
|
|
414
388
|
const typeName = pluginManager.resolveName({
|
|
415
389
|
name,
|
|
416
|
-
pluginKey: [
|
|
390
|
+
pluginKey: [pluginTs.pluginTsName],
|
|
417
391
|
type: "type"
|
|
418
392
|
});
|
|
419
393
|
const typeFileName = pluginManager.resolveName({
|
|
420
394
|
name: options.operationName || name,
|
|
421
|
-
pluginKey: [
|
|
395
|
+
pluginKey: [pluginTs.pluginTsName],
|
|
422
396
|
type: "file"
|
|
423
397
|
});
|
|
424
398
|
const typePath = pluginManager.resolvePath({
|
|
425
399
|
baseName: typeFileName,
|
|
426
|
-
pluginKey: [
|
|
427
|
-
options: { tag:
|
|
400
|
+
pluginKey: [pluginTs.pluginTsName],
|
|
401
|
+
options: { tag: options.operation?.getTags()[0]?.name }
|
|
428
402
|
});
|
|
429
403
|
const tree = generator.parse({ schema, name });
|
|
430
|
-
return /* @__PURE__ */
|
|
431
|
-
typeName && typePath && /* @__PURE__ */
|
|
432
|
-
plugin.options.dateParser && /* @__PURE__ */
|
|
433
|
-
mode === "split" && /* @__PURE__ */
|
|
434
|
-
/* @__PURE__ */
|
|
404
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(components.Oas.Schema, { name, value: schema, tree, children: [
|
|
405
|
+
typeName && typePath && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { isTypeOnly: true, root: file.path, path: typePath, name: [typeName] }),
|
|
406
|
+
plugin.options.dateParser && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { path: plugin.options.dateParser, name: plugin.options.dateParser }),
|
|
407
|
+
mode === "split" && /* @__PURE__ */ jsxRuntime.jsx(components.Oas.Schema.Imports, {}),
|
|
408
|
+
/* @__PURE__ */ jsxRuntime.jsx(OperationSchema, { description })
|
|
435
409
|
] }, i);
|
|
436
410
|
};
|
|
437
|
-
return /* @__PURE__ */
|
|
438
|
-
/* @__PURE__ */
|
|
439
|
-
plugin.options.regexGenerator === "randexp" && /* @__PURE__ */
|
|
411
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
412
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["faker"], path: "@faker-js/faker" }),
|
|
413
|
+
plugin.options.regexGenerator === "randexp" && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: "RandExp", path: "randexp" }),
|
|
440
414
|
items.map(mapItem)
|
|
441
|
-
] })
|
|
415
|
+
] });
|
|
442
416
|
};
|
|
443
|
-
|
|
444
|
-
// src/OperationGenerator.tsx
|
|
445
|
-
|
|
446
|
-
var OperationGenerator = class extends _pluginoas.OperationGenerator {
|
|
417
|
+
var OperationGenerator = class extends pluginOas.OperationGenerator {
|
|
447
418
|
async operation(operation, options) {
|
|
448
419
|
const { oas, pluginManager, plugin, mode } = this.context;
|
|
449
|
-
const root =
|
|
420
|
+
const root = react.createRoot({
|
|
450
421
|
logger: pluginManager.logger
|
|
451
422
|
});
|
|
452
423
|
root.render(
|
|
453
|
-
/* @__PURE__ */
|
|
424
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsxRuntime.jsx(components.Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsxRuntime.jsx(components.Oas.Operation, { operation, children: /* @__PURE__ */ jsxRuntime.jsx(OperationSchema.File, {}) }) }) })
|
|
454
425
|
);
|
|
455
426
|
return root.files;
|
|
456
427
|
}
|
|
@@ -458,7 +429,7 @@ var OperationGenerator = class extends _pluginoas.OperationGenerator {
|
|
|
458
429
|
|
|
459
430
|
// src/plugin.ts
|
|
460
431
|
var pluginFakerName = "plugin-faker";
|
|
461
|
-
var pluginFaker =
|
|
432
|
+
var pluginFaker = core.createPlugin((options) => {
|
|
462
433
|
const {
|
|
463
434
|
output = { path: "mocks" },
|
|
464
435
|
seed,
|
|
@@ -473,9 +444,13 @@ var pluginFaker = _core.createPlugin.call(void 0, (options) => {
|
|
|
473
444
|
dateParser,
|
|
474
445
|
regexGenerator = "faker"
|
|
475
446
|
} = options;
|
|
476
|
-
const template =
|
|
447
|
+
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
477
448
|
return {
|
|
478
449
|
name: pluginFakerName,
|
|
450
|
+
output: {
|
|
451
|
+
exportType: "barrelNamed",
|
|
452
|
+
...output
|
|
453
|
+
},
|
|
479
454
|
options: {
|
|
480
455
|
extName: output.extName,
|
|
481
456
|
transformers: transformers3,
|
|
@@ -487,45 +462,39 @@ var pluginFaker = _core.createPlugin.call(void 0, (options) => {
|
|
|
487
462
|
override,
|
|
488
463
|
regexGenerator
|
|
489
464
|
},
|
|
490
|
-
pre: [
|
|
465
|
+
pre: [pluginOas.pluginOasName, pluginTs.pluginTsName],
|
|
491
466
|
resolvePath(baseName, pathMode, options2) {
|
|
492
|
-
const root =
|
|
493
|
-
const mode =
|
|
467
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
468
|
+
const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
494
469
|
if (mode === "single") {
|
|
495
|
-
return
|
|
470
|
+
return path__default.default.resolve(root, output.path);
|
|
496
471
|
}
|
|
497
|
-
if (
|
|
498
|
-
const tag =
|
|
499
|
-
return
|
|
472
|
+
if (options2?.tag && group?.type === "tag") {
|
|
473
|
+
const tag = transformers.camelCase(options2.tag);
|
|
474
|
+
return path__default.default.resolve(root, utils.renderTemplate(template, { tag }), baseName);
|
|
500
475
|
}
|
|
501
|
-
return
|
|
476
|
+
return path__default.default.resolve(root, output.path, baseName);
|
|
502
477
|
},
|
|
503
478
|
resolveName(name, type) {
|
|
504
|
-
const resolvedName =
|
|
479
|
+
const resolvedName = transformers.camelCase(name, {
|
|
505
480
|
prefix: type ? "create" : void 0,
|
|
506
481
|
isFile: type === "file"
|
|
507
482
|
});
|
|
508
483
|
if (type) {
|
|
509
|
-
return
|
|
484
|
+
return transformers3?.name?.(resolvedName, type) || resolvedName;
|
|
510
485
|
}
|
|
511
486
|
return resolvedName;
|
|
512
487
|
},
|
|
513
|
-
async writeFile(path2, source) {
|
|
514
|
-
if (!path2.endsWith(".ts") || !source) {
|
|
515
|
-
return;
|
|
516
|
-
}
|
|
517
|
-
return this.fileManager.write(path2, source, { sanity: false });
|
|
518
|
-
},
|
|
519
488
|
async buildStart() {
|
|
520
|
-
const [swaggerPlugin] =
|
|
521
|
-
const oas = await swaggerPlugin.
|
|
522
|
-
const root =
|
|
523
|
-
const mode =
|
|
489
|
+
const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
|
|
490
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
491
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
492
|
+
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
524
493
|
const schemaGenerator = new SchemaGenerator2(this.plugin.options, {
|
|
525
494
|
oas,
|
|
526
495
|
pluginManager: this.pluginManager,
|
|
527
496
|
plugin: this.plugin,
|
|
528
|
-
contentType: swaggerPlugin.
|
|
497
|
+
contentType: swaggerPlugin.context.contentType,
|
|
529
498
|
include: void 0,
|
|
530
499
|
override,
|
|
531
500
|
mode,
|
|
@@ -537,7 +506,7 @@ var pluginFaker = _core.createPlugin.call(void 0, (options) => {
|
|
|
537
506
|
oas,
|
|
538
507
|
pluginManager: this.pluginManager,
|
|
539
508
|
plugin: this.plugin,
|
|
540
|
-
contentType: swaggerPlugin.
|
|
509
|
+
contentType: swaggerPlugin.context.contentType,
|
|
541
510
|
exclude,
|
|
542
511
|
include,
|
|
543
512
|
override,
|
|
@@ -545,35 +514,23 @@ var pluginFaker = _core.createPlugin.call(void 0, (options) => {
|
|
|
545
514
|
});
|
|
546
515
|
const operationFiles = await operationGenerator.build();
|
|
547
516
|
await this.addFile(...operationFiles);
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
if (this.config.output.write === false) {
|
|
551
|
-
return;
|
|
552
|
-
}
|
|
553
|
-
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
|
554
|
-
if (_optionalChain([group, 'optionalAccess', _31 => _31.type]) === "tag") {
|
|
555
|
-
const rootFiles = await _utils3.getGroupedByTagFiles.call(void 0, {
|
|
556
|
-
logger: this.logger,
|
|
557
|
-
files: this.fileManager.files,
|
|
558
|
-
plugin: this.plugin,
|
|
559
|
-
template,
|
|
560
|
-
exportAs: group.exportAs || "{{tag}}Mocks",
|
|
517
|
+
if (this.config.output.exportType) {
|
|
518
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
561
519
|
root,
|
|
562
|
-
output
|
|
520
|
+
output,
|
|
521
|
+
files: this.fileManager.files,
|
|
522
|
+
meta: {
|
|
523
|
+
pluginKey: this.plugin.key
|
|
524
|
+
},
|
|
525
|
+
logger: this.logger
|
|
563
526
|
});
|
|
564
|
-
await this.addFile(...
|
|
527
|
+
await this.addFile(...barrelFiles);
|
|
565
528
|
}
|
|
566
|
-
await this.fileManager.addIndexes({
|
|
567
|
-
root,
|
|
568
|
-
output,
|
|
569
|
-
meta: { pluginKey: this.plugin.key },
|
|
570
|
-
logger: this.logger
|
|
571
|
-
});
|
|
572
529
|
}
|
|
573
530
|
};
|
|
574
531
|
});
|
|
575
532
|
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
533
|
+
exports.pluginFaker = pluginFaker;
|
|
534
|
+
exports.pluginFakerName = pluginFakerName;
|
|
535
|
+
//# sourceMappingURL=index.cjs.map
|
|
579
536
|
//# sourceMappingURL=index.cjs.map
|