@kubb/plugin-faker 3.16.2 → 3.16.3
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-BpyQzZAY.cjs +324 -0
- package/dist/components-BpyQzZAY.cjs.map +1 -0
- package/dist/components-BwSq4Ikw.js +290 -0
- package/dist/components-BwSq4Ikw.js.map +1 -0
- package/dist/components.cjs +2 -11
- package/dist/components.d.cts +24 -15
- package/dist/components.d.ts +24 -15
- package/dist/components.js +3 -3
- package/dist/fakerGenerator-CXR9ksYA.js +199 -0
- package/dist/fakerGenerator-CXR9ksYA.js.map +1 -0
- package/dist/fakerGenerator-S8sgrtl5.cjs +204 -0
- package/dist/fakerGenerator-S8sgrtl5.cjs.map +1 -0
- package/dist/generators.cjs +3 -12
- package/dist/generators.d.cts +5 -6
- package/dist/generators.d.ts +5 -6
- package/dist/generators.js +4 -4
- package/dist/index.cjs +96 -124
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -7
- package/dist/index.d.ts +6 -7
- package/dist/index.js +96 -118
- package/dist/index.js.map +1 -1
- package/dist/types-Bh_6SttY.d.cts +1214 -0
- package/dist/types-DYUKPbgH.d.ts +1214 -0
- package/package.json +22 -27
- package/src/generators/__snapshots__/pet.ts +1 -0
- package/src/generators/__snapshots__/petWithDateString.ts +1 -0
- package/src/generators/__snapshots__/petWithDayjs.ts +1 -0
- package/src/generators/__snapshots__/petWithMapper.ts +1 -0
- package/src/generators/__snapshots__/petWithRandExp.ts +1 -0
- package/src/parser.ts +12 -3
- package/dist/chunk-BQQKSGJ4.js +0 -370
- package/dist/chunk-BQQKSGJ4.js.map +0 -1
- package/dist/chunk-DP3UK3GA.js +0 -137
- package/dist/chunk-DP3UK3GA.js.map +0 -1
- package/dist/chunk-DUV3ZLQX.cjs +0 -139
- package/dist/chunk-DUV3ZLQX.cjs.map +0 -1
- package/dist/chunk-ZA3QHI3O.cjs +0 -376
- package/dist/chunk-ZA3QHI3O.cjs.map +0 -1
- package/dist/components.cjs.map +0 -1
- package/dist/components.js.map +0 -1
- package/dist/generators.cjs.map +0 -1
- package/dist/generators.js.map +0 -1
- package/dist/types-kyHdJ8oH.d.cts +0 -107
- package/dist/types-kyHdJ8oH.d.ts +0 -107
package/dist/generators.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { P as PluginFaker } from './types-kyHdJ8oH.js';
|
|
3
|
-
import '@kubb/core';
|
|
4
|
-
import '@kubb/oas';
|
|
5
|
-
|
|
6
|
-
declare const fakerGenerator: _kubb_plugin_oas.Generator<PluginFaker>;
|
|
1
|
+
import { Generator, PluginFaker } from "./types-DYUKPbgH.js";
|
|
7
2
|
|
|
3
|
+
//#region src/generators/fakerGenerator.d.ts
|
|
4
|
+
declare const fakerGenerator: Generator<PluginFaker>;
|
|
5
|
+
//#endregion
|
|
8
6
|
export { fakerGenerator };
|
|
7
|
+
//# sourceMappingURL=generators.d.ts.map
|
package/dist/generators.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import "./components-BwSq4Ikw.js";
|
|
2
|
+
import { fakerGenerator } from "./fakerGenerator-CXR9ksYA.js";
|
|
3
|
+
|
|
4
|
+
export { fakerGenerator };
|
package/dist/index.cjs
CHANGED
|
@@ -1,130 +1,102 @@
|
|
|
1
|
-
|
|
1
|
+
const require_components = require('./components-BpyQzZAY.cjs');
|
|
2
|
+
const require_fakerGenerator = require('./fakerGenerator-S8sgrtl5.cjs');
|
|
3
|
+
const node_path = require_components.__toESM(require("node:path"));
|
|
4
|
+
const __kubb_core = require_components.__toESM(require("@kubb/core"));
|
|
5
|
+
const __kubb_core_transformers = require_components.__toESM(require("@kubb/core/transformers"));
|
|
6
|
+
const __kubb_plugin_oas = require_components.__toESM(require("@kubb/plugin-oas"));
|
|
7
|
+
const __kubb_plugin_ts = require_components.__toESM(require("@kubb/plugin-ts"));
|
|
2
8
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
pluginManager: this.pluginManager,
|
|
92
|
-
plugin: this.plugin,
|
|
93
|
-
contentType,
|
|
94
|
-
include: void 0,
|
|
95
|
-
override,
|
|
96
|
-
mode,
|
|
97
|
-
output: output.path
|
|
98
|
-
});
|
|
99
|
-
const schemaFiles = await schemaGenerator.build(...generators);
|
|
100
|
-
await this.addFile(...schemaFiles);
|
|
101
|
-
const operationGenerator = new pluginOas.OperationGenerator(this.plugin.options, {
|
|
102
|
-
oas,
|
|
103
|
-
pluginManager: this.pluginManager,
|
|
104
|
-
plugin: this.plugin,
|
|
105
|
-
contentType,
|
|
106
|
-
exclude,
|
|
107
|
-
include,
|
|
108
|
-
override,
|
|
109
|
-
mode
|
|
110
|
-
});
|
|
111
|
-
const operationFiles = await operationGenerator.build(...generators);
|
|
112
|
-
await this.addFile(...operationFiles);
|
|
113
|
-
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
114
|
-
type: output.barrelType ?? "named",
|
|
115
|
-
root,
|
|
116
|
-
output,
|
|
117
|
-
meta: {
|
|
118
|
-
pluginKey: this.plugin.key
|
|
119
|
-
},
|
|
120
|
-
logger: this.logger
|
|
121
|
-
});
|
|
122
|
-
await this.addFile(...barrelFiles);
|
|
123
|
-
}
|
|
124
|
-
};
|
|
9
|
+
//#region src/plugin.ts
|
|
10
|
+
const pluginFakerName = "plugin-faker";
|
|
11
|
+
const pluginFaker = (0, __kubb_core.createPlugin)((options) => {
|
|
12
|
+
const { output = {
|
|
13
|
+
path: "mocks",
|
|
14
|
+
barrelType: "named"
|
|
15
|
+
}, seed, group, exclude = [], include, override = [], transformers = {}, mapper = {}, unknownType = "any", emptySchemaType = unknownType, dateType = "string", dateParser = "faker", generators = [require_fakerGenerator.fakerGenerator].filter(Boolean), regexGenerator = "faker", contentType } = options;
|
|
16
|
+
return {
|
|
17
|
+
name: pluginFakerName,
|
|
18
|
+
options: {
|
|
19
|
+
output,
|
|
20
|
+
transformers,
|
|
21
|
+
seed,
|
|
22
|
+
dateType,
|
|
23
|
+
unknownType,
|
|
24
|
+
emptySchemaType,
|
|
25
|
+
dateParser,
|
|
26
|
+
mapper,
|
|
27
|
+
override,
|
|
28
|
+
regexGenerator,
|
|
29
|
+
group
|
|
30
|
+
},
|
|
31
|
+
pre: [__kubb_plugin_oas.pluginOasName, __kubb_plugin_ts.pluginTsName],
|
|
32
|
+
resolvePath(baseName, pathMode, options$1) {
|
|
33
|
+
const root = node_path.default.resolve(this.config.root, this.config.output.path);
|
|
34
|
+
const mode = pathMode ?? __kubb_core.FileManager.getMode(node_path.default.resolve(root, output.path));
|
|
35
|
+
if (mode === "single")
|
|
36
|
+
/**
|
|
37
|
+
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
38
|
+
* Other plugins then need to call addOrAppend instead of just add from the fileManager class
|
|
39
|
+
*/
|
|
40
|
+
return node_path.default.resolve(root, output.path);
|
|
41
|
+
if (group && (options$1?.group?.path || options$1?.group?.tag)) {
|
|
42
|
+
const groupName = group?.name ? group.name : (ctx) => {
|
|
43
|
+
if (group?.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
44
|
+
return `${(0, __kubb_core_transformers.camelCase)(ctx.group)}Controller`;
|
|
45
|
+
};
|
|
46
|
+
return node_path.default.resolve(root, output.path, groupName({ group: group.type === "path" ? options$1.group.path : options$1.group.tag }), baseName);
|
|
47
|
+
}
|
|
48
|
+
return node_path.default.resolve(root, output.path, baseName);
|
|
49
|
+
},
|
|
50
|
+
resolveName(name, type) {
|
|
51
|
+
const resolvedName = (0, __kubb_core_transformers.camelCase)(name, {
|
|
52
|
+
prefix: type ? "create" : void 0,
|
|
53
|
+
isFile: type === "file"
|
|
54
|
+
});
|
|
55
|
+
if (type) return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
56
|
+
return resolvedName;
|
|
57
|
+
},
|
|
58
|
+
async buildStart() {
|
|
59
|
+
const [swaggerPlugin] = __kubb_core.PluginManager.getDependedPlugins(this.plugins, [__kubb_plugin_oas.pluginOasName]);
|
|
60
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
61
|
+
const root = node_path.default.resolve(this.config.root, this.config.output.path);
|
|
62
|
+
const mode = __kubb_core.FileManager.getMode(node_path.default.resolve(root, output.path));
|
|
63
|
+
const schemaGenerator = new __kubb_plugin_oas.SchemaGenerator(this.plugin.options, {
|
|
64
|
+
oas,
|
|
65
|
+
pluginManager: this.pluginManager,
|
|
66
|
+
plugin: this.plugin,
|
|
67
|
+
contentType,
|
|
68
|
+
include: void 0,
|
|
69
|
+
override,
|
|
70
|
+
mode,
|
|
71
|
+
output: output.path
|
|
72
|
+
});
|
|
73
|
+
const schemaFiles = await schemaGenerator.build(...generators);
|
|
74
|
+
await this.addFile(...schemaFiles);
|
|
75
|
+
const operationGenerator = new __kubb_plugin_oas.OperationGenerator(this.plugin.options, {
|
|
76
|
+
oas,
|
|
77
|
+
pluginManager: this.pluginManager,
|
|
78
|
+
plugin: this.plugin,
|
|
79
|
+
contentType,
|
|
80
|
+
exclude,
|
|
81
|
+
include,
|
|
82
|
+
override,
|
|
83
|
+
mode
|
|
84
|
+
});
|
|
85
|
+
const operationFiles = await operationGenerator.build(...generators);
|
|
86
|
+
await this.addFile(...operationFiles);
|
|
87
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
88
|
+
type: output.barrelType ?? "named",
|
|
89
|
+
root,
|
|
90
|
+
output,
|
|
91
|
+
meta: { pluginKey: this.plugin.key },
|
|
92
|
+
logger: this.logger
|
|
93
|
+
});
|
|
94
|
+
await this.addFile(...barrelFiles);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
125
97
|
});
|
|
126
98
|
|
|
99
|
+
//#endregion
|
|
127
100
|
exports.pluginFaker = pluginFaker;
|
|
128
101
|
exports.pluginFakerName = pluginFakerName;
|
|
129
|
-
//# sourceMappingURL=index.cjs.map
|
|
130
102
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["fakerGenerator","pluginOasName","pluginTsName","options","path","FileManager","groupName: Group['name']","PluginManager","SchemaGenerator","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport { fakerGenerator } from './generators/fakerGenerator.tsx'\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', barrelType: 'named' },\n seed,\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n mapper = {},\n unknownType = 'any',\n emptySchemaType = unknownType,\n dateType = 'string',\n dateParser = 'faker',\n generators = [fakerGenerator].filter(Boolean),\n regexGenerator = 'faker',\n contentType,\n } = options\n\n return {\n name: pluginFakerName,\n options: {\n output,\n transformers,\n seed,\n dateType,\n unknownType,\n emptySchemaType,\n dateParser,\n mapper,\n override,\n regexGenerator,\n group,\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 (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\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,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\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,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.addFile(...operationFiles)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;AAaA,MAAa,kBAAkB;AAE/B,MAAa,4CAAwC,CAAC,YAAY;CAChE,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;CAAS,GAC/C,MACA,OACA,UAAU,CAAE,GACZ,SACA,WAAW,CAAE,GACb,eAAe,CAAE,GACjB,SAAS,CAAE,GACX,cAAc,OACd,kBAAkB,aAClB,WAAW,UACX,aAAa,SACb,aAAa,CAACA,qCAAe,EAAC,OAAO,QAAQ,EAC7C,iBAAiB,SACjB,aACD,GAAG;AAEJ,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACD;EACD,KAAK,CAACC,iCAAeC,6BAAa;EAClC,YAAY,UAAU,UAA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,KAAK;IACb;IACA,SAAS;IACT;IACA;IACA,QAAQ,OAAO;GAChB;GAED,MAAM,cAAc,MAAM,gBAAgB,MAAM,GAAG,WAAW;GAC9D,MAAM,KAAK,QAAQ,GAAG,YAAY;GAElC,MAAM,qBAAqB,IAAIC,qCAAmB,KAAK,OAAO,SAAS;IACrE;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;GACD;GAED,MAAM,iBAAiB,MAAM,mBAAmB,MAAM,GAAG,WAAW;GACpE,MAAM,KAAK,QAAQ,GAAG,eAAe;GAErC,MAAM,cAAc,MAAM,KAAK,YAAY,eAAe;IACxD,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,IACxB;IACD,QAAQ,KAAK;GACd,EAAC;GAEF,MAAM,KAAK,QAAQ,GAAG,YAAY;EACnC;CACF;AACF,EAAC"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { O as Options, P as PluginFaker } from './types-kyHdJ8oH.cjs';
|
|
3
|
-
import '@kubb/oas';
|
|
4
|
-
import '@kubb/plugin-oas';
|
|
1
|
+
import { Options, PluginFaker, UserPluginWithLifeCycle } from "./types-Bh_6SttY.cjs";
|
|
5
2
|
|
|
3
|
+
//#region src/plugin.d.ts
|
|
6
4
|
declare const pluginFakerName = "plugin-faker";
|
|
7
|
-
declare const pluginFaker: (options?: Options | undefined) =>
|
|
8
|
-
|
|
9
|
-
export { PluginFaker, pluginFaker, pluginFakerName };
|
|
5
|
+
declare const pluginFaker: (options?: Options | undefined) => UserPluginWithLifeCycle<PluginFaker>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { type PluginFaker, pluginFaker, pluginFakerName };
|
|
8
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { O as Options, P as PluginFaker } from './types-kyHdJ8oH.js';
|
|
3
|
-
import '@kubb/oas';
|
|
4
|
-
import '@kubb/plugin-oas';
|
|
1
|
+
import { Options, PluginFaker, UserPluginWithLifeCycle } from "./types-DYUKPbgH.js";
|
|
5
2
|
|
|
3
|
+
//#region src/plugin.d.ts
|
|
6
4
|
declare const pluginFakerName = "plugin-faker";
|
|
7
|
-
declare const pluginFaker: (options?: Options | undefined) =>
|
|
8
|
-
|
|
9
|
-
export { PluginFaker, pluginFaker, pluginFakerName };
|
|
5
|
+
declare const pluginFaker: (options?: Options | undefined) => UserPluginWithLifeCycle<PluginFaker>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { type PluginFaker, pluginFaker, pluginFakerName };
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,123 +1,101 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import path from
|
|
4
|
-
import {
|
|
5
|
-
import { camelCase } from
|
|
6
|
-
import {
|
|
7
|
-
import { pluginTsName } from
|
|
1
|
+
import "./components-BwSq4Ikw.js";
|
|
2
|
+
import { fakerGenerator } from "./fakerGenerator-CXR9ksYA.js";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { FileManager, PluginManager, createPlugin } from "@kubb/core";
|
|
5
|
+
import { camelCase } from "@kubb/core/transformers";
|
|
6
|
+
import { OperationGenerator, SchemaGenerator, pluginOasName } from "@kubb/plugin-oas";
|
|
7
|
+
import { pluginTsName } from "@kubb/plugin-ts";
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
pluginManager: this.pluginManager,
|
|
98
|
-
plugin: this.plugin,
|
|
99
|
-
contentType,
|
|
100
|
-
exclude,
|
|
101
|
-
include,
|
|
102
|
-
override,
|
|
103
|
-
mode
|
|
104
|
-
});
|
|
105
|
-
const operationFiles = await operationGenerator.build(...generators);
|
|
106
|
-
await this.addFile(...operationFiles);
|
|
107
|
-
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
108
|
-
type: output.barrelType ?? "named",
|
|
109
|
-
root,
|
|
110
|
-
output,
|
|
111
|
-
meta: {
|
|
112
|
-
pluginKey: this.plugin.key
|
|
113
|
-
},
|
|
114
|
-
logger: this.logger
|
|
115
|
-
});
|
|
116
|
-
await this.addFile(...barrelFiles);
|
|
117
|
-
}
|
|
118
|
-
};
|
|
9
|
+
//#region src/plugin.ts
|
|
10
|
+
const pluginFakerName = "plugin-faker";
|
|
11
|
+
const pluginFaker = createPlugin((options) => {
|
|
12
|
+
const { output = {
|
|
13
|
+
path: "mocks",
|
|
14
|
+
barrelType: "named"
|
|
15
|
+
}, seed, group, exclude = [], include, override = [], transformers: transformers$1 = {}, mapper = {}, unknownType = "any", emptySchemaType = unknownType, dateType = "string", dateParser = "faker", generators = [fakerGenerator].filter(Boolean), regexGenerator = "faker", contentType } = options;
|
|
16
|
+
return {
|
|
17
|
+
name: pluginFakerName,
|
|
18
|
+
options: {
|
|
19
|
+
output,
|
|
20
|
+
transformers: transformers$1,
|
|
21
|
+
seed,
|
|
22
|
+
dateType,
|
|
23
|
+
unknownType,
|
|
24
|
+
emptySchemaType,
|
|
25
|
+
dateParser,
|
|
26
|
+
mapper,
|
|
27
|
+
override,
|
|
28
|
+
regexGenerator,
|
|
29
|
+
group
|
|
30
|
+
},
|
|
31
|
+
pre: [pluginOasName, pluginTsName],
|
|
32
|
+
resolvePath(baseName, pathMode, options$1) {
|
|
33
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
34
|
+
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
35
|
+
if (mode === "single")
|
|
36
|
+
/**
|
|
37
|
+
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
38
|
+
* Other plugins then need to call addOrAppend instead of just add from the fileManager class
|
|
39
|
+
*/
|
|
40
|
+
return path.resolve(root, output.path);
|
|
41
|
+
if (group && (options$1?.group?.path || options$1?.group?.tag)) {
|
|
42
|
+
const groupName = group?.name ? group.name : (ctx) => {
|
|
43
|
+
if (group?.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
44
|
+
return `${camelCase(ctx.group)}Controller`;
|
|
45
|
+
};
|
|
46
|
+
return path.resolve(root, output.path, groupName({ group: group.type === "path" ? options$1.group.path : options$1.group.tag }), baseName);
|
|
47
|
+
}
|
|
48
|
+
return path.resolve(root, output.path, baseName);
|
|
49
|
+
},
|
|
50
|
+
resolveName(name, type) {
|
|
51
|
+
const resolvedName = camelCase(name, {
|
|
52
|
+
prefix: type ? "create" : void 0,
|
|
53
|
+
isFile: type === "file"
|
|
54
|
+
});
|
|
55
|
+
if (type) return transformers$1?.name?.(resolvedName, type) || resolvedName;
|
|
56
|
+
return resolvedName;
|
|
57
|
+
},
|
|
58
|
+
async buildStart() {
|
|
59
|
+
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
60
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
61
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
62
|
+
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
63
|
+
const schemaGenerator = new SchemaGenerator(this.plugin.options, {
|
|
64
|
+
oas,
|
|
65
|
+
pluginManager: this.pluginManager,
|
|
66
|
+
plugin: this.plugin,
|
|
67
|
+
contentType,
|
|
68
|
+
include: void 0,
|
|
69
|
+
override,
|
|
70
|
+
mode,
|
|
71
|
+
output: output.path
|
|
72
|
+
});
|
|
73
|
+
const schemaFiles = await schemaGenerator.build(...generators);
|
|
74
|
+
await this.addFile(...schemaFiles);
|
|
75
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
76
|
+
oas,
|
|
77
|
+
pluginManager: this.pluginManager,
|
|
78
|
+
plugin: this.plugin,
|
|
79
|
+
contentType,
|
|
80
|
+
exclude,
|
|
81
|
+
include,
|
|
82
|
+
override,
|
|
83
|
+
mode
|
|
84
|
+
});
|
|
85
|
+
const operationFiles = await operationGenerator.build(...generators);
|
|
86
|
+
await this.addFile(...operationFiles);
|
|
87
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
88
|
+
type: output.barrelType ?? "named",
|
|
89
|
+
root,
|
|
90
|
+
output,
|
|
91
|
+
meta: { pluginKey: this.plugin.key },
|
|
92
|
+
logger: this.logger
|
|
93
|
+
});
|
|
94
|
+
await this.addFile(...barrelFiles);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
119
97
|
});
|
|
120
98
|
|
|
99
|
+
//#endregion
|
|
121
100
|
export { pluginFaker, pluginFakerName };
|
|
122
|
-
//# sourceMappingURL=index.js.map
|
|
123
101
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["options","groupName: Group['name']","transformers"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport { fakerGenerator } from './generators/fakerGenerator.tsx'\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', barrelType: 'named' },\n seed,\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n mapper = {},\n unknownType = 'any',\n emptySchemaType = unknownType,\n dateType = 'string',\n dateParser = 'faker',\n generators = [fakerGenerator].filter(Boolean),\n regexGenerator = 'faker',\n contentType,\n } = options\n\n return {\n name: pluginFakerName,\n options: {\n output,\n transformers,\n seed,\n dateType,\n unknownType,\n emptySchemaType,\n dateParser,\n mapper,\n override,\n regexGenerator,\n group,\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 (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\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,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\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,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.addFile(...operationFiles)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;AAaA,MAAa,kBAAkB;AAE/B,MAAa,cAAc,aAA0B,CAAC,YAAY;CAChE,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;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