@kubb/plugin-msw 3.4.5 → 3.5.1

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.
@@ -0,0 +1,93 @@
1
+ import { MockWithFaker, Mock, Handlers } from './chunk-LOYUDIPB.js';
2
+ import { URLPath } from '@kubb/core/utils';
3
+ import { pluginFakerName } from '@kubb/plugin-faker';
4
+ import { createReactGenerator } from '@kubb/plugin-oas';
5
+ import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks';
6
+ import { getBanner, getFooter } from '@kubb/plugin-oas/utils';
7
+ import { pluginTsName } from '@kubb/plugin-ts';
8
+ import { useApp, File } from '@kubb/react';
9
+ import { jsxs, jsx } from '@kubb/react/jsx-runtime';
10
+
11
+ var mswGenerator = createReactGenerator({
12
+ name: "msw",
13
+ Operation({ operation }) {
14
+ const {
15
+ plugin: {
16
+ options: { output, parser }
17
+ }
18
+ } = useApp();
19
+ const oas = useOas();
20
+ const { getSchemas, getName, getFile } = useOperationManager();
21
+ const mock = {
22
+ name: getName(operation, { type: "function" }),
23
+ file: getFile(operation)
24
+ };
25
+ const faker = {
26
+ file: getFile(operation, { pluginKey: [pluginFakerName] }),
27
+ schemas: getSchemas(operation, { pluginKey: [pluginFakerName], type: "function" })
28
+ };
29
+ const type = {
30
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
31
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: "type" })
32
+ };
33
+ return /* @__PURE__ */ jsxs(File, { baseName: mock.file.baseName, path: mock.file.path, meta: mock.file.meta, banner: getBanner({ oas, output }), footer: getFooter({ oas, output }), children: [
34
+ /* @__PURE__ */ jsx(File.Import, { name: ["http"], path: "msw" }),
35
+ /* @__PURE__ */ jsx(File.Import, { name: ["ResponseResolver"], isTypeOnly: true, path: "msw" }),
36
+ /* @__PURE__ */ jsx(File.Import, { name: [type.schemas.response.name], path: type.file.path, root: mock.file.path, isTypeOnly: true }),
37
+ parser === "faker" && faker.file && faker.schemas.response && /* @__PURE__ */ jsx(File.Import, { name: [faker.schemas.response.name], root: mock.file.path, path: faker.file.path }),
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
+ )
58
+ ] });
59
+ }
60
+ });
61
+ var handlersGenerator = createReactGenerator({
62
+ name: "plugin-msw",
63
+ Operations({ operations }) {
64
+ const { pluginManager, plugin } = useApp();
65
+ const oas = useOas();
66
+ const { getName, getFile } = useOperationManager();
67
+ const file = pluginManager.getFile({ name: "handlers", extname: ".ts", pluginKey: plugin.key });
68
+ const imports = operations.map((operation) => {
69
+ const operationFile = getFile(operation, { pluginKey: plugin.key });
70
+ const operationName = getName(operation, { pluginKey: plugin.key, type: "function" });
71
+ return /* @__PURE__ */ jsx(File.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
72
+ });
73
+ const handlers = operations.map((operation) => `${getName(operation, { type: "function", pluginKey: plugin.key })}()`);
74
+ return /* @__PURE__ */ jsxs(
75
+ File,
76
+ {
77
+ baseName: file.baseName,
78
+ path: file.path,
79
+ meta: file.meta,
80
+ banner: getBanner({ oas, output: plugin.options.output }),
81
+ footer: getFooter({ oas, output: plugin.options.output }),
82
+ children: [
83
+ imports,
84
+ /* @__PURE__ */ jsx(Handlers, { name: "handlers", handlers })
85
+ ]
86
+ }
87
+ );
88
+ }
89
+ });
90
+
91
+ export { handlersGenerator, mswGenerator };
92
+ //# sourceMappingURL=chunk-DYRPP4NT.js.map
93
+ //# sourceMappingURL=chunk-DYRPP4NT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/generators/mswGenerator.tsx","../src/generators/handlersGenerator.tsx"],"names":["createReactGenerator","useApp","useOas","useOperationManager","jsx","File","jsxs","getBanner","getFooter"],"mappings":";;;;;;;;;;AAUO,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,MAAA,EAAQ,MAAO;AAAA;AAC5B,QACE,MAAkB,EAAA;AACtB,IAAA,MAAM,MAAM,MAAO,EAAA;AACnB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAY,mBAAoB,EAAA;AAE7D,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA;AAAA,MAC7C,IAAA,EAAM,QAAQ,SAAS;AAAA,KACzB;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,eAAe,CAAA,EAAG,IAAM,EAAA,UAAA,EAAY;AAAA,KACnF;AAEA,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,IAAA,EAAM,QAAQ,SAAW,EAAA,EAAE,WAAW,CAAC,YAAY,GAAG,CAAA;AAAA,MACtD,OAAA,EAAS,UAAW,CAAA,SAAA,EAAW,EAAE,SAAA,EAAW,CAAC,YAAY,CAAA,EAAG,IAAM,EAAA,MAAA,EAAQ;AAAA,KAC5E;AAEA,IACE,uBAAA,IAAA,CAAC,IAAK,EAAA,EAAA,QAAA,EAAU,IAAK,CAAA,IAAA,CAAK,QAAU,EAAA,IA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AAA,GAAA,EAAK,IAAM,EAAA,UAAA,EAAY,CAAA;AAEpF,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;AAAA,KAChH,CAAA;AAED,IAAA,MAAM,WAAW,UAAW,CAAA,GAAA,CAAI,CAAC,SAAA,KAAc,GAAG,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,SAAW,EAAA,MAAA,CAAO,GAAI,EAAC,CAAC,CAAI,EAAA,CAAA,CAAA;AAErH,IAAA,uBACEC,IAAAA;AAAA,MAACD,IAAAA;AAAA,MAAA;AAAA,QACC,UAAU,IAAK,CAAA,QAAA;AAAA,QACf,MAAM,IAAK,CAAA,IAAA;AAAA,QACX,MAAM,IAAK,CAAA,IAAA;AAAA,QACX,MAAA,EAAQE,UAAU,EAAE,GAAA,EAAK,QAAQ,MAAO,CAAA,OAAA,CAAQ,QAAQ,CAAA;AAAA,QACxD,MAAA,EAAQC,UAAU,EAAE,GAAA,EAAK,QAAQ,MAAO,CAAA,OAAA,CAAQ,QAAQ,CAAA;AAAA,QAEvD,QAAA,EAAA;AAAA,UAAA,OAAA;AAAA,0BACDJ,GAAAA,CAAC,QAAS,EAAA,EAAA,IAAA,EAAM,YAAY,QAAoB,EAAA;AAAA;AAAA;AAAA,KAClD;AAAA;AAGN,CAAC","file":"chunk-DYRPP4NT.js","sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\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 oas = useOas()\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={getBanner({ oas, output })} footer={getFooter({ oas, output })}>\n <File.Import name={['http']} path=\"msw\" />\n <File.Import name={['ResponseResolver']} isTypeOnly path=\"msw\" />\n <File.Import name={[type.schemas.response.name]} path={type.file.path} root={mock.file.path} isTypeOnly />\n {parser === 'faker' && faker.file && faker.schemas.response && (\n <File.Import name={[faker.schemas.response.name]} root={mock.file.path} path={faker.file.path} />\n )}\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 { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { Handlers } from '../components/Handlers.tsx'\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 oas = useOas()\n const { getName, getFile } = useOperationManager()\n\n const file = pluginManager.getFile({ name: 'handlers', extname: '.ts', pluginKey: plugin.key })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: plugin.key })\n const operationName = getName(operation, { pluginKey: plugin.key, 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: plugin.key })}()`)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}
@@ -0,0 +1,96 @@
1
+ 'use strict';
2
+
3
+ var chunkYYEGKAGZ_cjs = require('./chunk-YYEGKAGZ.cjs');
4
+ var utils$1 = require('@kubb/core/utils');
5
+ var pluginFaker = require('@kubb/plugin-faker');
6
+ var pluginOas = require('@kubb/plugin-oas');
7
+ var hooks = require('@kubb/plugin-oas/hooks');
8
+ var utils = require('@kubb/plugin-oas/utils');
9
+ var pluginTs = require('@kubb/plugin-ts');
10
+ var react = require('@kubb/react');
11
+ var jsxRuntime = require('@kubb/react/jsx-runtime');
12
+
13
+ var mswGenerator = pluginOas.createReactGenerator({
14
+ name: "msw",
15
+ Operation({ operation }) {
16
+ const {
17
+ plugin: {
18
+ options: { output, parser }
19
+ }
20
+ } = react.useApp();
21
+ const oas = hooks.useOas();
22
+ const { getSchemas, getName, getFile } = hooks.useOperationManager();
23
+ const mock = {
24
+ name: getName(operation, { type: "function" }),
25
+ file: getFile(operation)
26
+ };
27
+ const faker = {
28
+ file: getFile(operation, { pluginKey: [pluginFaker.pluginFakerName] }),
29
+ schemas: getSchemas(operation, { pluginKey: [pluginFaker.pluginFakerName], type: "function" })
30
+ };
31
+ const type = {
32
+ file: getFile(operation, { pluginKey: [pluginTs.pluginTsName] }),
33
+ schemas: getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" })
34
+ };
35
+ return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: mock.file.baseName, path: mock.file.path, meta: mock.file.meta, banner: utils.getBanner({ oas, output }), footer: utils.getFooter({ oas, output }), children: [
36
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["http"], path: "msw" }),
37
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["ResponseResolver"], isTypeOnly: true, path: "msw" }),
38
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [type.schemas.response.name], path: type.file.path, root: mock.file.path, isTypeOnly: true }),
39
+ parser === "faker" && faker.file && faker.schemas.response && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [faker.schemas.response.name], root: mock.file.path, path: faker.file.path }),
40
+ parser === "faker" && /* @__PURE__ */ jsxRuntime.jsx(
41
+ chunkYYEGKAGZ_cjs.MockWithFaker,
42
+ {
43
+ name: mock.name,
44
+ typeName: type.schemas.response.name,
45
+ fakerName: faker.schemas.response.name,
46
+ method: operation.method,
47
+ url: new utils$1.URLPath(operation.path).toURLPath()
48
+ }
49
+ ),
50
+ parser === "data" && /* @__PURE__ */ jsxRuntime.jsx(
51
+ chunkYYEGKAGZ_cjs.Mock,
52
+ {
53
+ name: mock.name,
54
+ typeName: type.schemas.response.name,
55
+ fakerName: faker.schemas.response.name,
56
+ method: operation.method,
57
+ url: new utils$1.URLPath(operation.path).toURLPath()
58
+ }
59
+ )
60
+ ] });
61
+ }
62
+ });
63
+ var handlersGenerator = pluginOas.createReactGenerator({
64
+ name: "plugin-msw",
65
+ Operations({ operations }) {
66
+ const { pluginManager, plugin } = react.useApp();
67
+ const oas = hooks.useOas();
68
+ const { getName, getFile } = hooks.useOperationManager();
69
+ const file = pluginManager.getFile({ name: "handlers", extname: ".ts", pluginKey: plugin.key });
70
+ const imports = operations.map((operation) => {
71
+ const operationFile = getFile(operation, { pluginKey: plugin.key });
72
+ const operationName = getName(operation, { pluginKey: plugin.key, type: "function" });
73
+ return /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
74
+ });
75
+ const handlers = operations.map((operation) => `${getName(operation, { type: "function", pluginKey: plugin.key })}()`);
76
+ return /* @__PURE__ */ jsxRuntime.jsxs(
77
+ react.File,
78
+ {
79
+ baseName: file.baseName,
80
+ path: file.path,
81
+ meta: file.meta,
82
+ banner: utils.getBanner({ oas, output: plugin.options.output }),
83
+ footer: utils.getFooter({ oas, output: plugin.options.output }),
84
+ children: [
85
+ imports,
86
+ /* @__PURE__ */ jsxRuntime.jsx(chunkYYEGKAGZ_cjs.Handlers, { name: "handlers", handlers })
87
+ ]
88
+ }
89
+ );
90
+ }
91
+ });
92
+
93
+ exports.handlersGenerator = handlersGenerator;
94
+ exports.mswGenerator = mswGenerator;
95
+ //# sourceMappingURL=chunk-EZNBG4T4.cjs.map
96
+ //# sourceMappingURL=chunk-EZNBG4T4.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/generators/mswGenerator.tsx","../src/generators/handlersGenerator.tsx"],"names":["createReactGenerator","useApp","useOas","useOperationManager","pluginFakerName","pluginTsName","jsxs","File","getBanner","getFooter","jsx","MockWithFaker","URLPath","Mock","Handlers"],"mappings":";;;;;;;;;;;;AAUO,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;AAAA;AAC5B,QACEC,YAAkB,EAAA;AACtB,IAAA,MAAM,MAAMC,YAAO,EAAA;AACnB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAYC,yBAAoB,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AAAA;AAAA,MAAA;AAAA,QACC,UAAU,IAAK,CAAA,QAAA;AAAA,QACf,MAAM,IAAK,CAAA,IAAA;AAAA,QACX,MAAM,IAAK,CAAA,IAAA;AAAA,QACX,MAAA,EAAQC,gBAAU,EAAE,GAAA,EAAK,QAAQ,MAAO,CAAA,OAAA,CAAQ,QAAQ,CAAA;AAAA,QACxD,MAAA,EAAQC,gBAAU,EAAE,GAAA,EAAK,QAAQ,MAAO,CAAA,OAAA,CAAQ,QAAQ,CAAA;AAAA,QAEvD,QAAA,EAAA;AAAA,UAAA,OAAA;AAAA,0BACDC,cAAAA,CAACI,0BAAS,EAAA,EAAA,IAAA,EAAM,YAAY,QAAoB,EAAA;AAAA;AAAA;AAAA,KAClD;AAAA;AAGN,CAAC","file":"chunk-EZNBG4T4.cjs","sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\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 oas = useOas()\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={getBanner({ oas, output })} footer={getFooter({ oas, output })}>\n <File.Import name={['http']} path=\"msw\" />\n <File.Import name={['ResponseResolver']} isTypeOnly path=\"msw\" />\n <File.Import name={[type.schemas.response.name]} path={type.file.path} root={mock.file.path} isTypeOnly />\n {parser === 'faker' && faker.file && faker.schemas.response && (\n <File.Import name={[faker.schemas.response.name]} root={mock.file.path} path={faker.file.path} />\n )}\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 { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { Handlers } from '../components/Handlers.tsx'\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 oas = useOas()\n const { getName, getFile } = useOperationManager()\n\n const file = pluginManager.getFile({ name: 'handlers', extname: '.ts', pluginKey: plugin.key })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: plugin.key })\n const operationName = getName(operation, { pluginKey: plugin.key, 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: plugin.key })}()`)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}
@@ -1,17 +1,17 @@
1
1
  'use strict';
