@kubb/plugin-faker 3.0.0-alpha.10 → 3.0.0-alpha.12
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 +132 -156
- package/dist/components.cjs.map +1 -1
- package/dist/components.js +63 -95
- package/dist/components.js.map +1 -1
- package/dist/index.cjs +132 -158
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +54 -88
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
- package/src/components/OperationSchema.tsx +0 -1
- package/src/components/Schema.tsx +18 -14
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 _plugints = require('@kubb/plugin-ts');
|
|
5
|
-
var _react = require('@kubb/react');
|
|
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,28 +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
|
-
|
|
268
|
-
|
|
269
|
-
// src/OperationGenerator.tsx
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
var _jsxruntime = require('@kubb/react/jsx-runtime');
|
|
274
|
-
var OperationGenerator = class extends _pluginoas.OperationGenerator {
|
|
257
|
+
var OperationGenerator = class extends pluginOas.OperationGenerator {
|
|
275
258
|
async operation(operation, options) {
|
|
276
259
|
const { oas, pluginManager, plugin, mode } = this.context;
|
|
277
|
-
const root =
|
|
260
|
+
const root = react.createRoot({
|
|
278
261
|
logger: pluginManager.logger
|
|
279
262
|
});
|
|
280
263
|
root.render(
|
|
281
|
-
/* @__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, {}) }) }) })
|
|
282
265
|
);
|
|
283
266
|
return root.files;
|
|
284
267
|
}
|
|
@@ -286,7 +269,7 @@ var OperationGenerator = class extends _pluginoas.OperationGenerator {
|
|
|
286
269
|
|
|
287
270
|
// src/plugin.ts
|
|
288
271
|
var pluginFakerName = "plugin-faker";
|
|
289
|
-
|
|
272
|
+
core.createPlugin((options) => {
|
|
290
273
|
const {
|
|
291
274
|
output = { path: "mocks" },
|
|
292
275
|
seed,
|
|
@@ -301,7 +284,7 @@ var pluginFaker = _core.createPlugin.call(void 0, (options) => {
|
|
|
301
284
|
dateParser,
|
|
302
285
|
regexGenerator = "faker"
|
|
303
286
|
} = options;
|
|
304
|
-
const template =
|
|
287
|
+
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
305
288
|
return {
|
|
306
289
|
name: pluginFakerName,
|
|
307
290
|
output: {
|
|
@@ -319,34 +302,34 @@ var pluginFaker = _core.createPlugin.call(void 0, (options) => {
|
|
|
319
302
|
override,
|
|
320
303
|
regexGenerator
|
|
321
304
|
},
|
|
322
|
-
pre: [
|
|
305
|
+
pre: [pluginOas.pluginOasName, pluginTs.pluginTsName],
|
|
323
306
|
resolvePath(baseName, pathMode, options2) {
|
|
324
|
-
const root =
|
|
325
|
-
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));
|
|
326
309
|
if (mode === "single") {
|
|
327
|
-
return
|
|
310
|
+
return path__default.default.resolve(root, output.path);
|
|
328
311
|
}
|
|
329
|
-
if (
|
|
330
|
-
const tag =
|
|
331
|
-
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);
|
|
332
315
|
}
|
|
333
|
-
return
|
|
316
|
+
return path__default.default.resolve(root, output.path, baseName);
|
|
334
317
|
},
|
|
335
318
|
resolveName(name, type) {
|
|
336
|
-
const resolvedName =
|
|
319
|
+
const resolvedName = transformers.camelCase(name, {
|
|
337
320
|
prefix: type ? "create" : void 0,
|
|
338
321
|
isFile: type === "file"
|
|
339
322
|
});
|
|
340
323
|
if (type) {
|
|
341
|
-
return
|
|
324
|
+
return transformers3?.name?.(resolvedName, type) || resolvedName;
|
|
342
325
|
}
|
|
343
326
|
return resolvedName;
|
|
344
327
|
},
|
|
345
328
|
async buildStart() {
|
|
346
|
-
const [swaggerPlugin] =
|
|
329
|
+
const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
|
|
347
330
|
const oas = await swaggerPlugin.context.getOas();
|
|
348
|
-
const root =
|
|
349
|
-
const mode =
|
|
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));
|
|
350
333
|
const schemaGenerator = new SchemaGenerator2(this.plugin.options, {
|
|
351
334
|
oas,
|
|
352
335
|
pluginManager: this.pluginManager,
|
|
@@ -386,18 +369,15 @@ var pluginFaker = _core.createPlugin.call(void 0, (options) => {
|
|
|
386
369
|
}
|
|
387
370
|
};
|
|
388
371
|
});
|
|
389
|
-
|
|
390
|
-
// src/components/Schema.tsx
|
|
391
|
-
|
|
392
372
|
function Schema(props) {
|
|
393
373
|
const { withData, description } = props;
|
|
394
|
-
const { tree, name } =
|
|
374
|
+
const { tree, name } = hooks.useSchema();
|
|
395
375
|
const {
|
|
396
376
|
pluginManager,
|
|
397
377
|
plugin: {
|
|
398
378
|
options: { dateParser, regexGenerator, mapper, seed }
|
|
399
379
|
}
|
|
400
|
-
} =
|
|
380
|
+
} = react.useApp();
|
|
401
381
|
const resolvedName = pluginManager.resolveName({
|
|
402
382
|
name,
|
|
403
383
|
pluginKey: [pluginFakerName],
|
|
@@ -405,7 +385,7 @@ function Schema(props) {
|
|
|
405
385
|
});
|
|
406
386
|
const typeName = pluginManager.resolveName({
|
|
407
387
|
name,
|
|
408
|
-
pluginKey: [
|
|
388
|
+
pluginKey: [pluginTs.pluginTsName],
|
|
409
389
|
type: "type"
|
|
410
390
|
});
|
|
411
391
|
const fakerText = joinItems(
|
|
@@ -428,34 +408,38 @@ function Schema(props) {
|
|
|
428
408
|
]`;
|
|
429
409
|
}
|
|
430
410
|
const params = fakerDefaultOverride ? `data: NonNullable<Partial<${typeName}>> = ${fakerDefaultOverride}` : `data?: NonNullable<Partial<${typeName}>>`;
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
411
|
+
const containsFaker = !!fakerTextWithOverride.match(/faker/) || !!seed;
|
|
412
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
413
|
+
containsFaker && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["faker"], path: "@faker-js/faker" }),
|
|
414
|
+
/* @__PURE__ */ jsxRuntime.jsxs(react.File.Source, { name: resolvedName, isExportable: true, isIndexable: true, children: [
|
|
415
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
416
|
+
react.Function,
|
|
417
|
+
{
|
|
418
|
+
export: true,
|
|
419
|
+
name: resolvedName,
|
|
420
|
+
JSDoc: { comments: [description ? `@description ${transformers__default.default.jsStringEscape(description)}` : void 0].filter(Boolean) },
|
|
421
|
+
params: withData ? params : "",
|
|
422
|
+
returnType: typeName ? `NonNullable<${typeName}>` : "",
|
|
423
|
+
children: [
|
|
424
|
+
seed ? `faker.seed(${JSON.stringify(seed)})` : "",
|
|
425
|
+
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
|
|
426
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.Function.Return, { children: fakerTextWithOverride })
|
|
427
|
+
]
|
|
428
|
+
}
|
|
429
|
+
),
|
|
430
|
+
/* @__PURE__ */ jsxRuntime.jsx("br", {})
|
|
431
|
+
] })
|
|
448
432
|
] });
|
|
449
433
|
}
|
|
450
434
|
Schema.File = function({}) {
|
|
451
|
-
const { pluginManager } =
|
|
452
|
-
const { tree, schema } =
|
|
435
|
+
const { pluginManager } = react.useApp();
|
|
436
|
+
const { tree, schema } = hooks.useSchema();
|
|
453
437
|
const withData = tree.some(
|
|
454
|
-
(schema2) => schema2.keyword ===
|
|
438
|
+
(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
|
|
455
439
|
);
|
|
456
|
-
return /* @__PURE__ */
|
|
457
|
-
/* @__PURE__ */
|
|
458
|
-
/* @__PURE__ */
|
|
440
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(components.Oas.Schema.File, { output: pluginManager.config.output.path, children: [
|
|
441
|
+
/* @__PURE__ */ jsxRuntime.jsx(Schema.Imports, {}),
|
|
442
|
+
/* @__PURE__ */ jsxRuntime.jsx(Schema, { description: schema?.description, withData })
|
|
459
443
|
] });
|
|
460
444
|
};
|
|
461
445
|
Schema.Imports = () => {
|
|
@@ -464,57 +448,50 @@ Schema.Imports = () => {
|
|
|
464
448
|
plugin: {
|
|
465
449
|
options: { extName, dateParser, regexGenerator }
|
|
466
450
|
}
|
|
467
|
-
} =
|
|
468
|
-
const { path: root } =
|
|
469
|
-
const { name, tree, schema } =
|
|
451
|
+
} = react.useApp();
|
|
452
|
+
const { path: root } = react.useFile();
|
|
453
|
+
const { name, tree, schema } = hooks.useSchema();
|
|
470
454
|
const typeName = pluginManager.resolveName({
|
|
471
455
|
name,
|
|
472
|
-
pluginKey: [
|
|
456
|
+
pluginKey: [pluginTs.pluginTsName],
|
|
473
457
|
type: "type"
|
|
474
458
|
});
|
|
475
459
|
const typeFileName = pluginManager.resolveName({
|
|
476
460
|
name,
|
|
477
|
-
pluginKey: [
|
|
461
|
+
pluginKey: [pluginTs.pluginTsName],
|
|
478
462
|
type: "file"
|
|
479
463
|
});
|
|
480
464
|
const typePath = pluginManager.resolvePath({
|
|
481
465
|
baseName: typeFileName,
|
|
482
|
-
pluginKey: [
|
|
466
|
+
pluginKey: [pluginTs.pluginTsName]
|
|
483
467
|
});
|
|
484
|
-
return /* @__PURE__ */
|
|
485
|
-
/* @__PURE__ */
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
typeName && typePath && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { isTypeOnly: true, root, path: typePath, name: [typeName] })
|
|
468
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
469
|
+
regexGenerator === "randexp" && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: "RandExp", path: "randexp" }),
|
|
470
|
+
dateParser && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { path: dateParser, name: dateParser }),
|
|
471
|
+
typeName && typePath && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { isTypeOnly: true, root, path: typePath, name: [typeName] })
|
|
489
472
|
] });
|
|
490
473
|
};
|
|
491
|
-
|
|
492
|
-
// src/SchemaGenerator.tsx
|
|
493
|
-
|
|
494
|
-
var SchemaGenerator2 = class extends _pluginoas.SchemaGenerator {
|
|
474
|
+
var SchemaGenerator2 = class extends pluginOas.SchemaGenerator {
|
|
495
475
|
async schema(name, schema, options) {
|
|
496
476
|
const { oas, pluginManager, plugin, mode, output } = this.context;
|
|
497
|
-
const root =
|
|
477
|
+
const root = react.createRoot({
|
|
498
478
|
logger: pluginManager.logger
|
|
499
479
|
});
|
|
500
480
|
const tree = this.parse({ schema, name });
|
|
501
481
|
root.render(
|
|
502
|
-
/* @__PURE__ */
|
|
482
|
+
/* @__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, {}) }) }) })
|
|
503
483
|
);
|
|
504
484
|
return root.files;
|
|
505
485
|
}
|
|
506
486
|
};
|
|
507
|
-
|
|
508
|
-
// src/components/OperationSchema.tsx
|
|
509
|
-
|
|
510
487
|
function OperationSchema({ description }) {
|
|
511
|
-
return /* @__PURE__ */
|
|
488
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Schema, { withData: false, description });
|
|
512
489
|
}
|
|
513
490
|
OperationSchema.File = function({}) {
|
|
514
|
-
const { plugin, pluginManager, mode } =
|
|
515
|
-
const oas =
|
|
516
|
-
const { getSchemas, getFile } =
|
|
517
|
-
const operation =
|
|
491
|
+
const { plugin, pluginManager, mode } = react.useApp();
|
|
492
|
+
const oas = hooks.useOas();
|
|
493
|
+
const { getSchemas, getFile } = hooks.useOperationManager();
|
|
494
|
+
const operation = hooks.useOperation();
|
|
518
495
|
const file = getFile(operation);
|
|
519
496
|
const schemas = getSchemas(operation);
|
|
520
497
|
const generator = new SchemaGenerator2(plugin.options, {
|
|
@@ -528,35 +505,34 @@ OperationSchema.File = function({}) {
|
|
|
528
505
|
const mapItem = ({ name, schema, description, ...options }, i) => {
|
|
529
506
|
const typeName = pluginManager.resolveName({
|
|
530
507
|
name,
|
|
531
|
-
pluginKey: [
|
|
508
|
+
pluginKey: [pluginTs.pluginTsName],
|
|
532
509
|
type: "type"
|
|
533
510
|
});
|
|
534
511
|
const typeFileName = pluginManager.resolveName({
|
|
535
512
|
name: options.operationName || name,
|
|
536
|
-
pluginKey: [
|
|
513
|
+
pluginKey: [pluginTs.pluginTsName],
|
|
537
514
|
type: "file"
|
|
538
515
|
});
|
|
539
516
|
const typePath = pluginManager.resolvePath({
|
|
540
517
|
baseName: typeFileName,
|
|
541
|
-
pluginKey: [
|
|
542
|
-
options: { tag:
|
|
518
|
+
pluginKey: [pluginTs.pluginTsName],
|
|
519
|
+
options: { tag: options.operation?.getTags()[0]?.name }
|
|
543
520
|
});
|
|
544
521
|
const tree = generator.parse({ schema, name });
|
|
545
|
-
return /* @__PURE__ */
|
|
546
|
-
typeName && typePath && /* @__PURE__ */
|
|
547
|
-
plugin.options.dateParser && /* @__PURE__ */
|
|
548
|
-
mode === "split" && /* @__PURE__ */
|
|
549
|
-
/* @__PURE__ */
|
|
522
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(components.Oas.Schema, { name, value: schema, tree, children: [
|
|
523
|
+
typeName && typePath && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { isTypeOnly: true, root: file.path, path: typePath, name: [typeName] }),
|
|
524
|
+
plugin.options.dateParser && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { path: plugin.options.dateParser, name: plugin.options.dateParser }),
|
|
525
|
+
mode === "split" && /* @__PURE__ */ jsxRuntime.jsx(components.Oas.Schema.Imports, {}),
|
|
526
|
+
/* @__PURE__ */ jsxRuntime.jsx(OperationSchema, { description })
|
|
550
527
|
] }, i);
|
|
551
528
|
};
|
|
552
|
-
return /* @__PURE__ */
|
|
553
|
-
/* @__PURE__ */
|
|
554
|
-
plugin.options.regexGenerator === "randexp" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: "RandExp", path: "randexp" }),
|
|
529
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
530
|
+
plugin.options.regexGenerator === "randexp" && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: "RandExp", path: "randexp" }),
|
|
555
531
|
items.map(mapItem)
|
|
556
532
|
] });
|
|
557
533
|
};
|
|
558
534
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
535
|
+
exports.OperationSchema = OperationSchema;
|
|
536
|
+
exports.Schema = Schema;
|
|
537
|
+
//# sourceMappingURL=components.cjs.map
|
|
562
538
|
//# sourceMappingURL=components.cjs.map
|