@kubb/plugin-faker 3.0.0-beta.1 → 3.0.0-beta.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/{chunk-KBSFZ5OP.cjs → chunk-FCIZHQ4X.cjs} +58 -30
- package/dist/chunk-FCIZHQ4X.cjs.map +1 -0
- package/dist/{chunk-U6LOSTOE.cjs → chunk-OOL6ZKDZ.cjs} +5 -5
- package/dist/chunk-OOL6ZKDZ.cjs.map +1 -0
- package/dist/{chunk-HTZ2R6MK.js → chunk-PLVSF3YP.js} +58 -30
- package/dist/chunk-PLVSF3YP.js.map +1 -0
- package/dist/{chunk-QFJUM25Z.js → chunk-ZOJMDISS.js} +3 -3
- package/dist/chunk-ZOJMDISS.js.map +1 -0
- package/dist/components.cjs +2 -2
- package/dist/components.d.cts +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/components.js +1 -1
- package/dist/generators.cjs +3 -3
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +2 -2
- package/dist/index.cjs +3 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/{types-C1bqlbxh.d.cts → types-Cq8z4Gto.d.cts} +2 -1
- package/dist/{types-C1bqlbxh.d.ts → types-Cq8z4Gto.d.ts} +2 -1
- package/package.json +12 -12
- package/src/components/Faker.tsx +25 -23
- package/src/generators/__snapshots__/createPet.ts +4 -4
- package/src/generators/__snapshots__/createPetSeed.ts +4 -4
- package/src/generators/__snapshots__/createPetUnknownTypeAny.ts +4 -4
- package/src/generators/__snapshots__/getPets.ts +4 -7
- package/src/generators/__snapshots__/pet.ts +2 -2
- package/src/generators/__snapshots__/petWithDateString.ts +2 -2
- package/src/generators/__snapshots__/petWithDayjs.ts +2 -2
- package/src/generators/__snapshots__/petWithMapper.ts +2 -2
- package/src/generators/__snapshots__/petWithRandExp.ts +2 -2
- package/src/generators/__snapshots__/pets.ts +3 -3
- package/src/generators/__snapshots__/showPetById.ts +4 -7
- package/src/parser/index.ts +36 -9
- package/src/plugin.ts +0 -1
- package/src/types.ts +2 -1
- package/dist/chunk-HTZ2R6MK.js.map +0 -1
- package/dist/chunk-KBSFZ5OP.cjs.map +0 -1
- package/dist/chunk-QFJUM25Z.js.map +0 -1
- package/dist/chunk-U6LOSTOE.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
3
|
+
var chunkOOL6ZKDZ_cjs = require('./chunk-OOL6ZKDZ.cjs');
|
|
4
|
+
require('./chunk-FCIZHQ4X.cjs');
|
|
5
5
|
var path = require('path');
|
|
6
6
|
var core = require('@kubb/core');
|
|
7
7
|
var transformers = require('@kubb/core/transformers');
|
|
8
|
-
require('@kubb/core/utils');
|
|
9
8
|
var pluginOas = require('@kubb/plugin-oas');
|
|
10
9
|
var pluginTs = require('@kubb/plugin-ts');
|
|
11
10
|
|
|
@@ -27,7 +26,7 @@ var pluginFaker = core.createPlugin((options) => {
|
|
|
27
26
|
unknownType = "any",
|
|
28
27
|
dateType = "string",
|
|
29
28
|
dateParser = "faker",
|
|
30
|
-
generators = [
|
|
29
|
+
generators = [chunkOOL6ZKDZ_cjs.fakerGenerator].filter(Boolean),
|
|
31
30
|
regexGenerator = "faker"
|
|
32
31
|
} = options;
|
|
33
32
|
return {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","fakerGenerator","pluginOasName","pluginTsName","options","path","FileManager","camelCase","PluginManager","SchemaGenerator","OperationGenerator"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","fakerGenerator","pluginOasName","pluginTsName","options","path","F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AAA,QACA,MAAA;AAAA,QACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,QACxB,IAAM,EAAA;AAAA,UACJ,SAAA,EAAW,KAAK,MAAO,CAAA;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA;AAAA,OACd,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAAA;AACnC,GACF;AACF,CAAC","file":"index.cjs","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport { fakerGenerator } from './generators/fakerGenerator.tsx'\nimport type { PluginFaker } from './types.ts'\n\nexport const pluginFakerName = 'plugin-faker' satisfies PluginFaker['name']\n\nexport const pluginFaker = createPlugin<PluginFaker>((options) => {\n const {\n output = { path: 'mocks', barrelType: 'named' },\n seed,\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n mapper = {},\n unknownType = 'any',\n dateType = 'string',\n dateParser = 'faker',\n generators = [fakerGenerator].filter(Boolean),\n regexGenerator = 'faker',\n } = options\n\n return {\n name: pluginFakerName,\n options: {\n output,\n transformers,\n seed,\n dateType,\n unknownType,\n dateParser,\n mapper,\n override,\n regexGenerator,\n },\n pre: [pluginOasName, pluginTsName],\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (options?.tag && group?.type === 'tag') {\n const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`\n\n return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)\n }\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 return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n prefix: type ? 'create' : undefined,\n isFile: type === 'file',\n })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.addFile(...operationFiles)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"]}
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { fakerGenerator } from './chunk-
|
|
2
|
-
import './chunk-
|
|
1
|
+
import { fakerGenerator } from './chunk-ZOJMDISS.js';
|
|
2
|
+
import './chunk-PLVSF3YP.js';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { createPlugin, FileManager, PluginManager } from '@kubb/core';
|
|
5
5
|
import { camelCase } from '@kubb/core/transformers';
|
|
6
|
-
import '@kubb/core/utils';
|
|
7
6
|
import { pluginOasName, SchemaGenerator, OperationGenerator } from '@kubb/plugin-oas';
|
|
8
7
|
import { pluginTsName } from '@kubb/plugin-ts';
|
|
9
8
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts"],"names":["options"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"names":["options"],"mappings":";;;;;;;;AAaO,IAAM,eAAkB,GAAA;AAElB,IAAA,WAAA,GAAc,YAA0B,CAAA,CAAC,OAAY,KAAA;AAChE,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,OAAA,EAAS,YAAY,OAAQ,EAAA;AAAA,IAC9C,IAAA;AAAA,IACA,KAAA;AAAA,IACA,UAAU,EAAC;AAAA,IACX,OAAA;AAAA,IACA,WAAW,EAAC;AAAA,IACZ,eAAe,EAAC;AAAA,IAChB,SAAS,EAAC;AAAA,IACV,WAAc,GAAA,KAAA;AAAA,IACd,QAAW,GAAA,QAAA;AAAA,IACX,UAAa,GAAA,OAAA;AAAA,IACb,UAAa,GAAA,CAAC,cAAc,CAAA,CAAE,OAAO,OAAO,CAAA;AAAA,IAC5C,cAAiB,GAAA;AAAA,GACf,GAAA,OAAA;AAEJ,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,eAAA;AAAA,IACN,OAAS,EAAA;AAAA,MACP,MAAA;AAAA,MACA,YAAA;AAAA,MACA,IAAA;AAAA,MACA,QAAA;AAAA,MACA,WAAA;AAAA,MACA,UAAA;AAAA,MACA,MAAA;AAAA,MACA,QAAA;AAAA,MACA;AAAA,KACF;AAAA,IACA,GAAA,EAAK,CAAC,aAAA,EAAe,YAAY,CAAA;AAAA,IACjC,WAAA,CAAY,QAAU,EAAA,QAAA,EAAUA,QAAS,EAAA;AACvC,MAAM,MAAA,I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AmB,CAAA,KAAA,CAAM,GAAG,UAAU,CAAA;AACnE,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,cAAc,CAAA;AAEpC,MAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,QACxD,IAAA,EAAM,OAAO,UAAc,IAAA,OAAA;AAAA,QAC3B,IAAA;AAAA,QACA,MAAA;AAAA,QACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,QACxB,IAAM,EAAA;AAAA,UACJ,SAAA,EAAW,KAAK,MAAO,CAAA;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA;AAAA,OACd,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAAA;AACnC,GACF;AACF,CAAC","file":"index.js","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport { fakerGenerator } from './generators/fakerGenerator.tsx'\nimport type { PluginFaker } from './types.ts'\n\nexport const pluginFakerName = 'plugin-faker' satisfies PluginFaker['name']\n\nexport const pluginFaker = createPlugin<PluginFaker>((options) => {\n const {\n output = { path: 'mocks', barrelType: 'named' },\n seed,\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n mapper = {},\n unknownType = 'any',\n dateType = 'string',\n dateParser = 'faker',\n generators = [fakerGenerator].filter(Boolean),\n regexGenerator = 'faker',\n } = options\n\n return {\n name: pluginFakerName,\n options: {\n output,\n transformers,\n seed,\n dateType,\n unknownType,\n dateParser,\n mapper,\n override,\n regexGenerator,\n },\n pre: [pluginOasName, pluginTsName],\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (options?.tag && group?.type === 'tag') {\n const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`\n\n return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)\n }\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 return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n prefix: type ? 'create' : undefined,\n isFile: type === 'file',\n })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.addFile(...operationFiles)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"]}
|
|
@@ -4,7 +4,8 @@ import { ResolvePathOptions, Exclude, Include, Override, Schema, Generator } fro
|
|
|
4
4
|
|
|
5
5
|
type Options = {
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Specify the export location for the files and define the behavior of the output
|
|
8
|
+
* @default { path: 'handlers', barrelType: 'named' }
|
|
8
9
|
*/
|
|
9
10
|
output?: Output;
|
|
10
11
|
/**
|
|
@@ -4,7 +4,8 @@ import { ResolvePathOptions, Exclude, Include, Override, Schema, Generator } fro
|
|
|
4
4
|
|
|
5
5
|
type Options = {
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Specify the export location for the files and define the behavior of the output
|
|
8
|
+
* @default { path: 'handlers', barrelType: 'named' }
|
|
8
9
|
*/
|
|
9
10
|
output?: Output;
|
|
10
11
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-faker",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.11",
|
|
4
4
|
"description": "Generator plugin-faker",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"faker",
|
|
@@ -61,21 +61,21 @@
|
|
|
61
61
|
"!/**/__tests__/**"
|
|
62
62
|
],
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@kubb/core": "3.0.0-beta.
|
|
65
|
-
"@kubb/fs": "3.0.0-beta.
|
|
66
|
-
"@kubb/oas": "3.0.0-beta.
|
|
67
|
-
"@kubb/plugin-oas": "3.0.0-beta.
|
|
68
|
-
"@kubb/plugin-ts": "3.0.0-beta.
|
|
69
|
-
"@kubb/react": "3.0.0-beta.
|
|
64
|
+
"@kubb/core": "3.0.0-beta.11",
|
|
65
|
+
"@kubb/fs": "3.0.0-beta.11",
|
|
66
|
+
"@kubb/oas": "3.0.0-beta.11",
|
|
67
|
+
"@kubb/plugin-oas": "3.0.0-beta.11",
|
|
68
|
+
"@kubb/plugin-ts": "3.0.0-beta.11",
|
|
69
|
+
"@kubb/react": "3.0.0-beta.11"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"tsup": "^8.3.
|
|
73
|
-
"typescript": "^5.6.
|
|
74
|
-
"@kubb/config-ts": "3.0.0-beta.
|
|
75
|
-
"@kubb/config-tsup": "3.0.0-beta.
|
|
72
|
+
"tsup": "^8.3.5",
|
|
73
|
+
"typescript": "^5.6.3",
|
|
74
|
+
"@kubb/config-ts": "3.0.0-beta.11",
|
|
75
|
+
"@kubb/config-tsup": "3.0.0-beta.11"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
|
-
"@kubb/react": "3.0.0-beta.
|
|
78
|
+
"@kubb/react": "3.0.0-beta.11"
|
|
79
79
|
},
|
|
80
80
|
"engines": {
|
|
81
81
|
"node": ">=20"
|
package/src/components/Faker.tsx
CHANGED
|
@@ -21,46 +21,48 @@ type Props = {
|
|
|
21
21
|
export function Faker({ tree, description, name, typeName, seed, regexGenerator, canOverride, mapper, dateParser }: Props): KubbNode {
|
|
22
22
|
const fakerText = parserFaker.joinItems(
|
|
23
23
|
tree
|
|
24
|
-
.map((schema) =>
|
|
25
|
-
parserFaker.parse(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
.map((schema, _index, siblings) =>
|
|
25
|
+
parserFaker.parse(
|
|
26
|
+
{ parent: undefined, current: schema, siblings },
|
|
27
|
+
{
|
|
28
|
+
name,
|
|
29
|
+
typeName,
|
|
30
|
+
seed,
|
|
31
|
+
regexGenerator,
|
|
32
|
+
mapper,
|
|
33
|
+
canOverride,
|
|
34
|
+
dateParser,
|
|
35
|
+
},
|
|
36
|
+
),
|
|
34
37
|
)
|
|
35
38
|
.filter(Boolean),
|
|
36
39
|
)
|
|
37
40
|
|
|
38
|
-
let fakerDefaultOverride: '' | '[]' | '{}' | undefined = undefined
|
|
39
41
|
let fakerTextWithOverride = fakerText
|
|
40
42
|
|
|
41
43
|
if (canOverride && fakerText.startsWith('{')) {
|
|
42
|
-
fakerDefaultOverride = '{}'
|
|
43
44
|
fakerTextWithOverride = `{
|
|
44
45
|
...${fakerText},
|
|
45
|
-
...data
|
|
46
|
+
...data || {}
|
|
46
47
|
}`
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
if (canOverride && fakerText.startsWith('faker.helpers.
|
|
50
|
-
|
|
50
|
+
if (canOverride && fakerText.startsWith('faker.helpers.arrayElement')) {
|
|
51
|
+
fakerTextWithOverride = `${fakerText} || data`
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if ((canOverride && fakerText.startsWith('faker.helpers.arrayElements')) || fakerText.startsWith('faker.helpers.multiple')) {
|
|
51
55
|
fakerTextWithOverride = `[
|
|
52
56
|
...${fakerText},
|
|
53
|
-
...data
|
|
57
|
+
...data || []
|
|
54
58
|
]`
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
const params = FunctionParams.factory({
|
|
58
|
-
data:
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
: undefined,
|
|
62
|
+
data: {
|
|
63
|
+
type: `Partial<${typeName}>`,
|
|
64
|
+
optional: true,
|
|
65
|
+
},
|
|
64
66
|
})
|
|
65
67
|
|
|
66
68
|
return (
|
|
@@ -69,7 +71,7 @@ export function Faker({ tree, description, name, typeName, seed, regexGenerator,
|
|
|
69
71
|
export
|
|
70
72
|
name={name}
|
|
71
73
|
JSDoc={{ comments: [description ? `@description ${transformers.jsStringEscape(description)}` : undefined].filter(Boolean) }}
|
|
72
|
-
params={params.toConstructor()}
|
|
74
|
+
params={canOverride ? params.toConstructor() : undefined}
|
|
73
75
|
>
|
|
74
76
|
{seed ? `faker.seed(${JSON.stringify(seed)})` : undefined}
|
|
75
77
|
<br />
|
|
@@ -14,13 +14,13 @@ export function createPetsError() {
|
|
|
14
14
|
return error();
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export function createPetsMutationRequest(data
|
|
17
|
+
export function createPetsMutationRequest(data?: Partial<CreatePetsMutationRequest>) {
|
|
18
18
|
return {
|
|
19
19
|
...{ "name": faker.string.alpha(), "tag": faker.string.alpha() },
|
|
20
|
-
...data
|
|
20
|
+
...data || {}
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export function createPetsMutationResponse() {
|
|
25
|
-
return
|
|
24
|
+
export function createPetsMutationResponse(data?: Partial<CreatePetsMutationResponse>) {
|
|
25
|
+
return faker.helpers.arrayElement<any>([createPets201()]) || data;
|
|
26
26
|
}
|
|
@@ -16,15 +16,15 @@ export function createPetsError() {
|
|
|
16
16
|
return error();
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export function createPetsMutationRequest(data
|
|
19
|
+
export function createPetsMutationRequest(data?: Partial<CreatePetsMutationRequest>) {
|
|
20
20
|
faker.seed([222]);
|
|
21
21
|
return {
|
|
22
22
|
...{ "name": faker.string.alpha(), "tag": faker.string.alpha() },
|
|
23
|
-
...data
|
|
23
|
+
...data || {}
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export function createPetsMutationResponse() {
|
|
27
|
+
export function createPetsMutationResponse(data?: Partial<CreatePetsMutationResponse>) {
|
|
28
28
|
faker.seed([222]);
|
|
29
|
-
return
|
|
29
|
+
return faker.helpers.arrayElement<any>([createPets201()]) || data;
|
|
30
30
|
}
|
|
@@ -14,13 +14,13 @@ export function createPetsError() {
|
|
|
14
14
|
return error();
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export function createPetsMutationRequest(data
|
|
17
|
+
export function createPetsMutationRequest(data?: Partial<CreatePetsMutationRequest>) {
|
|
18
18
|
return {
|
|
19
19
|
...{ "name": faker.string.alpha(), "tag": faker.string.alpha() },
|
|
20
|
-
...data
|
|
20
|
+
...data || {}
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export function createPetsMutationResponse() {
|
|
25
|
-
return
|
|
24
|
+
export function createPetsMutationResponse(data?: Partial<CreatePetsMutationResponse>) {
|
|
25
|
+
return faker.helpers.arrayElement<any>([createPets201()]) || data;
|
|
26
26
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { faker } from "@faker-js/faker";
|
|
2
2
|
|
|
3
|
-
export function listPetsQueryParams(data
|
|
3
|
+
export function listPetsQueryParams(data?: Partial<ListPetsQueryParams>) {
|
|
4
4
|
return {
|
|
5
5
|
...{ "limit": faker.string.alpha() },
|
|
6
|
-
...data
|
|
6
|
+
...data || {}
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
9
|
|
|
@@ -21,9 +21,6 @@ export function listPetsError() {
|
|
|
21
21
|
return error();
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*/
|
|
27
|
-
export function listPetsQueryResponse() {
|
|
28
|
-
return pets();
|
|
24
|
+
export function listPetsQueryResponse(data?: Partial<ListPetsQueryResponse>) {
|
|
25
|
+
return faker.helpers.arrayElement<any>([listPets200()]) || data;
|
|
29
26
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { faker } from "@faker-js/faker";
|
|
2
2
|
|
|
3
|
-
export function pet(data
|
|
3
|
+
export function pet(data?: Partial<Pet>) {
|
|
4
4
|
return {
|
|
5
5
|
...{ "id": faker.number.int(), "name": faker.string.alpha(), "tag": faker.string.alpha(), "code": faker.helpers.arrayElement<any>([faker.string.alpha(), faker.helpers.fromRegExp(new RegExp("\\b[1-9]\\b"))]), "shipDate": faker.date.anytime(), "shipTime": faker.date.anytime() },
|
|
6
|
-
...data
|
|
6
|
+
...data || {}
|
|
7
7
|
};
|
|
8
8
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { faker } from "@faker-js/faker";
|
|
2
2
|
|
|
3
|
-
export function pet(data
|
|
3
|
+
export function pet(data?: Partial<Pet>) {
|
|
4
4
|
return {
|
|
5
5
|
...{ "id": faker.number.int(), "name": faker.string.alpha(), "tag": faker.string.alpha(), "code": faker.helpers.arrayElement<any>([faker.string.alpha(), faker.helpers.fromRegExp(new RegExp("\\b[1-9]\\b"))]), "shipDate": faker.date.anytime().toString(), "shipTime": faker.date.anytime().toString() },
|
|
6
|
-
...data
|
|
6
|
+
...data || {}
|
|
7
7
|
};
|
|
8
8
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import dayjs from "dayjs";
|
|
2
2
|
import { faker } from "@faker-js/faker";
|
|
3
3
|
|
|
4
|
-
export function pet(data
|
|
4
|
+
export function pet(data?: Partial<Pet>) {
|
|
5
5
|
return {
|
|
6
6
|
...{ "id": faker.number.int(), "name": faker.string.alpha(), "tag": faker.string.alpha(), "code": faker.helpers.arrayElement<any>([faker.string.alpha(), faker.helpers.fromRegExp(new RegExp("\\b[1-9]\\b"))]), "shipDate": dayjs(faker.date.anytime()).format("YYYY-MM-DD"), "shipTime": dayjs(faker.date.anytime()).format("HH:mm:ss") },
|
|
7
|
-
...data
|
|
7
|
+
...data || {}
|
|
8
8
|
};
|
|
9
9
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { faker } from "@faker-js/faker";
|
|
2
2
|
|
|
3
|
-
export function pet(data
|
|
3
|
+
export function pet(data?: Partial<Pet>) {
|
|
4
4
|
return {
|
|
5
5
|
...{ "id": faker.string.fromCharacters("abc"), "name": faker.string.alpha({ casing: "lower" }), "tag": faker.string.alpha(), "code": faker.helpers.arrayElement<any>([faker.string.alpha(), faker.helpers.fromRegExp(new RegExp("\\b[1-9]\\b"))]), "shipDate": faker.date.anytime(), "shipTime": faker.date.anytime() },
|
|
6
|
-
...data
|
|
6
|
+
...data || {}
|
|
7
7
|
};
|
|
8
8
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import RandExp from "randexp";
|
|
2
2
|
import { faker } from "@faker-js/faker";
|
|
3
3
|
|
|
4
|
-
export function pet(data
|
|
4
|
+
export function pet(data?: Partial<Pet>) {
|
|
5
5
|
return {
|
|
6
6
|
...{ "id": faker.number.int(), "name": faker.string.alpha(), "tag": faker.string.alpha(), "code": faker.helpers.arrayElement<any>([faker.string.alpha(), new RandExp("\\b[1-9]\\b").gen()]), "shipDate": faker.date.anytime(), "shipTime": faker.date.anytime() },
|
|
7
|
-
...data
|
|
7
|
+
...data || {}
|
|
8
8
|
};
|
|
9
9
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { faker } from "@faker-js/faker";
|
|
2
2
|
|
|
3
|
-
export function pets(data
|
|
3
|
+
export function pets(data?: Partial<Pets>) {
|
|
4
4
|
return [
|
|
5
|
-
...faker.helpers.
|
|
6
|
-
...data
|
|
5
|
+
...faker.helpers.multiple(() => (pet())) as any,
|
|
6
|
+
...data || []
|
|
7
7
|
];
|
|
8
8
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { faker } from "@faker-js/faker";
|
|
2
2
|
|
|
3
|
-
export function showPetByIdPathParams(data
|
|
3
|
+
export function showPetByIdPathParams(data?: Partial<ShowPetByIdPathParams>) {
|
|
4
4
|
return {
|
|
5
5
|
...{ "petId": faker.string.alpha(), "testId": faker.string.alpha() },
|
|
6
|
-
...data
|
|
6
|
+
...data || {}
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
9
|
|
|
@@ -21,9 +21,6 @@ export function showPetByIdError() {
|
|
|
21
21
|
return error();
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*/
|
|
27
|
-
export function showPetByIdQueryResponse() {
|
|
28
|
-
return pet();
|
|
24
|
+
export function showPetByIdQueryResponse(data?: Partial<ShowPetByIdQueryResponse>) {
|
|
25
|
+
return faker.helpers.arrayElement<any>([showPetById200()]) || data;
|
|
29
26
|
}
|
package/src/parser/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import transformers from '@kubb/core/transformers'
|
|
2
|
-
import { SchemaGenerator, isKeyword, schemaKeywords } from '@kubb/plugin-oas'
|
|
2
|
+
import { SchemaGenerator, type SchemaTree, isKeyword, schemaKeywords } from '@kubb/plugin-oas'
|
|
3
3
|
|
|
4
4
|
import type { Schema, SchemaKeywordBase, SchemaKeywordMapper, SchemaMapper } from '@kubb/plugin-oas'
|
|
5
5
|
import type { Options } from '../types.ts'
|
|
@@ -55,7 +55,24 @@ const fakerKeywordMapper = {
|
|
|
55
55
|
boolean: () => 'faker.datatype.boolean()',
|
|
56
56
|
undefined: () => 'undefined',
|
|
57
57
|
null: () => 'null',
|
|
58
|
-
array: (items: string[] = []
|
|
58
|
+
array: (items: string[] = [], min?: number, max?: number) => {
|
|
59
|
+
if (items.length > 1) {
|
|
60
|
+
return `faker.helpers.arrayElements([${items.join(', ')}]) as any`
|
|
61
|
+
}
|
|
62
|
+
const item = items.at(0)
|
|
63
|
+
|
|
64
|
+
if (min !== undefined && max !== undefined) {
|
|
65
|
+
return `faker.helpers.multiple(() => (${item}), { count: { min: ${min}, max: ${max} }}) as any`
|
|
66
|
+
}
|
|
67
|
+
if (min !== undefined) {
|
|
68
|
+
return `faker.helpers.multiple(() => (${item}), { count: ${min} }) as any`
|
|
69
|
+
}
|
|
70
|
+
if (max !== undefined) {
|
|
71
|
+
return `faker.helpers.multiple(() => (${item}), { count: { min: 0, max: ${max} }}) as any`
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return `faker.helpers.multiple(() => (${item})) as any`
|
|
75
|
+
},
|
|
59
76
|
tuple: (items: string[] = []) => `faker.helpers.arrayElements([${items.join(', ')}]) as any`,
|
|
60
77
|
enum: (items: Array<string | number> = []) => `faker.helpers.arrayElement<any>([${items.join(', ')}])`,
|
|
61
78
|
union: (items: string[] = []) => `faker.helpers.arrayElement<any>([${items.join(', ')}])`,
|
|
@@ -171,7 +188,7 @@ type ParserOptions = {
|
|
|
171
188
|
mapper?: Record<string, string>
|
|
172
189
|
}
|
|
173
190
|
|
|
174
|
-
export function parse(parent
|
|
191
|
+
export function parse({ parent, current, siblings }: SchemaTree, options: ParserOptions): string | null | undefined {
|
|
175
192
|
const value = fakerKeywordMapper[current.keyword as keyof typeof fakerKeywordMapper]
|
|
176
193
|
|
|
177
194
|
if (!value) {
|
|
@@ -179,15 +196,23 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
|
|
|
179
196
|
}
|
|
180
197
|
|
|
181
198
|
if (isKeyword(current, schemaKeywords.union)) {
|
|
182
|
-
return fakerKeywordMapper.union(
|
|
199
|
+
return fakerKeywordMapper.union(
|
|
200
|
+
current.args.map((schema) => parse({ parent: current, current: schema, siblings }, { ...options, canOverride: false })).filter(Boolean),
|
|
201
|
+
)
|
|
183
202
|
}
|
|
184
203
|
|
|
185
204
|
if (isKeyword(current, schemaKeywords.and)) {
|
|
186
|
-
return fakerKeywordMapper.and(
|
|
205
|
+
return fakerKeywordMapper.and(
|
|
206
|
+
current.args.map((schema) => parse({ parent: current, current: schema, siblings }, { ...options, canOverride: false })).filter(Boolean),
|
|
207
|
+
)
|
|
187
208
|
}
|
|
188
209
|
|
|
189
210
|
if (isKeyword(current, schemaKeywords.array)) {
|
|
190
|
-
return fakerKeywordMapper.array(
|
|
211
|
+
return fakerKeywordMapper.array(
|
|
212
|
+
current.args.items.map((schema) => parse({ parent: current, current: schema, siblings }, { ...options, canOverride: false })).filter(Boolean),
|
|
213
|
+
current.args.min,
|
|
214
|
+
current.args.max,
|
|
215
|
+
)
|
|
191
216
|
}
|
|
192
217
|
|
|
193
218
|
if (isKeyword(current, schemaKeywords.enum)) {
|
|
@@ -231,7 +256,7 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
|
|
|
231
256
|
return `"${name}": ${joinItems(
|
|
232
257
|
schemas
|
|
233
258
|
.sort(schemaKeywordsorter)
|
|
234
|
-
.map((schema) => parse(current, schema, { ...options, canOverride: false }))
|
|
259
|
+
.map((schema) => parse({ parent: current, current: schema, siblings }, { ...options, canOverride: false }))
|
|
235
260
|
.filter(Boolean),
|
|
236
261
|
)}`
|
|
237
262
|
})
|
|
@@ -242,10 +267,12 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
|
|
|
242
267
|
|
|
243
268
|
if (isKeyword(current, schemaKeywords.tuple)) {
|
|
244
269
|
if (Array.isArray(current.args.items)) {
|
|
245
|
-
return fakerKeywordMapper.tuple(
|
|
270
|
+
return fakerKeywordMapper.tuple(
|
|
271
|
+
current.args.items.map((schema) => parse({ parent: current, current: schema, siblings }, { ...options, canOverride: false })).filter(Boolean),
|
|
272
|
+
)
|
|
246
273
|
}
|
|
247
274
|
|
|
248
|
-
return parse(current, current.args.items, { ...options, canOverride: false })
|
|
275
|
+
return parse({ parent: current, current: current.args.items, siblings }, { ...options, canOverride: false })
|
|
249
276
|
}
|
|
250
277
|
|
|
251
278
|
if (isKeyword(current, schemaKeywords.const)) {
|
package/src/plugin.ts
CHANGED
|
@@ -2,7 +2,6 @@ import path from 'node:path'
|
|
|
2
2
|
|
|
3
3
|
import { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'
|
|
4
4
|
import { camelCase } from '@kubb/core/transformers'
|
|
5
|
-
import { renderTemplate } from '@kubb/core/utils'
|
|
6
5
|
import { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'
|
|
7
6
|
|
|
8
7
|
import { pluginTsName } from '@kubb/plugin-ts'
|
package/src/types.ts
CHANGED
|
@@ -5,7 +5,8 @@ import type { Exclude, Generator, Include, Override, ResolvePathOptions, Schema
|
|
|
5
5
|
|
|
6
6
|
export type Options = {
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Specify the export location for the files and define the behavior of the output
|
|
9
|
+
* @default { path: 'handlers', barrelType: 'named' }
|
|
9
10
|
*/
|
|
10
11
|
output?: Output
|
|
11
12
|
/**
|