2
2
 
3
- var chunkX2L7FNJF_cjs = require('./chunk-X2L7FNJF.cjs');
3
+ var chunkEZNBG4T4_cjs = require('./chunk-EZNBG4T4.cjs');
4
4
  require('./chunk-YYEGKAGZ.cjs');
5
5
 
6
6
 
7
7
 
8
8
  Object.defineProperty(exports, "handlersGenerator", {
9
9
  enumerable: true,
10
- get: function () { return chunkX2L7FNJF_cjs.handlersGenerator; }
10
+ get: function () { return chunkEZNBG4T4_cjs.handlersGenerator; }
11
11
  });
12
12
  Object.defineProperty(exports, "mswGenerator", {
13
13
  enumerable: true,
14
- get: function () { return chunkX2L7FNJF_cjs.mswGenerator; }
14
+ get: function () { return chunkEZNBG4T4_cjs.mswGenerator; }
15
15
  });
16
16
  //# sourceMappingURL=generators.cjs.map
17
17
  //# sourceMappingURL=generators.cjs.map
@@ -1,6 +1,7 @@
1
1
  import * as _kubb_plugin_oas from '@kubb/plugin-oas';
2
- import { P as PluginMsw } from './types-DGHcSmpE.cjs';
2
+ import { P as PluginMsw } from './types-prSKduPd.cjs';
3
3
  import '@kubb/core';
