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