@kubb/plugin-msw 3.0.0-beta.8 → 3.0.0-beta.9
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-M6V4SSNZ.js → chunk-IRCHRJU5.js} +35 -9
- package/dist/chunk-IRCHRJU5.js.map +1 -0
- package/dist/{chunk-ZZ737QGY.cjs → chunk-U4NEGWMP.cjs} +36 -10
- package/dist/chunk-U4NEGWMP.cjs.map +1 -0
- package/dist/chunk-XLGN5MEF.cjs +45 -0
- package/dist/chunk-XLGN5MEF.cjs.map +1 -0
- package/dist/chunk-YG3WMS3Q.js +41 -0
- package/dist/chunk-YG3WMS3Q.js.map +1 -0
- package/dist/components.cjs +7 -3
- package/dist/components.d.cts +16 -3
- package/dist/components.d.ts +16 -3
- package/dist/components.js +1 -1
- package/dist/generators.cjs +4 -4
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +2 -2
- package/dist/index.cjs +4 -4
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/{types-BbAA5ZIy.d.cts → types-DFygD4LB.d.cts} +8 -0
- package/dist/{types-BbAA5ZIy.d.ts → types-DFygD4LB.d.ts} +8 -0
- package/package.json +13 -13
- package/src/components/Mock.tsx +15 -7
- package/src/components/MockWithFaker.tsx +38 -0
- package/src/components/index.ts +1 -0
- package/src/generators/__snapshots__/createPet.ts +8 -6
- package/src/generators/__snapshots__/deletePet.ts +8 -6
- package/src/generators/__snapshots__/getPets.ts +8 -6
- package/src/generators/__snapshots__/getPetsFaker.ts +11 -0
- package/src/generators/__snapshots__/handlers.ts +1 -1
- package/src/generators/__snapshots__/showPetById.ts +8 -6
- package/src/generators/handlersGenerator.tsx +1 -1
- package/src/generators/mswGenerator.tsx +27 -3
- package/src/plugin.ts +3 -2
- package/src/types.ts +8 -0
- package/dist/chunk-6M2QU6UL.js +0 -22
- package/dist/chunk-6M2QU6UL.js.map +0 -1
- package/dist/chunk-GODA4G5K.cjs +0 -25
- package/dist/chunk-GODA4G5K.cjs.map +0 -1
- package/dist/chunk-M6V4SSNZ.js.map +0 -1
- package/dist/chunk-ZZ737QGY.cjs.map +0 -1
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { Mock, Handlers } from './chunk-
|
|
1
|
+
import { MockWithFaker, Mock, Handlers } from './chunk-YG3WMS3Q.js';
|
|
2
2
|
import { URLPath } from '@kubb/core/utils';
|
|
3
3
|
import { pluginFakerName } from '@kubb/plugin-faker';
|
|
4
4
|
import { createReactGenerator, pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
|
|
5
5
|
import { useOperationManager } from '@kubb/plugin-oas/hooks';
|
|
6
|
+
import { pluginTsName } from '@kubb/plugin-ts';
|
|
6
7
|
import { useApp, File } from '@kubb/react';
|
|
7
8
|
import { jsxs, jsx } from '@kubb/react/jsx-runtime';
|
|
8
9
|
import path from 'node:path';
|
|
9
10
|
import { createPlugin, FileManager, PluginManager } from '@kubb/core';
|
|
10
11
|
import { camelCase } from '@kubb/core/transformers';
|
|
11
|
-
import { pluginTsName } from '@kubb/plugin-ts';
|
|
12
12
|
|
|
13
13
|
var mswGenerator = createReactGenerator({
|
|
14
14
|
name: "msw",
|
|
15
15
|
Operation({ operation }) {
|
|
16
16
|
const {
|
|
17
17
|
plugin: {
|
|
18
|
-
options: { output }
|
|
18
|
+
options: { output, parser }
|
|
19
19
|
}
|
|
20
20
|
} = useApp();
|
|
21
21
|
const { getSchemas, getName, getFile } = useOperationManager();
|
|
@@ -27,10 +27,34 @@ var mswGenerator = createReactGenerator({
|
|
|
27
27
|
file: getFile(operation, { pluginKey: [pluginFakerName] }),
|
|
28
28
|
schemas: getSchemas(operation, { pluginKey: [pluginFakerName], type: "function" })
|
|
29
29
|
};
|
|
30
|
+
const type = {
|
|
31
|
+
file: getFile(operation, { pluginKey: [pluginTsName] }),
|
|
32
|
+
schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: "type" })
|
|
33
|
+
};
|
|
30
34
|
return /* @__PURE__ */ jsxs(File, { baseName: mock.file.baseName, path: mock.file.path, meta: mock.file.meta, banner: output?.banner, footer: output?.footer, children: [
|
|
31
35
|
/* @__PURE__ */ jsx(File.Import, { name: ["http"], path: "msw" }),
|
|
36
|
+
/* @__PURE__ */ jsx(File.Import, { name: [type.schemas.response.name], path: type.file.path, root: mock.file.path, isTypeOnly: true }),
|
|
32
37
|
faker.file && faker.schemas.response && /* @__PURE__ */ jsx(File.Import, { name: [faker.schemas.response.name], root: mock.file.path, path: faker.file.path }),
|
|
33
|
-
/* @__PURE__ */ jsx(
|
|
38
|
+
parser === "faker" && /* @__PURE__ */ jsx(
|
|
39
|
+
MockWithFaker,
|
|
40
|
+
{
|
|
41
|
+
name: mock.name,
|
|
42
|
+
typeName: type.schemas.response.name,
|
|
43
|
+
fakerName: faker.schemas.response.name,
|
|
44
|
+
method: operation.method,
|
|
45
|
+
url: new URLPath(operation.path).toURLPath()
|
|
46
|
+
}
|
|
47
|
+
),
|
|
48
|
+
parser === "data" && /* @__PURE__ */ jsx(
|
|
49
|
+
Mock,
|
|
50
|
+
{
|
|
51
|
+
name: mock.name,
|
|
52
|
+
typeName: type.schemas.response.name,
|
|
53
|
+
fakerName: faker.schemas.response.name,
|
|
54
|
+
method: operation.method,
|
|
55
|
+
url: new URLPath(operation.path).toURLPath()
|
|
56
|
+
}
|
|
57
|
+
)
|
|
34
58
|
] });
|
|
35
59
|
}
|
|
36
60
|
});
|
|
@@ -44,14 +68,16 @@ var pluginMsw = createPlugin((options) => {
|
|
|
44
68
|
override = [],
|
|
45
69
|
transformers = {},
|
|
46
70
|
handlers = false,
|
|
71
|
+
parser = "data",
|
|
47
72
|
generators = [mswGenerator, handlers ? handlersGenerator : void 0].filter(Boolean)
|
|
48
73
|
} = options;
|
|
49
74
|
return {
|
|
50
75
|
name: pluginMswName,
|
|
51
76
|
options: {
|
|
52
|
-
output
|
|
77
|
+
output,
|
|
78
|
+
parser
|
|
53
79
|
},
|
|
54
|
-
pre: [pluginOasName, pluginTsName, pluginFakerName],
|
|
80
|
+
pre: [pluginOasName, pluginTsName, parser === "faker" ? pluginFakerName : void 0].filter(Boolean),
|
|
55
81
|
resolvePath(baseName, pathMode, options2) {
|
|
56
82
|
const root = path.resolve(this.config.root, this.config.output.path);
|
|
57
83
|
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
@@ -116,7 +142,7 @@ var handlersGenerator = createReactGenerator({
|
|
|
116
142
|
const operationName = getName(operation, { pluginKey: [pluginMswName], type: "function" });
|
|
117
143
|
return /* @__PURE__ */ jsx(File.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
|
|
118
144
|
});
|
|
119
|
-
const handlers = operations.map((operation) => getName(operation, { type: "function", pluginKey: [pluginMswName] }));
|
|
145
|
+
const handlers = operations.map((operation) => `${getName(operation, { type: "function", pluginKey: [pluginMswName] })}()`);
|
|
120
146
|
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: plugin.options.output?.banner, footer: plugin.options.output?.footer, children: [
|
|
121
147
|
imports,
|
|
122
148
|
/* @__PURE__ */ jsx(Handlers, { name: "handlers", handlers })
|
|
@@ -125,5 +151,5 @@ var handlersGenerator = createReactGenerator({
|
|
|
125
151
|
});
|
|
126
152
|
|
|
127
153
|
export { handlersGenerator, mswGenerator, pluginMsw, pluginMswName };
|
|
128
|
-
//# sourceMappingURL=chunk-
|
|
129
|
-
//# sourceMappingURL=chunk-
|
|
154
|
+
//# sourceMappingURL=chunk-IRCHRJU5.js.map
|
|
155
|
+
//# sourceMappingURL=chunk-IRCHRJU5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generators/mswGenerator.tsx","../src/plugin.ts","../src/generators/handlersGenerator.tsx"],"names":["pluginTsName","pluginFakerName","options","createReactGenerator","useApp","useOperationManager","jsx","File","jsxs"],"mappings":";;;;;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A,MAAA,EAAQ,OAAO,OAAQ,CAAA,MAAA,EAAQ,QAAQ,MAAQ,EAAA,MAAA,CAAO,OAAQ,CAAA,MAAA,EAAQ,MACpI,EAAA,QAAA,EAAA;AAAA,MAAA,OAAA;AAAA,sBACDD,GAAAA,CAAC,QAAS,EAAA,EAAA,IAAA,EAAM,YAAY,QAAoB,EAAA,CAAA;AAAA,KAClD,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-IRCHRJU5.js","sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Mock, MockWithFaker } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation }) {\n const {\n plugin: {\n options: { output, parser },\n },\n } = useApp<PluginMsw>()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginFakerName], type: 'function' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n return (\n <File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta} banner={output?.banner} footer={output?.footer}>\n <File.Import name={['http']} path={'msw'} />\n <File.Import name={[type.schemas.response.name]} path={type.file.path} root={mock.file.path} isTypeOnly />\n {faker.file && faker.schemas.response && <File.Import name={[faker.schemas.response.name]} root={mock.file.path} path={faker.file.path} />}\n\n {parser === 'faker' && (\n <MockWithFaker\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n method={operation.method}\n url={new URLPath(operation.path).toURLPath()}\n />\n )}\n {parser === 'data' && (\n <Mock\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n method={operation.method}\n url={new URLPath(operation.path).toURLPath()}\n />\n )}\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = createPlugin<PluginMsw>((options) => {\n const {\n output = { path: 'handlers', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n handlers = false,\n parser = 'data',\n generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n parser,\n },\n pre: [pluginOasName, pluginTsName, parser === 'faker' ? pluginFakerName : undefined].filter(Boolean),\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 suffix: type ? 'handler' : 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<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(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 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 files = await operationGenerator.build(...generators)\n await this.addFile(...files)\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","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Handlers } from '../components/Handlers.tsx'\nimport { pluginMswName } from '../plugin.ts'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations }) {\n const { pluginManager, plugin } = useApp<PluginMsw>()\n const { getName, getFile } = useOperationManager()\n\n const file = pluginManager.getFile({ name: 'handlers', extname: '.ts', pluginKey: [pluginMswName] })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: [pluginMswName] })\n const operationName = getName(operation, { pluginKey: [pluginMswName], type: 'function' })\n\n return <File.Import key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />\n })\n\n const handlers = operations.map((operation) => `${getName(operation, { type: 'function', pluginKey: [pluginMswName] })}()`)\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkXLGN5MEF_cjs = require('./chunk-XLGN5MEF.cjs');
|
|
4
4
|
var utils = require('@kubb/core/utils');
|
|
5
5
|
var pluginFaker = require('@kubb/plugin-faker');
|
|
6
6
|
var pluginOas = require('@kubb/plugin-oas');
|
|
7
7
|
var hooks = require('@kubb/plugin-oas/hooks');
|
|
8
|
+
var pluginTs = require('@kubb/plugin-ts');
|
|
8
9
|
var react = require('@kubb/react');
|
|
9
10
|
var jsxRuntime = require('@kubb/react/jsx-runtime');
|
|
10
11
|
var path = require('path');
|
|
11
12
|
var core = require('@kubb/core');
|
|
12
13
|
var transformers = require('@kubb/core/transformers');
|
|
13
|
-
var pluginTs = require('@kubb/plugin-ts');
|
|
14
14
|
|
|
15
15
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
16
|
|
|
@@ -21,7 +21,7 @@ var mswGenerator = pluginOas.createReactGenerator({
|
|
|
21
21
|
Operation({ operation }) {
|
|
22
22
|
const {
|
|
23
23
|
plugin: {
|
|
24
|
-
options: { output }
|
|
24
|
+
options: { output, parser }
|
|
25
25
|
}
|
|
26
26
|
} = react.useApp();
|
|
27
27
|
const { getSchemas, getName, getFile } = hooks.useOperationManager();
|
|
@@ -33,10 +33,34 @@ var mswGenerator = pluginOas.createReactGenerator({
|
|
|
33
33
|
file: getFile(operation, { pluginKey: [pluginFaker.pluginFakerName] }),
|
|
34
34
|
schemas: getSchemas(operation, { pluginKey: [pluginFaker.pluginFakerName], type: "function" })
|
|
35
35
|
};
|
|
36
|
+
const type = {
|
|
37
|
+
file: getFile(operation, { pluginKey: [pluginTs.pluginTsName] }),
|
|
38
|
+
schemas: getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" })
|
|
39
|
+
};
|
|
36
40
|
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: mock.file.baseName, path: mock.file.path, meta: mock.file.meta, banner: output?.banner, footer: output?.footer, children: [
|
|
37
41
|
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["http"], path: "msw" }),
|
|
42
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [type.schemas.response.name], path: type.file.path, root: mock.file.path, isTypeOnly: true }),
|
|
38
43
|
faker.file && faker.schemas.response && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [faker.schemas.response.name], root: mock.file.path, path: faker.file.path }),
|
|
39
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
44
|
+
parser === "faker" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
45
|
+
chunkXLGN5MEF_cjs.MockWithFaker,
|
|
46
|
+
{
|
|
47
|
+
name: mock.name,
|
|
48
|
+
typeName: type.schemas.response.name,
|
|
49
|
+
fakerName: faker.schemas.response.name,
|
|
50
|
+
method: operation.method,
|
|
51
|
+
url: new utils.URLPath(operation.path).toURLPath()
|
|
52
|
+
}
|
|
53
|
+
),
|
|
54
|
+
parser === "data" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
55
|
+
chunkXLGN5MEF_cjs.Mock,
|
|
56
|
+
{
|
|
57
|
+
name: mock.name,
|
|
58
|
+
typeName: type.schemas.response.name,
|
|
59
|
+
fakerName: faker.schemas.response.name,
|
|
60
|
+
method: operation.method,
|
|
61
|
+
url: new utils.URLPath(operation.path).toURLPath()
|
|
62
|
+
}
|
|
63
|
+
)
|
|
40
64
|
] });
|
|
41
65
|
}
|
|
42
66
|
});
|
|
@@ -50,14 +74,16 @@ var pluginMsw = core.createPlugin((options) => {
|
|
|
50
74
|
override = [],
|
|
51
75
|
transformers: transformers$1 = {},
|
|
52
76
|
handlers = false,
|
|
77
|
+
parser = "data",
|
|
53
78
|
generators = [mswGenerator, handlers ? handlersGenerator : void 0].filter(Boolean)
|
|
54
79
|
} = options;
|
|
55
80
|
return {
|
|
56
81
|
name: pluginMswName,
|
|
57
82
|
options: {
|
|
58
|
-
output
|
|
83
|
+
output,
|
|
84
|
+
parser
|
|
59
85
|
},
|
|
60
|
-
pre: [pluginOas.pluginOasName, pluginTs.pluginTsName, pluginFaker.pluginFakerName],
|
|
86
|
+
pre: [pluginOas.pluginOasName, pluginTs.pluginTsName, parser === "faker" ? pluginFaker.pluginFakerName : void 0].filter(Boolean),
|
|
61
87
|
resolvePath(baseName, pathMode, options2) {
|
|
62
88
|
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
63
89
|
const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
@@ -122,10 +148,10 @@ var handlersGenerator = pluginOas.createReactGenerator({
|
|
|
122
148
|
const operationName = getName(operation, { pluginKey: [pluginMswName], type: "function" });
|
|
123
149
|
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
|
|
124
150
|
});
|
|
125
|
-
const handlers = operations.map((operation) => getName(operation, { type: "function", pluginKey: [pluginMswName] }));
|
|
151
|
+
const handlers = operations.map((operation) => `${getName(operation, { type: "function", pluginKey: [pluginMswName] })}()`);
|
|
126
152
|
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: plugin.options.output?.banner, footer: plugin.options.output?.footer, children: [
|
|
127
153
|
imports,
|
|
128
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
154
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkXLGN5MEF_cjs.Handlers, { name: "handlers", handlers })
|
|
129
155
|
] });
|
|
130
156
|
}
|
|
131
157
|
});
|
|
@@ -134,5 +160,5 @@ exports.handlersGenerator = handlersGenerator;
|
|
|
134
160
|
exports.mswGenerator = mswGenerator;
|
|
135
161
|
exports.pluginMsw = pluginMsw;
|
|
136
162
|
exports.pluginMswName = pluginMswName;
|
|
137
|
-
//# sourceMappingURL=chunk-
|
|
138
|
-
//# sourceMappingURL=chunk-
|
|
163
|
+
//# sourceMappingURL=chunk-U4NEGWMP.cjs.map
|
|
164
|
+
//# sourceMappingURL=chunk-U4NEGWMP.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generators/mswGenerator.tsx","../src/plugin.ts","../src/generators/handlersGenerator.tsx"],"names":["createReactGenerator","useApp","useOperationManager","pluginFakerName","pluginTsName","File","jsx","MockWithFaker","URLPath","Mock","createPlugin","transformers","pluginOasName","options","path","FileManager","camelCase","PluginManager","OperationGenerator","jsxs","Handlers"],"mappings":";;;;;;;;;;;;;;;;;;AASO,IAAM,eAAeA,8BAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAA,CAAU,EAAE,SAAA,EAAa,EAAA;AACvB,IAAM,MAAA;AAAA,MACJ,MAAQ,EAAA;AAAA,QACN,OAAA,EAAS,EAAE,MAAA,EAAQ,MAAO,EAAA;AAAA,OAC5B;AAAA,QACEC,YAAkB,EAAA,CAAA;AACtB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAYC,yBAAoB,EAAA,CAAA;AAE7D,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA;AAAA,MAC7C,IAAA,EAAM,QAAQ,SAAS,CAAA;AAAA,KACzB,CAAA;AAEA,IAAA,MAAM,KAAQ,GAAA;AAAA,MACZ,IAAA,EAAM,QAAQ,SAAW,EAAA,EAAE,WAAW,CAACC,2BAAe,GAAG,CAAA;AAAA,MACzD,OAAA,EAAS,UAAW,CAAA,SAAA,EAAW,EAAE,SAAA,EAAW,CAACA,2BAAe,CAAA,EAAG,IAAM,EAAA,UAAA,EAAY,CAAA;AAAA,KACnF,CAAA;AAEA,IAAA,MAAM,IAAO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AAK,MAAL,EAAA,EAAqC,MAAM,CAAC,aAAa,CAAG,EAAA,IAAA,EAAM,KAAK,IAAM,EAAA,IAAA,EAAM,aAAc,CAAA,IAAA,EAAA,EAAhF,cAAc,IAAwE,CAAA,CAAA;AAAA,KAChH,CAAA,CAAA;AAED,IAAA,MAAM,WAAW,UAAW,CAAA,GAAA,CAAI,CAAC,SAAA,KAAc,GAAG,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,SAAW,EAAA,CAAC,aAAa,CAAE,EAAC,CAAC,CAAI,EAAA,CAAA,CAAA,CAAA;AAE1H,IACE,uBAAAc,gBAACd,UAAA,EAAA,EAAK,UAAU,IAAK,CAAA,QAAA,EAAU,IAAM,EAAA,IAAA,CAAK,IAAM,EAAA,IAAA,EAAM,KAAK,IAAM,EAAA,MAAA,EAAQ,OAAO,OAAQ,CAAA,MAAA,EAAQ,QAAQ,MAAQ,EAAA,MAAA,CAAO,OAAQ,CAAA,MAAA,EAAQ,MACpI,EAAA,QAAA,EAAA;AAAA,MAAA,OAAA;AAAA,sBACDC,cAAAA,CAACc,0BAAS,EAAA,EAAA,IAAA,EAAM,YAAY,QAAoB,EAAA,CAAA;AAAA,KAClD,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-U4NEGWMP.cjs","sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Mock, MockWithFaker } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation }) {\n const {\n plugin: {\n options: { output, parser },\n },\n } = useApp<PluginMsw>()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginFakerName], type: 'function' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n return (\n <File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta} banner={output?.banner} footer={output?.footer}>\n <File.Import name={['http']} path={'msw'} />\n <File.Import name={[type.schemas.response.name]} path={type.file.path} root={mock.file.path} isTypeOnly />\n {faker.file && faker.schemas.response && <File.Import name={[faker.schemas.response.name]} root={mock.file.path} path={faker.file.path} />}\n\n {parser === 'faker' && (\n <MockWithFaker\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n method={operation.method}\n url={new URLPath(operation.path).toURLPath()}\n />\n )}\n {parser === 'data' && (\n <Mock\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n method={operation.method}\n url={new URLPath(operation.path).toURLPath()}\n />\n )}\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = createPlugin<PluginMsw>((options) => {\n const {\n output = { path: 'handlers', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n handlers = false,\n parser = 'data',\n generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n parser,\n },\n pre: [pluginOasName, pluginTsName, parser === 'faker' ? pluginFakerName : undefined].filter(Boolean),\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 suffix: type ? 'handler' : 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<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(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 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 files = await operationGenerator.build(...generators)\n await this.addFile(...files)\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","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Handlers } from '../components/Handlers.tsx'\nimport { pluginMswName } from '../plugin.ts'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations }) {\n const { pluginManager, plugin } = useApp<PluginMsw>()\n const { getName, getFile } = useOperationManager()\n\n const file = pluginManager.getFile({ name: 'handlers', extname: '.ts', pluginKey: [pluginMswName] })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: [pluginMswName] })\n const operationName = getName(operation, { pluginKey: [pluginMswName], type: 'function' })\n\n return <File.Import key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />\n })\n\n const handlers = operations.map((operation) => `${getName(operation, { type: 'function', pluginKey: [pluginMswName] })}()`)\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('@kubb/react');
|
|
4
|
+
var jsxRuntime = require('@kubb/react/jsx-runtime');
|
|
5
|
+
|
|
6
|
+
// src/components/Mock.tsx
|
|
7
|
+
function Mock({ name, fakerName, typeName, url, method }) {
|
|
8
|
+
const params = react.FunctionParams.factory({
|
|
9
|
+
data: {
|
|
10
|
+
type: typeName,
|
|
11
|
+
optional: true
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { name, export: true, params: params.toConstructor(), children: `return http.${method}('*${url}', function handler(info) {
|
|
15
|
+
return new Response(JSON.stringify(data), {
|
|
16
|
+
headers: {
|
|
17
|
+
'Content-Type': 'application/json',
|
|
18
|
+
},
|
|
19
|
+
})
|
|
20
|
+
})` }) });
|
|
21
|
+
}
|
|
22
|
+
function Handlers({ name, handlers }) {
|
|
23
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isIndexable: true, isExportable: true, children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const` });
|
|
24
|
+
}
|
|
25
|
+
function MockWithFaker({ name, fakerName, typeName, url, method }) {
|
|
26
|
+
const params = react.FunctionParams.factory({
|
|
27
|
+
data: {
|
|
28
|
+
type: typeName,
|
|
29
|
+
optional: true
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { name, export: true, params: params.toConstructor(), children: `return http.${method}('*${url}', function handler(info) {
|
|
33
|
+
return new Response(JSON.stringify(${fakerName}(data)), {
|
|
34
|
+
headers: {
|
|
35
|
+
'Content-Type': 'application/json',
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
})` }) });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exports.Handlers = Handlers;
|
|
42
|
+
exports.Mock = Mock;
|
|
43
|
+
exports.MockWithFaker = MockWithFaker;
|
|
44
|
+
//# sourceMappingURL=chunk-XLGN5MEF.cjs.map
|
|
45
|
+
//# sourceMappingURL=chunk-XLGN5MEF.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/Mock.tsx","../src/components/Handlers.tsx","../src/components/MockWithFaker.tsx"],"names":["FunctionParams","jsx","File","Function"],"mappings":";;;;;;AAgBO,SAAS,KAAK,EAAE,IAAA,EAAM,WAAW,QAAU,EAAA,GAAA,EAAK,QAA4B,EAAA;AACjF,EAAM,MAAA,MAAA,GAASA,qBAAe,OAAQ,CAAA;AAAA,IACpC,IAAM,EAAA;AAAA,MACJ,IAAM,EAAA,QAAA;AAAA,MACN,QAAU,EAAA,IAAA;AAAA,KACZ;AAAA,GACD,CAAA,CAAA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M,GAAG,CAAA;AAAA,uCAAA,EACE,SAAS,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,CAAA,EAM5C,CACF,EAAA,CAAA,CAAA;AAEJ","file":"chunk-XLGN5MEF.cjs","sourcesContent":["import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function Mock({ name, fakerName, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: typeName,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('*${url}', function handler(info) {\n return new Response(JSON.stringify(data), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n","import { File } from '@kubb/react'\nimport type { ReactNode } from 'react'\n\ntype HandlersProps = {\n /**\n * Name of the function\n */\n name: string\n // custom\n handlers: string[]\n}\n\nexport function Handlers({ name, handlers }: HandlersProps): ReactNode {\n return (\n <File.Source name={name} isIndexable isExportable>\n {`export const ${name} = ${JSON.stringify(handlers).replaceAll(`\"`, '')} as const`}\n </File.Source>\n )\n}\n","import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function MockWithFaker({ name, fakerName, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: typeName,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('*${url}', function handler(info) {\n return new Response(JSON.stringify(${fakerName}(data)), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { FunctionParams, File, Function } from '@kubb/react';
|
|
2
|
+
import { jsx } from '@kubb/react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
// src/components/Mock.tsx
|
|
5
|
+
function Mock({ name, fakerName, typeName, url, method }) {
|
|
6
|
+
const params = FunctionParams.factory({
|
|
7
|
+
data: {
|
|
8
|
+
type: typeName,
|
|
9
|
+
optional: true
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
return /* @__PURE__ */ jsx(File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsx(Function, { name, export: true, params: params.toConstructor(), children: `return http.${method}('*${url}', function handler(info) {
|
|
13
|
+
return new Response(JSON.stringify(data), {
|
|
14
|
+
headers: {
|
|
15
|
+
'Content-Type': 'application/json',
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
})` }) });
|
|
19
|
+
}
|
|
20
|
+
function Handlers({ name, handlers }) {
|
|
21
|
+
return /* @__PURE__ */ jsx(File.Source, { name, isIndexable: true, isExportable: true, children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const` });
|
|
22
|
+
}
|
|
23
|
+
function MockWithFaker({ name, fakerName, typeName, url, method }) {
|
|
24
|
+
const params = FunctionParams.factory({
|
|
25
|
+
data: {
|
|
26
|
+
type: typeName,
|
|
27
|
+
optional: true
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return /* @__PURE__ */ jsx(File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsx(Function, { name, export: true, params: params.toConstructor(), children: `return http.${method}('*${url}', function handler(info) {
|
|
31
|
+
return new Response(JSON.stringify(${fakerName}(data)), {
|
|
32
|
+
headers: {
|
|
33
|
+
'Content-Type': 'application/json',
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
})` }) });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { Handlers, Mock, MockWithFaker };
|
|
40
|
+
//# sourceMappingURL=chunk-YG3WMS3Q.js.map
|
|
41
|
+
//# sourceMappingURL=chunk-YG3WMS3Q.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/Mock.tsx","../src/components/Handlers.tsx","../src/components/MockWithFaker.tsx"],"names":["jsx","File","FunctionParams","Function"],"mappings":";;;;AAgBO,SAAS,KAAK,EAAE,IAAA,EAAM,WAAW,QAAU,EAAA,GAAA,EAAK,QAA4B,EAAA;AACjF,EAAM,MAAA,MAAA,GAAS,eAAe,OAAQ,CAAA;AAAA,IACpC,IAAM,EAAA;AAAA,MACJ,IAAM,EAAA,QAAA;AAAA,MACN,QAAU,EAAA,IAAA;AAAA,KACZ;AAAA,GACD,CAAA,CAAA;AAED,EACE,uBAAA,GAAA,CAAC,KAAK,MAAL,EAAA,EAAY,MAAY,WAAW,EAAA,IAAA,EAAC,cAAY,IAC/C,EAAA,QAAA,kBAAA,GAAA,CAAC,YAAS,IAAY,EAAA,MAAA,EAAM,MAAC,MAAQ,EAAA,MAAA,CAAO,eACzC,EAAA,QAAA,EAAA,CAAA,YAAA,EAAe,MAAM,CAAA,GAAA,EAAM,GAAG,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,CAAA,EAOjC,CACF,EAAA,CAAA,CAAA;AAEJ,CAAA;ACzBO,SAAS,QAAS,CAAA,EAAE,IAAM,EAAA,QAAA,EAAsC,EAAA;AACrE,EACE,uBAAAA,IAACC,IAAK,CAAA,MAAA,EAAL,EAAY,IAAY,EAAA,WAAA,EAAW,MAAC,YAAY,EAAA,IAAA,EAC9C,0BAAgB,IAAI,CAAA,GAAA,EAAM,KAAK,SAAU,CAAA,QAAQ,EAAE,UAAW,CAAA,CAAA,CAAA,CAAA,EAAK,EAAE,CAAC,CACzE,SAAA,CAAA,EAAA,CAAA,CAAA;AAEJ,CAAA;ACFO,SAAS,cAAc,EAAE,IAAA,EAAM,WAAW,QAAU,EAAA,GAAA,EAAK,QAA4B,EAAA;AAC1F,EAAM,MAAA,MAAA,GAASC,eAAe,OAAQ,CAAA;AAAA,IACpC,IAAM,EAAA;AAAA,MACJ,IAAM,EAAA,QAAA;AAAA,MACN,QAAU,EAAA,IAAA;AAAA,KACZ;AAAA,GACD,CAAA,CAAA;AAED,EACE,uBAAAF,GAACC,CAAAA,IAAAA,CAAK,MAAL,EAAA,EAAY,MAAY,WAAW,EAAA,IAAA,EAAC,YAAY,EAAA,IAAA,EAC/C,QAAAD,kBAAAA,GAAAA,CAACG,UAAA,EAAS,IAAA,EAAY,MAAM,EAAA,IAAA,EAAC,MAAQ,EAAA,MAAA,CAAO,eACzC,EAAA,QAAA,EAAA,CAAA,YAAA,EAAe,MAAM,CAAA,GAAA,EAAM,GAAG,CAAA;AAAA,uCAAA,EACE,SAAS,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,CAAA,EAM5C,CACF,EAAA,CAAA,CAAA;AAEJ","file":"chunk-YG3WMS3Q.js","sourcesContent":["import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function Mock({ name, fakerName, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: typeName,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('*${url}', function handler(info) {\n return new Response(JSON.stringify(data), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n","import { File } from '@kubb/react'\nimport type { ReactNode } from 'react'\n\ntype HandlersProps = {\n /**\n * Name of the function\n */\n name: string\n // custom\n handlers: string[]\n}\n\nexport function Handlers({ name, handlers }: HandlersProps): ReactNode {\n return (\n <File.Source name={name} isIndexable isExportable>\n {`export const ${name} = ${JSON.stringify(handlers).replaceAll(`\"`, '')} as const`}\n </File.Source>\n )\n}\n","import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function MockWithFaker({ name, fakerName, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: typeName,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('*${url}', function handler(info) {\n return new Response(JSON.stringify(${fakerName}(data)), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n"]}
|
package/dist/components.cjs
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkXLGN5MEF_cjs = require('./chunk-XLGN5MEF.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
Object.defineProperty(exports, "Handlers", {
|
|
8
8
|
enumerable: true,
|
|
9
|
-
get: function () { return
|
|
9
|
+
get: function () { return chunkXLGN5MEF_cjs.Handlers; }
|
|
10
10
|
});
|
|
11
11
|
Object.defineProperty(exports, "Mock", {
|
|
12
12
|
enumerable: true,
|
|
13
|
-
get: function () { return
|
|
13
|
+
get: function () { return chunkXLGN5MEF_cjs.Mock; }
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(exports, "MockWithFaker", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return chunkXLGN5MEF_cjs.MockWithFaker; }
|
|
14
18
|
});
|
|
15
19
|
//# sourceMappingURL=components.cjs.map
|
|
16
20
|
//# sourceMappingURL=components.cjs.map
|
package/dist/components.d.cts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { HttpMethod } from '@kubb/oas';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
|
|
4
|
-
type Props = {
|
|
4
|
+
type Props$1 = {
|
|
5
5
|
/**
|
|
6
6
|
* Name of the function
|
|
7
7
|
*/
|
|
8
8
|
name: string;
|
|
9
|
+
typeName: string;
|
|
9
10
|
fakerName: string;
|
|
10
11
|
url: string;
|
|
11
12
|
method: HttpMethod;
|
|
12
13
|
};
|
|
13
|
-
declare function Mock({ name, fakerName, url, method }: Props): ReactNode;
|
|
14
|
+
declare function Mock({ name, fakerName, typeName, url, method }: Props$1): ReactNode;
|
|
14
15
|
|
|
15
16
|
type HandlersProps = {
|
|
16
17
|
/**
|
|
@@ -21,4 +22,16 @@ type HandlersProps = {
|
|
|
21
22
|
};
|
|
22
23
|
declare function Handlers({ name, handlers }: HandlersProps): ReactNode;
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
type Props = {
|
|
26
|
+
/**
|
|
27
|
+
* Name of the function
|
|
28
|
+
*/
|
|
29
|
+
name: string;
|
|
30
|
+
typeName: string;
|
|
31
|
+
fakerName: string;
|
|
32
|
+
url: string;
|
|
33
|
+
method: HttpMethod;
|
|
34
|
+
};
|
|
35
|
+
declare function MockWithFaker({ name, fakerName, typeName, url, method }: Props): ReactNode;
|
|
36
|
+
|
|
37
|
+
export { Handlers, Mock, MockWithFaker };
|
package/dist/components.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { HttpMethod } from '@kubb/oas';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
|
|
4
|
-
type Props = {
|
|
4
|
+
type Props$1 = {
|
|
5
5
|
/**
|
|
6
6
|
* Name of the function
|
|
7
7
|
*/
|
|
8
8
|
name: string;
|
|
9
|
+
typeName: string;
|
|
9
10
|
fakerName: string;
|
|
10
11
|
url: string;
|
|
11
12
|
method: HttpMethod;
|
|
12
13
|
};
|
|
13
|
-
declare function Mock({ name, fakerName, url, method }: Props): ReactNode;
|
|
14
|
+
declare function Mock({ name, fakerName, typeName, url, method }: Props$1): ReactNode;
|
|
14
15
|
|
|
15
16
|
type HandlersProps = {
|
|
16
17
|
/**
|
|
@@ -21,4 +22,16 @@ type HandlersProps = {
|
|
|
21
22
|
};
|
|
22
23
|
declare function Handlers({ name, handlers }: HandlersProps): ReactNode;
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
type Props = {
|
|
26
|
+
/**
|
|
27
|
+
* Name of the function
|
|
28
|
+
*/
|
|
29
|
+
name: string;
|
|
30
|
+
typeName: string;
|
|
31
|
+
fakerName: string;
|
|
32
|
+
url: string;
|
|
33
|
+
method: HttpMethod;
|
|
34
|
+
};
|
|
35
|
+
declare function MockWithFaker({ name, fakerName, typeName, url, method }: Props): ReactNode;
|
|
36
|
+
|
|
37
|
+
export { Handlers, Mock, MockWithFaker };
|
package/dist/components.js
CHANGED
package/dist/generators.cjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
3
|
+
var chunkU4NEGWMP_cjs = require('./chunk-U4NEGWMP.cjs');
|
|
4
|
+
require('./chunk-XLGN5MEF.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "handlersGenerator", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunkU4NEGWMP_cjs.handlersGenerator; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "mswGenerator", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkU4NEGWMP_cjs.mswGenerator; }
|
|
15
15
|
});
|
|
16
16
|
//# sourceMappingURL=generators.cjs.map
|
|
17
17
|
//# sourceMappingURL=generators.cjs.map
|
package/dist/generators.d.cts
CHANGED
package/dist/generators.d.ts
CHANGED
package/dist/generators.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { handlersGenerator, mswGenerator } from './chunk-
|
|
2
|
-
import './chunk-
|
|
1
|
+
export { handlersGenerator, mswGenerator } from './chunk-IRCHRJU5.js';
|
|
2
|
+
import './chunk-YG3WMS3Q.js';
|
|
3
3
|
//# sourceMappingURL=generators.js.map
|
|
4
4
|
//# sourceMappingURL=generators.js.map
|
package/dist/index.cjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
3
|
+
var chunkU4NEGWMP_cjs = require('./chunk-U4NEGWMP.cjs');
|
|
4
|
+
require('./chunk-XLGN5MEF.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "pluginMsw", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunkU4NEGWMP_cjs.pluginMsw; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "pluginMswName", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkU4NEGWMP_cjs.pluginMswName; }
|
|
15
15
|
});
|
|
16
16
|
//# sourceMappingURL=index.cjs.map
|
|
17
17
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -34,6 +34,13 @@ type Options = {
|
|
|
34
34
|
* @default false
|
|
35
35
|
*/
|
|
36
36
|
handlers?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Which parser can be used before returning the data
|
|
39
|
+
* - `'faker'` will use `@kubb/plugin-faker` to generate the data for the response
|
|
40
|
+
* - `'data'` will use your custom data to generate the data for the response
|
|
41
|
+
* @default 'data'
|
|
42
|
+
*/
|
|
43
|
+
parser?: 'data' | 'faker';
|
|
37
44
|
/**
|
|
38
45
|
* Define some generators next to the msw generators
|
|
39
46
|
*/
|
|
@@ -41,6 +48,7 @@ type Options = {
|
|
|
41
48
|
};
|
|
42
49
|
type ResolvedOptions = {
|
|
43
50
|
output: Output;
|
|
51
|
+
parser: NonNullable<Options['parser']>;
|
|
44
52
|
};
|
|
45
53
|
type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
46
54
|
|
|
@@ -34,6 +34,13 @@ type Options = {
|
|
|
34
34
|
* @default false
|
|
35
35
|
*/
|
|
36
36
|
handlers?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Which parser can be used before returning the data
|
|
39
|
+
* - `'faker'` will use `@kubb/plugin-faker` to generate the data for the response
|
|
40
|
+
* - `'data'` will use your custom data to generate the data for the response
|
|
41
|
+
* @default 'data'
|
|
42
|
+
*/
|
|
43
|
+
parser?: 'data' | 'faker';
|
|
37
44
|
/**
|
|
38
45
|
* Define some generators next to the msw generators
|
|
39
46
|
*/
|
|
@@ -41,6 +48,7 @@ type Options = {
|
|
|
41
48
|
};
|
|
42
49
|
type ResolvedOptions = {
|
|
43
50
|
output: Output;
|
|
51
|
+
parser: NonNullable<Options['parser']>;
|
|
44
52
|
};
|
|
45
53
|
type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
46
54
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-msw",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.9",
|
|
4
4
|
"description": "Generator swagger",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -74,24 +74,24 @@
|
|
|
74
74
|
"!/**/__tests__/**"
|
|
75
75
|
],
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@kubb/core": "3.0.0-beta.
|
|
78
|
-
"@kubb/fs": "3.0.0-beta.
|
|
79
|
-
"@kubb/oas": "3.0.0-beta.
|
|
80
|
-
"@kubb/plugin-faker": "3.0.0-beta.
|
|
81
|
-
"@kubb/plugin-oas": "3.0.0-beta.
|
|
82
|
-
"@kubb/plugin-ts": "3.0.0-beta.
|
|
83
|
-
"@kubb/react": "3.0.0-beta.
|
|
77
|
+
"@kubb/core": "3.0.0-beta.9",
|
|
78
|
+
"@kubb/fs": "3.0.0-beta.9",
|
|
79
|
+
"@kubb/oas": "3.0.0-beta.9",
|
|
80
|
+
"@kubb/plugin-faker": "3.0.0-beta.9",
|
|
81
|
+
"@kubb/plugin-oas": "3.0.0-beta.9",
|
|
82
|
+
"@kubb/plugin-ts": "3.0.0-beta.9",
|
|
83
|
+
"@kubb/react": "3.0.0-beta.9"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"@types/react": "^18.3.
|
|
86
|
+
"@types/react": "^18.3.12",
|
|
87
87
|
"react": "^18.3.1",
|
|
88
|
-
"tsup": "^8.3.
|
|
88
|
+
"tsup": "^8.3.4",
|
|
89
89
|
"typescript": "^5.6.3",
|
|
90
|
-
"@kubb/config-ts": "3.0.0-beta.
|
|
91
|
-
"@kubb/config-tsup": "3.0.0-beta.
|
|
90
|
+
"@kubb/config-ts": "3.0.0-beta.9",
|
|
91
|
+
"@kubb/config-tsup": "3.0.0-beta.9"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
|
-
"@kubb/react": "3.0.0-beta.
|
|
94
|
+
"@kubb/react": "3.0.0-beta.9"
|
|
95
95
|
},
|
|
96
96
|
"engines": {
|
|
97
97
|
"node": ">=20"
|
package/src/components/Mock.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { File } from '@kubb/react'
|
|
1
|
+
import { File, Function, FunctionParams } from '@kubb/react'
|
|
2
2
|
|
|
3
3
|
import type { HttpMethod } from '@kubb/oas'
|
|
4
4
|
import type { ReactNode } from 'react'
|
|
@@ -8,23 +8,31 @@ type Props = {
|
|
|
8
8
|
* Name of the function
|
|
9
9
|
*/
|
|
10
10
|
name: string
|
|
11
|
+
typeName: string
|
|
11
12
|
fakerName: string
|
|
12
13
|
url: string
|
|
13
14
|
method: HttpMethod
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
export function Mock({ name, fakerName, url, method }: Props): ReactNode {
|
|
17
|
+
export function Mock({ name, fakerName, typeName, url, method }: Props): ReactNode {
|
|
18
|
+
const params = FunctionParams.factory({
|
|
19
|
+
data: {
|
|
20
|
+
type: typeName,
|
|
21
|
+
optional: true,
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
|
|
17
25
|
return (
|
|
18
26
|
<File.Source name={name} isIndexable isExportable>
|
|
19
|
-
{
|
|
20
|
-
|
|
21
|
-
return new Response(JSON.stringify(
|
|
27
|
+
<Function name={name} export params={params.toConstructor()}>
|
|
28
|
+
{`return http.${method}('*${url}', function handler(info) {
|
|
29
|
+
return new Response(JSON.stringify(data), {
|
|
22
30
|
headers: {
|
|
23
31
|
'Content-Type': 'application/json',
|
|
24
32
|
},
|
|
25
33
|
})
|
|
26
|
-
})
|
|
27
|
-
|
|
34
|
+
})`}
|
|
35
|
+
</Function>
|
|
28
36
|
</File.Source>
|
|
29
37
|
)
|
|
30
38
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { File, Function, FunctionParams } from '@kubb/react'
|
|
2
|
+
|
|
3
|
+
import type { HttpMethod } from '@kubb/oas'
|
|
4
|
+
import type { ReactNode } from 'react'
|
|
5
|
+
|
|
6
|
+
type Props = {
|
|
7
|
+
/**
|
|
8
|
+
* Name of the function
|
|
9
|
+
*/
|
|
10
|
+
name: string
|
|
11
|
+
typeName: string
|
|
12
|
+
fakerName: string
|
|
13
|
+
url: string
|
|
14
|
+
method: HttpMethod
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function MockWithFaker({ name, fakerName, typeName, url, method }: Props): ReactNode {
|
|
18
|
+
const params = FunctionParams.factory({
|
|
19
|
+
data: {
|
|
20
|
+
type: typeName,
|
|
21
|
+
optional: true,
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<File.Source name={name} isIndexable isExportable>
|
|
27
|
+
<Function name={name} export params={params.toConstructor()}>
|
|
28
|
+
{`return http.${method}('*${url}', function handler(info) {
|
|
29
|
+
return new Response(JSON.stringify(${fakerName}(data)), {
|
|
30
|
+
headers: {
|
|
31
|
+
'Content-Type': 'application/json',
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
})`}
|
|
35
|
+
</Function>
|
|
36
|
+
</File.Source>
|
|
37
|
+
)
|
|
38
|
+
}
|
package/src/components/index.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { http } from "msw";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
return
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
export function createPets(data?: CreatePetsMutationResponse) {
|
|
4
|
+
return http.post("*/pets", function handler(info) {
|
|
5
|
+
return new Response(JSON.stringify(data), {
|
|
6
|
+
headers: {
|
|
7
|
+
"Content-Type": "application/json",
|
|
8
|
+
},
|
|
9
|
+
});
|
|
8
10
|
});
|
|
9
|
-
}
|
|
11
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { http } from "msw";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
return
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
export function deletePetsPetid(data?: DeletePetsPetidMutationResponse) {
|
|
4
|
+
return http.delete("*/pets/:petId", function handler(info) {
|
|
5
|
+
return new Response(JSON.stringify(data), {
|
|
6
|
+
headers: {
|
|
7
|
+
"Content-Type": "application/json",
|
|
8
|
+
},
|
|
9
|
+
});
|
|
8
10
|
});
|
|
9
|
-
}
|
|
11
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { http } from "msw";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
return
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
export function listPets(data?: ListPetsQueryResponse) {
|
|
4
|
+
return http.get("*/pets", function handler(info) {
|
|
5
|
+
return new Response(JSON.stringify(data), {
|
|
6
|
+
headers: {
|
|
7
|
+
"Content-Type": "application/json",
|
|
8
|
+
},
|
|
9
|
+
});
|
|
8
10
|
});
|
|
9
|
-
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { http } from "msw";
|
|
2
|
+
|
|
3
|
+
export function listPets(data?: ListPetsQueryResponse) {
|
|
4
|
+
return http.get("*/pets", function handler(info) {
|
|
5
|
+
return new Response(JSON.stringify(listPetsQueryResponse(data)), {
|
|
6
|
+
headers: {
|
|
7
|
+
"Content-Type": "application/json",
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { http } from "msw";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
return
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
export function showPetById(data?: ShowPetByIdQueryResponse) {
|
|
4
|
+
return http.get("*/pets/:petId", function handler(info) {
|
|
5
|
+
return new Response(JSON.stringify(data), {
|
|
6
|
+
headers: {
|
|
7
|
+
"Content-Type": "application/json",
|
|
8
|
+
},
|
|
9
|
+
});
|
|
8
10
|
});
|
|
9
|
-
}
|
|
11
|
+
}
|
|
@@ -20,7 +20,7 @@ export const handlersGenerator = createReactGenerator<PluginMsw>({
|
|
|
20
20
|
return <File.Import key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />
|
|
21
21
|
})
|
|
22
22
|
|
|
23
|
-
const handlers = operations.map((operation) => getName(operation, { type: 'function', pluginKey: [pluginMswName] }))
|
|
23
|
+
const handlers = operations.map((operation) => `${getName(operation, { type: 'function', pluginKey: [pluginMswName] })}()`)
|
|
24
24
|
|
|
25
25
|
return (
|
|
26
26
|
<File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>
|
|
@@ -2,8 +2,9 @@ import { URLPath } from '@kubb/core/utils'
|
|
|
2
2
|
import { pluginFakerName } from '@kubb/plugin-faker'
|
|
3
3
|
import { createReactGenerator } from '@kubb/plugin-oas'
|
|
4
4
|
import { useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
5
|
+
import { pluginTsName } from '@kubb/plugin-ts'
|
|
5
6
|
import { File, useApp } from '@kubb/react'
|
|
6
|
-
import { Mock } from '../components'
|
|
7
|
+
import { Mock, MockWithFaker } from '../components'
|
|
7
8
|
import type { PluginMsw } from '../types'
|
|
8
9
|
|
|
9
10
|
export const mswGenerator = createReactGenerator<PluginMsw>({
|
|
@@ -11,7 +12,7 @@ export const mswGenerator = createReactGenerator<PluginMsw>({
|
|
|
11
12
|
Operation({ operation }) {
|
|
12
13
|
const {
|
|
13
14
|
plugin: {
|
|
14
|
-
options: { output },
|
|
15
|
+
options: { output, parser },
|
|
15
16
|
},
|
|
16
17
|
} = useApp<PluginMsw>()
|
|
17
18
|
const { getSchemas, getName, getFile } = useOperationManager()
|
|
@@ -26,12 +27,35 @@ export const mswGenerator = createReactGenerator<PluginMsw>({
|
|
|
26
27
|
schemas: getSchemas(operation, { pluginKey: [pluginFakerName], type: 'function' }),
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
const type = {
|
|
31
|
+
file: getFile(operation, { pluginKey: [pluginTsName] }),
|
|
32
|
+
schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
|
|
33
|
+
}
|
|
34
|
+
|
|
29
35
|
return (
|
|
30
36
|
<File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
31
37
|
<File.Import name={['http']} path={'msw'} />
|
|
38
|
+
<File.Import name={[type.schemas.response.name]} path={type.file.path} root={mock.file.path} isTypeOnly />
|
|
32
39
|
{faker.file && faker.schemas.response && <File.Import name={[faker.schemas.response.name]} root={mock.file.path} path={faker.file.path} />}
|
|
33
40
|
|
|
34
|
-
|
|
41
|
+
{parser === 'faker' && (
|
|
42
|
+
<MockWithFaker
|
|
43
|
+
name={mock.name}
|
|
44
|
+
typeName={type.schemas.response.name}
|
|
45
|
+
fakerName={faker.schemas.response.name}
|
|
46
|
+
method={operation.method}
|
|
47
|
+
url={new URLPath(operation.path).toURLPath()}
|
|
48
|
+
/>
|
|
49
|
+
)}
|
|
50
|
+
{parser === 'data' && (
|
|
51
|
+
<Mock
|
|
52
|
+
name={mock.name}
|
|
53
|
+
typeName={type.schemas.response.name}
|
|
54
|
+
fakerName={faker.schemas.response.name}
|
|
55
|
+
method={operation.method}
|
|
56
|
+
url={new URLPath(operation.path).toURLPath()}
|
|
57
|
+
/>
|
|
58
|
+
)}
|
|
35
59
|
</File>
|
|
36
60
|
)
|
|
37
61
|
},
|
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, pluginOasName } from '@kubb/plugin-oas'
|
|
7
6
|
|
|
8
7
|
import { pluginFakerName } from '@kubb/plugin-faker'
|
|
@@ -24,6 +23,7 @@ export const pluginMsw = createPlugin<PluginMsw>((options) => {
|
|
|
24
23
|
override = [],
|
|
25
24
|
transformers = {},
|
|
26
25
|
handlers = false,
|
|
26
|
+
parser = 'data',
|
|
27
27
|
generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),
|
|
28
28
|
} = options
|
|
29
29
|
|
|
@@ -31,8 +31,9 @@ export const pluginMsw = createPlugin<PluginMsw>((options) => {
|
|
|
31
31
|
name: pluginMswName,
|
|
32
32
|
options: {
|
|
33
33
|
output,
|
|
34
|
+
parser,
|
|
34
35
|
},
|
|
35
|
-
pre: [pluginOasName, pluginTsName, pluginFakerName],
|
|
36
|
+
pre: [pluginOasName, pluginTsName, parser === 'faker' ? pluginFakerName : undefined].filter(Boolean),
|
|
36
37
|
resolvePath(baseName, pathMode, options) {
|
|
37
38
|
const root = path.resolve(this.config.root, this.config.output.path)
|
|
38
39
|
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))
|
package/src/types.ts
CHANGED
|
@@ -35,6 +35,13 @@ export type Options = {
|
|
|
35
35
|
* @default false
|
|
36
36
|
*/
|
|
37
37
|
handlers?: boolean
|
|
38
|
+
/**
|
|
39
|
+
* Which parser can be used before returning the data
|
|
40
|
+
* - `'faker'` will use `@kubb/plugin-faker` to generate the data for the response
|
|
41
|
+
* - `'data'` will use your custom data to generate the data for the response
|
|
42
|
+
* @default 'data'
|
|
43
|
+
*/
|
|
44
|
+
parser?: 'data' | 'faker'
|
|
38
45
|
/**
|
|
39
46
|
* Define some generators next to the msw generators
|
|
40
47
|
*/
|
|
@@ -42,6 +49,7 @@ export type Options = {
|
|
|
42
49
|
}
|
|
43
50
|
type ResolvedOptions = {
|
|
44
51
|
output: Output
|
|
52
|
+
parser: NonNullable<Options['parser']>
|
|
45
53
|
}
|
|
46
54
|
|
|
47
55
|
export type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, never, ResolvePathOptions>
|
package/dist/chunk-6M2QU6UL.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { File } from '@kubb/react';
|
|
2
|
-
import { jsx } from '@kubb/react/jsx-runtime';
|
|
3
|
-
|
|
4
|
-
// src/components/Mock.tsx
|
|
5
|
-
function Mock({ name, fakerName, url, method }) {
|
|
6
|
-
return /* @__PURE__ */ jsx(File.Source, { name, isIndexable: true, isExportable: true, children: `
|
|
7
|
-
export const ${name} = http.${method}('*${url}', function handler(info) {
|
|
8
|
-
return new Response(JSON.stringify(${fakerName}()), {
|
|
9
|
-
headers: {
|
|
10
|
-
'Content-Type': 'application/json',
|
|
11
|
-
},
|
|
12
|
-
})
|
|
13
|
-
})
|
|
14
|
-
` });
|
|
15
|
-
}
|
|
16
|
-
function Handlers({ name, handlers }) {
|
|
17
|
-
return /* @__PURE__ */ jsx(File.Source, { name, isIndexable: true, isExportable: true, children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const` });
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export { Handlers, Mock };
|
|
21
|
-
//# sourceMappingURL=chunk-6M2QU6UL.js.map
|
|
22
|
-
//# sourceMappingURL=chunk-6M2QU6UL.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Mock.tsx","../src/components/Handlers.tsx"],"names":["jsx","File"],"mappings":";;;;AAeO,SAAS,KAAK,EAAE,IAAA,EAAM,SAAW,EAAA,GAAA,EAAK,QAA4B,EAAA;AACvE,EACE,uBAAA,GAAA,CAAC,KAAK,MAAL,EAAA,EAAY,MAAY,WAAW,EAAA,IAAA,EAAC,cAAY,IAC9C,EAAA,QAAA,EAAA,CAAA;AAAA,eAAA,EACU,IAAI,CAAA,QAAA,EAAW,MAAM,CAAA,GAAA,EAAM,GAAG,CAAA;AAAA,uCAAA,EACN,SAAS,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO9C,CAAA,EAAA,CAAA,CAAA;AAEJ,CAAA;ACjBO,SAAS,QAAS,CAAA,EAAE,IAAM,EAAA,QAAA,EAAsC,EAAA;AACrE,EACE,uBAAAA,IAACC,IAAK,CAAA,MAAA,EAAL,EAAY,IAAY,EAAA,WAAA,EAAW,MAAC,YAAY,EAAA,IAAA,EAC9C,0BAAgB,IAAI,CAAA,GAAA,EAAM,KAAK,SAAU,CAAA,QAAQ,EAAE,UAAW,CAAA,CAAA,CAAA,CAAA,EAAK,EAAE,CAAC,CACzE,SAAA,CAAA,EAAA,CAAA,CAAA;AAEJ","file":"chunk-6M2QU6UL.js","sourcesContent":["import { File } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function Mock({ name, fakerName, url, method }: Props): ReactNode {\n return (\n <File.Source name={name} isIndexable isExportable>\n {`\n export const ${name} = http.${method}('*${url}', function handler(info) {\n return new Response(JSON.stringify(${fakerName}()), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })\n `}\n </File.Source>\n )\n}\n","import { File } from '@kubb/react'\nimport type { ReactNode } from 'react'\n\ntype HandlersProps = {\n /**\n * Name of the function\n */\n name: string\n // custom\n handlers: string[]\n}\n\nexport function Handlers({ name, handlers }: HandlersProps): ReactNode {\n return (\n <File.Source name={name} isIndexable isExportable>\n {`export const ${name} = ${JSON.stringify(handlers).replaceAll(`\"`, '')} as const`}\n </File.Source>\n )\n}\n"]}
|
package/dist/chunk-GODA4G5K.cjs
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var react = require('@kubb/react');
|
|
4
|
-
var jsxRuntime = require('@kubb/react/jsx-runtime');
|
|
5
|
-
|
|
6
|
-
// src/components/Mock.tsx
|
|
7
|
-
function Mock({ name, fakerName, url, method }) {
|
|
8
|
-
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isIndexable: true, isExportable: true, children: `
|
|
9
|
-
export const ${name} = http.${method}('*${url}', function handler(info) {
|
|
10
|
-
return new Response(JSON.stringify(${fakerName}()), {
|
|
11
|
-
headers: {
|
|
12
|
-
'Content-Type': 'application/json',
|
|
13
|
-
},
|
|
14
|
-
})
|
|
15
|
-
})
|
|
16
|
-
` });
|
|
17
|
-
}
|
|
18
|
-
function Handlers({ name, handlers }) {
|
|
19
|
-
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isIndexable: true, isExportable: true, children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const` });
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
exports.Handlers = Handlers;
|
|
23
|
-
exports.Mock = Mock;
|
|
24
|
-
//# sourceMappingURL=chunk-GODA4G5K.cjs.map
|
|
25
|
-
//# sourceMappingURL=chunk-GODA4G5K.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Mock.tsx","../src/components/Handlers.tsx"],"names":["jsx","File"],"mappings":";;;;;;AAeO,SAAS,KAAK,EAAE,IAAA,EAAM,SAAW,EAAA,GAAA,EAAK,QAA4B,EAAA;AACvE,EACE,uBAAAA,cAAA,CAACC,WAAK,MAAL,EAAA,EAAY,MAAY,WAAW,EAAA,IAAA,EAAC,cAAY,IAC9C,EAAA,QAAA,EAAA,CAAA;AAAA,eAAA,EACU,IAAI,CAAA,QAAA,EAAW,MAAM,CAAA,GAAA,EAAM,GAAG,CAAA;AAAA,uCAAA,EACN,SAAS,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO9C,CAAA,EAAA,CAAA,CAAA;AAEJ,CAAA;ACjBO,SAAS,QAAS,CAAA,EAAE,IAAM,EAAA,QAAA,EAAsC,EAAA;AACrE,EACE,uBAAAD,eAACC,UAAK,CAAA,MAAA,EAAL,EAAY,IAAY,EAAA,WAAA,EAAW,MAAC,YAAY,EAAA,IAAA,EAC9C,0BAAgB,IAAI,CAAA,GAAA,EAAM,KAAK,SAAU,CAAA,QAAQ,EAAE,UAAW,CAAA,CAAA,CAAA,CAAA,EAAK,EAAE,CAAC,CACzE,SAAA,CAAA,EAAA,CAAA,CAAA;AAEJ","file":"chunk-GODA4G5K.cjs","sourcesContent":["import { File } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function Mock({ name, fakerName, url, method }: Props): ReactNode {\n return (\n <File.Source name={name} isIndexable isExportable>\n {`\n export const ${name} = http.${method}('*${url}', function handler(info) {\n return new Response(JSON.stringify(${fakerName}()), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })\n `}\n </File.Source>\n )\n}\n","import { File } from '@kubb/react'\nimport type { ReactNode } from 'react'\n\ntype HandlersProps = {\n /**\n * Name of the function\n */\n name: string\n // custom\n handlers: string[]\n}\n\nexport function Handlers({ name, handlers }: HandlersProps): ReactNode {\n return (\n <File.Source name={name} isIndexable isExportable>\n {`export const ${name} = ${JSON.stringify(handlers).replaceAll(`\"`, '')} as const`}\n </File.Source>\n )\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generators/mswGenerator.tsx","../src/plugin.ts","../src/generators/handlersGenerator.tsx"],"names":["pluginFakerName","options","createReactGenerator","useApp","useOperationManager","jsx","File","jsxs"],"mappings":";;;;;;;;;;;;AAQO,IAAM,eAAe,oBAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAA,CAAU,EAAE,SAAA,EAAa,EAAA;AACvB,IAAM,MAAA;AAAA,MACJ,MAAQ,EAAA;AAAA,QACN,OAAA,EAAS,EAAE,MAAO,EAAA;AAAA,OACpB;AAAA,QACE,MAAkB,EAAA,CAAA;AACtB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAY,mBAAoB,EAAA,CAAA;AAE7D,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA;AAAA,MAC7C,IAAA,EAAM,QAAQ,SAAS,CAAA;AAAA,KACzB,CAAA;AAEA,IAAA,MAAM,KAAQ,GAAA;AAAA,MACZ,IAAA,EAAM,QAAQ,SAAW,EAAA,EAAE,WAAW,CAAC,eAAe,GAAG,CAAA;AAAA,MACzD,OAAA,EAAS,UAAW,CAAA,SAAA,EAAW,EAAE,SAAA,EAAW,CAAC,e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AAA,aAAA,GAAgB,OAAQ,CAAA,SAAA,EAAW,EAAE,SAAA,EAAW,CAAC,aAAa,CAAA,EAAG,IAAM,EAAA,UAAA,EAAY,CAAA,CAAA;AAEzF,MAAA,uBAAOC,GAACC,CAAAA,IAAAA,CAAK,MAAL,EAAA,EAAqC,MAAM,CAAC,aAAa,CAAG,EAAA,IAAA,EAAM,KAAK,IAAM,EAAA,IAAA,EAAM,aAAc,CAAA,IAAA,EAAA,EAAhF,cAAc,IAAwE,CAAA,CAAA;AAAA,KAChH,CAAA,CAAA;AAED,IAAA,MAAM,QAAW,GAAA,UAAA,CAAW,GAAI,CAAA,CAAC,cAAc,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,SAAW,EAAA,CAAC,aAAa,CAAA,EAAG,CAAC,CAAA,CAAA;AAEnH,IACE,uBAAAC,KAACD,IAAA,EAAA,EAAK,UAAU,IAAK,CAAA,QAAA,EAAU,IAAM,EAAA,IAAA,CAAK,IAAM,EAAA,IAAA,EAAM,KAAK,IAAM,EAAA,MAAA,EAAQ,OAAO,OAAQ,CAAA,MAAA,EAAQ,QAAQ,MAAQ,EAAA,MAAA,CAAO,OAAQ,CAAA,MAAA,EAAQ,MACpI,EAAA,QAAA,EAAA;AAAA,MAAA,OAAA;AAAA,sBACDD,GAAAA,CAAC,QAAS,EAAA,EAAA,IAAA,EAAM,YAAY,QAAoB,EAAA,CAAA;AAAA,KAClD,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-M6V4SSNZ.js","sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Mock } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation }) {\n const {\n plugin: {\n options: { output },\n },\n } = useApp<PluginMsw>()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginFakerName], type: 'function' }),\n }\n\n return (\n <File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta} banner={output?.banner} footer={output?.footer}>\n <File.Import name={['http']} path={'msw'} />\n {faker.file && faker.schemas.response && <File.Import name={[faker.schemas.response.name]} root={mock.file.path} path={faker.file.path} />}\n\n <Mock name={mock.name} fakerName={faker.schemas.response.name} method={operation.method} url={new URLPath(operation.path).toURLPath()} />\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = createPlugin<PluginMsw>((options) => {\n const {\n output = { path: 'handlers', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n handlers = false,\n generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n },\n pre: [pluginOasName, pluginTsName, pluginFakerName],\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 suffix: type ? 'handler' : 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<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(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 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 files = await operationGenerator.build(...generators)\n await this.addFile(...files)\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","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Handlers } from '../components/Handlers.tsx'\nimport { pluginMswName } from '../plugin.ts'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations }) {\n const { pluginManager, plugin } = useApp<PluginMsw>()\n const { getName, getFile } = useOperationManager()\n\n const file = pluginManager.getFile({ name: 'handlers', extname: '.ts', pluginKey: [pluginMswName] })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: [pluginMswName] })\n const operationName = getName(operation, { pluginKey: [pluginMswName], type: 'function' })\n\n return <File.Import key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />\n })\n\n const handlers = operations.map((operation) => getName(operation, { type: 'function', pluginKey: [pluginMswName] }))\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generators/mswGenerator.tsx","../src/plugin.ts","../src/generators/handlersGenerator.tsx"],"names":["createReactGenerator","useApp","useOperationManager","pluginFakerName","File","jsx","Mock","URLPath","createPlugin","transformers","pluginOasName","pluginTsName","options","path","FileManager","camelCase","PluginManager","OperationGenerator","jsxs","Handlers"],"mappings":";;;;;;;;;;;;;;;;;;AAQO,IAAM,eAAeA,8BAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAA,CAAU,EAAE,SAAA,EAAa,EAAA;AACvB,IAAM,MAAA;AAAA,MACJ,MAAQ,EAAA;AAAA,QACN,OAAA,EAAS,EAAE,MAAO,EAAA;AAAA,OACpB;AAAA,QACEC,YAAkB,EAAA,CAAA;AACtB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAYC,yBAAoB,EAAA,CAAA;AAE7D,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA;AAAA,MAC7C,IAAA,EAAM,QAAQ,SAAS,CAAA;AAAA,KACzB,CAAA;AAEA,IAAA,MAAM,KAAQ,GAAA;AAAA,MACZ,IAAA,EAAM,QAAQ,SAAW,EAAA,EAAE,WAAW,CAACC,2BAAe,GAAG,CAAA;AAAA,M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,KAAA;AAC5C,MAAM,MAAA,aAAA,GAAgB,QAAQ,SAAW,EAAA,EAAE,WAAW,CAAC,aAAa,GAAG,CAAA,CAAA;AACvE,MAAM,MAAA,aAAA,GAAgB,OAAQ,CAAA,SAAA,EAAW,EAAE,SAAA,EAAW,CAAC,aAAa,CAAA,EAAG,IAAM,EAAA,UAAA,EAAY,CAAA,CAAA;AAEzF,MAAA,uBAAOG,cAACD,CAAAA,UAAAA,CAAK,MAAL,EAAA,EAAqC,MAAM,CAAC,aAAa,CAAG,EAAA,IAAA,EAAM,KAAK,IAAM,EAAA,IAAA,EAAM,aAAc,CAAA,IAAA,EAAA,EAAhF,cAAc,IAAwE,CAAA,CAAA;AAAA,KAChH,CAAA,CAAA;AAED,IAAA,MAAM,QAAW,GAAA,UAAA,CAAW,GAAI,CAAA,CAAC,cAAc,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,SAAW,EAAA,CAAC,aAAa,CAAA,EAAG,CAAC,CAAA,CAAA;AAEnH,IACE,uBAAAc,gBAACd,UAAA,EAAA,EAAK,UAAU,IAAK,CAAA,QAAA,EAAU,IAAM,EAAA,IAAA,CAAK,IAAM,EAAA,IAAA,EAAM,KAAK,IAAM,EAAA,MAAA,EAAQ,OAAO,OAAQ,CAAA,MAAA,EAAQ,QAAQ,MAAQ,EAAA,MAAA,CAAO,OAAQ,CAAA,MAAA,EAAQ,MACpI,EAAA,QAAA,EAAA;AAAA,MAAA,OAAA;AAAA,sBACDC,cAAAA,CAACc,0BAAS,EAAA,EAAA,IAAA,EAAM,YAAY,QAAoB,EAAA,CAAA;AAAA,KAClD,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-ZZ737QGY.cjs","sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Mock } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation }) {\n const {\n plugin: {\n options: { output },\n },\n } = useApp<PluginMsw>()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginFakerName], type: 'function' }),\n }\n\n return (\n <File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta} banner={output?.banner} footer={output?.footer}>\n <File.Import name={['http']} path={'msw'} />\n {faker.file && faker.schemas.response && <File.Import name={[faker.schemas.response.name]} root={mock.file.path} path={faker.file.path} />}\n\n <Mock name={mock.name} fakerName={faker.schemas.response.name} method={operation.method} url={new URLPath(operation.path).toURLPath()} />\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = createPlugin<PluginMsw>((options) => {\n const {\n output = { path: 'handlers', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n handlers = false,\n generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n },\n pre: [pluginOasName, pluginTsName, pluginFakerName],\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 suffix: type ? 'handler' : 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<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(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 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 files = await operationGenerator.build(...generators)\n await this.addFile(...files)\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","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Handlers } from '../components/Handlers.tsx'\nimport { pluginMswName } from '../plugin.ts'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations }) {\n const { pluginManager, plugin } = useApp<PluginMsw>()\n const { getName, getFile } = useOperationManager()\n\n const file = pluginManager.getFile({ name: 'handlers', extname: '.ts', pluginKey: [pluginMswName] })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: [pluginMswName] })\n const operationName = getName(operation, { pluginKey: [pluginMswName], type: 'function' })\n\n return <File.Import key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />\n })\n\n const handlers = operations.map((operation) => getName(operation, { type: 'function', pluginKey: [pluginMswName] }))\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}
|