4
+ import '@kubb/oas';
4
5
 
5
6
  declare const mswGenerator: _kubb_plugin_oas.Generator<PluginMsw>;
6
7
 
@@ -1,6 +1,7 @@
1
1
  import * as _kubb_plugin_oas from '@kubb/plugin-oas';
2
- import { P as PluginMsw } from './types-DGHcSmpE.js';
2
+ import { P as PluginMsw } from './types-prSKduPd.js';
3
3
  import '@kubb/core';
4
+ import '@kubb/oas';
4
5
 
5
6
  declare const mswGenerator: _kubb_plugin_oas.Generator<PluginMsw>;
6
7
 
@@ -1,4 +1,4 @@
1
- export { handlersGenerator, mswGenerator } from './chunk-U7X3UKZD.js';
1
+ export { handlersGenerator, mswGenerator } from './chunk-DYRPP4NT.js';
2
2
  import './chunk-LOYUDIPB.js';
3
3
  //# sourceMappingURL=generators.js.map
4
4
  //# sourceMappingURL=generators.js.map
package/dist/index.cjs CHANGED
@@ -1,17 +1,106 @@
1
1
  'use strict';
2
2
 
3
- var chunkX2L7FNJF_cjs = require('./chunk-X2L7FNJF.cjs');
3
+ var chunkEZNBG4T4_cjs = require('./chunk-EZNBG4T4.cjs');
4
4
  require('./chunk-YYEGKAGZ.cjs');
5
+ var path = require('path');
6
+ var core = require('@kubb/core');
7
+ var transformers = require('@kubb/core/transformers');
8
+ var pluginOas = require('@kubb/plugin-oas');
9
+ var pluginFaker = require('@kubb/plugin-faker');
10
+ var pluginTs = require('@kubb/plugin-ts');
5
11
 
12
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
6
13
 
14
+ var path__default = /*#__PURE__*/_interopDefault(path);
7
15
 
