@kubb/plugin-faker 3.0.0-alpha.0 → 3.0.0-alpha.10
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 +26 -41
- package/dist/components.cjs.map +1 -1
- package/dist/components.js +27 -42
- package/dist/components.js.map +1 -1
- package/dist/index.cjs +24 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -5
- package/dist/index.d.ts +0 -5
- package/dist/index.js +27 -42
- 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/src/types.ts +0 -6
package/dist/components.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/components/OperationSchema.tsx
|
|
2
2
|
var _components = require('@kubb/plugin-oas/components');
|
|
3
3
|
var _hooks = require('@kubb/plugin-oas/hooks');
|
|
4
|
-
var _react = require('@kubb/react');
|
|
5
4
|
var _plugints = require('@kubb/plugin-ts');
|
|
5
|
+
var _react = require('@kubb/react');
|
|
6
6
|
|
|
7
7
|
// src/SchemaGenerator.tsx
|
|
8
8
|
var _pluginoas = require('@kubb/plugin-oas');
|
|
@@ -264,7 +264,6 @@ var _core = require('@kubb/core');
|
|
|
264
264
|
|
|
265
265
|
var _utils = require('@kubb/core/utils');
|
|
266
266
|
|
|
267
|
-
var _utils3 = require('@kubb/plugin-oas/utils');
|
|
268
267
|
|
|
269
268
|
|
|
270
269
|
// src/OperationGenerator.tsx
|
|
@@ -305,6 +304,10 @@ var pluginFaker = _core.createPlugin.call(void 0, (options) => {
|
|
|
305
304
|
const template = _optionalChain([group, 'optionalAccess', _20 => _20.output]) ? group.output : `${output.path}/{{tag}}Controller`;
|
|
306
305
|
return {
|
|
307
306
|
name: pluginFakerName,
|
|
307
|
+
output: {
|
|
308
|
+
exportType: "barrelNamed",
|
|
309
|
+
...output
|
|
310
|
+
},
|
|
308
311
|
options: {
|
|
309
312
|
extName: output.extName,
|
|
310
313
|
transformers: transformers3,
|
|
@@ -339,22 +342,16 @@ var pluginFaker = _core.createPlugin.call(void 0, (options) => {
|
|
|
339
342
|
}
|
|
340
343
|
return resolvedName;
|
|
341
344
|
},
|
|
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
345
|
async buildStart() {
|
|
349
346
|
const [swaggerPlugin] = _core.PluginManager.getDependedPlugins(this.plugins, [_pluginoas.pluginOasName]);
|
|
350
|
-
const oas = await swaggerPlugin.
|
|
347
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
351
348
|
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
|
352
349
|
const mode = _core.FileManager.getMode(_path2.default.resolve(root, output.path));
|
|
353
350
|
const schemaGenerator = new SchemaGenerator2(this.plugin.options, {
|
|
354
351
|
oas,
|
|
355
352
|
pluginManager: this.pluginManager,
|
|
356
353
|
plugin: this.plugin,
|
|
357
|
-
contentType: swaggerPlugin.
|
|
354
|
+
contentType: swaggerPlugin.context.contentType,
|
|
358
355
|
include: void 0,
|
|
359
356
|
override,
|
|
360
357
|
mode,
|
|
@@ -366,7 +363,7 @@ var pluginFaker = _core.createPlugin.call(void 0, (options) => {
|
|
|
366
363
|
oas,
|
|
367
364
|
pluginManager: this.pluginManager,
|
|
368
365
|
plugin: this.plugin,
|
|
369
|
-
contentType: swaggerPlugin.
|
|
366
|
+
contentType: swaggerPlugin.context.contentType,
|
|
370
367
|
exclude,
|
|
371
368
|
include,
|
|
372
369
|
override,
|
|
@@ -374,30 +371,18 @@ var pluginFaker = _core.createPlugin.call(void 0, (options) => {
|
|
|
374
371
|
});
|
|
375
372
|
const operationFiles = await operationGenerator.build();
|
|
376
373
|
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",
|
|
374
|
+
if (this.config.output.exportType) {
|
|
375
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
390
376
|
root,
|
|
391
|
-
output
|
|
377
|
+
output,
|
|
378
|
+
files: this.fileManager.files,
|
|
379
|
+
meta: {
|
|
380
|
+
pluginKey: this.plugin.key
|
|
381
|
+
},
|
|
382
|
+
logger: this.logger
|
|
392
383
|
});
|
|
393
|
-
await this.addFile(...
|
|
384
|
+
await this.addFile(...barrelFiles);
|
|
394
385
|
}
|
|
395
|
-
await this.fileManager.addIndexes({
|
|
396
|
-
root,
|
|
397
|
-
output,
|
|
398
|
-
meta: { pluginKey: this.plugin.key },
|
|
399
|
-
logger: this.logger
|
|
400
|
-
});
|
|
401
386
|
}
|
|
402
387
|
};
|
|
403
388
|
});
|
|
@@ -443,7 +428,7 @@ function Schema(props) {
|
|
|
443
428
|
]`;
|
|
444
429
|
}
|
|
445
430
|
const params = fakerDefaultOverride ? `data: NonNullable<Partial<${typeName}>> = ${fakerDefaultOverride}` : `data?: NonNullable<Partial<${typeName}>>`;
|
|
446
|
-
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
431
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File.Source, { name: resolvedName, isExportable: true, isIndexable: true, children: [
|
|
447
432
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
448
433
|
_react.Function,
|
|
449
434
|
{
|
|
@@ -470,7 +455,7 @@ Schema.File = function({}) {
|
|
|
470
455
|
);
|
|
471
456
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _components.Oas.Schema.File, { output: pluginManager.config.output.path, children: [
|
|
472
457
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema.Imports, {}),
|
|
473
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
458
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema, { description: _optionalChain([schema, 'optionalAccess', _25 => _25.description]), withData })
|
|
474
459
|
] });
|
|
475
460
|
};
|
|
476
461
|
Schema.Imports = () => {
|
|
@@ -500,7 +485,7 @@ Schema.Imports = () => {
|
|
|
500
485
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["faker"], path: "@faker-js/faker" }),
|
|
501
486
|
regexGenerator === "randexp" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: "RandExp", path: "randexp" }),
|
|
502
487
|
dateParser && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { path: dateParser, name: dateParser }),
|
|
503
|
-
typeName && typePath && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, {
|
|
488
|
+
typeName && typePath && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { isTypeOnly: true, root, path: typePath, name: [typeName] })
|
|
504
489
|
] });
|
|
505
490
|
};
|
|
506
491
|
|
|
@@ -554,21 +539,21 @@ OperationSchema.File = function({}) {
|
|
|
554
539
|
const typePath = pluginManager.resolvePath({
|
|
555
540
|
baseName: typeFileName,
|
|
556
541
|
pluginKey: [_plugints.pluginTsName],
|
|
557
|
-
options: { tag: _optionalChain([options, 'access',
|
|
542
|
+
options: { tag: _optionalChain([options, 'access', _26 => _26.operation, 'optionalAccess', _27 => _27.getTags, 'call', _28 => _28(), 'access', _29 => _29[0], 'optionalAccess', _30 => _30.name]) }
|
|
558
543
|
});
|
|
559
544
|
const tree = generator.parse({ schema, name });
|
|
560
545
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _components.Oas.Schema, { name, value: schema, tree, children: [
|
|
561
|
-
typeName && typePath && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, {
|
|
546
|
+
typeName && typePath && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { isTypeOnly: true, root: file.path, path: typePath, name: [typeName] }),
|
|
562
547
|
plugin.options.dateParser && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { path: plugin.options.dateParser, name: plugin.options.dateParser }),
|
|
563
|
-
mode === "split" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Schema.Imports, {
|
|
564
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
548
|
+
mode === "split" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Schema.Imports, {}),
|
|
549
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, OperationSchema, { description })
|
|
565
550
|
] }, i);
|
|
566
551
|
};
|
|
567
|
-
return /* @__PURE__ */ _jsxruntime.
|
|
552
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
568
553
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["faker"], path: "@faker-js/faker" }),
|
|
569
554
|
plugin.options.regexGenerator === "randexp" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: "RandExp", path: "randexp" }),
|
|
570
555
|
items.map(mapItem)
|
|
571
|
-
] })
|
|
556
|
+
] });
|
|
572
557
|
};
|
|
573
558
|
|
|
574
559
|
|
package/dist/components.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-faker/dist/components.cjs","../src/components/OperationSchema.tsx","../src/SchemaGenerator.tsx","../src/components/Schema.tsx","../src/parser/index.ts","../src/plugin.ts","../src/OperationGenerator.tsx"],"names":["value","options","transformers","path","pluginTsName","schema","jsx","SchemaGenerator"],"mappings":"AAAA;ACAA,yDAAoB;AACpB,+CAA0D;AAC1D,oCAAqC;AACrC,2CAA6B;ADE7B;AACA;AELA,6CAA6C;AAE7C;AACA;AFMA;AACA;AGXA;AACA;AACA;AAEA,mHAAyB;AACzB;AACA;AHYA;AACA;AInBA;AACA;AAKO,IAAM,mBAAA,EAAqB;AAAA,EAChC,GAAA,EAAK,CAAA,EAAA,GAAM,WAAA;AAAA,EACX,OAAA,EAAS,CAAA,EAAA,GAAM,SAAA;AAAA,EACf,MAAA,EAAQ,CAAC,GAAA,EAAc,GAAA,EAAA,GAAiB;AACtC,IAAA,GAAA,CAAI,IAAA,IAAQ,KAAA,EAAA,GAAa,IAAA,IAAQ,KAAA,CAAA,EAAW;AAC1C,MAAA,OAAO,CAAA,0BAAA,EAA6B,GAAG,CAAA,OAAA,EAAU,GAAG,CAAA,GAAA,CAAA;AAAA,IACtD;AAEA,IAAA,GAAA,CAAI,IAAA,IAAQ,KAAA,CAAA,EAAW;AACrB,MAAA,OAAO,CAAA,0BAAA,EAA6B,GAAG,CAAA,GAAA,CAAA;AAAA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,IAAA;AAGJ,IAAA;AACG,MAAA;AACO,MAAA;AAEE,MAAA;AACV,sBAAA;AAGF,IAAA;AAEJ,EAAA;AAGE,EAAA;AAEI,oBAAA;AACQ,IAAA;AACG,IAAA;AAEf,EAAA;AAEJ;ADyegB;AACA;AACA;AACA","file":"/home/runner/work/kubb/kubb/packages/plugin-faker/dist/components.cjs","sourcesContent":[null,"import { Oas } from '@kubb/plugin-oas/components'\nimport { useOas, useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, Parser, useApp } from '@kubb/react'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport { SchemaGenerator } from '../SchemaGenerator.tsx'\n\nimport type { OperationSchema as OperationSchemaType } from '@kubb/plugin-oas'\nimport type { ReactNode } from 'react'\nimport type { FileMeta, PluginFaker } from '../types.ts'\nimport { Schema } from './Schema.tsx'\n\ntype Props = {\n description?: string\n}\n\nexport function OperationSchema({ description }: Props): ReactNode {\n return <Schema withData={false} description={description} />\n}\n\ntype FileProps = {}\n\nOperationSchema.File = function ({}: FileProps): ReactNode {\n const { plugin, pluginManager, mode } = useApp<PluginFaker>()\n\n const oas = useOas()\n const { getSchemas, getFile } = useOperationManager()\n const operation = useOperation()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const generator = new SchemaGenerator(plugin.options, {\n oas,\n plugin,\n pluginManager,\n mode,\n override: plugin.options.override,\n })\n\n const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean)\n\n const mapItem = ({ name, schema, description, ...options }: OperationSchemaType, i: number) => {\n // used for this.options.typed\n const typeName = pluginManager.resolveName({\n name,\n pluginKey: [pluginTsName],\n type: 'type',\n })\n const typeFileName = pluginManager.resolveName({\n name: options.operationName || name,\n pluginKey: [pluginTsName],\n type: 'file',\n })\n const typePath = pluginManager.resolvePath({\n baseName: typeFileName,\n pluginKey: [pluginTsName],\n options: { tag: options.operation?.getTags()[0]?.name },\n })\n\n const tree = generator.parse({ schema, name })\n\n return (\n <Oas.Schema key={i} name={name} value={schema} tree={tree}>\n {typeName && typePath && <File.Import extName={plugin.options.extName} isTypeOnly root={file.path} path={typePath} name={[typeName]} />}\n {plugin.options.dateParser && <File.Import path={plugin.options.dateParser} name={plugin.options.dateParser} />}\n\n {mode === 'split' && <Oas.Schema.Imports extName={plugin.options.extName} />}\n <File.Source>\n <OperationSchema description={description} />\n </File.Source>\n </Oas.Schema>\n )\n }\n\n return (\n <Parser language=\"typescript\">\n <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>\n <File.Import name={['faker']} path=\"@faker-js/faker\" />\n {plugin.options.regexGenerator === 'randexp' && <File.Import name={'RandExp'} path={'randexp'} />}\n {items.map(mapItem)}\n </File>\n </Parser>\n )\n}\n","import type { SchemaObject } from '@kubb/oas'\nimport { SchemaGenerator as Generator } from '@kubb/plugin-oas'\nimport type { SchemaMethodResult } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { App, createRoot } from '@kubb/react'\nimport { Schema } from './components/Schema.tsx'\nimport type { FileMeta, PluginFaker } from './types.ts'\n\nexport class SchemaGenerator extends Generator<PluginFaker['resolvedOptions'], PluginFaker> {\n async schema(name: string, schema: SchemaObject, options: PluginFaker['resolvedOptions']): SchemaMethodResult<FileMeta> {\n const { oas, pluginManager, plugin, mode, output } = this.context\n\n const root = createRoot({\n logger: pluginManager.logger,\n })\n\n const tree = this.parse({ schema, name })\n\n root.render(\n <App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>\n <Oas oas={oas}>\n <Oas.Schema name={name} value={schema} tree={tree}>\n <Schema.File />\n </Oas.Schema>\n </Oas>\n </App>,\n )\n\n return root.files\n }\n}\n","import { Oas } from '@kubb/plugin-oas/components'\nimport { File, Function, useApp, useFile } from '@kubb/react'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport transformers from '@kubb/core/transformers'\nimport { schemaKeywords } from '@kubb/plugin-oas'\nimport { useSchema } from '@kubb/plugin-oas/hooks'\nimport type { ReactNode } from 'react'\nimport * as parserFaker from '../parser/index.ts'\nimport { pluginFakerName } from '../plugin.ts'\nimport type { PluginFaker } from '../types.ts'\n\ntype Props = {\n description?: string\n withData?: boolean\n}\n\nexport function Schema(props: Props): ReactNode {\n const { withData, description } = props\n const { tree, name } = useSchema()\n const {\n pluginManager,\n plugin: {\n options: { dateParser, regexGenerator, mapper, seed },\n },\n } = useApp<PluginFaker>()\n\n // all checks are also inside this.schema(React)\n const resolvedName = pluginManager.resolveName({\n name,\n pluginKey: [pluginFakerName],\n type: 'function',\n })\n\n const typeName = pluginManager.resolveName({\n name,\n pluginKey: [pluginTsName],\n type: 'type',\n })\n\n const fakerText = parserFaker.joinItems(\n tree\n .map((schema) => parserFaker.parse(undefined, schema, { name: resolvedName, typeName, seed, regexGenerator, mapper, withData, dateParser }))\n .filter(Boolean),\n )\n\n let fakerDefaultOverride: '' | '[]' | '{}' | undefined = undefined\n let fakerTextWithOverride = fakerText\n\n if (withData && fakerText.startsWith('{')) {\n fakerDefaultOverride = '{}'\n fakerTextWithOverride = `{\n ...${fakerText},\n ...data\n}`\n }\n\n if (withData && fakerText.startsWith('faker.helpers.arrayElements')) {\n fakerDefaultOverride = '[]'\n fakerTextWithOverride = `[\n ...${fakerText},\n ...data\n ]`\n }\n\n const params = fakerDefaultOverride ? `data: NonNullable<Partial<${typeName}>> = ${fakerDefaultOverride}` : `data?: NonNullable<Partial<${typeName}>>`\n\n return (\n <>\n <Function\n export\n name={resolvedName}\n JSDoc={{ comments: [description ? `@description ${transformers.jsStringEscape(description)}` : undefined].filter(Boolean) }}\n params={withData ? params : ''}\n returnType={typeName ? `NonNullable<${typeName}>` : ''}\n >\n {seed ? `faker.seed(${JSON.stringify(seed)})` : ''}\n <br />\n <Function.Return>{fakerTextWithOverride}</Function.Return>\n </Function>\n <br />\n </>\n )\n}\n\ntype FileProps = {}\n\nSchema.File = function ({}: FileProps): ReactNode {\n const { pluginManager } = useApp<PluginFaker>()\n const { tree, schema } = useSchema()\n\n const withData = tree.some(\n (schema) =>\n schema.keyword === schemaKeywords.array ||\n schema.keyword === schemaKeywords.and ||\n schema.keyword === schemaKeywords.object ||\n schema.keyword === schemaKeywords.union ||\n schema.keyword === schemaKeywords.tuple,\n )\n\n return (\n <Oas.Schema.File output={pluginManager.config.output.path}>\n <Schema.Imports />\n <File.Source>\n <Schema description={schema?.description} withData={withData} />\n </File.Source>\n </Oas.Schema.File>\n )\n}\nSchema.Imports = (): ReactNode => {\n const {\n pluginManager,\n plugin: {\n options: { extName, dateParser, regexGenerator },\n },\n } = useApp<PluginFaker>()\n const { path: root } = useFile()\n const { name, tree, schema } = useSchema()\n\n // used for this.options.typed\n const typeName = pluginManager.resolveName({\n name,\n pluginKey: [pluginTsName],\n type: 'type',\n })\n\n const typeFileName = pluginManager.resolveName({\n name: name,\n pluginKey: [pluginTsName],\n type: 'file',\n })\n\n const typePath = pluginManager.resolvePath({\n baseName: typeFileName,\n pluginKey: [pluginTsName],\n })\n\n return (\n <>\n <File.Import name={['faker']} path=\"@faker-js/faker\" />\n {regexGenerator === 'randexp' && <File.Import name={'RandExp'} path={'randexp'} />}\n {dateParser && <File.Import path={dateParser} name={dateParser} />}\n {typeName && typePath && <File.Import extName={extName} isTypeOnly root={root} path={typePath} name={[typeName]} />}\n </>\n )\n}\n","import transformers from '@kubb/core/transformers'\nimport { SchemaGenerator, isKeyword, schemaKeywords } from '@kubb/plugin-oas'\n\nimport type { Schema, SchemaKeywordBase, SchemaKeywordMapper, SchemaMapper } from '@kubb/plugin-oas'\nimport type { Options } from '../types.ts'\n\nexport const fakerKeywordMapper = {\n any: () => 'undefined',\n unknown: () => 'unknown',\n number: (min?: number, max?: number) => {\n if (max !== undefined && min !== undefined) {\n return `faker.number.float({ min: ${min}, max: ${max} })`\n }\n\n if (min !== undefined) {\n return `faker.number.float({ min: ${min} })`\n }\n\n if (max !== undefined) {\n return `faker.number.float({ max: ${max} })`\n }\n\n return 'faker.number.float()'\n },\n integer: (min?: number, max?: number) => {\n if (max !== undefined && min !== undefined) {\n return `faker.number.int({ min: ${min}, max: ${max} })`\n }\n\n if (min !== undefined) {\n return `faker.number.int({ min: ${min} })`\n }\n\n if (max !== undefined) {\n return `faker.number.int({ max: ${max} })`\n }\n\n return 'faker.number.int()'\n },\n string: (min?: number, max?: number) => {\n if (max !== undefined && min !== undefined) {\n return `faker.string.alpha({ length: { min: ${min}, max: ${max} } })`\n }\n\n if (min !== undefined) {\n return `faker.string.alpha({ length: { min: ${min} } })`\n }\n\n if (max !== undefined) {\n return `faker.string.alpha({ length: { max: ${max} } })`\n }\n\n return 'faker.string.alpha()'\n },\n boolean: () => 'faker.datatype.boolean()',\n undefined: () => 'undefined',\n null: () => 'null',\n array: (items: string[] = []) => `faker.helpers.arrayElements([${items.join(', ')}]) as any`,\n tuple: (items: string[] = []) => `faker.helpers.arrayElements([${items.join(', ')}]) as any`,\n enum: (items: Array<string | number> = []) => `faker.helpers.arrayElement<any>([${items.join(', ')}])`,\n union: (items: string[] = []) => `faker.helpers.arrayElement<any>([${items.join(', ')}])`,\n /**\n * ISO 8601\n */\n datetime: () => 'faker.date.anytime().toISOString()',\n /**\n * Type `'date'` Date\n * Type `'string'` ISO date format (YYYY-MM-DD)\n * @default ISO date format (YYYY-MM-DD)\n */\n date: (type: 'date' | 'string' = 'string', parser?: string) => {\n if (type === 'string') {\n if (parser) {\n return `${parser}(faker.date.anytime()).format(\"YYYY-MM-DD\")`\n }\n return 'faker.date.anytime().toString()'\n }\n return 'faker.date.anytime()'\n },\n /**\n * Type `'date'` Date\n * Type `'string'` ISO time format (HH:mm:ss[.SSSSSS])\n * @default ISO time format (HH:mm:ss[.SSSSSS])\n */\n time: (type: 'date' | 'string' = 'string', parser?: string) => {\n if (type === 'string') {\n if (parser) {\n return `${parser}(faker.date.anytime()).format(\"HH:mm:ss\")`\n }\n return 'faker.date.anytime().toString()'\n }\n return 'faker.date.anytime()'\n },\n uuid: () => 'faker.string.uuid()',\n url: () => 'faker.internet.url()',\n and: (items: string[] = []) => `Object.assign({}, ${items.join(', ')})`,\n object: () => 'object',\n ref: () => 'ref',\n matches: (value = '', regexGenerator: 'faker' | 'randexp' = 'faker') => {\n if (regexGenerator === 'randexp') {\n return `${transformers.toRegExpString(value, 'RandExp')}.gen()`\n }\n return `faker.helpers.fromRegExp(${transformers.toRegExpString(value)})`\n },\n email: () => 'faker.internet.email()',\n firstName: () => 'faker.person.firstName()',\n lastName: () => 'faker.person.lastName()',\n password: () => 'faker.internet.password()',\n phone: () => 'faker.phone.number()',\n blob: () => 'faker.image.imageUrl() as unknown as Blob',\n default: undefined,\n describe: undefined,\n const: (value?: string | number) => (value as string) ?? '',\n max: undefined,\n min: undefined,\n nullable: undefined,\n nullish: undefined,\n optional: undefined,\n readOnly: undefined,\n strict: undefined,\n deprecated: undefined,\n example: undefined,\n schema: undefined,\n catchall: undefined,\n name: undefined,\n} satisfies SchemaMapper<string | null | undefined>\n\n/**\n * @link based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398\n */\n\nfunction schemaKeywordsorter(a: Schema, b: Schema) {\n if (b.keyword === 'null') {\n return -1\n }\n\n return 0\n}\n\nexport function joinItems(items: string[]): string {\n switch (items.length) {\n case 0:\n return 'undefined'\n case 1:\n return items[0]!\n default:\n return fakerKeywordMapper.union(items)\n }\n}\n\ntype ParserOptions = {\n name: string\n typeName?: string\n description?: string\n\n seed?: number | number[]\n regexGenerator?: 'faker' | 'randexp'\n withData?: boolean\n dateParser?: Options['dateParser']\n mapper?: Record<string, string>\n}\n\nexport function parse(parent: Schema | undefined, current: Schema, options: ParserOptions): string | null | undefined {\n const value = fakerKeywordMapper[current.keyword as keyof typeof fakerKeywordMapper]\n\n if (!value) {\n return undefined\n }\n\n if (isKeyword(current, schemaKeywords.union)) {\n return fakerKeywordMapper.union(current.args.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean))\n }\n\n if (isKeyword(current, schemaKeywords.and)) {\n return fakerKeywordMapper.and(current.args.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean))\n }\n\n if (isKeyword(current, schemaKeywords.array)) {\n return fakerKeywordMapper.array(current.args.items.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean))\n }\n\n if (isKeyword(current, schemaKeywords.enum)) {\n return fakerKeywordMapper.enum(\n current.args.items.map((schema) => {\n if (schema.format === 'number') {\n return schema.name\n }\n return transformers.stringify(schema.name)\n }),\n )\n }\n\n if (isKeyword(current, schemaKeywords.ref)) {\n if (!current.args?.name) {\n throw new Error(`Name not defined for keyword ${current.keyword}`)\n }\n\n if (options.withData) {\n return `${current.args.name}(data)`\n }\n\n return `${current.args.name}()`\n }\n\n if (isKeyword(current, schemaKeywords.object)) {\n const argsObject = Object.entries(current.args?.properties || {})\n .filter((item) => {\n const schema = item[1]\n return schema && typeof schema.map === 'function'\n })\n .map(([name, schemas]) => {\n const nameSchema = schemas.find((schema) => schema.keyword === schemaKeywords.name) as SchemaKeywordMapper['name']\n const mappedName = nameSchema?.args || name\n\n // custom mapper(pluginOptions)\n if (options.mapper?.[mappedName]) {\n return `\"${name}\": ${options.mapper?.[mappedName]}`\n }\n\n return `\"${name}\": ${joinItems(\n schemas\n .sort(schemaKeywordsorter)\n .map((schema) => parse(current, schema, { ...options, withData: false }))\n .filter(Boolean),\n )}`\n })\n .join(',')\n\n return `{${argsObject}}`\n }\n\n if (isKeyword(current, schemaKeywords.tuple)) {\n if (Array.isArray(current.args.items)) {\n return fakerKeywordMapper.tuple(current.args.items.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean))\n }\n\n return parse(current, current.args.items, { ...options, withData: false })\n }\n\n if (isKeyword(current, schemaKeywords.const)) {\n if (current.args.format === 'number' && current.args.name !== undefined) {\n return fakerKeywordMapper.const(current.args.name?.toString())\n }\n return fakerKeywordMapper.const(transformers.stringify(current.args.value))\n }\n\n if (isKeyword(current, schemaKeywords.matches) && current.args) {\n return fakerKeywordMapper.matches(current.args, options.regexGenerator)\n }\n\n if (isKeyword(current, schemaKeywords.null) || isKeyword(current, schemaKeywords.undefined) || isKeyword(current, schemaKeywords.any)) {\n return value() || ''\n }\n\n if (isKeyword(current, schemaKeywords.string)) {\n if (parent) {\n const minSchema = SchemaGenerator.find([parent], schemaKeywords.min)\n const maxSchema = SchemaGenerator.find([parent], schemaKeywords.max)\n\n return fakerKeywordMapper.string(minSchema?.args, maxSchema?.args)\n }\n\n return fakerKeywordMapper.string()\n }\n\n if (isKeyword(current, schemaKeywords.number)) {\n if (parent) {\n const minSchema = SchemaGenerator.find([parent], schemaKeywords.min)\n const maxSchema = SchemaGenerator.find([parent], schemaKeywords.max)\n\n return fakerKeywordMapper.number(minSchema?.args, maxSchema?.args)\n }\n\n return fakerKeywordMapper.number()\n }\n\n if (isKeyword(current, schemaKeywords.integer)) {\n if (parent) {\n const minSchema = SchemaGenerator.find([parent], schemaKeywords.min)\n const maxSchema = SchemaGenerator.find([parent], schemaKeywords.max)\n\n return fakerKeywordMapper.integer(minSchema?.args, maxSchema?.args)\n }\n\n return fakerKeywordMapper.integer()\n }\n\n if (isKeyword(current, schemaKeywords.datetime)) {\n return fakerKeywordMapper.datetime()\n }\n\n if (isKeyword(current, schemaKeywords.date)) {\n return fakerKeywordMapper.date(current.args.type, options.dateParser)\n }\n\n if (isKeyword(current, schemaKeywords.time)) {\n return fakerKeywordMapper.time(current.args.type, options.dateParser)\n }\n\n if (current.keyword in fakerKeywordMapper && 'args' in current) {\n const value = fakerKeywordMapper[current.keyword as keyof typeof fakerKeywordMapper] as (typeof fakerKeywordMapper)['const']\n\n const options = JSON.stringify((current as SchemaKeywordBase<unknown>).args)\n\n return value(options)\n }\n\n if (current.keyword in fakerKeywordMapper) {\n return value()\n }\n\n return undefined\n}\n","import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { pluginOasName } from '@kubb/plugin-oas'\nimport { getGroupedByTagFiles } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport { OperationGenerator } from './OperationGenerator.tsx'\nimport { SchemaGenerator } from './SchemaGenerator.tsx'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport type { PluginFaker } from './types.ts'\n\nexport const pluginFakerName = 'plugin-faker' satisfies PluginFaker['name']\n\nexport const pluginFaker = createPlugin<PluginFaker>((options) => {\n const {\n output = { path: 'mocks' },\n seed,\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n mapper = {},\n dateType = 'string',\n unknownType = 'any',\n dateParser,\n regexGenerator = 'faker',\n } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginFakerName,\n options: {\n extName: output.extName,\n transformers,\n dateType,\n seed,\n unknownType,\n dateParser,\n mapper,\n override,\n regexGenerator,\n },\n pre: [pluginOasName, pluginTsName],\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n prefix: type ? 'create' : undefined,\n isFile: type === 'file',\n })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async writeFile(path, source) {\n if (!path.endsWith('.ts') || !source) {\n return\n }\n\n return this.fileManager.write(path, source, { sanity: false })\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.api.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.api.contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build()\n await this.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.api.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build()\n await this.addFile(...operationFiles)\n },\n async buildEnd() {\n if (this.config.output.write === false) {\n return\n }\n\n const root = path.resolve(this.config.root, this.config.output.path)\n\n if (group?.type === 'tag') {\n const rootFiles = await getGroupedByTagFiles({\n logger: this.logger,\n files: this.fileManager.files,\n plugin: this.plugin,\n template,\n exportAs: group.exportAs || '{{tag}}Mocks',\n root,\n output,\n })\n\n await this.addFile(...rootFiles)\n }\n\n await this.fileManager.addIndexes({\n root,\n output,\n meta: { pluginKey: this.plugin.key },\n logger: this.logger,\n })\n },\n }\n})\n","import { OperationGenerator as Generator } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { App, createRoot } from '@kubb/react'\n\nimport { OperationSchema } from './components/OperationSchema.tsx'\n\nimport type { Operation } from '@kubb/oas'\nimport type { OperationMethodResult } from '@kubb/plugin-oas'\nimport type { FileMeta, PluginFaker } from './types.ts'\n\nexport class OperationGenerator extends Generator<PluginFaker['resolvedOptions'], PluginFaker> {\n async operation(operation: Operation, options: PluginFaker['resolvedOptions']): OperationMethodResult<FileMeta> {\n const { oas, pluginManager, plugin, mode } = this.context\n\n const root = createRoot({\n logger: pluginManager.logger,\n })\n root.render(\n <App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>\n <Oas oas={oas} operations={[operation]} generator={this}>\n <Oas.Operation operation={operation}>\n <OperationSchema.File />\n </Oas.Operation>\n </Oas>\n </App>,\n )\n\n return root.files\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-faker/dist/components.cjs","../src/components/OperationSchema.tsx","../src/SchemaGenerator.tsx","../src/components/Schema.tsx","../src/parser/index.ts","../src/plugin.ts","../src/OperationGenerator.tsx"],"names":["value","options","transformers","pluginTsName","schema","jsx","SchemaGenerator"],"mappings":"AAAA;ACAA,yDAAoB;AACpB,+CAA0D;AAC1D,2CAA6B;AAC7B,oCAA6B;ADE7B;AACA;AELA,6CAA6C;AAE7C;AACA;AFMA;AACA;AGXA;AACA;AACA;AAEA,mHAAyB;AACzB;AACA;AHYA;AACA;AInBA;AACA;AAKO,IAAM,mBAAA,EAAqB;AAAA,EAChC,GAAA,EAAK,CAAA,EAAA,GAAM,WAAA;AAAA,EACX,OAAA,EAAS,CAAA,EAAA,GAAM,SAAA;AAAA,EACf,MAAA,EAAQ,CAAC,GAAA,EAAc,GAAA,EAAA,GAAiB;AACtC,IAAA,GAAA,CAAI,IAAA,IAAQ,KAAA,EAAA,GAAa,IAAA,IAAQ,KAAA,CAAA,EAAW;AAC1C,MAAA,OAAO,CAAA,0BAAA,EAA6B,GAAG,CAAA,OAAA,EAAU,GAAG,CAAA,GAAA,CAAA;AAAA,IACtD;AAEA,IAAA,GAAA,CAAI,IAAA,IAAQ,KAAA,CAAA,EAAW;AACrB,MAAA,OAAO,CAAA,0BAAA,EAA6B,GAAG,CAAA,GAAA,CAAA;AAAA,IACzC;AAEA,IAAA,GAAA,CAAI,IAAA,IAAQ,KAAA,CAAA,EAAW;AACrB,MAAA,OAAO,CAAA,0BAAA,EAA6B,GAAG,CAAA,GAAA,CAAA;AAAA,IACzC;AAEA,IAAA,OAAO,sBAAA;AAAA,EACT,CAAA;AAAA,E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J;AACO;AACC,EAAA;AACJ,IAAA;AACQ,IAAA;AACG,MAAA;AACX,IAAA;AACsB,EAAA;AACV,EAAA;AACA,EAAA;AAGR,EAAA;AACJ,IAAA;AACYD,IAAAA;AACN,IAAA;AACP,EAAA;AAEK,EAAA;AACJ,IAAA;AACYA,IAAAA;AACN,IAAA;AACP,EAAA;AAEK,EAAA;AACM,IAAA;AACEA,IAAAA;AACb,EAAA;AAGC,EAAA;AACE,oBAAA;AACC,IAAA;AACA,IAAA;AACY,IAAA;AACf,EAAA;AAEJ;AH2VgB;AACA;AErdJE;AAdCC;AACE,EAAA;AACH,IAAA;AAEF,IAAA;AACI,MAAA;AACT,IAAA;AAEK,IAAA;AAED,IAAA;AACH,sBAAA;AAOF,IAAA;AAEY,IAAA;AACd,EAAA;AACF;AF4dgB;AACA;AC1ePD;AADO;AACP,EAAA;AACT;AAIgB;AACN,EAAA;AAEI,EAAA;AACJ,EAAA;AACF,EAAA;AAEO,EAAA;AACP,EAAA;AACA,EAAA;AACJ,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACU,IAAA;AACX,EAAA;AAEa,EAAA;AAER,EAAA;AAEE,IAAA;AACJ,MAAA;AACA,MAAA;AACM,MAAA;AACP,IAAA;AACK,IAAA;AACE,MAAA;AACN,MAAA;AACM,MAAA;AACP,IAAA;AAGK,IAAA;AACM,MAAA;AACV,MAAA;AACS,MAAA;AACV,IAAA;AAEK,IAAA;AAGJ,IAAA;AACG,MAAA;AACO,MAAA;AAEE,MAAA;AACV,sBAAA;AACF,IAAA;AAEJ,EAAA;AAGE,EAAA;AACE,oBAAA;AACQ,IAAA;AACG,IAAA;AACb,EAAA;AAEJ;AD4dgB;AACA;AACA;AACA","file":"/home/runner/work/kubb/kubb/packages/plugin-faker/dist/components.cjs","sourcesContent":[null,"import { Oas } from '@kubb/plugin-oas/components'\nimport { useOas, useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\n\nimport { SchemaGenerator } from '../SchemaGenerator.tsx'\n\nimport type { OperationSchema as OperationSchemaType } from '@kubb/plugin-oas'\nimport type { ReactNode } from 'react'\nimport type { FileMeta, PluginFaker } from '../types.ts'\nimport { Schema } from './Schema.tsx'\n\ntype Props = {\n description?: string\n}\n\nexport function OperationSchema({ description }: Props): ReactNode {\n return <Schema withData={false} description={description} />\n}\n\ntype FileProps = {}\n\nOperationSchema.File = function ({}: FileProps): ReactNode {\n const { plugin, pluginManager, mode } = useApp<PluginFaker>()\n\n const oas = useOas()\n const { getSchemas, getFile } = useOperationManager()\n const operation = useOperation()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const generator = new SchemaGenerator(plugin.options, {\n oas,\n plugin,\n pluginManager,\n mode,\n override: plugin.options.override,\n })\n\n const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean)\n\n const mapItem = ({ name, schema, description, ...options }: OperationSchemaType, i: number) => {\n // used for this.options.typed\n const typeName = pluginManager.resolveName({\n name,\n pluginKey: [pluginTsName],\n type: 'type',\n })\n const typeFileName = pluginManager.resolveName({\n name: options.operationName || name,\n pluginKey: [pluginTsName],\n type: 'file',\n })\n\n // todo replace by getFile\n const typePath = pluginManager.resolvePath({\n baseName: typeFileName,\n pluginKey: [pluginTsName],\n options: { tag: options.operation?.getTags()[0]?.name },\n })\n\n const tree = generator.parse({ schema, name })\n\n return (\n <Oas.Schema key={i} name={name} value={schema} tree={tree}>\n {typeName && typePath && <File.Import isTypeOnly root={file.path} path={typePath} name={[typeName]} />}\n {plugin.options.dateParser && <File.Import path={plugin.options.dateParser} name={plugin.options.dateParser} />}\n\n {mode === 'split' && <Oas.Schema.Imports />}\n <OperationSchema description={description} />\n </Oas.Schema>\n )\n }\n\n return (\n <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>\n <File.Import name={['faker']} path=\"@faker-js/faker\" />\n {plugin.options.regexGenerator === 'randexp' && <File.Import name={'RandExp'} path={'randexp'} />}\n {items.map(mapItem)}\n </File>\n )\n}\n","import type { SchemaObject } from '@kubb/oas'\nimport { SchemaGenerator as Generator } from '@kubb/plugin-oas'\nimport type { SchemaMethodResult } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { App, createRoot } from '@kubb/react'\nimport { Schema } from './components/Schema.tsx'\nimport type { FileMeta, PluginFaker } from './types.ts'\n\nexport class SchemaGenerator extends Generator<PluginFaker['resolvedOptions'], PluginFaker> {\n async schema(name: string, schema: SchemaObject, options: PluginFaker['resolvedOptions']): SchemaMethodResult<FileMeta> {\n const { oas, pluginManager, plugin, mode, output } = this.context\n\n const root = createRoot({\n logger: pluginManager.logger,\n })\n\n const tree = this.parse({ schema, name })\n\n root.render(\n <App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>\n <Oas oas={oas}>\n <Oas.Schema name={name} value={schema} tree={tree}>\n <Schema.File />\n </Oas.Schema>\n </Oas>\n </App>,\n )\n\n return root.files\n }\n}\n","import { Oas } from '@kubb/plugin-oas/components'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, Function, useApp, useFile } from '@kubb/react'\n\nimport transformers from '@kubb/core/transformers'\nimport { schemaKeywords } from '@kubb/plugin-oas'\nimport { useSchema } from '@kubb/plugin-oas/hooks'\nimport type { ReactNode } from 'react'\nimport * as parserFaker from '../parser/index.ts'\nimport { pluginFakerName } from '../plugin.ts'\nimport type { PluginFaker } from '../types.ts'\n\ntype Props = {\n description?: string\n withData?: boolean\n}\n\nexport function Schema(props: Props): ReactNode {\n const { withData, description } = props\n const { tree, name } = useSchema()\n const {\n pluginManager,\n plugin: {\n options: { dateParser, regexGenerator, mapper, seed },\n },\n } = useApp<PluginFaker>()\n\n // all checks are also inside this.schema(React)\n const resolvedName = pluginManager.resolveName({\n name,\n pluginKey: [pluginFakerName],\n type: 'function',\n })\n\n const typeName = pluginManager.resolveName({\n name,\n pluginKey: [pluginTsName],\n type: 'type',\n })\n\n const fakerText = parserFaker.joinItems(\n tree\n .map((schema) => parserFaker.parse(undefined, schema, { name: resolvedName, typeName, seed, regexGenerator, mapper, withData, dateParser }))\n .filter(Boolean),\n )\n\n let fakerDefaultOverride: '' | '[]' | '{}' | undefined = undefined\n let fakerTextWithOverride = fakerText\n\n if (withData && fakerText.startsWith('{')) {\n fakerDefaultOverride = '{}'\n fakerTextWithOverride = `{\n ...${fakerText},\n ...data\n}`\n }\n\n if (withData && fakerText.startsWith('faker.helpers.arrayElements')) {\n fakerDefaultOverride = '[]'\n fakerTextWithOverride = `[\n ...${fakerText},\n ...data\n ]`\n }\n\n const params = fakerDefaultOverride ? `data: NonNullable<Partial<${typeName}>> = ${fakerDefaultOverride}` : `data?: NonNullable<Partial<${typeName}>>`\n\n return (\n <File.Source name={resolvedName} isExportable isIndexable>\n <Function\n export\n name={resolvedName}\n JSDoc={{ comments: [description ? `@description ${transformers.jsStringEscape(description)}` : undefined].filter(Boolean) }}\n params={withData ? params : ''}\n returnType={typeName ? `NonNullable<${typeName}>` : ''}\n >\n {seed ? `faker.seed(${JSON.stringify(seed)})` : ''}\n <br />\n <Function.Return>{fakerTextWithOverride}</Function.Return>\n </Function>\n <br />\n </File.Source>\n )\n}\n\ntype FileProps = {}\n\nSchema.File = function ({}: FileProps): ReactNode {\n const { pluginManager } = useApp<PluginFaker>()\n const { tree, schema } = useSchema()\n\n const withData = tree.some(\n (schema) =>\n schema.keyword === schemaKeywords.array ||\n schema.keyword === schemaKeywords.and ||\n schema.keyword === schemaKeywords.object ||\n schema.keyword === schemaKeywords.union ||\n schema.keyword === schemaKeywords.tuple,\n )\n\n return (\n <Oas.Schema.File output={pluginManager.config.output.path}>\n <Schema.Imports />\n <Schema description={schema?.description} withData={withData} />\n </Oas.Schema.File>\n )\n}\nSchema.Imports = (): ReactNode => {\n const {\n pluginManager,\n plugin: {\n options: { extName, dateParser, regexGenerator },\n },\n } = useApp<PluginFaker>()\n const { path: root } = useFile()\n const { name, tree, schema } = useSchema()\n\n // used for this.options.typed\n const typeName = pluginManager.resolveName({\n name,\n pluginKey: [pluginTsName],\n type: 'type',\n })\n\n const typeFileName = pluginManager.resolveName({\n name: name,\n pluginKey: [pluginTsName],\n type: 'file',\n })\n\n const typePath = pluginManager.resolvePath({\n baseName: typeFileName,\n pluginKey: [pluginTsName],\n })\n\n return (\n <>\n <File.Import name={['faker']} path=\"@faker-js/faker\" />\n {regexGenerator === 'randexp' && <File.Import name={'RandExp'} path={'randexp'} />}\n {dateParser && <File.Import path={dateParser} name={dateParser} />}\n {typeName && typePath && <File.Import isTypeOnly root={root} path={typePath} name={[typeName]} />}\n </>\n )\n}\n","import transformers from '@kubb/core/transformers'\nimport { SchemaGenerator, isKeyword, schemaKeywords } from '@kubb/plugin-oas'\n\nimport type { Schema, SchemaKeywordBase, SchemaKeywordMapper, SchemaMapper } from '@kubb/plugin-oas'\nimport type { Options } from '../types.ts'\n\nexport const fakerKeywordMapper = {\n any: () => 'undefined',\n unknown: () => 'unknown',\n number: (min?: number, max?: number) => {\n if (max !== undefined && min !== undefined) {\n return `faker.number.float({ min: ${min}, max: ${max} })`\n }\n\n if (min !== undefined) {\n return `faker.number.float({ min: ${min} })`\n }\n\n if (max !== undefined) {\n return `faker.number.float({ max: ${max} })`\n }\n\n return 'faker.number.float()'\n },\n integer: (min?: number, max?: number) => {\n if (max !== undefined && min !== undefined) {\n return `faker.number.int({ min: ${min}, max: ${max} })`\n }\n\n if (min !== undefined) {\n return `faker.number.int({ min: ${min} })`\n }\n\n if (max !== undefined) {\n return `faker.number.int({ max: ${max} })`\n }\n\n return 'faker.number.int()'\n },\n string: (min?: number, max?: number) => {\n if (max !== undefined && min !== undefined) {\n return `faker.string.alpha({ length: { min: ${min}, max: ${max} } })`\n }\n\n if (min !== undefined) {\n return `faker.string.alpha({ length: { min: ${min} } })`\n }\n\n if (max !== undefined) {\n return `faker.string.alpha({ length: { max: ${max} } })`\n }\n\n return 'faker.string.alpha()'\n },\n boolean: () => 'faker.datatype.boolean()',\n undefined: () => 'undefined',\n null: () => 'null',\n array: (items: string[] = []) => `faker.helpers.arrayElements([${items.join(', ')}]) as any`,\n tuple: (items: string[] = []) => `faker.helpers.arrayElements([${items.join(', ')}]) as any`,\n enum: (items: Array<string | number> = []) => `faker.helpers.arrayElement<any>([${items.join(', ')}])`,\n union: (items: string[] = []) => `faker.helpers.arrayElement<any>([${items.join(', ')}])`,\n /**\n * ISO 8601\n */\n datetime: () => 'faker.date.anytime().toISOString()',\n /**\n * Type `'date'` Date\n * Type `'string'` ISO date format (YYYY-MM-DD)\n * @default ISO date format (YYYY-MM-DD)\n */\n date: (type: 'date' | 'string' = 'string', parser?: string) => {\n if (type === 'string') {\n if (parser) {\n return `${parser}(faker.date.anytime()).format(\"YYYY-MM-DD\")`\n }\n return 'faker.date.anytime().toString()'\n }\n return 'faker.date.anytime()'\n },\n /**\n * Type `'date'` Date\n * Type `'string'` ISO time format (HH:mm:ss[.SSSSSS])\n * @default ISO time format (HH:mm:ss[.SSSSSS])\n */\n time: (type: 'date' | 'string' = 'string', parser?: string) => {\n if (type === 'string') {\n if (parser) {\n return `${parser}(faker.date.anytime()).format(\"HH:mm:ss\")`\n }\n return 'faker.date.anytime().toString()'\n }\n return 'faker.date.anytime()'\n },\n uuid: () => 'faker.string.uuid()',\n url: () => 'faker.internet.url()',\n and: (items: string[] = []) => `Object.assign({}, ${items.join(', ')})`,\n object: () => 'object',\n ref: () => 'ref',\n matches: (value = '', regexGenerator: 'faker' | 'randexp' = 'faker') => {\n if (regexGenerator === 'randexp') {\n return `${transformers.toRegExpString(value, 'RandExp')}.gen()`\n }\n return `faker.helpers.fromRegExp(${transformers.toRegExpString(value)})`\n },\n email: () => 'faker.internet.email()',\n firstName: () => 'faker.person.firstName()',\n lastName: () => 'faker.person.lastName()',\n password: () => 'faker.internet.password()',\n phone: () => 'faker.phone.number()',\n blob: () => 'faker.image.imageUrl() as unknown as Blob',\n default: undefined,\n describe: undefined,\n const: (value?: string | number) => (value as string) ?? '',\n max: undefined,\n min: undefined,\n nullable: undefined,\n nullish: undefined,\n optional: undefined,\n readOnly: undefined,\n strict: undefined,\n deprecated: undefined,\n example: undefined,\n schema: undefined,\n catchall: undefined,\n name: undefined,\n} satisfies SchemaMapper<string | null | undefined>\n\n/**\n * @link based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398\n */\n\nfunction schemaKeywordsorter(a: Schema, b: Schema) {\n if (b.keyword === 'null') {\n return -1\n }\n\n return 0\n}\n\nexport function joinItems(items: string[]): string {\n switch (items.length) {\n case 0:\n return 'undefined'\n case 1:\n return items[0]!\n default:\n return fakerKeywordMapper.union(items)\n }\n}\n\ntype ParserOptions = {\n name: string\n typeName?: string\n description?: string\n\n seed?: number | number[]\n regexGenerator?: 'faker' | 'randexp'\n withData?: boolean\n dateParser?: Options['dateParser']\n mapper?: Record<string, string>\n}\n\nexport function parse(parent: Schema | undefined, current: Schema, options: ParserOptions): string | null | undefined {\n const value = fakerKeywordMapper[current.keyword as keyof typeof fakerKeywordMapper]\n\n if (!value) {\n return undefined\n }\n\n if (isKeyword(current, schemaKeywords.union)) {\n return fakerKeywordMapper.union(current.args.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean))\n }\n\n if (isKeyword(current, schemaKeywords.and)) {\n return fakerKeywordMapper.and(current.args.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean))\n }\n\n if (isKeyword(current, schemaKeywords.array)) {\n return fakerKeywordMapper.array(current.args.items.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean))\n }\n\n if (isKeyword(current, schemaKeywords.enum)) {\n return fakerKeywordMapper.enum(\n current.args.items.map((schema) => {\n if (schema.format === 'number') {\n return schema.name\n }\n return transformers.stringify(schema.name)\n }),\n )\n }\n\n if (isKeyword(current, schemaKeywords.ref)) {\n if (!current.args?.name) {\n throw new Error(`Name not defined for keyword ${current.keyword}`)\n }\n\n if (options.withData) {\n return `${current.args.name}(data)`\n }\n\n return `${current.args.name}()`\n }\n\n if (isKeyword(current, schemaKeywords.object)) {\n const argsObject = Object.entries(current.args?.properties || {})\n .filter((item) => {\n const schema = item[1]\n return schema && typeof schema.map === 'function'\n })\n .map(([name, schemas]) => {\n const nameSchema = schemas.find((schema) => schema.keyword === schemaKeywords.name) as SchemaKeywordMapper['name']\n const mappedName = nameSchema?.args || name\n\n // custom mapper(pluginOptions)\n if (options.mapper?.[mappedName]) {\n return `\"${name}\": ${options.mapper?.[mappedName]}`\n }\n\n return `\"${name}\": ${joinItems(\n schemas\n .sort(schemaKeywordsorter)\n .map((schema) => parse(current, schema, { ...options, withData: false }))\n .filter(Boolean),\n )}`\n })\n .join(',')\n\n return `{${argsObject}}`\n }\n\n if (isKeyword(current, schemaKeywords.tuple)) {\n if (Array.isArray(current.args.items)) {\n return fakerKeywordMapper.tuple(current.args.items.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean))\n }\n\n return parse(current, current.args.items, { ...options, withData: false })\n }\n\n if (isKeyword(current, schemaKeywords.const)) {\n if (current.args.format === 'number' && current.args.name !== undefined) {\n return fakerKeywordMapper.const(current.args.name?.toString())\n }\n return fakerKeywordMapper.const(transformers.stringify(current.args.value))\n }\n\n if (isKeyword(current, schemaKeywords.matches) && current.args) {\n return fakerKeywordMapper.matches(current.args, options.regexGenerator)\n }\n\n if (isKeyword(current, schemaKeywords.null) || isKeyword(current, schemaKeywords.undefined) || isKeyword(current, schemaKeywords.any)) {\n return value() || ''\n }\n\n if (isKeyword(current, schemaKeywords.string)) {\n if (parent) {\n const minSchema = SchemaGenerator.find([parent], schemaKeywords.min)\n const maxSchema = SchemaGenerator.find([parent], schemaKeywords.max)\n\n return fakerKeywordMapper.string(minSchema?.args, maxSchema?.args)\n }\n\n return fakerKeywordMapper.string()\n }\n\n if (isKeyword(current, schemaKeywords.number)) {\n if (parent) {\n const minSchema = SchemaGenerator.find([parent], schemaKeywords.min)\n const maxSchema = SchemaGenerator.find([parent], schemaKeywords.max)\n\n return fakerKeywordMapper.number(minSchema?.args, maxSchema?.args)\n }\n\n return fakerKeywordMapper.number()\n }\n\n if (isKeyword(current, schemaKeywords.integer)) {\n if (parent) {\n const minSchema = SchemaGenerator.find([parent], schemaKeywords.min)\n const maxSchema = SchemaGenerator.find([parent], schemaKeywords.max)\n\n return fakerKeywordMapper.integer(minSchema?.args, maxSchema?.args)\n }\n\n return fakerKeywordMapper.integer()\n }\n\n if (isKeyword(current, schemaKeywords.datetime)) {\n return fakerKeywordMapper.datetime()\n }\n\n if (isKeyword(current, schemaKeywords.date)) {\n return fakerKeywordMapper.date(current.args.type, options.dateParser)\n }\n\n if (isKeyword(current, schemaKeywords.time)) {\n return fakerKeywordMapper.time(current.args.type, options.dateParser)\n }\n\n if (current.keyword in fakerKeywordMapper && 'args' in current) {\n const value = fakerKeywordMapper[current.keyword as keyof typeof fakerKeywordMapper] as (typeof fakerKeywordMapper)['const']\n\n const options = JSON.stringify((current as SchemaKeywordBase<unknown>).args)\n\n return value(options)\n }\n\n if (current.keyword in fakerKeywordMapper) {\n return value()\n }\n\n return undefined\n}\n","import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport { OperationGenerator } from './OperationGenerator.tsx'\nimport { SchemaGenerator } from './SchemaGenerator.tsx'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport type { PluginFaker } from './types.ts'\n\nexport const pluginFakerName = 'plugin-faker' satisfies PluginFaker['name']\n\nexport const pluginFaker = createPlugin<PluginFaker>((options) => {\n const {\n output = { path: 'mocks' },\n seed,\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n mapper = {},\n dateType = 'string',\n unknownType = 'any',\n dateParser,\n regexGenerator = 'faker',\n } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginFakerName,\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n options: {\n extName: output.extName,\n transformers,\n dateType,\n seed,\n unknownType,\n dateParser,\n mapper,\n override,\n regexGenerator,\n },\n pre: [pluginOasName, pluginTsName],\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n prefix: type ? 'create' : undefined,\n isFile: type === 'file',\n })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build()\n await this.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build()\n await this.addFile(...operationFiles)\n\n if (this.config.output.exportType) {\n const barrelFiles = await this.fileManager.getBarrelFiles({\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n }\n },\n }\n})\n","import { OperationGenerator as Generator } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { App, createRoot } from '@kubb/react'\n\nimport { OperationSchema } from './components/OperationSchema.tsx'\n\nimport type { Operation } from '@kubb/oas'\nimport type { OperationMethodResult } from '@kubb/plugin-oas'\nimport type { FileMeta, PluginFaker } from './types.ts'\n\nexport class OperationGenerator extends Generator<PluginFaker['resolvedOptions'], PluginFaker> {\n async operation(operation: Operation, options: PluginFaker['resolvedOptions']): OperationMethodResult<FileMeta> {\n const { oas, pluginManager, plugin, mode } = this.context\n\n const root = createRoot({\n logger: pluginManager.logger,\n })\n\n root.render(\n <App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>\n <Oas oas={oas} operations={[operation]} generator={this}>\n <Oas.Operation operation={operation}>\n <OperationSchema.File />\n </Oas.Operation>\n </Oas>\n </App>,\n )\n\n return root.files\n }\n}\n"]}
|
package/dist/components.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/components/OperationSchema.tsx
|
|
2
2
|
import { Oas as Oas4 } from "@kubb/plugin-oas/components";
|
|
3
3
|
import { useOas, useOperation, useOperationManager } from "@kubb/plugin-oas/hooks";
|
|
4
|
-
import { File as File2, Parser, useApp as useApp2 } from "@kubb/react";
|
|
5
4
|
import { pluginTsName as pluginTsName3 } from "@kubb/plugin-ts";
|
|
5
|
+
import { File as File2, useApp as useApp2 } from "@kubb/react";
|
|
6
6
|
|
|
7
7
|
// src/SchemaGenerator.tsx
|
|
8
8
|
import { SchemaGenerator as Generator2 } from "@kubb/plugin-oas";
|
|
@@ -11,8 +11,8 @@ import { App as App2, createRoot as createRoot2 } from "@kubb/react";
|
|
|
11
11
|
|
|
12
12
|
// src/components/Schema.tsx
|
|
13
13
|
import { Oas as Oas2 } from "@kubb/plugin-oas/components";
|
|
14
|
-
import { File, Function, useApp, useFile } from "@kubb/react";
|
|
15
14
|
import { pluginTsName as pluginTsName2 } from "@kubb/plugin-ts";
|
|
15
|
+
import { File, Function, useApp, useFile } from "@kubb/react";
|
|
16
16
|
import transformers2 from "@kubb/core/transformers";
|
|
17
17
|
import { schemaKeywords as schemaKeywords2 } from "@kubb/plugin-oas";
|
|
18
18
|
import { useSchema } from "@kubb/plugin-oas/hooks";
|
|
@@ -259,12 +259,11 @@ function parse(parent, current, options) {
|
|
|
259
259
|
}
|
|
260
260
|
|
|
261
261
|
// src/plugin.ts
|
|
262
|
-
import path from "path";
|
|
262
|
+
import path from "node:path";
|
|
263
263
|
import { FileManager, PluginManager, createPlugin } from "@kubb/core";
|
|
264
264
|
import { camelCase } from "@kubb/core/transformers";
|
|
265
265
|
import { renderTemplate } from "@kubb/core/utils";
|
|
266
266
|
import { pluginOasName } from "@kubb/plugin-oas";
|
|
267
|
-
import { getGroupedByTagFiles } from "@kubb/plugin-oas/utils";
|
|
268
267
|
import { pluginTsName } from "@kubb/plugin-ts";
|
|
269
268
|
|
|
270
269
|
// src/OperationGenerator.tsx
|
|
@@ -305,6 +304,10 @@ var pluginFaker = createPlugin((options) => {
|
|
|
305
304
|
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
306
305
|
return {
|
|
307
306
|
name: pluginFakerName,
|
|
307
|
+
output: {
|
|
308
|
+
exportType: "barrelNamed",
|
|
309
|
+
...output
|
|
310
|
+
},
|
|
308
311
|
options: {
|
|
309
312
|
extName: output.extName,
|
|
310
313
|
transformers: transformers3,
|
|
@@ -339,22 +342,16 @@ var pluginFaker = createPlugin((options) => {
|
|
|
339
342
|
}
|
|
340
343
|
return resolvedName;
|
|
341
344
|
},
|
|
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
345
|
async buildStart() {
|
|
349
346
|
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
350
|
-
const oas = await swaggerPlugin.
|
|
347
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
351
348
|
const root = path.resolve(this.config.root, this.config.output.path);
|
|
352
349
|
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
353
350
|
const schemaGenerator = new SchemaGenerator2(this.plugin.options, {
|
|
354
351
|
oas,
|
|
355
352
|
pluginManager: this.pluginManager,
|
|
356
353
|
plugin: this.plugin,
|
|
357
|
-
contentType: swaggerPlugin.
|
|
354
|
+
contentType: swaggerPlugin.context.contentType,
|
|
358
355
|
include: void 0,
|
|
359
356
|
override,
|
|
360
357
|
mode,
|
|
@@ -366,7 +363,7 @@ var pluginFaker = createPlugin((options) => {
|
|
|
366
363
|
oas,
|
|
367
364
|
pluginManager: this.pluginManager,
|
|
368
365
|
plugin: this.plugin,
|
|
369
|
-
contentType: swaggerPlugin.
|
|
366
|
+
contentType: swaggerPlugin.context.contentType,
|
|
370
367
|
exclude,
|
|
371
368
|
include,
|
|
372
369
|
override,
|
|
@@ -374,30 +371,18 @@ var pluginFaker = createPlugin((options) => {
|
|
|
374
371
|
});
|
|
375
372
|
const operationFiles = await operationGenerator.build();
|
|
376
373
|
await this.addFile(...operationFiles);
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
if (this.config.output.write === false) {
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
const root = path.resolve(this.config.root, this.config.output.path);
|
|
383
|
-
if (group?.type === "tag") {
|
|
384
|
-
const rootFiles = await getGroupedByTagFiles({
|
|
385
|
-
logger: this.logger,
|
|
386
|
-
files: this.fileManager.files,
|
|
387
|
-
plugin: this.plugin,
|
|
388
|
-
template,
|
|
389
|
-
exportAs: group.exportAs || "{{tag}}Mocks",
|
|
374
|
+
if (this.config.output.exportType) {
|
|
375
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
390
376
|
root,
|
|
391
|
-
output
|
|
377
|
+
output,
|
|
378
|
+
files: this.fileManager.files,
|
|
379
|
+
meta: {
|
|
380
|
+
pluginKey: this.plugin.key
|
|
381
|
+
},
|
|
382
|
+
logger: this.logger
|
|
392
383
|
});
|
|
393
|
-
await this.addFile(...
|
|
384
|
+
await this.addFile(...barrelFiles);
|
|
394
385
|
}
|
|
395
|
-
await this.fileManager.addIndexes({
|
|
396
|
-
root,
|
|
397
|
-
output,
|
|
398
|
-
meta: { pluginKey: this.plugin.key },
|
|
399
|
-
logger: this.logger
|
|
400
|
-
});
|
|
401
386
|
}
|
|
402
387
|
};
|
|
403
388
|
});
|
|
@@ -443,7 +428,7 @@ function Schema(props) {
|
|
|
443
428
|
]`;
|
|
444
429
|
}
|
|
445
430
|
const params = fakerDefaultOverride ? `data: NonNullable<Partial<${typeName}>> = ${fakerDefaultOverride}` : `data?: NonNullable<Partial<${typeName}>>`;
|
|
446
|
-
return /* @__PURE__ */ jsxs(
|
|
431
|
+
return /* @__PURE__ */ jsxs(File.Source, { name: resolvedName, isExportable: true, isIndexable: true, children: [
|
|
447
432
|
/* @__PURE__ */ jsxs(
|
|
448
433
|
Function,
|
|
449
434
|
{
|
|
@@ -470,7 +455,7 @@ Schema.File = function({}) {
|
|
|
470
455
|
);
|
|
471
456
|
return /* @__PURE__ */ jsxs(Oas2.Schema.File, { output: pluginManager.config.output.path, children: [
|
|
472
457
|
/* @__PURE__ */ jsx2(Schema.Imports, {}),
|
|
473
|
-
/* @__PURE__ */ jsx2(
|
|
458
|
+
/* @__PURE__ */ jsx2(Schema, { description: schema?.description, withData })
|
|
474
459
|
] });
|
|
475
460
|
};
|
|
476
461
|
Schema.Imports = () => {
|
|
@@ -500,7 +485,7 @@ Schema.Imports = () => {
|
|
|
500
485
|
/* @__PURE__ */ jsx2(File.Import, { name: ["faker"], path: "@faker-js/faker" }),
|
|
501
486
|
regexGenerator === "randexp" && /* @__PURE__ */ jsx2(File.Import, { name: "RandExp", path: "randexp" }),
|
|
502
487
|
dateParser && /* @__PURE__ */ jsx2(File.Import, { path: dateParser, name: dateParser }),
|
|
503
|
-
typeName && typePath && /* @__PURE__ */ jsx2(File.Import, {
|
|
488
|
+
typeName && typePath && /* @__PURE__ */ jsx2(File.Import, { isTypeOnly: true, root, path: typePath, name: [typeName] })
|
|
504
489
|
] });
|
|
505
490
|
};
|
|
506
491
|
|
|
@@ -558,17 +543,17 @@ OperationSchema.File = function({}) {
|
|
|
558
543
|
});
|
|
559
544
|
const tree = generator.parse({ schema, name });
|
|
560
545
|
return /* @__PURE__ */ jsxs2(Oas4.Schema, { name, value: schema, tree, children: [
|
|
561
|
-
typeName && typePath && /* @__PURE__ */ jsx4(File2.Import, {
|
|
546
|
+
typeName && typePath && /* @__PURE__ */ jsx4(File2.Import, { isTypeOnly: true, root: file.path, path: typePath, name: [typeName] }),
|
|
562
547
|
plugin.options.dateParser && /* @__PURE__ */ jsx4(File2.Import, { path: plugin.options.dateParser, name: plugin.options.dateParser }),
|
|
563
|
-
mode === "split" && /* @__PURE__ */ jsx4(Oas4.Schema.Imports, {
|
|
564
|
-
/* @__PURE__ */ jsx4(
|
|
548
|
+
mode === "split" && /* @__PURE__ */ jsx4(Oas4.Schema.Imports, {}),
|
|
549
|
+
/* @__PURE__ */ jsx4(OperationSchema, { description })
|
|
565
550
|
] }, i);
|
|
566
551
|
};
|
|
567
|
-
return /* @__PURE__ */
|
|
552
|
+
return /* @__PURE__ */ jsxs2(File2, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
568
553
|
/* @__PURE__ */ jsx4(File2.Import, { name: ["faker"], path: "@faker-js/faker" }),
|
|
569
554
|
plugin.options.regexGenerator === "randexp" && /* @__PURE__ */ jsx4(File2.Import, { name: "RandExp", path: "randexp" }),
|
|
570
555
|
items.map(mapItem)
|
|
571
|
-
] })
|
|
556
|
+
] });
|
|
572
557
|
};
|
|
573
558
|
export {
|
|
574
559
|
OperationSchema,
|