@kubb/plugin-msw 3.0.0-alpha.15 → 3.0.0-alpha.16
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-HYNRHFXE.cjs → chunk-5YD7CUAH.cjs} +27 -26
- package/dist/chunk-5YD7CUAH.cjs.map +1 -0
- package/dist/{chunk-2H7SYKGX.js → chunk-6M2QU6UL.js} +5 -7
- package/dist/chunk-6M2QU6UL.js.map +1 -0
- package/dist/{chunk-SFLIUHHL.cjs → chunk-GODA4G5K.cjs} +5 -7
- package/dist/chunk-GODA4G5K.cjs.map +1 -0
- package/dist/{chunk-YSIJ7IAG.js → chunk-XXDW7ZSY.js} +26 -25
- package/dist/chunk-XXDW7ZSY.js.map +1 -0
- package/dist/components.cjs +3 -3
- package/dist/components.d.cts +5 -4
- package/dist/components.d.ts +5 -4
- package/dist/components.js +1 -1
- package/dist/generators.cjs +5 -5
- package/dist/generators.d.cts +2 -2
- package/dist/generators.d.ts +2 -2
- package/dist/generators.js +2 -2
- package/dist/index.cjs +4 -4
- package/dist/index.js +2 -2
- package/package.json +14 -14
- package/src/components/Mock.tsx +7 -10
- package/src/generators/__snapshots__/createPet.ts +9 -0
- package/src/generators/__snapshots__/deletePet.ts +9 -0
- package/src/generators/__snapshots__/getPets.ts +9 -0
- package/src/generators/__snapshots__/handlers.ts +3 -0
- package/src/generators/__snapshots__/showPetById.ts +9 -0
- package/src/generators/handlersGenerator.tsx +2 -2
- package/src/generators/index.ts +1 -1
- package/src/generators/mswGenerator.tsx +36 -0
- package/src/plugin.ts +2 -2
- package/dist/chunk-2H7SYKGX.js.map +0 -1
- package/dist/chunk-HYNRHFXE.cjs.map +0 -1
- package/dist/chunk-SFLIUHHL.cjs.map +0 -1
- package/dist/chunk-YSIJ7IAG.js.map +0 -1
- package/src/components/__snapshots__/Mock/Pets.ts +0 -7
- package/src/components/__snapshots__/Mock/showPetsById.ts +0 -7
- package/src/generators/mockGenerator.tsx +0 -35
|
@@ -1,39 +1,40 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkGODA4G5K_cjs = require('./chunk-GODA4G5K.cjs');
|
|
4
|
+
var utils = require('@kubb/core/utils');
|
|
4
5
|
var pluginFaker = require('@kubb/plugin-faker');
|
|
5
6
|
var pluginOas = require('@kubb/plugin-oas');
|
|
6
7
|
var hooks = require('@kubb/plugin-oas/hooks');
|
|
7
|
-
var pluginTs = require('@kubb/plugin-ts');
|
|
8
8
|
var react = require('@kubb/react');
|
|
9
9
|
var jsxRuntime = require('@kubb/react/jsx-runtime');
|
|
10
10
|
var path = require('path');
|
|
11
11
|
var core = require('@kubb/core');
|
|
12
12
|
var transformers = require('@kubb/core/transformers');
|
|
13
|
-
var
|
|
13
|
+
var pluginTs = require('@kubb/plugin-ts');
|
|
14
14
|
|
|
15
15
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
16
|
|
|
17
17
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
18
18
|
|
|
19
|
-
var
|
|
20
|
-
name: "
|
|
19
|
+
var mswGenerator = pluginOas.createReactGenerator({
|
|
20
|
+
name: "msw",
|
|
21
21
|
Operation({ operation }) {
|
|
22
|
-
const {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
type: "function"
|
|
32
|
-
|
|
33
|
-
|
|
22
|
+
const {
|
|
23
|
+
plugin: { output }
|
|
24
|
+
} = react.useApp();
|
|
25
|
+
const { getSchemaName, getName, getFile } = hooks.useOperationManager();
|
|
26
|
+
const mock = {
|
|
27
|
+
name: getName(operation, { type: "function" }),
|
|
28
|
+
file: getFile(operation)
|
|
29
|
+
};
|
|
30
|
+
const faker = {
|
|
31
|
+
name: getSchemaName(operation, "response", { pluginKey: [pluginFaker.pluginFakerName], type: "function" }),
|
|
32
|
+
file: getFile(operation, { pluginKey: [pluginFaker.pluginFakerName] })
|
|
33
|
+
};
|
|
34
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: mock.file.baseName, path: mock.file.path, meta: mock.file.meta, children: [
|
|
34
35
|
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["http"], path: "msw" }),
|
|
35
|
-
|
|
36
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
36
|
+
faker.file && faker.name && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { extName: output?.extName, name: [faker.name], root: mock.file.path, path: faker.file.path }),
|
|
37
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkGODA4G5K_cjs.Mock, { name: mock.name, fakerName: faker.name, method: operation.method, url: new utils.URLPath(operation.path).toURLPath() })
|
|
37
38
|
] });
|
|
38
39
|
}
|
|
39
40
|
});
|
|
@@ -86,7 +87,7 @@ var pluginMsw = core.createPlugin((options) => {
|
|
|
86
87
|
override,
|
|
87
88
|
mode
|
|
88
89
|
});
|
|
89
|
-
const files = await operationGenerator.build(...[
|
|
90
|
+
const files = await operationGenerator.build(...[mswGenerator, handlers ? handlersGenerator : void 0].filter(Boolean));
|
|
90
91
|
await this.addFile(...files);
|
|
91
92
|
if (this.config.output.exportType) {
|
|
92
93
|
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
@@ -106,25 +107,25 @@ var pluginMsw = core.createPlugin((options) => {
|
|
|
106
107
|
var handlersGenerator = pluginOas.createReactGenerator({
|
|
107
108
|
name: "plugin-msw",
|
|
108
109
|
Operations({ operations }) {
|
|
109
|
-
const { pluginManager } = react.useApp();
|
|
110
|
+
const { pluginManager, plugin } = react.useApp();
|
|
110
111
|
const { getName, getFile } = hooks.useOperationManager();
|
|
111
112
|
const file = pluginManager.getFile({ name: "handlers", extName: ".ts", pluginKey: [pluginMswName] });
|
|
112
113
|
const imports = operations.map((operation) => {
|
|
113
114
|
const operationFile = getFile(operation, { pluginKey: [pluginMswName] });
|
|
114
115
|
const operationName = getName(operation, { pluginKey: [pluginMswName], type: "function" });
|
|
115
|
-
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
|
|
116
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { extName: plugin.output?.extName, name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
|
|
116
117
|
});
|
|
117
118
|
const handlers = operations.map((operation) => getName(operation, { type: "function", pluginKey: [pluginMswName] }));
|
|
118
119
|
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
119
120
|
imports,
|
|
120
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
121
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkGODA4G5K_cjs.Handlers, { name: "handlers", handlers })
|
|
121
122
|
] });
|
|
122
123
|
}
|
|
123
124
|
});
|
|
124
125
|
|
|
125
126
|
exports.handlersGenerator = handlersGenerator;
|
|
126
|
-
exports.
|
|
127
|
+
exports.mswGenerator = mswGenerator;
|
|
127
128
|
exports.pluginMsw = pluginMsw;
|
|
128
129
|
exports.pluginMswName = pluginMswName;
|
|
129
|
-
//# sourceMappingURL=chunk-
|
|
130
|
-
//# sourceMappingURL=chunk-
|
|
130
|
+
//# sourceMappingURL=chunk-5YD7CUAH.cjs.map
|
|
131
|
+
//# sourceMappingURL=chunk-5YD7CUAH.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","jsxs","File","jsx","Mock","URLPath","createPlugin","transformers","pluginOasName","pluginTsName","options","path","FileManager","camelCase","renderTemplate","PluginManager","OperationGenerator","Handlers"],"mappings":";;;;;;;;;;;;;;;;;;AAQO,IAAM,eAAeA,8BAAgC,CAAA;AAAA,EAC1D,I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M,IAAK,CAAA,IAAA,EAAM,IAAM,EAAA,IAAA,CAAK,IACxD,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-5YD7CUAH.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: { output },\n } = useApp<PluginMsw>()\n const { getSchemaName, getName, getFile } = useOperationManager()\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n name: getSchemaName(operation, 'response', { pluginKey: [pluginFakerName], type: 'function' }),\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n }\n\n return (\n <File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta}>\n <File.Import name={['http']} path={'msw'} />\n {faker.file && faker.name && <File.Import extName={output?.extName} name={[faker.name]} root={mock.file.path} path={faker.file.path} />}\n\n <Mock name={mock.name} fakerName={faker.name} method={operation.method} url={new URLPath(operation.path).toURLPath()} />\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { 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 { output = { path: 'handlers' }, group, exclude = [], include, override = [], transformers = {}, handlers = false } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginMswName,\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n options: {},\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 (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\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(...[mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean))\n await this.addFile(...files)\n\n if (this.config.output.exportType) {\n const barrelFiles = await this.fileManager.getBarrelFiles({\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n }\n },\n }\n})\n","import { 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 extName={plugin.output?.extName} 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}>\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { URLPath } from '@kubb/core/utils';
|
|
2
1
|
import { File } from '@kubb/react';
|
|
3
2
|
import { jsx } from '@kubb/react/jsx-runtime';
|
|
4
3
|
|
|
5
4
|
// src/components/Mock.tsx
|
|
6
|
-
function Mock({ name,
|
|
7
|
-
const path = new URLPath(operation.path);
|
|
5
|
+
function Mock({ name, fakerName, url, method }) {
|
|
8
6
|
return /* @__PURE__ */ jsx(File.Source, { name, isIndexable: true, isExportable: true, children: `
|
|
9
|
-
export const ${name} = http.${
|
|
10
|
-
return new Response(JSON.stringify(${
|
|
7
|
+
export const ${name} = http.${method}('*${url}', function handler(info) {
|
|
8
|
+
return new Response(JSON.stringify(${fakerName}()), {
|
|
11
9
|
headers: {
|
|
12
10
|
'Content-Type': 'application/json',
|
|
13
11
|
},
|
|
@@ -20,5 +18,5 @@ function Handlers({ name, handlers }) {
|
|
|
20
18
|
}
|
|
21
19
|
|
|
22
20
|
export { Handlers, Mock };
|
|
23
|
-
//# sourceMappingURL=chunk-
|
|
24
|
-
//# sourceMappingURL=chunk-
|
|
21
|
+
//# sourceMappingURL=chunk-6M2QU6UL.js.map
|
|
22
|
+
//# sourceMappingURL=chunk-6M2QU6UL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var utils = require('@kubb/core/utils');
|
|
4
3
|
var react = require('@kubb/react');
|
|
5
4
|
var jsxRuntime = require('@kubb/react/jsx-runtime');
|
|
6
5
|
|
|
7
6
|
// src/components/Mock.tsx
|
|
8
|
-
function Mock({ name,
|
|
9
|
-
const path = new utils.URLPath(operation.path);
|
|
7
|
+
function Mock({ name, fakerName, url, method }) {
|
|
10
8
|
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isIndexable: true, isExportable: true, children: `
|
|
11
|
-
export const ${name} = http.${
|
|
12
|
-
return new Response(JSON.stringify(${
|
|
9
|
+
export const ${name} = http.${method}('*${url}', function handler(info) {
|
|
10
|
+
return new Response(JSON.stringify(${fakerName}()), {
|
|
13
11
|
headers: {
|
|
14
12
|
'Content-Type': 'application/json',
|
|
15
13
|
},
|
|
@@ -23,5 +21,5 @@ function Handlers({ name, handlers }) {
|
|
|
23
21
|
|
|
24
22
|
exports.Handlers = Handlers;
|
|
25
23
|
exports.Mock = Mock;
|
|
26
|
-
//# sourceMappingURL=chunk-
|
|
27
|
-
//# sourceMappingURL=chunk-
|
|
24
|
+
//# sourceMappingURL=chunk-GODA4G5K.cjs.map
|
|
25
|
+
//# sourceMappingURL=chunk-GODA4G5K.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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,33 +1,34 @@
|
|
|
1
|
-
import { Mock, Handlers } from './chunk-
|
|
1
|
+
import { Mock, Handlers } from './chunk-6M2QU6UL.js';
|
|
2
|
+
import { URLPath, renderTemplate } from '@kubb/core/utils';
|
|
2
3
|
import { pluginFakerName } from '@kubb/plugin-faker';
|
|
3
4
|
import { createReactGenerator, pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
|
|
4
5
|
import { useOperationManager } from '@kubb/plugin-oas/hooks';
|
|
5
|
-
import { pluginTsName } from '@kubb/plugin-ts';
|
|
6
6
|
import { useApp, File } from '@kubb/react';
|
|
7
7
|
import { jsxs, jsx } from '@kubb/react/jsx-runtime';
|
|
8
8
|
import path from 'node:path';
|
|
9
9
|
import { createPlugin, FileManager, PluginManager } from '@kubb/core';
|
|
10
10
|
import { camelCase } from '@kubb/core/transformers';
|
|
11
|
-
import {
|
|
11
|
+
import { pluginTsName } from '@kubb/plugin-ts';
|
|
12
12
|
|
|
13
|
-
var
|
|
14
|
-
name: "
|
|
13
|
+
var mswGenerator = createReactGenerator({
|
|
14
|
+
name: "msw",
|
|
15
15
|
Operation({ operation }) {
|
|
16
|
-
const {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
type: "function"
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
const {
|
|
17
|
+
plugin: { output }
|
|
18
|
+
} = useApp();
|
|
19
|
+
const { getSchemaName, getName, getFile } = useOperationManager();
|
|
20
|
+
const mock = {
|
|
21
|
+
name: getName(operation, { type: "function" }),
|
|
22
|
+
file: getFile(operation)
|
|
23
|
+
};
|
|
24
|
+
const faker = {
|
|
25
|
+
name: getSchemaName(operation, "response", { pluginKey: [pluginFakerName], type: "function" }),
|
|
26
|
+
file: getFile(operation, { pluginKey: [pluginFakerName] })
|
|
27
|
+
};
|
|
28
|
+
return /* @__PURE__ */ jsxs(File, { baseName: mock.file.baseName, path: mock.file.path, meta: mock.file.meta, children: [
|
|
28
29
|
/* @__PURE__ */ jsx(File.Import, { name: ["http"], path: "msw" }),
|
|
29
|
-
|
|
30
|
-
/* @__PURE__ */ jsx(Mock, { name,
|
|
30
|
+
faker.file && faker.name && /* @__PURE__ */ jsx(File.Import, { extName: output?.extName, name: [faker.name], root: mock.file.path, path: faker.file.path }),
|
|
31
|
+
/* @__PURE__ */ jsx(Mock, { name: mock.name, fakerName: faker.name, method: operation.method, url: new URLPath(operation.path).toURLPath() })
|
|
31
32
|
] });
|
|
32
33
|
}
|
|
33
34
|
});
|
|
@@ -80,7 +81,7 @@ var pluginMsw = createPlugin((options) => {
|
|
|
80
81
|
override,
|
|
81
82
|
mode
|
|
82
83
|
});
|
|
83
|
-
const files = await operationGenerator.build(...[
|
|
84
|
+
const files = await operationGenerator.build(...[mswGenerator, handlers ? handlersGenerator : void 0].filter(Boolean));
|
|
84
85
|
await this.addFile(...files);
|
|
85
86
|
if (this.config.output.exportType) {
|
|
86
87
|
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
@@ -100,13 +101,13 @@ var pluginMsw = createPlugin((options) => {
|
|
|
100
101
|
var handlersGenerator = createReactGenerator({
|
|
101
102
|
name: "plugin-msw",
|
|
102
103
|
Operations({ operations }) {
|
|
103
|
-
const { pluginManager } = useApp();
|
|
104
|
+
const { pluginManager, plugin } = useApp();
|
|
104
105
|
const { getName, getFile } = useOperationManager();
|
|
105
106
|
const file = pluginManager.getFile({ name: "handlers", extName: ".ts", pluginKey: [pluginMswName] });
|
|
106
107
|
const imports = operations.map((operation) => {
|
|
107
108
|
const operationFile = getFile(operation, { pluginKey: [pluginMswName] });
|
|
108
109
|
const operationName = getName(operation, { pluginKey: [pluginMswName], type: "function" });
|
|
109
|
-
return /* @__PURE__ */ jsx(File.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
|
|
110
|
+
return /* @__PURE__ */ jsx(File.Import, { extName: plugin.output?.extName, name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
|
|
110
111
|
});
|
|
111
112
|
const handlers = operations.map((operation) => getName(operation, { type: "function", pluginKey: [pluginMswName] }));
|
|
112
113
|
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
@@ -116,6 +117,6 @@ var handlersGenerator = createReactGenerator({
|
|
|
116
117
|
}
|
|
117
118
|
});
|
|
118
119
|
|
|
119
|
-
export { handlersGenerator,
|
|
120
|
-
//# sourceMappingURL=chunk-
|
|
121
|
-
//# sourceMappingURL=chunk-
|
|
120
|
+
export { handlersGenerator, mswGenerator, pluginMsw, pluginMswName };
|
|
121
|
+
//# sourceMappingURL=chunk-XXDW7ZSY.js.map
|
|
122
|
+
//# sourceMappingURL=chunk-XXDW7ZSY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,MAAA,EAAQ,EAAE,MAAO,EAAA;AAAA,QACf,MAAkB,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,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-XXDW7ZSY.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: { output },\n } = useApp<PluginMsw>()\n const { getSchemaName, getName, getFile } = useOperationManager()\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n name: getSchemaName(operation, 'response', { pluginKey: [pluginFakerName], type: 'function' }),\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n }\n\n return (\n <File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta}>\n <File.Import name={['http']} path={'msw'} />\n {faker.file && faker.name && <File.Import extName={output?.extName} name={[faker.name]} root={mock.file.path} path={faker.file.path} />}\n\n <Mock name={mock.name} fakerName={faker.name} method={operation.method} url={new URLPath(operation.path).toURLPath()} />\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { 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 { output = { path: 'handlers' }, group, exclude = [], include, override = [], transformers = {}, handlers = false } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginMswName,\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n options: {},\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 (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\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(...[mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean))\n await this.addFile(...files)\n\n if (this.config.output.exportType) {\n const barrelFiles = await this.fileManager.getBarrelFiles({\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n }\n },\n }\n})\n","import { 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 extName={plugin.output?.extName} 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}>\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}
|
package/dist/components.cjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkGODA4G5K_cjs = require('./chunk-GODA4G5K.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 chunkGODA4G5K_cjs.Handlers; }
|
|
10
10
|
});
|
|
11
11
|
Object.defineProperty(exports, "Mock", {
|
|
12
12
|
enumerable: true,
|
|
13
|
-
get: function () { return
|
|
13
|
+
get: function () { return chunkGODA4G5K_cjs.Mock; }
|
|
14
14
|
});
|
|
15
15
|
//# sourceMappingURL=components.cjs.map
|
|
16
16
|
//# sourceMappingURL=components.cjs.map
|
package/dist/components.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HttpMethod } from '@kubb/oas';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
|
|
4
4
|
type Props = {
|
|
@@ -6,10 +6,11 @@ type Props = {
|
|
|
6
6
|
* Name of the function
|
|
7
7
|
*/
|
|
8
8
|
name: string;
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
fakerName: string;
|
|
10
|
+
url: string;
|
|
11
|
+
method: HttpMethod;
|
|
11
12
|
};
|
|
12
|
-
declare function Mock({ name,
|
|
13
|
+
declare function Mock({ name, fakerName, url, method }: Props): ReactNode;
|
|
13
14
|
|
|
14
15
|
type HandlersProps = {
|
|
15
16
|
/**
|
package/dist/components.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HttpMethod } from '@kubb/oas';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
|
|
4
4
|
type Props = {
|
|
@@ -6,10 +6,11 @@ type Props = {
|
|
|
6
6
|
* Name of the function
|
|
7
7
|
*/
|
|
8
8
|
name: string;
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
fakerName: string;
|
|
10
|
+
url: string;
|
|
11
|
+
method: HttpMethod;
|
|
11
12
|
};
|
|
12
|
-
declare function Mock({ name,
|
|
13
|
+
declare function Mock({ name, fakerName, url, method }: Props): ReactNode;
|
|
13
14
|
|
|
14
15
|
type HandlersProps = {
|
|
15
16
|
/**
|
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 chunk5YD7CUAH_cjs = require('./chunk-5YD7CUAH.cjs');
|
|
4
|
+
require('./chunk-GODA4G5K.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 chunk5YD7CUAH_cjs.handlersGenerator; }
|
|
11
11
|
});
|
|
12
|
-
Object.defineProperty(exports, "
|
|
12
|
+
Object.defineProperty(exports, "mswGenerator", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunk5YD7CUAH_cjs.mswGenerator; }
|
|
15
15
|
});
|
|
16
16
|
//# sourceMappingURL=generators.cjs.map
|
|
17
17
|
//# sourceMappingURL=generators.cjs.map
|
package/dist/generators.d.cts
CHANGED
|
@@ -3,8 +3,8 @@ import { P as PluginMsw } from './types-cZ4a5aFe.cjs';
|
|
|
3
3
|
import '@kubb/core';
|
|
4
4
|
import '@kubb/fs/types';
|
|
5
5
|
|
|
6
|
-
declare const
|
|
6
|
+
declare const mswGenerator: _kubb_plugin_oas.Generator<PluginMsw>;
|
|
7
7
|
|
|
8
8
|
declare const handlersGenerator: _kubb_plugin_oas.Generator<PluginMsw>;
|
|
9
9
|
|
|
10
|
-
export { handlersGenerator,
|
|
10
|
+
export { handlersGenerator, mswGenerator };
|
package/dist/generators.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { P as PluginMsw } from './types-cZ4a5aFe.js';
|
|
|
3
3
|
import '@kubb/core';
|
|
4
4
|
import '@kubb/fs/types';
|
|
5
5
|
|
|
6
|
-
declare const
|
|
6
|
+
declare const mswGenerator: _kubb_plugin_oas.Generator<PluginMsw>;
|
|
7
7
|
|
|
8
8
|
declare const handlersGenerator: _kubb_plugin_oas.Generator<PluginMsw>;
|
|
9
9
|
|
|
10
|
-
export { handlersGenerator,
|
|
10
|
+
export { handlersGenerator, mswGenerator };
|
package/dist/generators.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { handlersGenerator,
|
|
2
|
-
import './chunk-
|
|
1
|
+
export { handlersGenerator, mswGenerator } from './chunk-XXDW7ZSY.js';
|
|
2
|
+
import './chunk-6M2QU6UL.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 chunk5YD7CUAH_cjs = require('./chunk-5YD7CUAH.cjs');
|
|
4
|
+
require('./chunk-GODA4G5K.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 chunk5YD7CUAH_cjs.pluginMsw; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "pluginMswName", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunk5YD7CUAH_cjs.pluginMswName; }
|
|
15
15
|
});
|
|
16
16
|
//# sourceMappingURL=index.cjs.map
|
|
17
17
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-msw",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.16",
|
|
4
4
|
"description": "Generator swagger",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -74,27 +74,27 @@
|
|
|
74
74
|
"!/**/__tests__/**"
|
|
75
75
|
],
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@kubb/core": "3.0.0-alpha.
|
|
78
|
-
"@kubb/fs": "3.0.0-alpha.
|
|
79
|
-
"@kubb/oas": "3.0.0-alpha.
|
|
80
|
-
"@kubb/parser-ts": "3.0.0-alpha.
|
|
81
|
-
"@kubb/plugin-faker": "3.0.0-alpha.
|
|
82
|
-
"@kubb/plugin-oas": "3.0.0-alpha.
|
|
83
|
-
"@kubb/plugin-ts": "3.0.0-alpha.
|
|
84
|
-
"@kubb/react": "3.0.0-alpha.
|
|
77
|
+
"@kubb/core": "3.0.0-alpha.16",
|
|
78
|
+
"@kubb/fs": "3.0.0-alpha.16",
|
|
79
|
+
"@kubb/oas": "3.0.0-alpha.16",
|
|
80
|
+
"@kubb/parser-ts": "3.0.0-alpha.16",
|
|
81
|
+
"@kubb/plugin-faker": "3.0.0-alpha.16",
|
|
82
|
+
"@kubb/plugin-oas": "3.0.0-alpha.16",
|
|
83
|
+
"@kubb/plugin-ts": "3.0.0-alpha.16",
|
|
84
|
+
"@kubb/react": "3.0.0-alpha.16"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@types/react": "^18.3.5",
|
|
88
88
|
"@types/react-dom": "^18.3.0",
|
|
89
89
|
"react": "^18.3.1",
|
|
90
90
|
"tsup": "^8.2.4",
|
|
91
|
-
"typescript": "^5.
|
|
92
|
-
"@kubb/config-biome": "3.0.0-alpha.
|
|
93
|
-
"@kubb/config-ts": "3.0.0-alpha.
|
|
94
|
-
"@kubb/config-tsup": "3.0.0-alpha.
|
|
91
|
+
"typescript": "^5.6.2",
|
|
92
|
+
"@kubb/config-biome": "3.0.0-alpha.16",
|
|
93
|
+
"@kubb/config-ts": "3.0.0-alpha.16",
|
|
94
|
+
"@kubb/config-tsup": "3.0.0-alpha.16"
|
|
95
95
|
},
|
|
96
96
|
"peerDependencies": {
|
|
97
|
-
"@kubb/react": "3.0.0-alpha.
|
|
97
|
+
"@kubb/react": "3.0.0-alpha.16"
|
|
98
98
|
},
|
|
99
99
|
"engines": {
|
|
100
100
|
"node": ">=20"
|
package/src/components/Mock.tsx
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { URLPath } from '@kubb/core/utils'
|
|
2
1
|
import { File } from '@kubb/react'
|
|
3
2
|
|
|
4
|
-
import type {
|
|
3
|
+
import type { HttpMethod } from '@kubb/oas'
|
|
5
4
|
import type { ReactNode } from 'react'
|
|
6
5
|
|
|
7
6
|
type Props = {
|
|
@@ -9,19 +8,17 @@ type Props = {
|
|
|
9
8
|
* Name of the function
|
|
10
9
|
*/
|
|
11
10
|
name: string
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
fakerName: string
|
|
12
|
+
url: string
|
|
13
|
+
method: HttpMethod
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
export function Mock({ name,
|
|
18
|
-
const path = new URLPath(operation.path)
|
|
19
|
-
|
|
16
|
+
export function Mock({ name, fakerName, url, method }: Props): ReactNode {
|
|
20
17
|
return (
|
|
21
18
|
<File.Source name={name} isIndexable isExportable>
|
|
22
19
|
{`
|
|
23
|
-
export const ${name} = http.${
|
|
24
|
-
return new Response(JSON.stringify(${
|
|
20
|
+
export const ${name} = http.${method}('*${url}', function handler(info) {
|
|
21
|
+
return new Response(JSON.stringify(${fakerName}()), {
|
|
25
22
|
headers: {
|
|
26
23
|
'Content-Type': 'application/json',
|
|
27
24
|
},
|
|
@@ -8,7 +8,7 @@ import type { PluginMsw } from '../types'
|
|
|
8
8
|
export const handlersGenerator = createReactGenerator<PluginMsw>({
|
|
9
9
|
name: 'plugin-msw',
|
|
10
10
|
Operations({ operations }) {
|
|
11
|
-
const { pluginManager } = useApp<PluginMsw>()
|
|
11
|
+
const { pluginManager, plugin } = useApp<PluginMsw>()
|
|
12
12
|
const { getName, getFile } = useOperationManager()
|
|
13
13
|
|
|
14
14
|
const file = pluginManager.getFile({ name: 'handlers', extName: '.ts', pluginKey: [pluginMswName] })
|
|
@@ -17,7 +17,7 @@ export const handlersGenerator = createReactGenerator<PluginMsw>({
|
|
|
17
17
|
const operationFile = getFile(operation, { pluginKey: [pluginMswName] })
|
|
18
18
|
const operationName = getName(operation, { pluginKey: [pluginMswName], type: 'function' })
|
|
19
19
|
|
|
20
|
-
return <File.Import key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />
|
|
20
|
+
return <File.Import extName={plugin.output?.extName} key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />
|
|
21
21
|
})
|
|
22
22
|
|
|
23
23
|
const handlers = operations.map((operation) => getName(operation, { type: 'function', pluginKey: [pluginMswName] }))
|
package/src/generators/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { mswGenerator } from './mswGenerator.tsx'
|
|
2
2
|
export { handlersGenerator } from './handlersGenerator.tsx'
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { URLPath } from '@kubb/core/utils'
|
|
2
|
+
import { pluginFakerName } from '@kubb/plugin-faker'
|
|
3
|
+
import { createReactGenerator } from '@kubb/plugin-oas'
|
|
4
|
+
import { useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
5
|
+
import { File, useApp } from '@kubb/react'
|
|
6
|
+
import { Mock } from '../components'
|
|
7
|
+
import type { PluginMsw } from '../types'
|
|
8
|
+
|
|
9
|
+
export const mswGenerator = createReactGenerator<PluginMsw>({
|
|
10
|
+
name: 'msw',
|
|
11
|
+
Operation({ operation }) {
|
|
12
|
+
const {
|
|
13
|
+
plugin: { output },
|
|
14
|
+
} = useApp<PluginMsw>()
|
|
15
|
+
const { getSchemaName, getName, getFile } = useOperationManager()
|
|
16
|
+
|
|
17
|
+
const mock = {
|
|
18
|
+
name: getName(operation, { type: 'function' }),
|
|
19
|
+
file: getFile(operation),
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const faker = {
|
|
23
|
+
name: getSchemaName(operation, 'response', { pluginKey: [pluginFakerName], type: 'function' }),
|
|
24
|
+
file: getFile(operation, { pluginKey: [pluginFakerName] }),
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta}>
|
|
29
|
+
<File.Import name={['http']} path={'msw'} />
|
|
30
|
+
{faker.file && faker.name && <File.Import extName={output?.extName} name={[faker.name]} root={mock.file.path} path={faker.file.path} />}
|
|
31
|
+
|
|
32
|
+
<Mock name={mock.name} fakerName={faker.name} method={operation.method} url={new URLPath(operation.path).toURLPath()} />
|
|
33
|
+
</File>
|
|
34
|
+
)
|
|
35
|
+
},
|
|
36
|
+
})
|
package/src/plugin.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { pluginTsName } from '@kubb/plugin-ts'
|
|
|
10
10
|
|
|
11
11
|
import type { Plugin } from '@kubb/core'
|
|
12
12
|
import type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'
|
|
13
|
-
import { handlersGenerator,
|
|
13
|
+
import { handlersGenerator, mswGenerator } from './generators'
|
|
14
14
|
import type { PluginMsw } from './types.ts'
|
|
15
15
|
|
|
16
16
|
export const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']
|
|
@@ -76,7 +76,7 @@ export const pluginMsw = createPlugin<PluginMsw>((options) => {
|
|
|
76
76
|
mode,
|
|
77
77
|
})
|
|
78
78
|
|
|
79
|
-
const files = await operationGenerator.build(...[
|
|
79
|
+
const files = await operationGenerator.build(...[mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean))
|
|
80
80
|
await this.addFile(...files)
|
|
81
81
|
|
|
82
82
|
if (this.config.output.exportType) {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Mock.tsx","../src/components/Handlers.tsx"],"names":["jsx","File"],"mappings":";;;;;AAgBO,SAAS,IAAK,CAAA,EAAE,IAAM,EAAA,YAAA,EAAc,WAA+B,EAAA;AACxE,EAAA,MAAM,IAAO,GAAA,IAAI,OAAQ,CAAA,SAAA,CAAU,IAAI,CAAA,CAAA;AAEvC,EACE,uBAAA,GAAA,CAAC,KAAK,MAAL,EAAA,EAAY,MAAY,WAAW,EAAA,IAAA,EAAC,cAAY,IAC9C,EAAA,QAAA,EAAA,CAAA;AAAA,eAAA,EACU,IAAI,CAAW,QAAA,EAAA,SAAA,CAAU,MAAM,CAAM,GAAA,EAAA,IAAA,CAAK,WAAW,CAAA;AAAA,uCAAA,EAC7B,YAAY,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOjD,CAAA,EAAA,CAAA,CAAA;AAEJ,CAAA;ACpBO,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-2H7SYKGX.js","sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { File } from '@kubb/react'\n\nimport type { Operation } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n operation: Operation\n // custom\n responseName: string\n}\n\nexport function Mock({ name, responseName, operation }: Props): ReactNode {\n const path = new URLPath(operation.path)\n\n return (\n <File.Source name={name} isIndexable isExportable>\n {`\n export const ${name} = http.${operation.method}('*${path.toURLPath()}', function handler(info) {\n return new Response(JSON.stringify(${responseName}()), {\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/mockGenerator.tsx","../src/plugin.ts","../src/generators/handlersGenerator.tsx"],"names":["createReactGenerator","useApp","useOperationManager","pluginFakerName","pluginTsName","jsxs","File","jsx","Mock","createPlugin","transform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AA,IAAA,CAAK,IACxD,EAAA,QAAA,EAAA;AAAA,MAAA,OAAA;AAAA,sBACDC,cAAAA,CAACY,0BAAS,EAAA,EAAA,IAAA,EAAM,YAAY,QAAoB,EAAA,CAAA;AAAA,KAClD,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-HYNRHFXE.cjs","sourcesContent":["import { 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 } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mockGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operation({ operation }) {\n const { pluginManager, plugin } = useApp<PluginMsw>()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const name = getName(operation, { type: 'function' })\n const file = getFile(operation)\n const fakerFile = getFile(operation, { pluginKey: [pluginFakerName] })\n const fakerSchemas = getSchemas(operation, { pluginKey: [pluginTsName] })\n\n const responseName = pluginManager.resolveName({\n pluginKey: [pluginFakerName],\n name: fakerSchemas.response.name,\n type: 'function',\n })\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta}>\n <File.Import name={['http']} path={'msw'} />\n {fakerFile && responseName && <File.Import extName={plugin.output?.extName} name={[responseName]} root={file.path} path={fakerFile.path} />}\n\n <Mock name={name} responseName={responseName} operation={operation} />\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { 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, mockGenerator } 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 { output = { path: 'handlers' }, group, exclude = [], include, override = [], transformers = {}, handlers = false } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginMswName,\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n options: {},\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 (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\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(...[mockGenerator, handlers ? handlersGenerator : undefined].filter(Boolean))\n await this.addFile(...files)\n\n if (this.config.output.exportType) {\n const barrelFiles = await this.fileManager.getBarrelFiles({\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n }\n },\n }\n})\n","import { 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 } = 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}>\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Mock.tsx","../src/components/Handlers.tsx"],"names":["URLPath","jsx","File"],"mappings":";;;;;;;AAgBO,SAAS,IAAK,CAAA,EAAE,IAAM,EAAA,YAAA,EAAc,WAA+B,EAAA;AACxE,EAAA,MAAM,IAAO,GAAA,IAAIA,aAAQ,CAAA,SAAA,CAAU,IAAI,CAAA,CAAA;AAEvC,EACE,uBAAAC,cAAA,CAACC,WAAK,MAAL,EAAA,EAAY,MAAY,WAAW,EAAA,IAAA,EAAC,cAAY,IAC9C,EAAA,QAAA,EAAA,CAAA;AAAA,eAAA,EACU,IAAI,CAAW,QAAA,EAAA,SAAA,CAAU,MAAM,CAAM,GAAA,EAAA,IAAA,CAAK,WAAW,CAAA;AAAA,uCAAA,EAC7B,YAAY,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOjD,CAAA,EAAA,CAAA,CAAA;AAEJ,CAAA;ACpBO,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-SFLIUHHL.cjs","sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { File } from '@kubb/react'\n\nimport type { Operation } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n operation: Operation\n // custom\n responseName: string\n}\n\nexport function Mock({ name, responseName, operation }: Props): ReactNode {\n const path = new URLPath(operation.path)\n\n return (\n <File.Source name={name} isIndexable isExportable>\n {`\n export const ${name} = http.${operation.method}('*${path.toURLPath()}', function handler(info) {\n return new Response(JSON.stringify(${responseName}()), {\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/mockGenerator.tsx","../src/plugin.ts","../src/generators/handlersGenerator.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AA;AAAA,sBACDD,GAAAA,CAAC,QAAS,EAAA,EAAA,IAAA,EAAM,YAAY,QAAoB,EAAA,CAAA;AAAA,KAClD,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-YSIJ7IAG.js","sourcesContent":["import { 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 } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mockGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operation({ operation }) {\n const { pluginManager, plugin } = useApp<PluginMsw>()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const name = getName(operation, { type: 'function' })\n const file = getFile(operation)\n const fakerFile = getFile(operation, { pluginKey: [pluginFakerName] })\n const fakerSchemas = getSchemas(operation, { pluginKey: [pluginTsName] })\n\n const responseName = pluginManager.resolveName({\n pluginKey: [pluginFakerName],\n name: fakerSchemas.response.name,\n type: 'function',\n })\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta}>\n <File.Import name={['http']} path={'msw'} />\n {fakerFile && responseName && <File.Import extName={plugin.output?.extName} name={[responseName]} root={file.path} path={fakerFile.path} />}\n\n <Mock name={name} responseName={responseName} operation={operation} />\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { 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, mockGenerator } 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 { output = { path: 'handlers' }, group, exclude = [], include, override = [], transformers = {}, handlers = false } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginMswName,\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n options: {},\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 (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\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(...[mockGenerator, handlers ? handlersGenerator : undefined].filter(Boolean))\n await this.addFile(...files)\n\n if (this.config.output.exportType) {\n const barrelFiles = await this.fileManager.getBarrelFiles({\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n }\n },\n }\n})\n","import { 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 } = 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}>\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { pluginFakerName } from '@kubb/plugin-faker'
|
|
2
|
-
import { createReactGenerator } from '@kubb/plugin-oas'
|
|
3
|
-
import { useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
4
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
5
|
-
import { File, useApp } from '@kubb/react'
|
|
6
|
-
import { Mock } from '../components'
|
|
7
|
-
import type { PluginMsw } from '../types'
|
|
8
|
-
|
|
9
|
-
export const mockGenerator = createReactGenerator<PluginMsw>({
|
|
10
|
-
name: 'plugin-msw',
|
|
11
|
-
Operation({ operation }) {
|
|
12
|
-
const { pluginManager, plugin } = useApp<PluginMsw>()
|
|
13
|
-
const { getSchemas, getName, getFile } = useOperationManager()
|
|
14
|
-
|
|
15
|
-
const name = getName(operation, { type: 'function' })
|
|
16
|
-
const file = getFile(operation)
|
|
17
|
-
const fakerFile = getFile(operation, { pluginKey: [pluginFakerName] })
|
|
18
|
-
const fakerSchemas = getSchemas(operation, { pluginKey: [pluginTsName] })
|
|
19
|
-
|
|
20
|
-
const responseName = pluginManager.resolveName({
|
|
21
|
-
pluginKey: [pluginFakerName],
|
|
22
|
-
name: fakerSchemas.response.name,
|
|
23
|
-
type: 'function',
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
<File baseName={file.baseName} path={file.path} meta={file.meta}>
|
|
28
|
-
<File.Import name={['http']} path={'msw'} />
|
|
29
|
-
{fakerFile && responseName && <File.Import extName={plugin.output?.extName} name={[responseName]} root={file.path} path={fakerFile.path} />}
|
|
30
|
-
|
|
31
|
-
<Mock name={name} responseName={responseName} operation={operation} />
|
|
32
|
-
</File>
|
|
33
|
-
)
|
|
34
|
-
},
|
|
35
|
-
})
|