8
- Object.defineProperty(exports, "pluginMsw", {
9
- enumerable: true,
10
- get: function () { return chunkX2L7FNJF_cjs.pluginMsw; }
11
- });
12
- Object.defineProperty(exports, "pluginMswName", {
13
- enumerable: true,
14
- get: function () { return chunkX2L7FNJF_cjs.pluginMswName; }
16
+ var pluginMswName = "plugin-msw";
17
+ var pluginMsw = core.createPlugin((options) => {
18
+ const {
19
+ output = { path: "handlers", barrelType: "named" },
20
+ group,
21
+ exclude = [],
22
+ include,
23
+ override = [],
24
+ transformers: transformers$1 = {},
25
+ handlers = false,
26
+ parser = "data",
27
+ generators = [chunkEZNBG4T4_cjs.mswGenerator, handlers ? chunkEZNBG4T4_cjs.handlersGenerator : void 0].filter(Boolean)
28
+ } = options;
29
+ return {
30
+ name: pluginMswName,
31
+ options: {
32
+ output,
33
+ parser,
34
+ group
35
+ },
36
+ pre: [pluginOas.pluginOasName, pluginTs.pluginTsName, parser === "faker" ? pluginFaker.pluginFakerName : void 0].filter(Boolean),
37
+ resolvePath(baseName, pathMode, options2) {
38
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
39
+ const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
40
+ if (mode === "single") {
41
+ return path__default.default.resolve(root, output.path);
42
+ }
43
+ if (group && (options2?.group?.path || options2?.group?.tag)) {
44
+ const groupName = group?.name ? group.name : (ctx) => {
45
+ if (group?.type === "path") {
46
+ return `${ctx.group.split("/")[1]}`;
47
+ }
48
+ return `${transformers.camelCase(ctx.group)}Controller`;
49
+ };
50
+ return path__default.default.resolve(
51
+ root,
52
+ output.path,
53
+ groupName({
54
+ group: group.type === "path" ? options2.group.path : options2.group.tag
55
+ }),
56
+ baseName
57
+ );
58
+ }
59
+ return path__default.default.resolve(root, output.path, baseName);
60
+ },
61
+ resolveName(name, type) {
62
+ const resolvedName = transformers.camelCase(name, {
63
+ suffix: type ? "handler" : void 0,
64
+ isFile: type === "file"
65
+ });
66
+ if (type) {
67
+ return transformers$1?.name?.(resolvedName, type) || resolvedName;
68
+ }
69
+ return resolvedName;
70
+ },
71
+ async buildStart() {
72
+ const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
73
+ const oas = await swaggerPlugin.context.getOas();
74
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
75
+ const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
76
+ const operationGenerator = new pluginOas.OperationGenerator(this.plugin.options, {
77
+ oas,
78
+ pluginManager: this.pluginManager,
79
+ plugin: this.plugin,
80
+ contentType: swaggerPlugin.context.contentType,
81
+ exclude,
82
+ include,
83
+ override,
84
+ mode
85
+ });
86
+ const files = await operationGenerator.build(...generators);
87
+ await this.addFile(...files);
88
+ const barrelFiles = await this.fileManager.getBarrelFiles({
89
+ type: output.barrelType ?? "named",
90
+ root,
91
+ output,
92
+ files: this.fileManager.files,
93
+ meta: {
94
+ pluginKey: this.plugin.key
95
+ },
96
+ logger: this.logger
97
+ });
98
+ await this.addFile(...barrelFiles);
99
+ }
100
+ };
15
101
  });
102
+
103
+ exports.pluginMsw = pluginMsw;
104
+ exports.pluginMswName = pluginMswName;
16
105
  //# sourceMappingURL=index.cjs.map
17
106
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
1
+ {"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","mswGenerator","handlersGenerator","pluginOasName","pluginTsName","pluginFakerName","options","path","FileManager","camelCase","PluginManager","OperationGenerator"],"mappings":";;;;;;;;;;;;;;;AAcO,IAAM,aAAgB,GAAA;AAEhB,IAAA,SAAA,GAAYA,iBAAwB,CAAA,CAAC,OAAY,KAAA;AAC5D,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,UAAA,EAAY,YAAY,OAAQ,EAAA;AAAA,IACjD,KAAA;AAAA,IACA,UAAU,EAAC;AAAA,IACX,OAAA;AAAA,IACA,WAAW,EAAC;AAAA,kBACZC,iBAAe,EAAC;AAAA,IAChB,QAAW,GAAA,KAAA;AAAA,IACX,MAAS,GAAA,MAAA;AAAA,IACT,UAAA,GAAa,CAACC,8BAAc,EAAA,QAAA,GAAWC,sCAAoB,KAAS,CAAA,CAAA,CAAE,OAAO,OAAO;AAAA,GAClF,GAAA,OAAA;AAEJ,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,aAAA;AAAA,IACN,OAAS,EAAA;AAAA,MACP,MAAA;AAAA,MACA,MAAA;AAAA,MACA;AAAA,KACF;AAAA,IACA,GAAA,EAAK,CAACC,uBAAA,EAAeC,qBAAc,EAAA,MAAA,KAAW,UAAUC,2BAAkB,GAAA,KAAA,CAAS,CAAE,CAAA,MAAA,CAAO,OAAO,CAAA;AAAA,IACnG,WAAA,CAAY,QAAU,EAAA,QAAA,EAAUC,QAAS,EAAA;AACvC,MAAM,MAAA,IAAA,GAAOC,sBAAK,OAAQ,CAAA,IAAA,CAAK,OAAO,IAAM,EAAA,IAAA,CAAK,MAAO,CAAA,MAAA,CAAO,IAAI,CAAA;AACnE,MAAM,MAAA,IAAA,GAAO,YAAYC,gBAAY,CAAA,OAAA,CAAQD,sBAAK,OAAQ,CAAA,IAAA,EAAM,MAAO,CAAA,IAAI,CAAC,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A;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA;AAAA,OACd,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAAA;AACnC,GACF;AACF,CAAC","file":"index.cjs","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, 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 group,\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 (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n 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"]}
package/dist/index.d.cts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
- import { O as Options, P as PluginMsw } from './types-DGHcSmpE.cjs';
2
+ import { O as Options, P as PluginMsw } from './types-prSKduPd.cjs';
3
+ import '@kubb/oas';
3
4
  import '@kubb/plugin-oas';
4
5
 
5
6
  declare const pluginMswName = "plugin-msw";
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
- import { O as Options, P as PluginMsw } from './types-DGHcSmpE.js';
2
+ import { O as Options, P as PluginMsw } from './types-prSKduPd.js';
3
+ import '@kubb/oas';
3
4
  import '@kubb/plugin-oas';
4
5
 
5
6
  declare const pluginMswName = "plugin-msw";
package/dist/index.js CHANGED
@@ -1,4 +1,99 @@
1
- export { pluginMsw, pluginMswName } from './chunk-U7X3UKZD.js';
1
+ import { mswGenerator, handlersGenerator } from './chunk-DYRPP4NT.js';
2
2
  import './chunk-LOYUDIPB.js';
