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