@kubb/plugin-faker 5.0.0-alpha.1 → 5.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components.d.ts +1 -1
- package/dist/{fakerGenerator-Nu5PFwS9.cjs → fakerGenerator-CYUCNH3Q.cjs} +10 -10
- package/dist/fakerGenerator-CYUCNH3Q.cjs.map +1 -0
- package/dist/{fakerGenerator-BztogaeO.js → fakerGenerator-M5oCrPmy.js} +11 -11
- package/dist/fakerGenerator-M5oCrPmy.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +55 -47
- package/dist/generators.js +1 -1
- package/dist/index.cjs +5 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/{types-WKLWEptG.d.ts → types-r7BubMLO.d.ts} +3 -3
- package/package.json +6 -6
- package/src/generators/fakerGenerator.tsx +10 -10
- package/src/plugin.ts +5 -5
- package/dist/fakerGenerator-BztogaeO.js.map +0 -1
- package/dist/fakerGenerator-Nu5PFwS9.cjs.map +0 -1
package/dist/components.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { n as PluginFaker } from "./types-
|
|
2
|
+
import { n as PluginFaker } from "./types-r7BubMLO.js";
|
|
3
3
|
import { Schema } from "@kubb/plugin-oas";
|
|
4
4
|
import { FabricReactNode } from "@kubb/react-fabric/types";
|
|
5
5
|
|
|
@@ -13,7 +13,7 @@ const fakerGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
13
13
|
Operation({ operation, generator, plugin }) {
|
|
14
14
|
const { options, options: { dateParser, regexGenerator, seed, mapper } } = plugin;
|
|
15
15
|
const mode = (0, _kubb_core_hooks.useMode)();
|
|
16
|
-
const
|
|
16
|
+
const driver = (0, _kubb_core_hooks.usePluginDriver)();
|
|
17
17
|
const oas = (0, _kubb_plugin_oas_hooks.useOas)();
|
|
18
18
|
const { getSchemas, getFile, getGroup } = (0, _kubb_plugin_oas_hooks.useOperationManager)(generator);
|
|
19
19
|
const schemaManager = (0, _kubb_plugin_oas_hooks.useSchemaManager)();
|
|
@@ -24,7 +24,7 @@ const fakerGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
24
24
|
oas,
|
|
25
25
|
plugin,
|
|
26
26
|
events: generator.context.events,
|
|
27
|
-
|
|
27
|
+
driver,
|
|
28
28
|
mode,
|
|
29
29
|
override: options.override
|
|
30
30
|
});
|
|
@@ -52,10 +52,10 @@ const fakerGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
52
52
|
const type = {
|
|
53
53
|
name: schemaManager.getName(name, {
|
|
54
54
|
type: "type",
|
|
55
|
-
|
|
55
|
+
pluginName: _kubb_plugin_ts.pluginTsName
|
|
56
56
|
}),
|
|
57
57
|
file: schemaManager.getFile(options.operationName || name, {
|
|
58
|
-
|
|
58
|
+
pluginName: _kubb_plugin_ts.pluginTsName,
|
|
59
59
|
group
|
|
60
60
|
})
|
|
61
61
|
};
|
|
@@ -96,7 +96,7 @@ const fakerGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
96
96
|
banner: (0, _kubb_plugin_oas_utils.getBanner)({
|
|
97
97
|
oas,
|
|
98
98
|
output: plugin.options.output,
|
|
99
|
-
config:
|
|
99
|
+
config: driver.config
|
|
100
100
|
}),
|
|
101
101
|
footer: (0, _kubb_plugin_oas_utils.getFooter)({
|
|
102
102
|
oas,
|
|
@@ -122,7 +122,7 @@ const fakerGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
122
122
|
Schema({ schema, plugin }) {
|
|
123
123
|
const { getName, getFile } = (0, _kubb_plugin_oas_hooks.useSchemaManager)();
|
|
124
124
|
const { options: { output, dateParser, regexGenerator, seed, mapper } } = plugin;
|
|
125
|
-
const
|
|
125
|
+
const driver = (0, _kubb_core_hooks.usePluginDriver)();
|
|
126
126
|
const oas = (0, _kubb_plugin_oas_hooks.useOas)();
|
|
127
127
|
const imports = (0, _kubb_plugin_oas_utils.getImports)(schema.tree);
|
|
128
128
|
const faker = {
|
|
@@ -132,9 +132,9 @@ const fakerGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
132
132
|
const type = {
|
|
133
133
|
name: getName(schema.name, {
|
|
134
134
|
type: "type",
|
|
135
|
-
|
|
135
|
+
pluginName: _kubb_plugin_ts.pluginTsName
|
|
136
136
|
}),
|
|
137
|
-
file: getFile(schema.name, {
|
|
137
|
+
file: getFile(schema.name, { pluginName: _kubb_plugin_ts.pluginTsName })
|
|
138
138
|
};
|
|
139
139
|
const canOverride = schema.tree.some(({ keyword }) => keyword === _kubb_plugin_oas.schemaKeywords.array || keyword === _kubb_plugin_oas.schemaKeywords.and || keyword === _kubb_plugin_oas.schemaKeywords.object || keyword === _kubb_plugin_oas.schemaKeywords.union || keyword === _kubb_plugin_oas.schemaKeywords.tuple || keyword === _kubb_plugin_oas.schemaKeywords.ref || keyword === _kubb_plugin_oas.schemaKeywords.enum || keyword === _kubb_plugin_oas.schemaKeywords.string || keyword === _kubb_plugin_oas.schemaKeywords.integer || keyword === _kubb_plugin_oas.schemaKeywords.number);
|
|
140
140
|
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
|
|
@@ -144,7 +144,7 @@ const fakerGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
144
144
|
banner: (0, _kubb_plugin_oas_utils.getBanner)({
|
|
145
145
|
oas,
|
|
146
146
|
output,
|
|
147
|
-
config:
|
|
147
|
+
config: driver.config
|
|
148
148
|
}),
|
|
149
149
|
footer: (0, _kubb_plugin_oas_utils.getFooter)({
|
|
150
150
|
oas,
|
|
@@ -201,4 +201,4 @@ Object.defineProperty(exports, "fakerGenerator", {
|
|
|
201
201
|
}
|
|
202
202
|
});
|
|
203
203
|
|
|
204
|
-
//# sourceMappingURL=fakerGenerator-
|
|
204
|
+
//# sourceMappingURL=fakerGenerator-CYUCNH3Q.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fakerGenerator-CYUCNH3Q.cjs","names":["SchemaGenerator","pluginTsName","schemaKeywords","File","Faker"],"sources":["../src/generators/fakerGenerator.tsx"],"sourcesContent":["import { useMode, usePluginDriver } from '@kubb/core/hooks'\nimport { type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { applyParamsCasing, getBanner, getFooter, getImports, isParameterSchema } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } from '@kubb/react-fabric'\nimport { Faker } from '../components'\nimport type { PluginFaker } from '../types'\n\nexport const fakerGenerator = createReactGenerator<PluginFaker>({\n name: 'faker',\n Operation({ operation, generator, plugin }) {\n const {\n options,\n options: { dateParser, regexGenerator, seed, mapper },\n } = plugin\n const mode = useMode()\n const driver = usePluginDriver()\n\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = useOperationManager(generator)\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n fabric: generator.context.fabric,\n oas,\n plugin,\n events: generator.context.events,\n driver,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter((x): x is OperationSchemaType => Boolean(x))\n\n const mapOperationSchema = ({ name, schema, description, ...options }: OperationSchemaType) => {\n // Apply paramsCasing transformation if enabled and this is a parameter schema\n const shouldTransform = isParameterSchema(name) && plugin.options.paramsCasing\n const transformedSchema = shouldTransform ? applyParamsCasing(schema, plugin.options.paramsCasing) : schema\n\n const tree = schemaGenerator.parse({ schema: transformedSchema, name, parentName: null })\n const imports = getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const faker = {\n name: schemaManager.getName(name, { type: 'function' }),\n file: schemaManager.getFile(name),\n }\n\n const type = {\n name: schemaManager.getName(name, { type: 'type', pluginName: pluginTsName }),\n file: schemaManager.getFile(options.operationName || name, { pluginName: pluginTsName, group }),\n }\n\n const canOverride = tree.some(\n ({ keyword }) =>\n keyword === schemaKeywords.array ||\n keyword === schemaKeywords.and ||\n keyword === schemaKeywords.object ||\n keyword === schemaKeywords.union ||\n keyword === schemaKeywords.tuple ||\n keyword === schemaKeywords.enum ||\n keyword === schemaKeywords.ref,\n )\n\n return (\n <>\n {canOverride && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} />\n ))}\n <Faker\n name={faker.name}\n typeName={type.name}\n description={description}\n tree={tree}\n regexGenerator={regexGenerator}\n dateParser={dateParser}\n mapper={mapper}\n seed={seed}\n canOverride={canOverride}\n />\n </>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: driver.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n <File.Import name={['faker']} path=\"@faker-js/faker\" />\n {regexGenerator === 'randexp' && <File.Import name={'RandExp'} path={'randexp'} />}\n {dateParser !== 'faker' && <File.Import path={dateParser} name={dateParser} />}\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ schema, plugin }) {\n const { getName, getFile } = useSchemaManager()\n const {\n options: { output, dateParser, regexGenerator, seed, mapper },\n } = plugin\n const driver = usePluginDriver()\n const oas = useOas()\n const imports = getImports(schema.tree)\n\n const faker = {\n name: getName(schema.name, { type: 'function' }),\n file: getFile(schema.name),\n }\n\n const type = {\n name: getName(schema.name, { type: 'type', pluginName: pluginTsName }),\n file: getFile(schema.name, { pluginName: pluginTsName }),\n }\n\n const canOverride = schema.tree.some(\n ({ keyword }) =>\n keyword === schemaKeywords.array ||\n keyword === schemaKeywords.and ||\n keyword === schemaKeywords.object ||\n keyword === schemaKeywords.union ||\n keyword === schemaKeywords.tuple ||\n keyword === schemaKeywords.ref ||\n keyword === schemaKeywords.enum ||\n keyword === schemaKeywords.string ||\n keyword === schemaKeywords.integer ||\n keyword === schemaKeywords.number,\n )\n\n return (\n <File\n baseName={faker.file.baseName}\n path={faker.file.path}\n meta={faker.file.meta}\n banner={getBanner({ oas, output, config: driver.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['faker']} path=\"@faker-js/faker\" />\n {regexGenerator === 'randexp' && <File.Import name={'RandExp'} path={'randexp'} />}\n {dateParser !== 'faker' && <File.Import path={dateParser} name={dateParser} />}\n <File.Import isTypeOnly root={faker.file.path} path={type.file.path} name={[type.name]} />\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={faker.file.path} path={imp.path} name={imp.name} />\n ))}\n\n <Faker\n name={faker.name}\n typeName={type.name}\n description={schema.value.description}\n tree={schema.tree}\n regexGenerator={regexGenerator}\n dateParser={dateParser}\n mapper={mapper}\n seed={seed}\n canOverride={canOverride}\n />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;AAUA,MAAa,kBAAA,GAAA,4BAAA,sBAAmD;CAC9D,MAAM;CACN,UAAU,EAAE,WAAW,WAAW,UAAU;EAC1C,MAAM,EACJ,SACA,SAAS,EAAE,YAAY,gBAAgB,MAAM,aAC3C;EACJ,MAAM,QAAA,GAAA,iBAAA,UAAgB;EACtB,MAAM,UAAA,GAAA,iBAAA,kBAA0B;EAEhC,MAAM,OAAA,GAAA,uBAAA,SAAc;EACpB,MAAM,EAAE,YAAY,SAAS,cAAA,GAAA,uBAAA,qBAAiC,UAAU;EACxE,MAAM,iBAA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+BAAA,KAACA,mBAAAA,KAAK,QAAN;KAAa,MAAM,CAAC,QAAQ;KAAE,MAAK;KAAoB,CAAA;IACtD,mBAAmB,aAAa,iBAAA,GAAA,+BAAA,KAACA,mBAAAA,KAAK,QAAN;KAAa,MAAM;KAAW,MAAM;KAAa,CAAA;IACjF,eAAe,WAAW,iBAAA,GAAA,+BAAA,KAACA,mBAAAA,KAAK,QAAN;KAAa,MAAM;KAAY,MAAM;KAAc,CAAA;IAC9E,iBAAA,GAAA,+BAAA,KAACA,mBAAAA,KAAK,QAAN;KAAa,YAAA;KAAW,MAAM,MAAM,KAAK;KAAM,MAAM,KAAK,KAAK;KAAM,MAAM,CAAC,KAAK,KAAK;KAAI,CAAA;IACzF,QAAQ,KAAK,QACZ,iBAAA,GAAA,+BAAA,KAACA,mBAAAA,KAAK,QAAN;KAAkE,MAAM,MAAM,KAAK;KAAM,MAAM,IAAI;KAAM,MAAM,IAAI;KAAQ,EAAzG;KAAC,IAAI;KAAM,IAAI;KAAM,IAAI;KAAW,CAAC,KAAK,IAAI,CAA2D,CAC3H;IAEF,iBAAA,GAAA,+BAAA,KAACC,mBAAAA,OAAD;KACE,MAAM,MAAM;KACZ,UAAU,KAAK;KACf,aAAa,OAAO,MAAM;KAC1B,MAAM,OAAO;KACG;KACJ;KACJ;KACF;KACO;KACb,CAAA;IACG;;;CAGZ,CAAC"}
|
|
@@ -2,7 +2,7 @@ import "./chunk--u3MIqq1.js";
|
|
|
2
2
|
import { t as Faker } from "./components-BkBIov4R.js";
|
|
3
3
|
import { SchemaGenerator, schemaKeywords } from "@kubb/plugin-oas";
|
|
4
4
|
import { pluginTsName } from "@kubb/plugin-ts";
|
|
5
|
-
import { useMode,
|
|
5
|
+
import { useMode, usePluginDriver } from "@kubb/core/hooks";
|
|
6
6
|
import { createReactGenerator } from "@kubb/plugin-oas/generators";
|
|
7
7
|
import { useOas, useOperationManager, useSchemaManager } from "@kubb/plugin-oas/hooks";
|
|
8
8
|
import { applyParamsCasing, getBanner, getFooter, getImports, isParameterSchema } from "@kubb/plugin-oas/utils";
|
|
@@ -14,7 +14,7 @@ const fakerGenerator = createReactGenerator({
|
|
|
14
14
|
Operation({ operation, generator, plugin }) {
|
|
15
15
|
const { options, options: { dateParser, regexGenerator, seed, mapper } } = plugin;
|
|
16
16
|
const mode = useMode();
|
|
17
|
-
const
|
|
17
|
+
const driver = usePluginDriver();
|
|
18
18
|
const oas = useOas();
|
|
19
19
|
const { getSchemas, getFile, getGroup } = useOperationManager(generator);
|
|
20
20
|
const schemaManager = useSchemaManager();
|
|
@@ -25,7 +25,7 @@ const fakerGenerator = createReactGenerator({
|
|
|
25
25
|
oas,
|
|
26
26
|
plugin,
|
|
27
27
|
events: generator.context.events,
|
|
28
|
-
|
|
28
|
+
driver,
|
|
29
29
|
mode,
|
|
30
30
|
override: options.override
|
|
31
31
|
});
|
|
@@ -53,10 +53,10 @@ const fakerGenerator = createReactGenerator({
|
|
|
53
53
|
const type = {
|
|
54
54
|
name: schemaManager.getName(name, {
|
|
55
55
|
type: "type",
|
|
56
|
-
|
|
56
|
+
pluginName: pluginTsName
|
|
57
57
|
}),
|
|
58
58
|
file: schemaManager.getFile(options.operationName || name, {
|
|
59
|
-
|
|
59
|
+
pluginName: pluginTsName,
|
|
60
60
|
group
|
|
61
61
|
})
|
|
62
62
|
};
|
|
@@ -97,7 +97,7 @@ const fakerGenerator = createReactGenerator({
|
|
|
97
97
|
banner: getBanner({
|
|
98
98
|
oas,
|
|
99
99
|
output: plugin.options.output,
|
|
100
|
-
config:
|
|
100
|
+
config: driver.config
|
|
101
101
|
}),
|
|
102
102
|
footer: getFooter({
|
|
103
103
|
oas,
|
|
@@ -123,7 +123,7 @@ const fakerGenerator = createReactGenerator({
|
|
|
123
123
|
Schema({ schema, plugin }) {
|
|
124
124
|
const { getName, getFile } = useSchemaManager();
|
|
125
125
|
const { options: { output, dateParser, regexGenerator, seed, mapper } } = plugin;
|
|
126
|
-
const
|
|
126
|
+
const driver = usePluginDriver();
|
|
127
127
|
const oas = useOas();
|
|
128
128
|
const imports = getImports(schema.tree);
|
|
129
129
|
const faker = {
|
|
@@ -133,9 +133,9 @@ const fakerGenerator = createReactGenerator({
|
|
|
133
133
|
const type = {
|
|
134
134
|
name: getName(schema.name, {
|
|
135
135
|
type: "type",
|
|
136
|
-
|
|
136
|
+
pluginName: pluginTsName
|
|
137
137
|
}),
|
|
138
|
-
file: getFile(schema.name, {
|
|
138
|
+
file: getFile(schema.name, { pluginName: pluginTsName })
|
|
139
139
|
};
|
|
140
140
|
const canOverride = schema.tree.some(({ keyword }) => keyword === schemaKeywords.array || keyword === schemaKeywords.and || keyword === schemaKeywords.object || keyword === schemaKeywords.union || keyword === schemaKeywords.tuple || keyword === schemaKeywords.ref || keyword === schemaKeywords.enum || keyword === schemaKeywords.string || keyword === schemaKeywords.integer || keyword === schemaKeywords.number);
|
|
141
141
|
return /* @__PURE__ */ jsxs(File, {
|
|
@@ -145,7 +145,7 @@ const fakerGenerator = createReactGenerator({
|
|
|
145
145
|
banner: getBanner({
|
|
146
146
|
oas,
|
|
147
147
|
output,
|
|
148
|
-
config:
|
|
148
|
+
config: driver.config
|
|
149
149
|
}),
|
|
150
150
|
footer: getFooter({
|
|
151
151
|
oas,
|
|
@@ -197,4 +197,4 @@ const fakerGenerator = createReactGenerator({
|
|
|
197
197
|
//#endregion
|
|
198
198
|
export { fakerGenerator as t };
|
|
199
199
|
|
|
200
|
-
//# sourceMappingURL=fakerGenerator-
|
|
200
|
+
//# sourceMappingURL=fakerGenerator-M5oCrPmy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fakerGenerator-M5oCrPmy.js","names":[],"sources":["../src/generators/fakerGenerator.tsx"],"sourcesContent":["import { useMode, usePluginDriver } from '@kubb/core/hooks'\nimport { type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { applyParamsCasing, getBanner, getFooter, getImports, isParameterSchema } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } from '@kubb/react-fabric'\nimport { Faker } from '../components'\nimport type { PluginFaker } from '../types'\n\nexport const fakerGenerator = createReactGenerator<PluginFaker>({\n name: 'faker',\n Operation({ operation, generator, plugin }) {\n const {\n options,\n options: { dateParser, regexGenerator, seed, mapper },\n } = plugin\n const mode = useMode()\n const driver = usePluginDriver()\n\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = useOperationManager(generator)\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n fabric: generator.context.fabric,\n oas,\n plugin,\n events: generator.context.events,\n driver,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter((x): x is OperationSchemaType => Boolean(x))\n\n const mapOperationSchema = ({ name, schema, description, ...options }: OperationSchemaType) => {\n // Apply paramsCasing transformation if enabled and this is a parameter schema\n const shouldTransform = isParameterSchema(name) && plugin.options.paramsCasing\n const transformedSchema = shouldTransform ? applyParamsCasing(schema, plugin.options.paramsCasing) : schema\n\n const tree = schemaGenerator.parse({ schema: transformedSchema, name, parentName: null })\n const imports = getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const faker = {\n name: schemaManager.getName(name, { type: 'function' }),\n file: schemaManager.getFile(name),\n }\n\n const type = {\n name: schemaManager.getName(name, { type: 'type', pluginName: pluginTsName }),\n file: schemaManager.getFile(options.operationName || name, { pluginName: pluginTsName, group }),\n }\n\n const canOverride = tree.some(\n ({ keyword }) =>\n keyword === schemaKeywords.array ||\n keyword === schemaKeywords.and ||\n keyword === schemaKeywords.object ||\n keyword === schemaKeywords.union ||\n keyword === schemaKeywords.tuple ||\n keyword === schemaKeywords.enum ||\n keyword === schemaKeywords.ref,\n )\n\n return (\n <>\n {canOverride && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} />\n ))}\n <Faker\n name={faker.name}\n typeName={type.name}\n description={description}\n tree={tree}\n regexGenerator={regexGenerator}\n dateParser={dateParser}\n mapper={mapper}\n seed={seed}\n canOverride={canOverride}\n />\n </>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: driver.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n <File.Import name={['faker']} path=\"@faker-js/faker\" />\n {regexGenerator === 'randexp' && <File.Import name={'RandExp'} path={'randexp'} />}\n {dateParser !== 'faker' && <File.Import path={dateParser} name={dateParser} />}\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ schema, plugin }) {\n const { getName, getFile } = useSchemaManager()\n const {\n options: { output, dateParser, regexGenerator, seed, mapper },\n } = plugin\n const driver = usePluginDriver()\n const oas = useOas()\n const imports = getImports(schema.tree)\n\n const faker = {\n name: getName(schema.name, { type: 'function' }),\n file: getFile(schema.name),\n }\n\n const type = {\n name: getName(schema.name, { type: 'type', pluginName: pluginTsName }),\n file: getFile(schema.name, { pluginName: pluginTsName }),\n }\n\n const canOverride = schema.tree.some(\n ({ keyword }) =>\n keyword === schemaKeywords.array ||\n keyword === schemaKeywords.and ||\n keyword === schemaKeywords.object ||\n keyword === schemaKeywords.union ||\n keyword === schemaKeywords.tuple ||\n keyword === schemaKeywords.ref ||\n keyword === schemaKeywords.enum ||\n keyword === schemaKeywords.string ||\n keyword === schemaKeywords.integer ||\n keyword === schemaKeywords.number,\n )\n\n return (\n <File\n baseName={faker.file.baseName}\n path={faker.file.path}\n meta={faker.file.meta}\n banner={getBanner({ oas, output, config: driver.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['faker']} path=\"@faker-js/faker\" />\n {regexGenerator === 'randexp' && <File.Import name={'RandExp'} path={'randexp'} />}\n {dateParser !== 'faker' && <File.Import path={dateParser} name={dateParser} />}\n <File.Import isTypeOnly root={faker.file.path} path={type.file.path} name={[type.name]} />\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={faker.file.path} path={imp.path} name={imp.name} />\n ))}\n\n <Faker\n name={faker.name}\n typeName={type.name}\n description={schema.value.description}\n tree={schema.tree}\n regexGenerator={regexGenerator}\n dateParser={dateParser}\n mapper={mapper}\n seed={seed}\n canOverride={canOverride}\n />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;AAUA,MAAa,iBAAiB,qBAAkC;CAC9D,MAAM;CACN,UAAU,EAAE,WAAW,WAAW,UAAU;EAC1C,MAAM,EACJ,SACA,SAAS,EAAE,YAAY,gBAAgB,MAAM,aAC3C;EACJ,MAAM,OAAO,SAAS;EACtB,MAAM,SAAS,iBAAiB;EAEhC,MAAM,MAAM,QAAQ;EACpB,MAAM,EAAE,YAAY,SAAS,aAAa,oBAAoB,UAAU;EACxE,MAAM,gBAAgB,kBAAkB;EAExC,MAAM,OAAO,QAAQ,UAAU;EAC/B,MAAM,UAAU,WAAW,UAAU;EACrC,MAAM,kBAAkB,IAAI,gBAAgB,SAAS;GACnD,QAAQ,UAAU,QAAQ;GAC1B;GACA;GACA,QAAQ,UAAU,QAAQ;GAC1B;GACA;GACA,UAAU,QAAQ;GACnB,CAAC;EAEF,MAAM,mBAAmB;GAAC,QAAQ;GAAY,QAAQ;GAAa,QAAQ;GAAc,QAAQ;GAAa,QAAQ;GAAS,QAAQ;GAAS,CAC7I,MAAM,CACN,QAAQ,MAAgC,QAAQ,EAAE,CAAC;EAEtD,MAAM,sBAAsB,EAAE,MAAM,QAAQ,aAAa,GAAG,cAAmC;GAG7F,MAAM,oBADkB,kBAAkB,KAAK,IAAI,OAAO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,QAAQ,UAAU;IAAE;IAAK;IAAQ,QAAQ,OAAO;IAAQ,CAAC;GACzD,QAAQ,UAAU;IAAE;IAAK;IAAQ,CAAC;aALpC;IAOE,oBAAC,KAAK,QAAN;KAAa,MAAM,CAAC,QAAQ;KAAE,MAAK;KAAoB,CAAA;IACtD,mBAAmB,aAAa,oBAAC,KAAK,QAAN;KAAa,MAAM;KAAW,MAAM;KAAa,CAAA;IACjF,eAAe,WAAW,oBAAC,KAAK,QAAN;KAAa,MAAM;KAAY,MAAM;KAAc,CAAA;IAC9E,oBAAC,KAAK,QAAN;KAAa,YAAA;KAAW,MAAM,MAAM,KAAK;KAAM,MAAM,KAAK,KAAK;KAAM,MAAM,CAAC,KAAK,KAAK;KAAI,CAAA;IACzF,QAAQ,KAAK,QACZ,oBAAC,KAAK,QAAN;KAAkE,MAAM,MAAM,KAAK;KAAM,MAAM,IAAI;KAAM,MAAM,IAAI;KAAQ,EAAzG;KAAC,IAAI;KAAM,IAAI;KAAM,IAAI;KAAW,CAAC,KAAK,IAAI,CAA2D,CAC3H;IAEF,oBAAC,OAAD;KACE,MAAM,MAAM;KACZ,UAAU,KAAK;KACf,aAAa,OAAO,MAAM;KAC1B,MAAM,OAAO;KACG;KACJ;KACJ;KACF;KACO;KACb,CAAA;IACG;;;CAGZ,CAAC"}
|
package/dist/generators.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_fakerGenerator = require("./fakerGenerator-
|
|
2
|
+
const require_fakerGenerator = require("./fakerGenerator-CYUCNH3Q.cjs");
|
|
3
3
|
exports.fakerGenerator = require_fakerGenerator.fakerGenerator;
|
package/dist/generators.d.ts
CHANGED
|
@@ -1,12 +1,39 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { n as PluginFaker } from "./types-
|
|
3
|
-
import {
|
|
4
|
-
import { Fabric } from "@kubb/react-fabric";
|
|
2
|
+
import { n as PluginFaker } from "./types-r7BubMLO.js";
|
|
3
|
+
import { Config, FileMetaBase, Generator, Group, KubbEvents, Output, Plugin, PluginDriver, PluginFactoryOptions, ResolveNameParams } from "@kubb/core";
|
|
5
4
|
import { FabricReactNode } from "@kubb/react-fabric/types";
|
|
6
5
|
import { HttpMethod, Oas, Operation, SchemaObject, contentType } from "@kubb/oas";
|
|
7
|
-
import {
|
|
8
|
-
import { KubbFile } from "@kubb/fabric-core/types";
|
|
6
|
+
import { Fabric, KubbFile } from "@kubb/fabric-core/types";
|
|
9
7
|
|
|
8
|
+
//#region ../../internals/utils/src/asyncEventEmitter.d.ts
|
|
9
|
+
/** A function that can be registered as an event listener, synchronous or async. */
|
|
10
|
+
type AsyncListener<TArgs extends unknown[]> = (...args: TArgs) => void | Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* A typed EventEmitter that awaits all async listeners before resolving.
|
|
13
|
+
* Wraps Node's `EventEmitter` with full TypeScript event-map inference.
|
|
14
|
+
*/
|
|
15
|
+
declare class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[] }> {
|
|
16
|
+
#private;
|
|
17
|
+
/**
|
|
18
|
+
* `maxListener` controls the maximum number of listeners per event before Node emits a memory-leak warning.
|
|
19
|
+
* @default 10
|
|
20
|
+
*/
|
|
21
|
+
constructor(maxListener?: number);
|
|
22
|
+
/**
|
|
23
|
+
* Emits an event and awaits all registered listeners in parallel.
|
|
24
|
+
* Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.
|
|
25
|
+
*/
|
|
26
|
+
emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void>;
|
|
27
|
+
/** Registers a persistent listener for the given event. */
|
|
28
|
+
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
29
|
+
/** Registers a one-shot listener that removes itself after the first invocation. */
|
|
30
|
+
onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
31
|
+
/** Removes a previously registered listener. */
|
|
32
|
+
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
33
|
+
/** Removes all listeners from every event channel. */
|
|
34
|
+
removeAll(): void;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
10
37
|
//#region ../plugin-oas/src/types.d.ts
|
|
11
38
|
type GetOasOptions = {
|
|
12
39
|
validate?: boolean;
|
|
@@ -26,14 +53,14 @@ declare global {
|
|
|
26
53
|
*
|
|
27
54
|
* `originalName` is the original name used(in PascalCase), only used to remove duplicates
|
|
28
55
|
*
|
|
29
|
-
* `
|
|
56
|
+
* `pluginName` can be used to override the current plugin being used, handy when you want to import a type/schema out of another plugin
|
|
30
57
|
* @example import a type(plugin-ts) for a mock file(swagger-faker)
|
|
31
58
|
*/
|
|
32
59
|
type Ref = {
|
|
33
60
|
propertyName: string;
|
|
34
61
|
originalName: string;
|
|
35
62
|
path: KubbFile.Path;
|
|
36
|
-
|
|
63
|
+
pluginName?: string;
|
|
37
64
|
};
|
|
38
65
|
type Refs = Record<string, Ref>;
|
|
39
66
|
type OperationSchema = {
|
|
@@ -93,8 +120,8 @@ type ByContentType = {
|
|
|
93
120
|
type: 'contentType';
|
|
94
121
|
pattern: string | RegExp;
|
|
95
122
|
};
|
|
96
|
-
type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
|
|
97
|
-
type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
|
|
123
|
+
type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
|
|
124
|
+
type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
|
|
98
125
|
type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
|
|
99
126
|
options: Partial<TOptions>;
|
|
100
127
|
};
|
|
@@ -107,7 +134,7 @@ type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
|
107
134
|
include: Array<Include> | undefined;
|
|
108
135
|
override: Array<Override<TOptions>> | undefined;
|
|
109
136
|
contentType: contentType | undefined;
|
|
110
|
-
|
|
137
|
+
driver: PluginDriver;
|
|
111
138
|
events?: AsyncEventEmitter<KubbEvents>;
|
|
112
139
|
/**
|
|
113
140
|
* Current plugin
|
|
@@ -133,7 +160,7 @@ declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = P
|
|
|
133
160
|
method: HttpMethod;
|
|
134
161
|
operation: Operation;
|
|
135
162
|
}>>;
|
|
136
|
-
build(...generators: Array<Generator<TPluginOptions
|
|
163
|
+
build(...generators: Array<Generator$1<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
|
|
137
164
|
}
|
|
138
165
|
//#endregion
|
|
139
166
|
//#region ../plugin-oas/src/SchemaMapper.d.ts
|
|
@@ -361,7 +388,7 @@ type Schema = {
|
|
|
361
388
|
type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
362
389
|
fabric: Fabric;
|
|
363
390
|
oas: Oas;
|
|
364
|
-
|
|
391
|
+
driver: PluginDriver;
|
|
365
392
|
events?: AsyncEventEmitter<KubbEvents>;
|
|
366
393
|
/**
|
|
367
394
|
* Current plugin
|
|
@@ -423,46 +450,33 @@ declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGe
|
|
|
423
450
|
static deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]>;
|
|
424
451
|
static find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
|
|
425
452
|
static combineObjects(tree: Schema[] | undefined): Schema[];
|
|
426
|
-
build(...generators: Array<Generator<TPluginOptions
|
|
453
|
+
build(...generators: Array<Generator$1<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
|
|
427
454
|
}
|
|
428
455
|
//#endregion
|
|
429
456
|
//#region ../plugin-oas/src/generators/createGenerator.d.ts
|
|
430
|
-
type CoreGenerator<TOptions extends PluginFactoryOptions
|
|
457
|
+
type CoreGenerator<TOptions extends PluginFactoryOptions> = {
|
|
431
458
|
name: string;
|
|
432
459
|
type: 'core';
|
|
433
|
-
version:
|
|
434
|
-
operations: (props: OperationsProps<TOptions
|
|
435
|
-
operation: (props: OperationProps<TOptions
|
|
436
|
-
schema: (props: SchemaProps<TOptions
|
|
460
|
+
version: '1';
|
|
461
|
+
operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
462
|
+
operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
463
|
+
schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
437
464
|
};
|
|
438
465
|
//#endregion
|
|
439
466
|
//#region ../plugin-oas/src/generators/types.d.ts
|
|
440
|
-
type
|
|
441
|
-
type OperationsV1Props<TOptions extends PluginFactoryOptions> = {
|
|
467
|
+
type OperationsProps<TOptions extends PluginFactoryOptions> = {
|
|
442
468
|
config: Config;
|
|
443
469
|
generator: Omit<OperationGenerator<TOptions>, 'build'>;
|
|
444
470
|
plugin: Plugin<TOptions>;
|
|
445
471
|
operations: Array<Operation>;
|
|
446
472
|
};
|
|
447
|
-
type
|
|
448
|
-
config: Config;
|
|
449
|
-
plugin: Plugin<TOptions>;
|
|
450
|
-
nodes: Array<OperationNode>;
|
|
451
|
-
};
|
|
452
|
-
type OperationV1Props<TOptions extends PluginFactoryOptions> = {
|
|
473
|
+
type OperationProps<TOptions extends PluginFactoryOptions> = {
|
|
453
474
|
config: Config;
|
|
454
475
|
generator: Omit<OperationGenerator<TOptions>, 'build'>;
|
|
455
476
|
plugin: Plugin<TOptions>;
|
|
456
477
|
operation: Operation;
|
|
457
478
|
};
|
|
458
|
-
type
|
|
459
|
-
config: Config;
|
|
460
|
-
plugin: Plugin<TOptions>;
|
|
461
|
-
node: OperationNode;
|
|
462
|
-
};
|
|
463
|
-
type OperationsProps<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'> = TVersion extends '2' ? OperationsV2Props<TOptions> : OperationsV1Props<TOptions>;
|
|
464
|
-
type OperationProps<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'> = TVersion extends '2' ? OperationV2Props<TOptions> : OperationV1Props<TOptions>;
|
|
465
|
-
type SchemaV1Props<TOptions extends PluginFactoryOptions> = {
|
|
479
|
+
type SchemaProps<TOptions extends PluginFactoryOptions> = {
|
|
466
480
|
config: Config;
|
|
467
481
|
generator: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
|
|
468
482
|
plugin: Plugin<TOptions>;
|
|
@@ -472,26 +486,20 @@ type SchemaV1Props<TOptions extends PluginFactoryOptions> = {
|
|
|
472
486
|
value: SchemaObject;
|
|
473
487
|
};
|
|
474
488
|
};
|
|
475
|
-
type
|
|
476
|
-
config: Config;
|
|
477
|
-
plugin: Plugin<TOptions>;
|
|
478
|
-
node: SchemaNode;
|
|
479
|
-
};
|
|
480
|
-
type SchemaProps<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'> = TVersion extends '2' ? SchemaV2Props<TOptions> : SchemaV1Props<TOptions>;
|
|
481
|
-
type Generator<TOptions extends PluginFactoryOptions, TVersion extends Version = Version> = CoreGenerator<TOptions, TVersion> | ReactGenerator<TOptions, TVersion>;
|
|
489
|
+
type Generator$1<TOptions extends PluginFactoryOptions> = CoreGenerator<TOptions> | ReactGenerator<TOptions> | Generator<TOptions>;
|
|
482
490
|
//#endregion
|
|
483
491
|
//#region ../plugin-oas/src/generators/createReactGenerator.d.ts
|
|
484
|
-
type ReactGenerator<TOptions extends PluginFactoryOptions
|
|
492
|
+
type ReactGenerator<TOptions extends PluginFactoryOptions> = {
|
|
485
493
|
name: string;
|
|
486
494
|
type: 'react';
|
|
487
|
-
version:
|
|
488
|
-
Operations: (props: OperationsProps<TOptions
|
|
489
|
-
Operation: (props: OperationProps<TOptions
|
|
490
|
-
Schema: (props: SchemaProps<TOptions
|
|
495
|
+
version: '1';
|
|
496
|
+
Operations: (props: OperationsProps<TOptions>) => FabricReactNode;
|
|
497
|
+
Operation: (props: OperationProps<TOptions>) => FabricReactNode;
|
|
498
|
+
Schema: (props: SchemaProps<TOptions>) => FabricReactNode;
|
|
491
499
|
};
|
|
492
500
|
//#endregion
|
|
493
501
|
//#region src/generators/fakerGenerator.d.ts
|
|
494
|
-
declare const fakerGenerator: ReactGenerator<PluginFaker
|
|
502
|
+
declare const fakerGenerator: ReactGenerator<PluginFaker>;
|
|
495
503
|
//#endregion
|
|
496
504
|
export { fakerGenerator };
|
|
497
505
|
//# sourceMappingURL=generators.d.ts.map
|
package/dist/generators.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as fakerGenerator } from "./fakerGenerator-
|
|
1
|
+
import { t as fakerGenerator } from "./fakerGenerator-M5oCrPmy.js";
|
|
2
2
|
export { fakerGenerator };
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_components = require("./components-IdP8GXXX.cjs");
|
|
3
|
-
const require_fakerGenerator = require("./fakerGenerator-
|
|
3
|
+
const require_fakerGenerator = require("./fakerGenerator-CYUCNH3Q.cjs");
|
|
4
4
|
let node_path = require("node:path");
|
|
5
5
|
node_path = require_components.__toESM(node_path);
|
|
6
6
|
let _kubb_core = require("@kubb/core");
|
|
@@ -48,7 +48,7 @@ function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
|
48
48
|
//#endregion
|
|
49
49
|
//#region src/plugin.ts
|
|
50
50
|
const pluginFakerName = "plugin-faker";
|
|
51
|
-
const pluginFaker = (0, _kubb_core.
|
|
51
|
+
const pluginFaker = (0, _kubb_core.createPlugin)((options) => {
|
|
52
52
|
const { output = {
|
|
53
53
|
path: "mocks",
|
|
54
54
|
barrelType: "named"
|
|
@@ -104,7 +104,7 @@ const pluginFaker = (0, _kubb_core.definePlugin)((options) => {
|
|
|
104
104
|
const schemaFiles = await new _kubb_plugin_oas.SchemaGenerator(this.plugin.options, {
|
|
105
105
|
fabric: this.fabric,
|
|
106
106
|
oas,
|
|
107
|
-
|
|
107
|
+
driver: this.driver,
|
|
108
108
|
events: this.events,
|
|
109
109
|
plugin: this.plugin,
|
|
110
110
|
contentType,
|
|
@@ -117,7 +117,7 @@ const pluginFaker = (0, _kubb_core.definePlugin)((options) => {
|
|
|
117
117
|
const operationFiles = await new _kubb_plugin_oas.OperationGenerator(this.plugin.options, {
|
|
118
118
|
fabric: this.fabric,
|
|
119
119
|
oas,
|
|
120
|
-
|
|
120
|
+
driver: this.driver,
|
|
121
121
|
events: this.events,
|
|
122
122
|
plugin: this.plugin,
|
|
123
123
|
contentType,
|
|
@@ -131,7 +131,7 @@ const pluginFaker = (0, _kubb_core.definePlugin)((options) => {
|
|
|
131
131
|
type: output.barrelType ?? "named",
|
|
132
132
|
root,
|
|
133
133
|
output,
|
|
134
|
-
meta: {
|
|
134
|
+
meta: { pluginName: this.plugin.name }
|
|
135
135
|
});
|
|
136
136
|
await this.upsertFile(...barrelFiles);
|
|
137
137
|
}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["fakerGenerator","pluginOasName","pluginTsName","path","SchemaGenerator","OperationGenerator"],"sources":["../../../internals/utils/src/casing.ts","../src/plugin.ts"],"sourcesContent":["type Options = {\n /** When `true`, dot-separated segments are split on `.` and joined with `/` after casing. */\n isFile?: boolean\n /** Text prepended before casing is applied. */\n prefix?: string\n /** Text appended before casing is applied. */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split('.')\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","import path from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\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 = definePlugin<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 integerType = 'number',\n dateParser = 'faker',\n generators = [fakerGenerator].filter(Boolean),\n regexGenerator = 'faker',\n paramsCasing,\n contentType,\n } = options\n\n // @deprecated Will be removed in v5 when collisionDetection defaults to true\n const usedEnumNames = {}\n\n return {\n name: pluginFakerName,\n options: {\n output,\n transformers,\n seed,\n dateType,\n integerType,\n unknownType,\n emptySchemaType,\n dateParser,\n mapper,\n override,\n regexGenerator,\n paramsCasing,\n group,\n usedEnumNames,\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 ?? 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 install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\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.upsertFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\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.upsertFile(...operationFiles)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },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K,OAAO,OAAO,KAAK;GACpE,MAAM,QAAA,GAAA,WAAA,SAAeA,UAAAA,QAAK,QAAQ,MAAM,OAAO,KAAK,CAAC;GACrD,MAAM,MAAM,MAAM,KAAK,QAAQ;GAe/B,MAAM,cAAc,MAbI,IAAIC,iBAAAA,gBAAgB,KAAK,OAAO,SAAS;IAC/D,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA,SAAS,KAAA;IACT;IACA;IACA,QAAQ,OAAO;IAChB,CAAC,CAEwC,MAAM,GAAG,WAAW;AAC9D,SAAM,KAAK,WAAW,GAAG,YAAY;GAerC,MAAM,iBAAiB,MAbI,IAAIC,iBAAAA,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAE8C,MAAM,GAAG,WAAW;AACpE,SAAM,KAAK,WAAW,GAAG,eAAe;GAExC,MAAM,cAAc,OAAA,GAAA,WAAA,gBAAqB,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["fakerGenerator","pluginOasName","pluginTsName","path","SchemaGenerator","OperationGenerator"],"sources":["../../../internals/utils/src/casing.ts","../src/plugin.ts"],"sourcesContent":["type Options = {\n /** When `true`, dot-separated segments are split on `.` and joined with `/` after casing. */\n isFile?: boolean\n /** Text prepended before casing is applied. */\n prefix?: string\n /** Text appended before casing is applied. */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split('.')\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","import path from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport { createPlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\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 integerType = 'number',\n dateParser = 'faker',\n generators = [fakerGenerator].filter(Boolean),\n regexGenerator = 'faker',\n paramsCasing,\n contentType,\n } = options\n\n // @deprecated Will be removed in v5 when collisionDetection defaults to true\n const usedEnumNames = {}\n\n return {\n name: pluginFakerName,\n options: {\n output,\n transformers,\n seed,\n dateType,\n integerType,\n unknownType,\n emptySchemaType,\n dateParser,\n mapper,\n override,\n regexGenerator,\n paramsCasing,\n group,\n usedEnumNames,\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 ?? 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 install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n driver: this.driver,\n events: this.events,\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.upsertFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n driver: this.driver,\n events: this.events,\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.upsertFile(...operationFiles)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,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QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;GACpE,MAAM,QAAA,GAAA,WAAA,SAAeA,UAAAA,QAAK,QAAQ,MAAM,OAAO,KAAK,CAAC;GACrD,MAAM,MAAM,MAAM,KAAK,QAAQ;GAe/B,MAAM,cAAc,MAbI,IAAIC,iBAAAA,gBAAgB,KAAK,OAAO,SAAS;IAC/D,QAAQ,KAAK;IACb;IACA,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA,SAAS,KAAA;IACT;IACA;IACA,QAAQ,OAAO;IAChB,CAAC,CAEwC,MAAM,GAAG,WAAW;AAC9D,SAAM,KAAK,WAAW,GAAG,YAAY;GAerC,MAAM,iBAAiB,MAbI,IAAIC,iBAAAA,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAE8C,MAAM,GAAG,WAAW;AACpE,SAAM,KAAK,WAAW,GAAG,eAAe;GAExC,MAAM,cAAc,OAAA,GAAA,WAAA,gBAAqB,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,YAAY,KAAK,OAAO,MACzB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import { t as fakerGenerator } from "./fakerGenerator-
|
|
2
|
+
import { t as fakerGenerator } from "./fakerGenerator-M5oCrPmy.js";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { createPlugin, getBarrelFiles, getMode } from "@kubb/core";
|
|
5
5
|
import { OperationGenerator, SchemaGenerator, pluginOasName } from "@kubb/plugin-oas";
|
|
6
6
|
import { pluginTsName } from "@kubb/plugin-ts";
|
|
7
7
|
//#region ../../internals/utils/src/casing.ts
|
|
@@ -46,7 +46,7 @@ function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
|
46
46
|
//#endregion
|
|
47
47
|
//#region src/plugin.ts
|
|
48
48
|
const pluginFakerName = "plugin-faker";
|
|
49
|
-
const pluginFaker =
|
|
49
|
+
const pluginFaker = createPlugin((options) => {
|
|
50
50
|
const { output = {
|
|
51
51
|
path: "mocks",
|
|
52
52
|
barrelType: "named"
|
|
@@ -102,7 +102,7 @@ const pluginFaker = definePlugin((options) => {
|
|
|
102
102
|
const schemaFiles = await new SchemaGenerator(this.plugin.options, {
|
|
103
103
|
fabric: this.fabric,
|
|
104
104
|
oas,
|
|
105
|
-
|
|
105
|
+
driver: this.driver,
|
|
106
106
|
events: this.events,
|
|
107
107
|
plugin: this.plugin,
|
|
108
108
|
contentType,
|
|
@@ -115,7 +115,7 @@ const pluginFaker = definePlugin((options) => {
|
|
|
115
115
|
const operationFiles = await new OperationGenerator(this.plugin.options, {
|
|
116
116
|
fabric: this.fabric,
|
|
117
117
|
oas,
|
|
118
|
-
|
|
118
|
+
driver: this.driver,
|
|
119
119
|
events: this.events,
|
|
120
120
|
plugin: this.plugin,
|
|
121
121
|
contentType,
|
|
@@ -129,7 +129,7 @@ const pluginFaker = definePlugin((options) => {
|
|
|
129
129
|
type: output.barrelType ?? "named",
|
|
130
130
|
root,
|
|
131
131
|
output,
|
|
132
|
-
meta: {
|
|
132
|
+
meta: { pluginName: this.plugin.name }
|
|
133
133
|
});
|
|
134
134
|
await this.upsertFile(...barrelFiles);
|
|
135
135
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../internals/utils/src/casing.ts","../src/plugin.ts"],"sourcesContent":["type Options = {\n /** When `true`, dot-separated segments are split on `.` and joined with `/` after casing. */\n isFile?: boolean\n /** Text prepended before casing is applied. */\n prefix?: string\n /** Text appended before casing is applied. */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split('.')\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","import path from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\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 = definePlugin<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 integerType = 'number',\n dateParser = 'faker',\n generators = [fakerGenerator].filter(Boolean),\n regexGenerator = 'faker',\n paramsCasing,\n contentType,\n } = options\n\n // @deprecated Will be removed in v5 when collisionDetection defaults to true\n const usedEnumNames = {}\n\n return {\n name: pluginFakerName,\n options: {\n output,\n transformers,\n seed,\n dateType,\n integerType,\n unknownType,\n emptySchemaType,\n dateParser,\n mapper,\n override,\n regexGenerator,\n paramsCasing,\n group,\n usedEnumNames,\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 ?? 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 install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\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.upsertFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\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.upsertFile(...operationFiles)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;AAgBA,SAAS,gBAAgB,MAAc,QAAyB;AAS9D,QARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,gBAAgB,QAAQ,CAEV,MAAM,gBAAgB,CAAC,OAAO,QAAQ,CAG5D,KAAK,MAAM,MAAM;AAEhB,MADiB,KAAK,SAAS,KAAK,SAAS,KAAK,aAAa,CACjD,QAAO;AACrB,MAAI,MAAM,KAAK,CAAC,OAAQ,QAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;AAC3E,SAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;GACnD,CACD,KAAK,GAAG,CACR,QAAQ,iBAAiB,GAAG;;;;;;;AAQjC,SAAS,iBAAiB,MAAc,eAAkE;CACxG,MAAM,QAAQ,KAAK,MAAM,IAAI;AAC7B,QAAO,MAAM,KAAK,MAAM,MAAM,cAAc,MAAM,MAAM,MAAM,SAAS,EAAE,CAAC,CAAC,KAAK,IAAI;;;;;;;;;;AAWtF,SAAgB,UAAU,MAAc,EAAE,QAAQ,SAAS,IAAI,SAAS,OAAgB,EAAE,EAAU;AAClG,KAAI,OACF,QAAO,iBAAiB,OAAO,MAAM,WAAW,UAAU,MAAM,SAAS;EAAE;EAAQ;EAAQ,GAAG,EAAE,CAAC,CAAC;AAGpG,QAAO,gBAAgB,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU,MAAM;;;;ACnD9D,MAAa,kBAA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AAc,OAAO,cAAc,KAAK,IAAI;AAGrD,UAAO;;EAET,MAAM,UAAU;GACd,MAAM,OAAO,KAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;GACpE,MAAM,OAAO,QAAQ,KAAK,QAAQ,MAAM,OAAO,KAAK,CAAC;GACrD,MAAM,MAAM,MAAM,KAAK,QAAQ;GAe/B,MAAM,cAAc,MAbI,IAAI,gBAAgB,KAAK,OAAO,SAAS;IAC/D,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA,SAAS,KAAA;IACT;IACA;IACA,QAAQ,OAAO;IAChB,CAAC,CAEwC,MAAM,GAAG,WAAW;AAC9D,SAAM,KAAK,WAAW,GAAG,YAAY;GAerC,MAAM,iBAAiB,MAbI,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAE8C,MAAM,GAAG,WAAW;AACpE,SAAM,KAAK,WAAW,GAAG,eAAe;GAExC,MAAM,cAAc,MAAM,eAAe,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../internals/utils/src/casing.ts","../src/plugin.ts"],"sourcesContent":["type Options = {\n /** When `true`, dot-separated segments are split on `.` and joined with `/` after casing. */\n isFile?: boolean\n /** Text prepended before casing is applied. */\n prefix?: string\n /** Text appended before casing is applied. */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split('.')\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","import path from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport { createPlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\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 integerType = 'number',\n dateParser = 'faker',\n generators = [fakerGenerator].filter(Boolean),\n regexGenerator = 'faker',\n paramsCasing,\n contentType,\n } = options\n\n // @deprecated Will be removed in v5 when collisionDetection defaults to true\n const usedEnumNames = {}\n\n return {\n name: pluginFakerName,\n options: {\n output,\n transformers,\n seed,\n dateType,\n integerType,\n unknownType,\n emptySchemaType,\n dateParser,\n mapper,\n override,\n regexGenerator,\n paramsCasing,\n group,\n usedEnumNames,\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 ?? 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 install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n driver: this.driver,\n events: this.events,\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.upsertFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n driver: this.driver,\n events: this.events,\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.upsertFile(...operationFiles)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n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AO,KAAK,CAAC;GACrD,MAAM,MAAM,MAAM,KAAK,QAAQ;GAe/B,MAAM,cAAc,MAbI,IAAI,gBAAgB,KAAK,OAAO,SAAS;IAC/D,QAAQ,KAAK;IACb;IACA,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA,SAAS,KAAA;IACT;IACA;IACA,QAAQ,OAAO;IAChB,CAAC,CAEwC,MAAM,GAAG,WAAW;AAC9D,SAAM,KAAK,WAAW,GAAG,YAAY;GAerC,MAAM,iBAAiB,MAbI,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAE8C,MAAM,GAAG,WAAW;AACpE,SAAM,KAAK,WAAW,GAAG,eAAe;GAExC,MAAM,cAAc,MAAM,eAAe,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,YAAY,KAAK,OAAO,MACzB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
2
|
import { Group, Output, PluginFactoryOptions, ResolveNameParams } from "@kubb/core";
|
|
3
3
|
import { Exclude, Include, Override, ResolvePathOptions, Schema } from "@kubb/plugin-oas";
|
|
4
|
-
import { Generator } from "@kubb/plugin-oas/generators";
|
|
4
|
+
import { Generator as Generator$1 } from "@kubb/plugin-oas/generators";
|
|
5
5
|
import { Oas, SchemaObject, contentType } from "@kubb/oas";
|
|
6
6
|
|
|
7
7
|
//#region src/types.d.ts
|
|
@@ -109,7 +109,7 @@ type Options = {
|
|
|
109
109
|
/**
|
|
110
110
|
* Define some generators next to the faker generators
|
|
111
111
|
*/
|
|
112
|
-
generators?: Array<Generator<PluginFaker>>;
|
|
112
|
+
generators?: Array<Generator$1<PluginFaker>>;
|
|
113
113
|
};
|
|
114
114
|
type ResolvedOptions = {
|
|
115
115
|
output: Output<Oas>;
|
|
@@ -129,4 +129,4 @@ type ResolvedOptions = {
|
|
|
129
129
|
type PluginFaker = PluginFactoryOptions<'plugin-faker', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
130
130
|
//#endregion
|
|
131
131
|
export { PluginFaker as n, Options as t };
|
|
132
|
-
//# sourceMappingURL=types-
|
|
132
|
+
//# sourceMappingURL=types-r7BubMLO.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-faker",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.11",
|
|
4
4
|
"description": "Faker.js data generator plugin for Kubb, creating realistic mock data from OpenAPI specifications for development and testing.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"faker",
|
|
@@ -71,11 +71,11 @@
|
|
|
71
71
|
}
|
|
72
72
|
],
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@kubb/react-fabric": "0.
|
|
75
|
-
"@kubb/core": "5.0.0-alpha.
|
|
76
|
-
"@kubb/oas": "5.0.0-alpha.
|
|
77
|
-
"@kubb/plugin-oas": "5.0.0-alpha.
|
|
78
|
-
"@kubb/plugin-ts": "5.0.0-alpha.
|
|
74
|
+
"@kubb/react-fabric": "0.14.0",
|
|
75
|
+
"@kubb/core": "5.0.0-alpha.11",
|
|
76
|
+
"@kubb/oas": "5.0.0-alpha.11",
|
|
77
|
+
"@kubb/plugin-oas": "5.0.0-alpha.11",
|
|
78
|
+
"@kubb/plugin-ts": "5.0.0-alpha.11"
|
|
79
79
|
},
|
|
80
80
|
"engines": {
|
|
81
81
|
"node": ">=22"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMode,
|
|
1
|
+
import { useMode, usePluginDriver } from '@kubb/core/hooks'
|
|
2
2
|
import { type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'
|
|
3
3
|
import { createReactGenerator } from '@kubb/plugin-oas/generators'
|
|
4
4
|
import { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'
|
|
@@ -16,7 +16,7 @@ export const fakerGenerator = createReactGenerator<PluginFaker>({
|
|
|
16
16
|
options: { dateParser, regexGenerator, seed, mapper },
|
|
17
17
|
} = plugin
|
|
18
18
|
const mode = useMode()
|
|
19
|
-
const
|
|
19
|
+
const driver = usePluginDriver()
|
|
20
20
|
|
|
21
21
|
const oas = useOas()
|
|
22
22
|
const { getSchemas, getFile, getGroup } = useOperationManager(generator)
|
|
@@ -29,7 +29,7 @@ export const fakerGenerator = createReactGenerator<PluginFaker>({
|
|
|
29
29
|
oas,
|
|
30
30
|
plugin,
|
|
31
31
|
events: generator.context.events,
|
|
32
|
-
|
|
32
|
+
driver,
|
|
33
33
|
mode,
|
|
34
34
|
override: options.override,
|
|
35
35
|
})
|
|
@@ -53,8 +53,8 @@ export const fakerGenerator = createReactGenerator<PluginFaker>({
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
const type = {
|
|
56
|
-
name: schemaManager.getName(name, { type: 'type',
|
|
57
|
-
file: schemaManager.getFile(options.operationName || name, {
|
|
56
|
+
name: schemaManager.getName(name, { type: 'type', pluginName: pluginTsName }),
|
|
57
|
+
file: schemaManager.getFile(options.operationName || name, { pluginName: pluginTsName, group }),
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
const canOverride = tree.some(
|
|
@@ -94,7 +94,7 @@ export const fakerGenerator = createReactGenerator<PluginFaker>({
|
|
|
94
94
|
baseName={file.baseName}
|
|
95
95
|
path={file.path}
|
|
96
96
|
meta={file.meta}
|
|
97
|
-
banner={getBanner({ oas, output: plugin.options.output, config:
|
|
97
|
+
banner={getBanner({ oas, output: plugin.options.output, config: driver.config })}
|
|
98
98
|
footer={getFooter({ oas, output: plugin.options.output })}
|
|
99
99
|
>
|
|
100
100
|
<File.Import name={['faker']} path="@faker-js/faker" />
|
|
@@ -109,7 +109,7 @@ export const fakerGenerator = createReactGenerator<PluginFaker>({
|
|
|
109
109
|
const {
|
|
110
110
|
options: { output, dateParser, regexGenerator, seed, mapper },
|
|
111
111
|
} = plugin
|
|
112
|
-
const
|
|
112
|
+
const driver = usePluginDriver()
|
|
113
113
|
const oas = useOas()
|
|
114
114
|
const imports = getImports(schema.tree)
|
|
115
115
|
|
|
@@ -119,8 +119,8 @@ export const fakerGenerator = createReactGenerator<PluginFaker>({
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
const type = {
|
|
122
|
-
name: getName(schema.name, { type: 'type',
|
|
123
|
-
file: getFile(schema.name, {
|
|
122
|
+
name: getName(schema.name, { type: 'type', pluginName: pluginTsName }),
|
|
123
|
+
file: getFile(schema.name, { pluginName: pluginTsName }),
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
const canOverride = schema.tree.some(
|
|
@@ -142,7 +142,7 @@ export const fakerGenerator = createReactGenerator<PluginFaker>({
|
|
|
142
142
|
baseName={faker.file.baseName}
|
|
143
143
|
path={faker.file.path}
|
|
144
144
|
meta={faker.file.meta}
|
|
145
|
-
banner={getBanner({ oas, output, config:
|
|
145
|
+
banner={getBanner({ oas, output, config: driver.config })}
|
|
146
146
|
footer={getFooter({ oas, output })}
|
|
147
147
|
>
|
|
148
148
|
<File.Import name={['faker']} path="@faker-js/faker" />
|
package/src/plugin.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
import { camelCase } from '@internals/utils'
|
|
3
|
-
import {
|
|
3
|
+
import { createPlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'
|
|
4
4
|
import { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'
|
|
5
5
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
6
6
|
import { fakerGenerator } from './generators/fakerGenerator.tsx'
|
|
@@ -8,7 +8,7 @@ import type { PluginFaker } from './types.ts'
|
|
|
8
8
|
|
|
9
9
|
export const pluginFakerName = 'plugin-faker' satisfies PluginFaker['name']
|
|
10
10
|
|
|
11
|
-
export const pluginFaker =
|
|
11
|
+
export const pluginFaker = createPlugin<PluginFaker>((options) => {
|
|
12
12
|
const {
|
|
13
13
|
output = { path: 'mocks', barrelType: 'named' },
|
|
14
14
|
seed,
|
|
@@ -105,7 +105,7 @@ export const pluginFaker = definePlugin<PluginFaker>((options) => {
|
|
|
105
105
|
const schemaGenerator = new SchemaGenerator(this.plugin.options, {
|
|
106
106
|
fabric: this.fabric,
|
|
107
107
|
oas,
|
|
108
|
-
|
|
108
|
+
driver: this.driver,
|
|
109
109
|
events: this.events,
|
|
110
110
|
plugin: this.plugin,
|
|
111
111
|
contentType,
|
|
@@ -121,7 +121,7 @@ export const pluginFaker = definePlugin<PluginFaker>((options) => {
|
|
|
121
121
|
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
122
122
|
fabric: this.fabric,
|
|
123
123
|
oas,
|
|
124
|
-
|
|
124
|
+
driver: this.driver,
|
|
125
125
|
events: this.events,
|
|
126
126
|
plugin: this.plugin,
|
|
127
127
|
contentType,
|
|
@@ -139,7 +139,7 @@ export const pluginFaker = definePlugin<PluginFaker>((options) => {
|
|
|
139
139
|
root,
|
|
140
140
|
output,
|
|
141
141
|
meta: {
|
|
142
|
-
|
|
142
|
+
pluginName: this.plugin.name,
|
|
143
143
|
},
|
|
144
144
|
})
|
|
145
145
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fakerGenerator-BztogaeO.js","names":[],"sources":["../src/generators/fakerGenerator.tsx"],"sourcesContent":["import { useMode, usePluginManager } from '@kubb/core/hooks'\nimport { type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { applyParamsCasing, getBanner, getFooter, getImports, isParameterSchema } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } from '@kubb/react-fabric'\nimport { Faker } from '../components'\nimport type { PluginFaker } from '../types'\n\nexport const fakerGenerator = createReactGenerator<PluginFaker>({\n name: 'faker',\n Operation({ operation, generator, plugin }) {\n const {\n options,\n options: { dateParser, regexGenerator, seed, mapper },\n } = plugin\n const mode = useMode()\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = useOperationManager(generator)\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n fabric: generator.context.fabric,\n oas,\n plugin,\n events: generator.context.events,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter((x): x is OperationSchemaType => Boolean(x))\n\n const mapOperationSchema = ({ name, schema, description, ...options }: OperationSchemaType) => {\n // Apply paramsCasing transformation if enabled and this is a parameter schema\n const shouldTransform = isParameterSchema(name) && plugin.options.paramsCasing\n const transformedSchema = shouldTransform ? applyParamsCasing(schema, plugin.options.paramsCasing) : schema\n\n const tree = schemaGenerator.parse({ schema: transformedSchema, name, parentName: null })\n const imports = getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const faker = {\n name: schemaManager.getName(name, { type: 'function' }),\n file: schemaManager.getFile(name),\n }\n\n const type = {\n name: schemaManager.getName(name, { type: 'type', pluginKey: [pluginTsName] }),\n file: schemaManager.getFile(options.operationName || name, { pluginKey: [pluginTsName], group }),\n }\n\n const canOverride = tree.some(\n ({ keyword }) =>\n keyword === schemaKeywords.array ||\n keyword === schemaKeywords.and ||\n keyword === schemaKeywords.object ||\n keyword === schemaKeywords.union ||\n keyword === schemaKeywords.tuple ||\n keyword === schemaKeywords.enum ||\n keyword === schemaKeywords.ref,\n )\n\n return (\n <>\n {canOverride && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} />\n ))}\n <Faker\n name={faker.name}\n typeName={type.name}\n description={description}\n tree={tree}\n regexGenerator={regexGenerator}\n dateParser={dateParser}\n mapper={mapper}\n seed={seed}\n canOverride={canOverride}\n />\n </>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n <File.Import name={['faker']} path=\"@faker-js/faker\" />\n {regexGenerator === 'randexp' && <File.Import name={'RandExp'} path={'randexp'} />}\n {dateParser !== 'faker' && <File.Import path={dateParser} name={dateParser} />}\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ schema, plugin }) {\n const { getName, getFile } = useSchemaManager()\n const {\n options: { output, dateParser, regexGenerator, seed, mapper },\n } = plugin\n const pluginManager = usePluginManager()\n const oas = useOas()\n const imports = getImports(schema.tree)\n\n const faker = {\n name: getName(schema.name, { type: 'function' }),\n file: getFile(schema.name),\n }\n\n const type = {\n name: getName(schema.name, { type: 'type', pluginKey: [pluginTsName] }),\n file: getFile(schema.name, { pluginKey: [pluginTsName] }),\n }\n\n const canOverride = schema.tree.some(\n ({ keyword }) =>\n keyword === schemaKeywords.array ||\n keyword === schemaKeywords.and ||\n keyword === schemaKeywords.object ||\n keyword === schemaKeywords.union ||\n keyword === schemaKeywords.tuple ||\n keyword === schemaKeywords.ref ||\n keyword === schemaKeywords.enum ||\n keyword === schemaKeywords.string ||\n keyword === schemaKeywords.integer ||\n keyword === schemaKeywords.number,\n )\n\n return (\n <File\n baseName={faker.file.baseName}\n path={faker.file.path}\n meta={faker.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['faker']} path=\"@faker-js/faker\" />\n {regexGenerator === 'randexp' && <File.Import name={'RandExp'} path={'randexp'} />}\n {dateParser !== 'faker' && <File.Import path={dateParser} name={dateParser} />}\n <File.Import isTypeOnly root={faker.file.path} path={type.file.path} name={[type.name]} />\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={faker.file.path} path={imp.path} name={imp.name} />\n ))}\n\n <Faker\n name={faker.name}\n typeName={type.name}\n description={schema.value.description}\n tree={schema.tree}\n regexGenerator={regexGenerator}\n dateParser={dateParser}\n mapper={mapper}\n seed={seed}\n canOverride={canOverride}\n />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;AAUA,MAAa,iBAAiB,qBAAkC;CAC9D,MAAM;CACN,UAAU,EAAE,WAAW,WAAW,UAAU;EAC1C,MAAM,EACJ,SACA,SAAS,EAAE,YAAY,gBAAgB,MAAM,aAC3C;EACJ,MAAM,OAAO,SAAS;EACtB,MAAM,gBAAgB,kBAAkB;EAExC,MAAM,MAAM,QAAQ;EACpB,MAAM,EAAE,YAAY,SAAS,aAAa,oBAAoB,UAAU;EACxE,MAAM,gBAAgB,kBAAkB;EAExC,MAAM,OAAO,QAAQ,UAAU;EAC/B,MAAM,UAAU,WAAW,UAAU;EACrC,MAAM,kBAAkB,IAAI,gBAAgB,SAAS;GACnD,QAAQ,UAAU,QAAQ;GAC1B;GACA;GACA,QAAQ,UAAU,QAAQ;GAC1B;GACA;GACA,UAAU,QAAQ;GACnB,CAAC;EAEF,MAAM,mBAAmB;GAAC,QAAQ;GAAY,QAAQ;GAAa,QAAQ;GAAc,QAAQ;GAAa,QAAQ;GAAS,QAAQ;GAAS,CAC7I,MAAM,CACN,QAAQ,MAAgC,QAAQ,EAAE,CAAC;EAEtD,MAAM,sBAAsB,EAAE,MAAM,QAAQ,aAAa,GAAG,cAAmC;GAG7F,MAAM,oBADkB,kBAAkB,KAAK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AAM,KAAK;GACrB,MAAM,MAAM,KAAK;GACjB,MAAM,MAAM,KAAK;GACjB,QAAQ,UAAU;IAAE;IAAK;IAAQ,QAAQ,cAAc;IAAQ,CAAC;GAChE,QAAQ,UAAU;IAAE;IAAK;IAAQ,CAAC;aALpC;IAOE,oBAAC,KAAK,QAAN;KAAa,MAAM,CAAC,QAAQ;KAAE,MAAK;KAAoB,CAAA;IACtD,mBAAmB,aAAa,oBAAC,KAAK,QAAN;KAAa,MAAM;KAAW,MAAM;KAAa,CAAA;IACjF,eAAe,WAAW,oBAAC,KAAK,QAAN;KAAa,MAAM;KAAY,MAAM;KAAc,CAAA;IAC9E,oBAAC,KAAK,QAAN;KAAa,YAAA;KAAW,MAAM,MAAM,KAAK;KAAM,MAAM,KAAK,KAAK;KAAM,MAAM,CAAC,KAAK,KAAK;KAAI,CAAA;IACzF,QAAQ,KAAK,QACZ,oBAAC,KAAK,QAAN;KAAkE,MAAM,MAAM,KAAK;KAAM,MAAM,IAAI;KAAM,MAAM,IAAI;KAAQ,EAAzG;KAAC,IAAI;KAAM,IAAI;KAAM,IAAI;KAAW,CAAC,KAAK,IAAI,CAA2D,CAC3H;IAEF,oBAAC,OAAD;KACE,MAAM,MAAM;KACZ,UAAU,KAAK;KACf,aAAa,OAAO,MAAM;KAC1B,MAAM,OAAO;KACG;KACJ;KACJ;KACF;KACO;KACb,CAAA;IACG;;;CAGZ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fakerGenerator-Nu5PFwS9.cjs","names":["SchemaGenerator","pluginTsName","schemaKeywords","File","Faker"],"sources":["../src/generators/fakerGenerator.tsx"],"sourcesContent":["import { useMode, usePluginManager } from '@kubb/core/hooks'\nimport { type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { applyParamsCasing, getBanner, getFooter, getImports, isParameterSchema } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } from '@kubb/react-fabric'\nimport { Faker } from '../components'\nimport type { PluginFaker } from '../types'\n\nexport const fakerGenerator = createReactGenerator<PluginFaker>({\n name: 'faker',\n Operation({ operation, generator, plugin }) {\n const {\n options,\n options: { dateParser, regexGenerator, seed, mapper },\n } = plugin\n const mode = useMode()\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = useOperationManager(generator)\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n fabric: generator.context.fabric,\n oas,\n plugin,\n events: generator.context.events,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter((x): x is OperationSchemaType => Boolean(x))\n\n const mapOperationSchema = ({ name, schema, description, ...options }: OperationSchemaType) => {\n // Apply paramsCasing transformation if enabled and this is a parameter schema\n const shouldTransform = isParameterSchema(name) && plugin.options.paramsCasing\n const transformedSchema = shouldTransform ? applyParamsCasing(schema, plugin.options.paramsCasing) : schema\n\n const tree = schemaGenerator.parse({ schema: transformedSchema, name, parentName: null })\n const imports = getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const faker = {\n name: schemaManager.getName(name, { type: 'function' }),\n file: schemaManager.getFile(name),\n }\n\n const type = {\n name: schemaManager.getName(name, { type: 'type', pluginKey: [pluginTsName] }),\n file: schemaManager.getFile(options.operationName || name, { pluginKey: [pluginTsName], group }),\n }\n\n const canOverride = tree.some(\n ({ keyword }) =>\n keyword === schemaKeywords.array ||\n keyword === schemaKeywords.and ||\n keyword === schemaKeywords.object ||\n keyword === schemaKeywords.union ||\n keyword === schemaKeywords.tuple ||\n keyword === schemaKeywords.enum ||\n keyword === schemaKeywords.ref,\n )\n\n return (\n <>\n {canOverride && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} />\n ))}\n <Faker\n name={faker.name}\n typeName={type.name}\n description={description}\n tree={tree}\n regexGenerator={regexGenerator}\n dateParser={dateParser}\n mapper={mapper}\n seed={seed}\n canOverride={canOverride}\n />\n </>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n <File.Import name={['faker']} path=\"@faker-js/faker\" />\n {regexGenerator === 'randexp' && <File.Import name={'RandExp'} path={'randexp'} />}\n {dateParser !== 'faker' && <File.Import path={dateParser} name={dateParser} />}\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ schema, plugin }) {\n const { getName, getFile } = useSchemaManager()\n const {\n options: { output, dateParser, regexGenerator, seed, mapper },\n } = plugin\n const pluginManager = usePluginManager()\n const oas = useOas()\n const imports = getImports(schema.tree)\n\n const faker = {\n name: getName(schema.name, { type: 'function' }),\n file: getFile(schema.name),\n }\n\n const type = {\n name: getName(schema.name, { type: 'type', pluginKey: [pluginTsName] }),\n file: getFile(schema.name, { pluginKey: [pluginTsName] }),\n }\n\n const canOverride = schema.tree.some(\n ({ keyword }) =>\n keyword === schemaKeywords.array ||\n keyword === schemaKeywords.and ||\n keyword === schemaKeywords.object ||\n keyword === schemaKeywords.union ||\n keyword === schemaKeywords.tuple ||\n keyword === schemaKeywords.ref ||\n keyword === schemaKeywords.enum ||\n keyword === schemaKeywords.string ||\n keyword === schemaKeywords.integer ||\n keyword === schemaKeywords.number,\n )\n\n return (\n <File\n baseName={faker.file.baseName}\n path={faker.file.path}\n meta={faker.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['faker']} path=\"@faker-js/faker\" />\n {regexGenerator === 'randexp' && <File.Import name={'RandExp'} path={'randexp'} />}\n {dateParser !== 'faker' && <File.Import path={dateParser} name={dateParser} />}\n <File.Import isTypeOnly root={faker.file.path} path={type.file.path} name={[type.name]} />\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={faker.file.path} path={imp.path} name={imp.name} />\n ))}\n\n <Faker\n name={faker.name}\n typeName={type.name}\n description={schema.value.description}\n tree={schema.tree}\n regexGenerator={regexGenerator}\n dateParser={dateParser}\n mapper={mapper}\n seed={seed}\n canOverride={canOverride}\n />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;AAUA,MAAa,kBAAA,GAAA,4BAAA,sBAAmD;CAC9D,MAAM;CACN,UAAU,EAAE,WAAW,WAAW,UAAU;EAC1C,MAAM,EACJ,SACA,SAAS,EAAE,YAAY,gBAAgB,MAAM,aAC3C;EACJ,MAAM,QAAA,GAAA,iBAAA,UAAgB;EACtB,MAAM,iBAAA,GAAA,iBAAA,mBAAkC;EAExC,MAAM,OAAA,GAAA,uBAAA,SAAc;EACpB,MAAM,EAAE,YAAY,SAAS,cAAA,GAAA,uBAAA,qBAAiC,UAAU;EACxE,MAAM,iBAAA,GAAA,uBAAA,mBAAkC;EAExC,MAAM,OAAO,QAAQ,UAAU;EAC/B,MAAM,UAAU,WAAW,UAAU;EACrC,MAAM,kBAAkB,IAAIA,iBAAAA,gBAAgB,SAAS;GACnD,QAAQ,UAAU,QAAQ;GAC1B;GACA;GACA,QAAQ,UAAU,QAAQ;GAC1B;GACA;GACA,UAAU,QAAQ;GACnB,CAAC;EAEF,MAAM,mBAAmB;GAAC,QAAQ;GAAY,QAAQ;GAAa,QAAQ;GAAc,QAAQ;GAAa,QAAQ;GAAS,QAAQ;GAAS,CAC7I,MAAM,CACN,QAAQ,MAAgC,QAAQ,EAAE,CAAC;EAEtD,MAAM,sBAAsB,EAAE,MAAM,QAAQ,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