3
+ import path from 'node:path';
4
+ import { createPlugin, FileManager, PluginManager } from '@kubb/core';
5
+ import { camelCase } from '@kubb/core/transformers';
6
+ import { pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
7
+ import { pluginFakerName } from '@kubb/plugin-faker';
8
+ import { pluginTsName } from '@kubb/plugin-ts';
9
+
10
+ var pluginMswName = "plugin-msw";
11
+ var pluginMsw = createPlugin((options) => {
12
+ const {
13
+ output = { path: "handlers", barrelType: "named" },
14
+ group,
15
+ exclude = [],
16
+ include,
17
+ override = [],
18
+ transformers = {},
19
+ handlers = false,
20
+ parser = "data",
21
+ generators = [mswGenerator, handlers ? handlersGenerator : void 0].filter(Boolean)
22
+ } = options;
23
+ return {
24
+ name: pluginMswName,
25
+ options: {
26
+ output,
27
+ parser,
28
+ group
29
+ },
30
+ pre: [pluginOasName, pluginTsName, parser === "faker" ? pluginFakerName : void 0].filter(Boolean),
31
+ resolvePath(baseName, pathMode, options2) {
32
+ const root = path.resolve(this.config.root, this.config.output.path);
33
+ const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
34
+ if (mode === "single") {
35
+ return path.resolve(root, output.path);
36
+ }
37
+ if (group && (options2?.group?.path || options2?.group?.tag)) {
38
+ const groupName = group?.name ? group.name : (ctx) => {
39
+ if (group?.type === "path") {
40
+ return `${ctx.group.split("/")[1]}`;
41
+ }
42
+ return `${camelCase(ctx.group)}Controller`;
43
+ };
44
+ return path.resolve(
45
+ root,
46
+ output.path,
47
+ groupName({
48
+ group: group.type === "path" ? options2.group.path : options2.group.tag
49
+ }),
50
+ baseName
51
+ );
52
+ }
53
+ return path.resolve(root, output.path, baseName);
54
+ },
55
+ resolveName(name, type) {
56
+ const resolvedName = camelCase(name, {
57
+ suffix: type ? "handler" : void 0,
58
+ isFile: type === "file"
59
+ });
60
+ if (type) {
61
+ return transformers?.name?.(resolvedName, type) || resolvedName;
62
+ }
63
+ return resolvedName;
64
+ },
65
+ async buildStart() {
66
+ const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
67
+ const oas = await swaggerPlugin.context.getOas();
68
+ const root = path.resolve(this.config.root, this.config.output.path);
69
+ const mode = FileManager.getMode(path.resolve(root, output.path));
70
+ const operationGenerator = new OperationGenerator(this.plugin.options, {
71
+ oas,
72
+ pluginManager: this.pluginManager,
73
+ plugin: this.plugin,
74
+ contentType: swaggerPlugin.context.contentType,
75
+ exclude,
76
+ include,
77
+ override,
78
+ mode
79
+ });
80
+ const files = await operationGenerator.build(...generators);
81
+ await this.addFile(...files);
82
+ const barrelFiles = await this.fileManager.getBarrelFiles({
83
+ type: output.barrelType ?? "named",
84
+ root,
85
+ output,
86
+ files: this.fileManager.files,
87
+ meta: {
88
+ pluginKey: this.plugin.key
89
+ },
90
+ logger: this.logger
91
+ });
92
+ await this.addFile(...barrelFiles);
93
+ }
94
+ };
95
+ });
96
+
97
+ export { pluginMsw, pluginMswName };
3
98
  //# sourceMappingURL=index.js.map
4
99
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
1
+ {"version":3,"sources":["../src/plugin.ts"],"names":["options"],"mappings":";;;;;;;;;AAcO,IAAM,aAAgB,GAAA;AAEhB,IAAA,SAAA,GAAY,YAAwB,CAAA,CAAC,OAAY,KAAA;AAC5D,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,UAAA,EAAY,YAAY,OAAQ,EAAA;AAAA,IACjD,KAAA;AAAA,IACA,UAAU,EAAC;AAAA,IACX,OAAA;AAAA,IACA,WAAW,EAAC;AAAA,IACZ,eAAe,EAAC;AAAA,IAChB,QAAW,GAAA,KAAA;AAAA,IACX,MAAS,GAAA,MAAA;AAAA,IACT,UAAA,GA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,OAAS,EAAA;AAAA,QACrE,GAAA;AAAA,QACA,eAAe,IAAK,CAAA,aAAA;AAAA,QACpB,QAAQ,IAAK,CAAA,MAAA;AAAA,QACb,WAAA,EAAa,cAAc,OAAQ,CAAA,WAAA;AAAA,QACnC,OAAA;AAAA,QACA,OAAA;AAAA,QACA,QAAA;AAAA,QACA;AAAA,OACD,CAAA;AAED,MAAA,MAAM,KAAQ,GAAA,MAAM,kBAAmB,CAAA,KAAA,CAAM,GAAG,UAAU,CAAA;AAC1D,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,KAAK,CAAA;AAE3B,MAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,QACxD,IAAA,EAAM,OAAO,UAAc,IAAA,OAAA;AAAA,QAC3B,IAAA;AAAA,QACA,MAAA;AAAA,QACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,QACxB,IAAM,EAAA;AAAA,UACJ,SAAA,EAAW,KAAK,MAAO,CAAA;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA;AAAA,OACd,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAAA;AACnC,GACF;AACF,CAAC","file":"index.js","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, 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 group,\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 (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n 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"]}
@@ -1,4 +1,5 @@
1
1
  import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
2
+ import { Oas } from '@kubb/oas';
2
3
  import { ResolvePathOptions, Exclude, Include, Override, Generator } from '@kubb/plugin-oas';
3
4
 
4
5
  type Options = {
@@ -6,7 +7,7 @@ type Options = {
6
7
  * Specify the export location for the files and define the behavior of the output
7
8
  * @default { path: 'mocks', barrelType: 'named' }
8
9
  */
9
- output?: Output;
10
+ output?: Output<Oas>;
10
11
  /**
11
12
  * Group the MSW mocks based on the provided name.
12
13
  */
@@ -47,7 +48,7 @@ type Options = {
47
48
  generators?: Array<Generator<PluginMsw>>;
48
49
  };
49
50
  type ResolvedOptions = {
50
- output: Output;
51
+ output: Output<Oas>;
51
52
  group: Options['group'];
52
53
  parser: NonNullable<Options['parser']>;
53
54
  };
@@ -1,4 +1,5 @@
1
1
  import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
2
+ import { Oas } from '@kubb/oas';
2
3
  import { ResolvePathOptions, Exclude, Include, Override, Generator } from '@kubb/plugin-oas';
3
4
 
4
5
  type Options = {
@@ -6,7 +7,7 @@ type Options = {
6
7
  * Specify the export location for the files and define the behavior of the output
7
8
  * @default { path: 'mocks', barrelType: 'named' }
8
9
  */
9
- output?: Output;
10
+ output?: Output<Oas>;
10
11
  /**
11
12
  * Group the MSW mocks based on the provided name.
12
13
  */
@@ -47,7 +48,7 @@ type Options = {
47
48
  generators?: Array<Generator<PluginMsw>>;
48
49
  };
49
50
  type ResolvedOptions = {
50
- output: Output;
51
+ output: Output<Oas>;
51
52
  group: Options['group'];
52
53
  parser: NonNullable<Options['parser']>;
53
54
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-msw",
3
- "version": "3.4.5",
3
+ "version": "3.5.1",
4
4
  "description": "Generator swagger",
5
5
  "keywords": [
6
6
  "typescript",
@@ -74,21 +74,21 @@
74
74
  "!/**/__tests__/**"
75
75
  ],
76
76
  "dependencies": {
77
- "@kubb/core": "3.4.5",
78
- "@kubb/fs": "3.4.5",
79
- "@kubb/oas": "3.4.5",
80
- "@kubb/plugin-faker": "3.4.5",
81
- "@kubb/plugin-oas": "3.4.5",
82
- "@kubb/plugin-ts": "3.4.5",
83
- "@kubb/react": "3.4.5"
77
+ "@kubb/core": "3.5.1",
78
+ "@kubb/fs": "3.5.1",
79
+ "@kubb/oas": "3.5.1",
80
+ "@kubb/plugin-faker": "3.5.1",
81
+ "@kubb/plugin-oas": "3.5.1",
82
+ "@kubb/plugin-ts": "3.5.1",
83
+ "@kubb/react": "3.5.1"
84
84
  },
85
85
  "devDependencies": {
86
86
  "@types/react": "^18.3.18",
87
87
  "react": "^18.3.1",
88
88
  "tsup": "^8.3.5",
89
89
  "typescript": "^5.7.3",
90
- "@kubb/config-ts": "3.4.5",
91
- "@kubb/config-tsup": "3.4.5"
90
+ "@kubb/config-ts": "3.5.1",
91
+ "@kubb/config-tsup": "3.5.1"
92
92
  },
93
93
  "peerDependencies": {
94
94
  "@kubb/react": "^3.0.0"
@@ -1,14 +1,15 @@
1
1
  import { createReactGenerator } from '@kubb/plugin-oas'
2
- import { useOperationManager } from '@kubb/plugin-oas/hooks'
2
+ import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
3
+ import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
3
4
  import { File, useApp } from '@kubb/react'
4
5
  import { Handlers } from '../components/Handlers.tsx'
5
- import { pluginMswName } from '../plugin.ts'
6
6
  import type { PluginMsw } from '../types'
7
7
 
8
8
  export const handlersGenerator = createReactGenerator<PluginMsw>({
9
9
  name: 'plugin-msw',
10
10
  Operations({ operations }) {
11
11
  const { pluginManager, plugin } = useApp<PluginMsw>()
12
+ const oas = useOas()
12
13
  const { getName, getFile } = useOperationManager()
13
14
 
14
15
  const file = pluginManager.getFile({ name: 'handlers', extname: '.ts', pluginKey: plugin.key })
@@ -23,7 +24,13 @@ export const handlersGenerator = createReactGenerator<PluginMsw>({
23
24
  const handlers = operations.map((operation) => `${getName(operation, { type: 'function', pluginKey: plugin.key })}()`)
24
25
 
25
26
  return (
26
- <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>
27
+ <File
28
+ baseName={file.baseName}
29
+ path={file.path}
30
+ meta={file.meta}
31
+ banner={getBanner({ oas, output: plugin.options.output })}
32
+ footer={getFooter({ oas, output: plugin.options.output })}
33
+ >
27
34
  {imports}
28
35
  <Handlers name={'handlers'} handlers={handlers} />
29
36
  </File>
@@ -1,7 +1,8 @@
1
1
  import { URLPath } from '@kubb/core/utils'
2
2
  import { pluginFakerName } from '@kubb/plugin-faker'
3
3
  import { createReactGenerator } from '@kubb/plugin-oas'
4
- import { useOperationManager } from '@kubb/plugin-oas/hooks'
4
+ import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
5
+ import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
5
6
  import { pluginTsName } from '@kubb/plugin-ts'
6
7
  import { File, useApp } from '@kubb/react'
7
8
  import { Mock, MockWithFaker } from '../components'
@@ -15,6 +16,7 @@ export const mswGenerator = createReactGenerator<PluginMsw>({
15
16
  options: { output, parser },
16
17
  },
17
18
  } = useApp<PluginMsw>()
19
+ const oas = useOas()
18
20
  const { getSchemas, getName, getFile } = useOperationManager()
19
21
 
20
22
  const mock = {
@@ -33,7 +35,7 @@ export const mswGenerator = createReactGenerator<PluginMsw>({
33
35
  }
34
36
 
35
37
  return (
36
- <File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta} banner={output?.banner} footer={output?.footer}>
38
+ <File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta} banner={getBanner({ oas, output })} footer={getFooter({ oas, output })}>
37
39
  <File.Import name={['http']} path="msw" />
38
40
  <File.Import name={['ResponseResolver']} isTypeOnly path="msw" />
39
41
  <File.Import name={[type.schemas.response.name]} path={type.file.path} root={mock.file.path} isTypeOnly />
package/src/types.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
2
2
 
3
+ import type { Oas } from '@kubb/oas'
3
4
  import type { Exclude, Generator, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
4
5
 
5
6
  export type Options = {
@@ -7,7 +8,7 @@ export type Options = {
7
8
  * Specify the export location for the files and define the behavior of the output
8
9
  * @default { path: 'mocks', barrelType: 'named' }
9
10
  */
10
- output?: Output
11
+ output?: Output<Oas>
11
12
  /**
12
13
  * Group the MSW mocks based on the provided name.
13
14
  */
@@ -48,7 +49,7 @@ export type Options = {
48
49
  generators?: Array<Generator<PluginMsw>>
49
50
  }
50
51
  type ResolvedOptions = {
51
- output: Output
52
+ output: Output<Oas>
52
53
  group: Options['group']
53
54
  parser: NonNullable<Options['parser']>
54
55
  }
@@ -1,169 +0,0 @@
1
- import { MockWithFaker, Mock, Handlers } from './chunk-LOYUDIPB.js';
2
- import { URLPath } from '@kubb/core/utils';
3
- import { pluginFakerName } from '@kubb/plugin-faker';
4
- import { createReactGenerator, pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
5
- import { useOperationManager } from '@kubb/plugin-oas/hooks';
6
- import { pluginTsName } from '@kubb/plugin-ts';
7
- import { useApp, File } from '@kubb/react';
8
- import { jsxs, jsx } from '@kubb/react/jsx-runtime';
9
- import path from 'node:path';
10
- import { createPlugin, FileManager, PluginManager } from '@kubb/core';
11
- import { camelCase } from '@kubb/core/transformers';
12
-
13
- var mswGenerator = createReactGenerator({
14
- name: "msw",
15
- Operation({ operation }) {
16
- const {
17
- plugin: {
18
- options: { output, parser }
19
- }
20
- } = useApp();
21
- const { getSchemas, getName, getFile } = useOperationManager();
22
- const mock = {
23
- name: getName(operation, { type: "function" }),
24
- file: getFile(operation)
25
- };
26
- const faker = {
27
- file: getFile(operation, { pluginKey: [pluginFakerName] }),
28
- schemas: getSchemas(operation, { pluginKey: [pluginFakerName], type: "function" })
29
- };
30
- const type = {
31
- file: getFile(operation, { pluginKey: [pluginTsName] }),
32
- schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: "type" })
33
- };
34
- return /* @__PURE__ */ jsxs(File, { baseName: mock.file.baseName, path: mock.file.path, meta: mock.file.meta, banner: output?.banner, footer: output?.footer, children: [
35
- /* @__PURE__ */ jsx(File.Import, { name: ["http"], path: "msw" }),
36
- /* @__PURE__ */ jsx(File.Import, { name: ["ResponseResolver"], isTypeOnly: true, path: "msw" }),
37
- /* @__PURE__ */ jsx(File.Import, { name: [type.schemas.response.name], path: type.file.path, root: mock.file.path, isTypeOnly: true }),
38
- parser === "faker" && faker.file && faker.schemas.response && /* @__PURE__ */ jsx(File.Import, { name: [faker.schemas.response.name], root: mock.file.path, path: faker.file.path }),
39
- parser === "faker" && /* @__PURE__ */ jsx(
40
- MockWithFaker,
41
- {
42
- name: mock.name,
43
- typeName: type.schemas.response.name,
44
- fakerName: faker.schemas.response.name,
45
- method: operation.method,
46
- url: new URLPath(operation.path).toURLPath()
47
- }
48
- ),
49
- parser === "data" && /* @__PURE__ */ jsx(
50
- Mock,
51
- {
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
- )
59
- ] });
60
- }
61
- });
62
- var pluginMswName = "plugin-msw";
63
- var pluginMsw = createPlugin((options) => {
64
- const {
65
- output = { path: "handlers", barrelType: "named" },
66
- group,
67
- exclude = [],
68
- include,
69
- override = [],
70
- transformers = {},
71
- handlers = false,
72
- parser = "data",
73
- generators = [mswGenerator, handlers ? handlersGenerator : void 0].filter(Boolean)
74
- } = options;
75
- return {
76
- name: pluginMswName,
77
- options: {
78
- output,
79
- parser,
80
- group
81
- },
82
- pre: [pluginOasName, pluginTsName, parser === "faker" ? pluginFakerName : void 0].filter(Boolean),
83
- resolvePath(baseName, pathMode, options2) {
84
- const root = path.resolve(this.config.root, this.config.output.path);
85
- const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
86
- if (mode === "single") {
87
- return path.resolve(root, output.path);
88
- }
89
- if (group && (options2?.group?.path || options2?.group?.tag)) {
90
- const groupName = group?.name ? group.name : (ctx) => {
91
- if (group?.type === "path") {
92
- return `${ctx.group.split("/")[1]}`;
93
- }
94
- return `${camelCase(ctx.group)}Controller`;
95
- };
96
- return path.resolve(
97
- root,
98
- output.path,
99
- groupName({
100
- group: group.type === "path" ? options2.group.path : options2.group.tag
101
- }),
102
- baseName
103
- );
104
- }
105
- return path.resolve(root, output.path, baseName);
106
- },
107
- resolveName(name, type) {
108
- const resolvedName = camelCase(name, {
109
- suffix: type ? "handler" : void 0,
110
- isFile: type === "file"
111
- });
112
- if (type) {
113
- return transformers?.name?.(resolvedName, type) || resolvedName;
114
- }
115
- return resolvedName;
116
- },
117
- async buildStart() {
118
- const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
119
- const oas = await swaggerPlugin.context.getOas();
120
- const root = path.resolve(this.config.root, this.config.output.path);
121
- const mode = FileManager.getMode(path.resolve(root, output.path));
122
- const operationGenerator = new OperationGenerator(this.plugin.options, {
123
- oas,
124
- pluginManager: this.pluginManager,
125
- plugin: this.plugin,
126
- contentType: swaggerPlugin.context.contentType,
127
- exclude,
128
- include,
129
- override,
130
- mode
131
- });
132
- const files = await operationGenerator.build(...generators);
133
- await this.addFile(...files);
134
- const barrelFiles = await this.fileManager.getBarrelFiles({
135
- type: output.barrelType ?? "named",
136
- root,
137
- output,
138
- files: this.fileManager.files,
139
- meta: {
140
- pluginKey: this.plugin.key
141
- },
142
- logger: this.logger
143
- });
144
- await this.addFile(...barrelFiles);
145
- }
146
- };
147
- });
148
- var handlersGenerator = createReactGenerator({
149
- name: "plugin-msw",
150
- Operations({ operations }) {
151
- const { pluginManager, plugin } = useApp();
152
- const { getName, getFile } = useOperationManager();
153
- const file = pluginManager.getFile({ name: "handlers", extname: ".ts", pluginKey: plugin.key });
154
- const imports = operations.map((operation) => {
155
- const operationFile = getFile(operation, { pluginKey: plugin.key });
156
- const operationName = getName(operation, { pluginKey: plugin.key, type: "function" });
157
- return /* @__PURE__ */ jsx(File.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
158
- });
159
- const handlers = operations.map((operation) => `${getName(operation, { type: "function", pluginKey: plugin.key })}()`);
160
- return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: plugin.options.output?.banner, footer: plugin.options.output?.footer, children: [
161
- imports,
162
- /* @__PURE__ */ jsx(Handlers, { name: "handlers", handlers })
163
- ] });
164
- }
165
- });
166
-
167
- export { handlersGenerator, mswGenerator, pluginMsw, pluginMswName };
168
- //# sourceMappingURL=chunk-U7X3UKZD.js.map
169
- //# sourceMappingURL=chunk-U7X3UKZD.js.map
@@ -1 +0,0 @@
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":";;;;;;;;;;;;AASO,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,MAAA,EAAQ,MAAO;AAAA;AAC5B,QACE,MAAkB,EAAA;AACtB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAY,mBAAoB,EAAA;AAE7D,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA;AAAA,MAC7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","file":"chunk-U7X3UKZD.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={['ResponseResolver']} isTypeOnly path=\"msw\" />\n <File.Import name={[type.schemas.response.name]} path={type.file.path} root={mock.file.path} isTypeOnly />\n {parser === 'faker' && faker.file && faker.schemas.response && (\n <File.Import name={[faker.schemas.response.name]} root={mock.file.path} path={faker.file.path} />\n )}\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 group,\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 (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n 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: plugin.key })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: plugin.key })\n const operationName = getName(operation, { pluginKey: plugin.key, 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: plugin.key })}()`)\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,178 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkYYEGKAGZ_cjs = require('./chunk-YYEGKAGZ.cjs');
4
- var utils = require('@kubb/core/utils');
5
- var pluginFaker = require('@kubb/plugin-faker');
6
- var pluginOas = require('@kubb/plugin-oas');
7
- var hooks = require('@kubb/plugin-oas/hooks');
8
- var pluginTs = require('@kubb/plugin-ts');
9
- var react = require('@kubb/react');
10
- var jsxRuntime = require('@kubb/react/jsx-runtime');
11
- var path = require('path');
12
- var core = require('@kubb/core');
13
- var transformers = require('@kubb/core/transformers');
14
-
15
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
16
-
17
- var path__default = /*#__PURE__*/_interopDefault(path);
18
-
19
- var mswGenerator = pluginOas.createReactGenerator({
20
- name: "msw",
21
- Operation({ operation }) {
22
- const {
23
- plugin: {
24
- options: { output, parser }
25
- }
26
- } = react.useApp();
27
- const { getSchemas, getName, getFile } = hooks.useOperationManager();
28
- const mock = {
29
- name: getName(operation, { type: "function" }),
30
- file: getFile(operation)
31
- };
32
- const faker = {
33
- file: getFile(operation, { pluginKey: [pluginFaker.pluginFakerName] }),
34
- schemas: getSchemas(operation, { pluginKey: [pluginFaker.pluginFakerName], type: "function" })
35
- };
36
- const type = {
37
- file: getFile(operation, { pluginKey: [pluginTs.pluginTsName] }),
38
- schemas: getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" })
39
- };
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: [
41
- /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["http"], path: "msw" }),
42
- /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["ResponseResolver"], isTypeOnly: true, path: "msw" }),
43
- /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [type.schemas.response.name], path: type.file.path, root: mock.file.path, isTypeOnly: true }),
44
- parser === "faker" && faker.file && faker.schemas.response && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [faker.schemas.response.name], root: mock.file.path, path: faker.file.path }),
45
- parser === "faker" && /* @__PURE__ */ jsxRuntime.jsx(
46
- chunkYYEGKAGZ_cjs.MockWithFaker,
47
- {
48
- name: mock.name,
49
- typeName: type.schemas.response.name,
50
- fakerName: faker.schemas.response.name,
51
- method: operation.method,
52
- url: new utils.URLPath(operation.path).toURLPath()
53
- }
54
- ),
55
- parser === "data" && /* @__PURE__ */ jsxRuntime.jsx(
56
- chunkYYEGKAGZ_cjs.Mock,
57
- {
58
- name: mock.name,
59
- typeName: type.schemas.response.name,
60
- fakerName: faker.schemas.response.name,
61
- method: operation.method,
62
- url: new utils.URLPath(operation.path).toURLPath()
63
- }
64
- )
65
- ] });
66
- }
67
- });
68
- var pluginMswName = "plugin-msw";
69
- var pluginMsw = core.createPlugin((options) => {
70
- const {
71
- output = { path: "handlers", barrelType: "named" },
72
- group,
73
- exclude = [],
74
- include,
75
- override = [],
76
- transformers: transformers$1 = {},
77
- handlers = false,
78
- parser = "data",
79
- generators = [mswGenerator, handlers ? handlersGenerator : void 0].filter(Boolean)
80
- } = options;
81
- return {
82
- name: pluginMswName,
83
- options: {
84
- output,
85
- parser,
86
- group
87
- },
88
- pre: [pluginOas.pluginOasName, pluginTs.pluginTsName, parser === "faker" ? pluginFaker.pluginFakerName : void 0].filter(Boolean),
89
- resolvePath(baseName, pathMode, options2) {
90
- const root = path__default.default.resolve(this.config.root, this.config.output.path);
91
- const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
92
- if (mode === "single") {
93
- return path__default.default.resolve(root, output.path);
94
- }
95
- if (group && (options2?.group?.path || options2?.group?.tag)) {
96
- const groupName = group?.name ? group.name : (ctx) => {
97
- if (group?.type === "path") {
98
- return `${ctx.group.split("/")[1]}`;
99
- }
100
- return `${transformers.camelCase(ctx.group)}Controller`;
101
- };
102
- return path__default.default.resolve(
103
- root,
104
- output.path,
105
- groupName({
106
- group: group.type === "path" ? options2.group.path : options2.group.tag
107
- }),
108
- baseName
109
- );
110
- }
111
- return path__default.default.resolve(root, output.path, baseName);
112
- },
113
- resolveName(name, type) {
114
- const resolvedName = transformers.camelCase(name, {
115
- suffix: type ? "handler" : void 0,
116
- isFile: type === "file"
117
- });
118
- if (type) {
119
- return transformers$1?.name?.(resolvedName, type) || resolvedName;
120
- }
121
- return resolvedName;
122
- },
123
- async buildStart() {
124
- const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
125
- const oas = await swaggerPlugin.context.getOas();
126
- const root = path__default.default.resolve(this.config.root, this.config.output.path);
127
- const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
128
- const operationGenerator = new pluginOas.OperationGenerator(this.plugin.options, {
129
- oas,
130
- pluginManager: this.pluginManager,
131
- plugin: this.plugin,
132
- contentType: swaggerPlugin.context.contentType,
133
- exclude,
134
- include,
135
- override,
136
- mode
137
- });
138
- const files = await operationGenerator.build(...generators);
139
- await this.addFile(...files);
140
- const barrelFiles = await this.fileManager.getBarrelFiles({
141
- type: output.barrelType ?? "named",
142
- root,
143
- output,
144
- files: this.fileManager.files,
145
- meta: {
146
- pluginKey: this.plugin.key
147
- },
148
- logger: this.logger
149
- });
150
- await this.addFile(...barrelFiles);
151
- }
152
- };
153
- });
154
- var handlersGenerator = pluginOas.createReactGenerator({
155
- name: "plugin-msw",
156
- Operations({ operations }) {
157
- const { pluginManager, plugin } = react.useApp();
158
- const { getName, getFile } = hooks.useOperationManager();
159
- const file = pluginManager.getFile({ name: "handlers", extname: ".ts", pluginKey: plugin.key });
160
- const imports = operations.map((operation) => {
161
- const operationFile = getFile(operation, { pluginKey: plugin.key });
162
- const operationName = getName(operation, { pluginKey: plugin.key, type: "function" });
163
- return /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
164
- });
165
- const handlers = operations.map((operation) => `${getName(operation, { type: "function", pluginKey: plugin.key })}()`);
166
- 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: [
167
- imports,
168
- /* @__PURE__ */ jsxRuntime.jsx(chunkYYEGKAGZ_cjs.Handlers, { name: "handlers", handlers })
169
- ] });
170
- }
171
- });
172
-
173
- exports.handlersGenerator = handlersGenerator;
174
- exports.mswGenerator = mswGenerator;
175
- exports.pluginMsw = pluginMsw;
176
- exports.pluginMswName = pluginMswName;
177
- //# sourceMappingURL=chunk-X2L7FNJF.cjs.map
178
- //# sourceMappingURL=chunk-X2L7FNJF.cjs.map
@@ -1 +0,0 @@
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;AAAA;AAC5B,QACEC,YAAkB,EAAA;AACtB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAYC,yBAAoB,EAAA;AAE7D,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA;AAAA,MAC7C,IAAA,EAAM,QAAQ,SAAS;AAAA,KACzB;AAEA,IAAA,MAAM,KAAQ,GAAA;AAAA,MACZ,IAAA,EAAM,QAAQ,SAAW,EAAA,EAAE,WAAW,CAACC,2BAAe,GAAG,CAA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\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={['ResponseResolver']} isTypeOnly path=\"msw\" />\n <File.Import name={[type.schemas.response.name]} path={type.file.path} root={mock.file.path} isTypeOnly />\n {parser === 'faker' && faker.file && faker.schemas.response && (\n <File.Import name={[faker.schemas.response.name]} root={mock.file.path} path={faker.file.path} />\n )}\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 group,\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 (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n 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: plugin.key })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: plugin.key })\n const operationName = getName(operation, { pluginKey: plugin.key, 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: plugin.key })}()`)\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"]}