@kubb/plugin-msw 3.5.8 → 3.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-DYRPP4NT.js → chunk-4SW3NCYH.js} +6 -4
- package/dist/chunk-4SW3NCYH.js.map +1 -0
- package/dist/{chunk-YYEGKAGZ.cjs → chunk-MZZLONMV.cjs} +6 -6
- package/dist/chunk-MZZLONMV.cjs.map +1 -0
- package/dist/{chunk-EZNBG4T4.cjs → chunk-U26REKBP.cjs} +9 -7
- package/dist/chunk-U26REKBP.cjs.map +1 -0
- package/dist/{chunk-LOYUDIPB.js → chunk-VFRXFST2.js} +6 -6
- package/dist/chunk-VFRXFST2.js.map +1 -0
- package/dist/components.cjs +4 -4
- package/dist/components.d.cts +4 -2
- package/dist/components.d.ts +4 -2
- package/dist/components.js +1 -1
- package/dist/generators.cjs +4 -4
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +2 -2
- package/dist/index.cjs +7 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/{types-DUuqB-g_.d.cts → types-C3ki-pJc.d.cts} +2 -0
- package/dist/{types-DUuqB-g_.d.ts → types-C3ki-pJc.d.ts} +2 -0
- package/package.json +10 -10
- package/src/components/Mock.tsx +3 -2
- package/src/components/MockWithFaker.tsx +3 -2
- package/src/generators/__snapshots__/createPet.ts +1 -1
- package/src/generators/__snapshots__/deletePet.ts +1 -1
- package/src/generators/__snapshots__/getPets.ts +1 -1
- package/src/generators/__snapshots__/getPetsFaker.ts +1 -1
- package/src/generators/__snapshots__/showPetById.ts +1 -1
- package/src/generators/mswGenerator.tsx +3 -1
- package/src/plugin.ts +2 -0
- package/src/types.ts +2 -0
- package/dist/chunk-DYRPP4NT.js.map +0 -1
- package/dist/chunk-EZNBG4T4.cjs.map +0 -1
- package/dist/chunk-LOYUDIPB.js.map +0 -1
- package/dist/chunk-YYEGKAGZ.cjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MockWithFaker, Mock, Handlers } from './chunk-
|
|
1
|
+
import { MockWithFaker, Mock, Handlers } from './chunk-VFRXFST2.js';
|
|
2
2
|
import { URLPath } from '@kubb/core/utils';
|
|
3
3
|
import { pluginFakerName } from '@kubb/plugin-faker';
|
|
4
4
|
import { createReactGenerator } from '@kubb/plugin-oas';
|
|
@@ -13,7 +13,7 @@ var mswGenerator = createReactGenerator({
|
|
|
13
13
|
Operation({ operation }) {
|
|
14
14
|
const {
|
|
15
15
|
plugin: {
|
|
16
|
-
options: { output, parser }
|
|
16
|
+
options: { output, parser, baseURL }
|
|
17
17
|
}
|
|
18
18
|
} = useApp();
|
|
19
19
|
const oas = useOas();
|
|
@@ -42,6 +42,7 @@ var mswGenerator = createReactGenerator({
|
|
|
42
42
|
typeName: type.schemas.response.name,
|
|
43
43
|
fakerName: faker.schemas.response.name,
|
|
44
44
|
method: operation.method,
|
|
45
|
+
baseURL,
|
|
45
46
|
url: new URLPath(operation.path).toURLPath()
|
|
46
47
|
}
|
|
47
48
|
),
|
|
@@ -52,6 +53,7 @@ var mswGenerator = createReactGenerator({
|
|
|
52
53
|
typeName: type.schemas.response.name,
|
|
53
54
|
fakerName: faker.schemas.response.name,
|
|
54
55
|
method: operation.method,
|
|
56
|
+
baseURL,
|
|
55
57
|
url: new URLPath(operation.path).toURLPath()
|
|
56
58
|
}
|
|
57
59
|
)
|
|
@@ -89,5 +91,5 @@ var handlersGenerator = createReactGenerator({
|
|
|
89
91
|
});
|
|
90
92
|
|
|
91
93
|
export { handlersGenerator, mswGenerator };
|
|
92
|
-
//# sourceMappingURL=chunk-
|
|
93
|
-
//# sourceMappingURL=chunk-
|
|
94
|
+
//# sourceMappingURL=chunk-4SW3NCYH.js.map
|
|
95
|
+
//# sourceMappingURL=chunk-4SW3NCYH.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,OAAS,EAAA,EAAE,MAAQ,EAAA,MAAA,EAAQ,OAAQ;AAAA;AACrC,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,C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,aAAA,GAAgB,QAAQ,SAAW,EAAA,EAAE,WAAW,MAAO,CAAA,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-4SW3NCYH.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, baseURL },\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 baseURL={baseURL}\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 baseURL={baseURL}\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"]}
|
|
@@ -4,7 +4,7 @@ var react = require('@kubb/react');
|
|
|
4
4
|
var jsxRuntime = require('@kubb/react/jsx-runtime');
|
|
5
5
|
|
|
6
6
|
// src/components/Mock.tsx
|
|
7
|
-
function Mock({ name, typeName, url, method }) {
|
|
7
|
+
function Mock({ baseURL = "", name, typeName, url, method }) {
|
|
8
8
|
const params = react.FunctionParams.factory({
|
|
9
9
|
data: {
|
|
10
10
|
type: `${typeName} | ((
|
|
@@ -13,7 +13,7 @@ function Mock({ name, typeName, url, method }) {
|
|
|
13
13
|
optional: true
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
-
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { name, export: true, params: params.toConstructor(), children: `return http.${method}('
|
|
16
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { name, export: true, params: params.toConstructor(), children: `return http.${method}('${baseURL}${url}', function handler(info) {
|
|
17
17
|
if(typeof data === 'function') return data(info)
|
|
18
18
|
|
|
19
19
|
return new Response(JSON.stringify(data), {
|
|
@@ -26,7 +26,7 @@ function Mock({ name, typeName, url, method }) {
|
|
|
26
26
|
function Handlers({ name, handlers }) {
|
|
27
27
|
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isIndexable: true, isExportable: true, children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const` });
|
|
28
28
|
}
|
|
29
|
-
function MockWithFaker({ name, fakerName, typeName, url, method }) {
|
|
29
|
+
function MockWithFaker({ baseURL = "", name, fakerName, typeName, url, method }) {
|
|
30
30
|
const params = react.FunctionParams.factory({
|
|
31
31
|
data: {
|
|
32
32
|
type: `${typeName} | ((
|
|
@@ -35,7 +35,7 @@ function MockWithFaker({ name, fakerName, typeName, url, method }) {
|
|
|
35
35
|
optional: true
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
|
-
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { name, export: true, params: params.toConstructor(), children: `return http.${method}('
|
|
38
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { name, export: true, params: params.toConstructor(), children: `return http.${method}('${baseURL}${url}', function handler(info) {
|
|
39
39
|
if(typeof data === 'function') return data(info)
|
|
40
40
|
|
|
41
41
|
return new Response(JSON.stringify(data || ${fakerName}(data)), {
|
|
@@ -49,5 +49,5 @@ function MockWithFaker({ name, fakerName, typeName, url, method }) {
|
|
|
49
49
|
exports.Handlers = Handlers;
|
|
50
50
|
exports.Mock = Mock;
|
|
51
51
|
exports.MockWithFaker = MockWithFaker;
|
|
52
|
-
//# sourceMappingURL=chunk-
|
|
53
|
-
//# sourceMappingURL=chunk-
|
|
52
|
+
//# sourceMappingURL=chunk-MZZLONMV.cjs.map
|
|
53
|
+
//# sourceMappingURL=chunk-MZZLONMV.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/Mock.tsx","../src/components/Handlers.tsx","../src/components/MockWithFaker.tsx"],"names":["FunctionParams","jsx","File","Function"],"mappings":";;;;;;AAiBO,SAAS,IAAA,CAAK,EAAE,OAAU,GAAA,EAAA,EAAI,MAAM,QAAU,EAAA,GAAA,EAAK,QAA4B,EAAA;AACpF,EAAM,MAAA,MAAA,GAASA,qBAAe,OAAQ,CAAA;AAAA,IACpC,IAAM,EAAA;AAAA,MACJ,IAAA,EAAM,GAAG,QAAQ,CAAA;AAAA,gDAAA,EAC2B,MAAM,CAAA;AAAA,oBAAA,CAAA;AAAA,MAElD,QAAU,EAAA;AAAA;AACZ,GACD,CAAA;AAED,EACE,uBAAAC,cAAA,CAACC,WAAK,MAAL,EAAA,EAAY,MAAY,WAAW,EAAA,IAAA,EAAC,YAAY,EAAA,IAAA,EAC/C,QAAC,kBAAAD,cAAA,CAAAE,cAAA,EAAA,EAAS,MAAY,MAAM,EAAA,IAAA,EAAC,MAAQ,EAAA,MAAA,CAAO,aAAc,EAAA,EACvD,yBAAe,MAAM,CAAA,EAAA,EAAK,OAAO,CAAA,EAAG,GAAG,CAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,CAAA,EAS1C,CACF,EAAA,CAAA;AAEJ;AC9BO,SAAS,QAAS,CAAA,EAAE,IAAM,EAAA,QAAA,EAAsC,EAAA;AACrE,EACE,uBAAAF,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;AAEJ;ACDO,SAAS,aAAA,CAAc,EAAE,OAAU,GAAA,EAAA,EAAI,MAAM,SAAW,EAAA,QAAA,EAAU,GAAK,EAAA,MAAA,EAA4B,EAAA;AACxG,EAAM,MAAA,MAAA,GAASF,qBAAe,OAAQ,CAAA;AAAA,IACpC,IAAM,EAAA;AAAA,MACJ,IAAA,EAAM,GAAG,QAAQ,CAAA;AAAA,gDAAA,EAC2B,MAAM,CAAA;AAAA,oBAAA,CAAA;AAAA,MAElD,QAAU,EAAA;AAAA;AACZ,GACD,CAAA;AAED,EACE,uBAAAC,cAACC,CAAAA,UAAAA,CAAK,MAAL,EAAA,EAAY,IAAY,EAAA,WAAA,EAAW,IAAC,EAAA,YAAA,EAAY,IAC/C,EAAA,QAAA,kBAAAD,cAACE,CAAAA,cAAAA,EAAA,EAAS,IAAY,EAAA,MAAA,EAAM,IAAC,EAAA,MAAA,EAAQ,MAAO,CAAA,aAAA,EACzC,EAAA,QAAA,EAAA,CAAA,YAAA,EAAe,MAAM,CAAA,EAAA,EAAK,OAAO,CAAA,EAAG,GAAG,CAAA;AAAA;;AAAA,+CAAA,EAGC,SAAS,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,CAAA,EAMpD,CACF,EAAA,CAAA;AAEJ","file":"chunk-MZZLONMV.cjs","sourcesContent":["import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n url: string\n baseURL: string | undefined\n method: HttpMethod\n}\n\nexport function Mock({ baseURL = '', name, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: `${typeName} | ((\n info: Parameters<Parameters<typeof http.${method}>[1]>[0],\n ) => Response)`,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('${baseURL}${url}', function handler(info) {\n if(typeof data === 'function') return data(info)\n\n return new Response(JSON.stringify(data), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n","import { File } from '@kubb/react'\nimport type { ReactNode } from 'react'\n\ntype HandlersProps = {\n /**\n * Name of the function\n */\n name: string\n // custom\n handlers: string[]\n}\n\nexport function Handlers({ name, handlers }: HandlersProps): ReactNode {\n return (\n <File.Source name={name} isIndexable isExportable>\n {`export const ${name} = ${JSON.stringify(handlers).replaceAll(`\"`, '')} as const`}\n </File.Source>\n )\n}\n","import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n baseURL: string | undefined\n url: string\n method: HttpMethod\n}\n\nexport function MockWithFaker({ baseURL = '', name, fakerName, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: `${typeName} | ((\n info: Parameters<Parameters<typeof http.${method}>[1]>[0],\n ) => Response)`,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('${baseURL}${url}', function handler(info) {\n if(typeof data === 'function') return data(info)\n\n return new Response(JSON.stringify(data || ${fakerName}(data)), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkMZZLONMV_cjs = require('./chunk-MZZLONMV.cjs');
|
|
4
4
|
var utils$1 = require('@kubb/core/utils');
|
|
5
5
|
var pluginFaker = require('@kubb/plugin-faker');
|
|
6
6
|
var pluginOas = require('@kubb/plugin-oas');
|
|
@@ -15,7 +15,7 @@ var mswGenerator = pluginOas.createReactGenerator({
|
|
|
15
15
|
Operation({ operation }) {
|
|
16
16
|
const {
|
|
17
17
|
plugin: {
|
|
18
|
-
options: { output, parser }
|
|
18
|
+
options: { output, parser, baseURL }
|
|
19
19
|
}
|
|
20
20
|
} = react.useApp();
|
|
21
21
|
const oas = hooks.useOas();
|
|
@@ -38,22 +38,24 @@ var mswGenerator = pluginOas.createReactGenerator({
|
|
|
38
38
|
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [type.schemas.response.name], path: type.file.path, root: mock.file.path, isTypeOnly: true }),
|
|
39
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
40
|
parser === "faker" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
41
|
-
|
|
41
|
+
chunkMZZLONMV_cjs.MockWithFaker,
|
|
42
42
|
{
|
|
43
43
|
name: mock.name,
|
|
44
44
|
typeName: type.schemas.response.name,
|
|
45
45
|
fakerName: faker.schemas.response.name,
|
|
46
46
|
method: operation.method,
|
|
47
|
+
baseURL,
|
|
47
48
|
url: new utils$1.URLPath(operation.path).toURLPath()
|
|
48
49
|
}
|
|
49
50
|
),
|
|
50
51
|
parser === "data" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
51
|
-
|
|
52
|
+
chunkMZZLONMV_cjs.Mock,
|
|
52
53
|
{
|
|
53
54
|
name: mock.name,
|
|
54
55
|
typeName: type.schemas.response.name,
|
|
55
56
|
fakerName: faker.schemas.response.name,
|
|
56
57
|
method: operation.method,
|
|
58
|
+
baseURL,
|
|
57
59
|
url: new utils$1.URLPath(operation.path).toURLPath()
|
|
58
60
|
}
|
|
59
61
|
)
|
|
@@ -83,7 +85,7 @@ var handlersGenerator = pluginOas.createReactGenerator({
|
|
|
83
85
|
footer: utils.getFooter({ oas, output: plugin.options.output }),
|
|
84
86
|
children: [
|
|
85
87
|
imports,
|
|
86
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
88
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkMZZLONMV_cjs.Handlers, { name: "handlers", handlers })
|
|
87
89
|
]
|
|
88
90
|
}
|
|
89
91
|
);
|
|
@@ -92,5 +94,5 @@ var handlersGenerator = pluginOas.createReactGenerator({
|
|
|
92
94
|
|
|
93
95
|
exports.handlersGenerator = handlersGenerator;
|
|
94
96
|
exports.mswGenerator = mswGenerator;
|
|
95
|
-
//# sourceMappingURL=chunk-
|
|
96
|
-
//# sourceMappingURL=chunk-
|
|
97
|
+
//# sourceMappingURL=chunk-U26REKBP.cjs.map
|
|
98
|
+
//# sourceMappingURL=chunk-U26REKBP.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,OAAS,EAAA,EAAE,MAAQ,EAAA,MAAA,EAAQ,OAAQ;AAAA;AACrC,QACEC,YAAkB,EAAA;AACtB,IAAA,MAAM,MAAMC,YAAO,EAAA;AACnB,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,GAA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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-U26REKBP.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, baseURL },\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 baseURL={baseURL}\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 baseURL={baseURL}\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"]}
|
|
@@ -2,7 +2,7 @@ import { FunctionParams, File, Function } from '@kubb/react';
|
|
|
2
2
|
import { jsx } from '@kubb/react/jsx-runtime';
|
|
3
3
|
|
|
4
4
|
// src/components/Mock.tsx
|
|
5
|
-
function Mock({ name, typeName, url, method }) {
|
|
5
|
+
function Mock({ baseURL = "", name, typeName, url, method }) {
|
|
6
6
|
const params = FunctionParams.factory({
|
|
7
7
|
data: {
|
|
8
8
|
type: `${typeName} | ((
|
|
@@ -11,7 +11,7 @@ function Mock({ name, typeName, url, method }) {
|
|
|
11
11
|
optional: true
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
|
-
return /* @__PURE__ */ jsx(File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsx(Function, { name, export: true, params: params.toConstructor(), children: `return http.${method}('
|
|
14
|
+
return /* @__PURE__ */ jsx(File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsx(Function, { name, export: true, params: params.toConstructor(), children: `return http.${method}('${baseURL}${url}', function handler(info) {
|
|
15
15
|
if(typeof data === 'function') return data(info)
|
|
16
16
|
|
|
17
17
|
return new Response(JSON.stringify(data), {
|
|
@@ -24,7 +24,7 @@ function Mock({ name, typeName, url, method }) {
|
|
|
24
24
|
function Handlers({ name, handlers }) {
|
|
25
25
|
return /* @__PURE__ */ jsx(File.Source, { name, isIndexable: true, isExportable: true, children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const` });
|
|
26
26
|
}
|
|
27
|
-
function MockWithFaker({ name, fakerName, typeName, url, method }) {
|
|
27
|
+
function MockWithFaker({ baseURL = "", name, fakerName, typeName, url, method }) {
|
|
28
28
|
const params = FunctionParams.factory({
|
|
29
29
|
data: {
|
|
30
30
|
type: `${typeName} | ((
|
|
@@ -33,7 +33,7 @@ function MockWithFaker({ name, fakerName, typeName, url, method }) {
|
|
|
33
33
|
optional: true
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
|
-
return /* @__PURE__ */ jsx(File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsx(Function, { name, export: true, params: params.toConstructor(), children: `return http.${method}('
|
|
36
|
+
return /* @__PURE__ */ jsx(File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsx(Function, { name, export: true, params: params.toConstructor(), children: `return http.${method}('${baseURL}${url}', function handler(info) {
|
|
37
37
|
if(typeof data === 'function') return data(info)
|
|
38
38
|
|
|
39
39
|
return new Response(JSON.stringify(data || ${fakerName}(data)), {
|
|
@@ -45,5 +45,5 @@ function MockWithFaker({ name, fakerName, typeName, url, method }) {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
export { Handlers, Mock, MockWithFaker };
|
|
48
|
-
//# sourceMappingURL=chunk-
|
|
49
|
-
//# sourceMappingURL=chunk-
|
|
48
|
+
//# sourceMappingURL=chunk-VFRXFST2.js.map
|
|
49
|
+
//# sourceMappingURL=chunk-VFRXFST2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/Mock.tsx","../src/components/Handlers.tsx","../src/components/MockWithFaker.tsx"],"names":["jsx","File","FunctionParams","Function"],"mappings":";;;;AAiBO,SAAS,IAAA,CAAK,EAAE,OAAU,GAAA,EAAA,EAAI,MAAM,QAAU,EAAA,GAAA,EAAK,QAA4B,EAAA;AACpF,EAAM,MAAA,MAAA,GAAS,eAAe,OAAQ,CAAA;AAAA,IACpC,IAAM,EAAA;AAAA,MACJ,IAAA,EAAM,GAAG,QAAQ,CAAA;AAAA,gDAAA,EAC2B,MAAM,CAAA;AAAA,oBAAA,CAAA;AAAA,MAElD,QAAU,EAAA;AAAA;AACZ,GACD,CAAA;AAED,EACE,uBAAA,GAAA,CAAC,KAAK,MAAL,EAAA,EAAY,MAAY,WAAW,EAAA,IAAA,EAAC,YAAY,EAAA,IAAA,EAC/C,QAAC,kBAAA,GAAA,CAAA,QAAA,EAAA,EAAS,MAAY,MAAM,EAAA,IAAA,EAAC,MAAQ,EAAA,MAAA,CAAO,aAAc,EAAA,EACvD,yBAAe,MAAM,CAAA,EAAA,EAAK,OAAO,CAAA,EAAG,GAAG,CAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,CAAA,EAS1C,CACF,EAAA,CAAA;AAEJ;AC9BO,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;AAEJ;ACDO,SAAS,aAAA,CAAc,EAAE,OAAU,GAAA,EAAA,EAAI,MAAM,SAAW,EAAA,QAAA,EAAU,GAAK,EAAA,MAAA,EAA4B,EAAA;AACxG,EAAM,MAAA,MAAA,GAASC,eAAe,OAAQ,CAAA;AAAA,IACpC,IAAM,EAAA;AAAA,MACJ,IAAA,EAAM,GAAG,QAAQ,CAAA;AAAA,gDAAA,EAC2B,MAAM,CAAA;AAAA,oBAAA,CAAA;AAAA,MAElD,QAAU,EAAA;AAAA;AACZ,GACD,CAAA;AAED,EACE,uBAAAF,GAACC,CAAAA,IAAAA,CAAK,MAAL,EAAA,EAAY,IAAY,EAAA,WAAA,EAAW,IAAC,EAAA,YAAA,EAAY,IAC/C,EAAA,QAAA,kBAAAD,GAACG,CAAAA,QAAAA,EAAA,EAAS,IAAY,EAAA,MAAA,EAAM,IAAC,EAAA,MAAA,EAAQ,MAAO,CAAA,aAAA,EACzC,EAAA,QAAA,EAAA,CAAA,YAAA,EAAe,MAAM,CAAA,EAAA,EAAK,OAAO,CAAA,EAAG,GAAG,CAAA;AAAA;;AAAA,+CAAA,EAGC,SAAS,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,CAAA,EAMpD,CACF,EAAA,CAAA;AAEJ","file":"chunk-VFRXFST2.js","sourcesContent":["import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n url: string\n baseURL: string | undefined\n method: HttpMethod\n}\n\nexport function Mock({ baseURL = '', name, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: `${typeName} | ((\n info: Parameters<Parameters<typeof http.${method}>[1]>[0],\n ) => Response)`,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('${baseURL}${url}', function handler(info) {\n if(typeof data === 'function') return data(info)\n\n return new Response(JSON.stringify(data), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n","import { File } from '@kubb/react'\nimport type { ReactNode } from 'react'\n\ntype HandlersProps = {\n /**\n * Name of the function\n */\n name: string\n // custom\n handlers: string[]\n}\n\nexport function Handlers({ name, handlers }: HandlersProps): ReactNode {\n return (\n <File.Source name={name} isIndexable isExportable>\n {`export const ${name} = ${JSON.stringify(handlers).replaceAll(`\"`, '')} as const`}\n </File.Source>\n )\n}\n","import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n baseURL: string | undefined\n url: string\n method: HttpMethod\n}\n\nexport function MockWithFaker({ baseURL = '', name, fakerName, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: `${typeName} | ((\n info: Parameters<Parameters<typeof http.${method}>[1]>[0],\n ) => Response)`,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('${baseURL}${url}', function handler(info) {\n if(typeof data === 'function') return data(info)\n\n return new Response(JSON.stringify(data || ${fakerName}(data)), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n"]}
|
package/dist/components.cjs
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkMZZLONMV_cjs = require('./chunk-MZZLONMV.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 chunkMZZLONMV_cjs.Handlers; }
|
|
10
10
|
});
|
|
11
11
|
Object.defineProperty(exports, "Mock", {
|
|
12
12
|
enumerable: true,
|
|
13
|
-
get: function () { return
|
|
13
|
+
get: function () { return chunkMZZLONMV_cjs.Mock; }
|
|
14
14
|
});
|
|
15
15
|
Object.defineProperty(exports, "MockWithFaker", {
|
|
16
16
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
17
|
+
get: function () { return chunkMZZLONMV_cjs.MockWithFaker; }
|
|
18
18
|
});
|
|
19
19
|
//# sourceMappingURL=components.cjs.map
|
|
20
20
|
//# sourceMappingURL=components.cjs.map
|
package/dist/components.d.cts
CHANGED
|
@@ -9,9 +9,10 @@ type Props$1 = {
|
|
|
9
9
|
typeName: string;
|
|
10
10
|
fakerName: string;
|
|
11
11
|
url: string;
|
|
12
|
+
baseURL: string | undefined;
|
|
12
13
|
method: HttpMethod;
|
|
13
14
|
};
|
|
14
|
-
declare function Mock({ name, typeName, url, method }: Props$1): ReactNode;
|
|
15
|
+
declare function Mock({ baseURL, name, typeName, url, method }: Props$1): ReactNode;
|
|
15
16
|
|
|
16
17
|
type HandlersProps = {
|
|
17
18
|
/**
|
|
@@ -29,9 +30,10 @@ type Props = {
|
|
|
29
30
|
name: string;
|
|
30
31
|
typeName: string;
|
|
31
32
|
fakerName: string;
|
|
33
|
+
baseURL: string | undefined;
|
|
32
34
|
url: string;
|
|
33
35
|
method: HttpMethod;
|
|
34
36
|
};
|
|
35
|
-
declare function MockWithFaker({ name, fakerName, typeName, url, method }: Props): ReactNode;
|
|
37
|
+
declare function MockWithFaker({ baseURL, name, fakerName, typeName, url, method }: Props): ReactNode;
|
|
36
38
|
|
|
37
39
|
export { Handlers, Mock, MockWithFaker };
|
package/dist/components.d.ts
CHANGED
|
@@ -9,9 +9,10 @@ type Props$1 = {
|
|
|
9
9
|
typeName: string;
|
|
10
10
|
fakerName: string;
|
|
11
11
|
url: string;
|
|
12
|
+
baseURL: string | undefined;
|
|
12
13
|
method: HttpMethod;
|
|
13
14
|
};
|
|
14
|
-
declare function Mock({ name, typeName, url, method }: Props$1): ReactNode;
|
|
15
|
+
declare function Mock({ baseURL, name, typeName, url, method }: Props$1): ReactNode;
|
|
15
16
|
|
|
16
17
|
type HandlersProps = {
|
|
17
18
|
/**
|
|
@@ -29,9 +30,10 @@ type Props = {
|
|
|
29
30
|
name: string;
|
|
30
31
|
typeName: string;
|
|
31
32
|
fakerName: string;
|
|
33
|
+
baseURL: string | undefined;
|
|
32
34
|
url: string;
|
|
33
35
|
method: HttpMethod;
|
|
34
36
|
};
|
|
35
|
-
declare function MockWithFaker({ name, fakerName, typeName, url, method }: Props): ReactNode;
|
|
37
|
+
declare function MockWithFaker({ baseURL, name, fakerName, typeName, url, method }: Props): ReactNode;
|
|
36
38
|
|
|
37
39
|
export { Handlers, Mock, MockWithFaker };
|
package/dist/components.js
CHANGED
package/dist/generators.cjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
3
|
+
var chunkU26REKBP_cjs = require('./chunk-U26REKBP.cjs');
|
|
4
|
+
require('./chunk-MZZLONMV.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 chunkU26REKBP_cjs.handlersGenerator; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "mswGenerator", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkU26REKBP_cjs.mswGenerator; }
|
|
15
15
|
});
|
|
16
16
|
//# sourceMappingURL=generators.cjs.map
|
|
17
17
|
//# sourceMappingURL=generators.cjs.map
|
package/dist/generators.d.cts
CHANGED
package/dist/generators.d.ts
CHANGED
package/dist/generators.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { handlersGenerator, mswGenerator } from './chunk-
|
|
2
|
-
import './chunk-
|
|
1
|
+
export { handlersGenerator, mswGenerator } from './chunk-4SW3NCYH.js';
|
|
2
|
+
import './chunk-VFRXFST2.js';
|
|
3
3
|
//# sourceMappingURL=generators.js.map
|
|
4
4
|
//# sourceMappingURL=generators.js.map
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
3
|
+
var chunkU26REKBP_cjs = require('./chunk-U26REKBP.cjs');
|
|
4
|
+
require('./chunk-MZZLONMV.cjs');
|
|
5
5
|
var path = require('path');
|
|
6
6
|
var core = require('@kubb/core');
|
|
7
7
|
var transformers = require('@kubb/core/transformers');
|
|
@@ -24,15 +24,17 @@ var pluginMsw = core.createPlugin((options) => {
|
|
|
24
24
|
transformers: transformers$1 = {},
|
|
25
25
|
handlers = false,
|
|
26
26
|
parser = "data",
|
|
27
|
-
generators = [
|
|
28
|
-
contentType
|
|
27
|
+
generators = [chunkU26REKBP_cjs.mswGenerator, handlers ? chunkU26REKBP_cjs.handlersGenerator : undefined].filter(Boolean),
|
|
28
|
+
contentType,
|
|
29
|
+
baseURL
|
|
29
30
|
} = options;
|
|
30
31
|
return {
|
|
31
32
|
name: pluginMswName,
|
|
32
33
|
options: {
|
|
33
34
|
output,
|
|
34
35
|
parser,
|
|
35
|
-
group
|
|
36
|
+
group,
|
|
37
|
+
baseURL
|
|
36
38
|
},
|
|
37
39
|
pre: [pluginOas.pluginOasName, pluginTs.pluginTsName, parser === "faker" ? pluginFaker.pluginFakerName : undefined].filter(Boolean),
|
|
38
40
|
resolvePath(baseName, pathMode, options2) {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,SAAS,CAAA,CAAE,OAAO,OAAO,CAAA;AAAA,IACpF;AAAA,GACE,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,SAAS,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,CA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QACA,MAAA;AAAA,QACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,QACxB,IAAM,EAAA;AAAA,UACJ,SAAA,EAAW,KAAK,MAAO,CAAA;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA;AAAA,OACd,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAAA;AACnC,GACF;AACF,CAAC","file":"index.cjs","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, 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 contentType,\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,\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
|
+
{"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,OAA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O,IAAI,CAAA;AACnE,MAAM,MAAA,IAAA,GAAOC,iBAAY,OAAQ,CAAAD,qBAAA,CAAK,QAAQ,IAAM,EAAA,MAAA,CAAO,IAAI,CAAC,CAAA;AAEhE,MAAA,MAAM,kBAAqB,GAAA,IAAII,4BAAmB,CAAA,IAAA,CAAK,OAAO,OAAS,EAAA;AAAA,QACrE,GAAA;AAAA,QACA,eAAe,IAAK,CAAA,aAAA;AAAA,QACpB,QAAQ,IAAK,CAAA,MAAA;AAAA,QACb,WAAA;AAAA,QACA,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.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 contentType,\n baseURL,\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n parser,\n group,\n baseURL,\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,\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
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { mswGenerator, handlersGenerator } from './chunk-
|
|
2
|
-
import './chunk-
|
|
1
|
+
import { mswGenerator, handlersGenerator } from './chunk-4SW3NCYH.js';
|
|
2
|
+
import './chunk-VFRXFST2.js';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { createPlugin, FileManager, PluginManager } from '@kubb/core';
|
|
5
5
|
import { camelCase } from '@kubb/core/transformers';
|
|
@@ -19,14 +19,16 @@ var pluginMsw = createPlugin((options) => {
|
|
|
19
19
|
handlers = false,
|
|
20
20
|
parser = "data",
|
|
21
21
|
generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),
|
|
22
|
-
contentType
|
|
22
|
+
contentType,
|
|
23
|
+
baseURL
|
|
23
24
|
} = options;
|
|
24
25
|
return {
|
|
25
26
|
name: pluginMswName,
|
|
26
27
|
options: {
|
|
27
28
|
output,
|
|
28
29
|
parser,
|
|
29
|
-
group
|
|
30
|
+
group,
|
|
31
|
+
baseURL
|
|
30
32
|
},
|
|
31
33
|
pre: [pluginOasName, pluginTsName, parser === "faker" ? pluginFakerName : undefined].filter(Boolean),
|
|
32
34
|
resolvePath(baseName, pathMode, options2) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts"],"names":["options"],"mappings":";;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AAM,GAAA,MAAM,aAAc,CAAA,OAAA,CAAQ,MAAO,EAAA;AAC/C,MAAM,MAAA,IAAA,GAAO,KAAK,OAAQ,CAAA,IAAA,CAAK,OAAO,IAAM,EAAA,IAAA,CAAK,MAAO,CAAA,MAAA,CAAO,IAAI,CAAA;AACnE,MAAM,MAAA,IAAA,GAAO,YAAY,OAAQ,CAAA,IAAA,CAAK,QAAQ,IAAM,EAAA,MAAA,CAAO,IAAI,CAAC,CAAA;AAEhE,MAAA,MAAM,kBAAqB,GAAA,IAAI,kBAAmB,CAAA,IAAA,CAAK,OAAO,OAAS,EAAA;AAAA,QACrE,GAAA;AAAA,QACA,eAAe,IAAK,CAAA,aAAA;AAAA,QACpB,QAAQ,IAAK,CAAA,MAAA;AAAA,QACb,WAAA;AAAA,QACA,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 contentType,\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,\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
|
+
{"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,GAAa,CAAC,YAAc,EAAA,QAAA,GAAW,oBAAoB,SAAS,CAAA,CAAE,OAAO,OAAO,CAAA;AAAA,IACpF,WAAA;AAAA,IACA;AAAA,GACE,GAAA,OAAA;AAEJ,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,aAAA;AAAA,IACN,OAAS,EAAA;AAAA,MACP,MAAA;AAAA,MACA,MAAA;AAAA,MACA,KAAA;AAAA,MACA;AAAA,KACF;AAAA,IACA,GAAA,EAAK,CAAC,aAAA,EAAe,YAAc,EAAA,MAAA,KAAW,UAAU,eAAkB,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AAA,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 contentType,\n baseURL,\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n parser,\n group,\n baseURL,\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,\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"]}
|
|
@@ -13,6 +13,7 @@ type Options = {
|
|
|
13
13
|
* By default, the first JSON valid mediaType will be used
|
|
14
14
|
*/
|
|
15
15
|
contentType?: contentType;
|
|
16
|
+
baseURL?: string;
|
|
16
17
|
/**
|
|
17
18
|
* Group the MSW mocks based on the provided name.
|
|
18
19
|
*/
|
|
@@ -56,6 +57,7 @@ type ResolvedOptions = {
|
|
|
56
57
|
output: Output<Oas>;
|
|
57
58
|
group: Options['group'];
|
|
58
59
|
parser: NonNullable<Options['parser']>;
|
|
60
|
+
baseURL: Options['baseURL'] | undefined;
|
|
59
61
|
};
|
|
60
62
|
type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
61
63
|
|
|
@@ -13,6 +13,7 @@ type Options = {
|
|
|
13
13
|
* By default, the first JSON valid mediaType will be used
|
|
14
14
|
*/
|
|
15
15
|
contentType?: contentType;
|
|
16
|
+
baseURL?: string;
|
|
16
17
|
/**
|
|
17
18
|
* Group the MSW mocks based on the provided name.
|
|
18
19
|
*/
|
|
@@ -56,6 +57,7 @@ type ResolvedOptions = {
|
|
|
56
57
|
output: Output<Oas>;
|
|
57
58
|
group: Options['group'];
|
|
58
59
|
parser: NonNullable<Options['parser']>;
|
|
60
|
+
baseURL: Options['baseURL'] | undefined;
|
|
59
61
|
};
|
|
60
62
|
type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
61
63
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-msw",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.9",
|
|
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.5.
|
|
78
|
-
"@kubb/fs": "3.5.
|
|
79
|
-
"@kubb/oas": "3.5.
|
|
80
|
-
"@kubb/plugin-faker": "3.5.
|
|
81
|
-
"@kubb/plugin-oas": "3.5.
|
|
82
|
-
"@kubb/plugin-ts": "3.5.
|
|
83
|
-
"@kubb/react": "3.5.
|
|
77
|
+
"@kubb/core": "3.5.9",
|
|
78
|
+
"@kubb/fs": "3.5.9",
|
|
79
|
+
"@kubb/oas": "3.5.9",
|
|
80
|
+
"@kubb/plugin-faker": "3.5.9",
|
|
81
|
+
"@kubb/plugin-oas": "3.5.9",
|
|
82
|
+
"@kubb/plugin-ts": "3.5.9",
|
|
83
|
+
"@kubb/react": "3.5.9"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@types/react": "^18.3.18",
|
|
87
87
|
"react": "^18.3.1",
|
|
88
88
|
"tsup": "^8.3.6",
|
|
89
89
|
"typescript": "^5.7.3",
|
|
90
|
-
"@kubb/config-ts": "3.5.
|
|
91
|
-
"@kubb/config-tsup": "3.5.
|
|
90
|
+
"@kubb/config-ts": "3.5.9",
|
|
91
|
+
"@kubb/config-tsup": "3.5.9"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
94
|
"@kubb/react": "^3.0.0"
|
package/src/components/Mock.tsx
CHANGED
|
@@ -11,10 +11,11 @@ type Props = {
|
|
|
11
11
|
typeName: string
|
|
12
12
|
fakerName: string
|
|
13
13
|
url: string
|
|
14
|
+
baseURL: string | undefined
|
|
14
15
|
method: HttpMethod
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
export function Mock({ name, typeName, url, method }: Props): ReactNode {
|
|
18
|
+
export function Mock({ baseURL = '', name, typeName, url, method }: Props): ReactNode {
|
|
18
19
|
const params = FunctionParams.factory({
|
|
19
20
|
data: {
|
|
20
21
|
type: `${typeName} | ((
|
|
@@ -27,7 +28,7 @@ export function Mock({ name, typeName, url, method }: Props): ReactNode {
|
|
|
27
28
|
return (
|
|
28
29
|
<File.Source name={name} isIndexable isExportable>
|
|
29
30
|
<Function name={name} export params={params.toConstructor()}>
|
|
30
|
-
{`return http.${method}('
|
|
31
|
+
{`return http.${method}('${baseURL}${url}', function handler(info) {
|
|
31
32
|
if(typeof data === 'function') return data(info)
|
|
32
33
|
|
|
33
34
|
return new Response(JSON.stringify(data), {
|
|
@@ -10,11 +10,12 @@ type Props = {
|
|
|
10
10
|
name: string
|
|
11
11
|
typeName: string
|
|
12
12
|
fakerName: string
|
|
13
|
+
baseURL: string | undefined
|
|
13
14
|
url: string
|
|
14
15
|
method: HttpMethod
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
export function MockWithFaker({ name, fakerName, typeName, url, method }: Props): ReactNode {
|
|
18
|
+
export function MockWithFaker({ baseURL = '', name, fakerName, typeName, url, method }: Props): ReactNode {
|
|
18
19
|
const params = FunctionParams.factory({
|
|
19
20
|
data: {
|
|
20
21
|
type: `${typeName} | ((
|
|
@@ -27,7 +28,7 @@ export function MockWithFaker({ name, fakerName, typeName, url, method }: Props)
|
|
|
27
28
|
return (
|
|
28
29
|
<File.Source name={name} isIndexable isExportable>
|
|
29
30
|
<Function name={name} export params={params.toConstructor()}>
|
|
30
|
-
{`return http.${method}('
|
|
31
|
+
{`return http.${method}('${baseURL}${url}', function handler(info) {
|
|
31
32
|
if(typeof data === 'function') return data(info)
|
|
32
33
|
|
|
33
34
|
return new Response(JSON.stringify(data || ${fakerName}(data)), {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { http } from 'msw'
|
|
2
2
|
|
|
3
3
|
export function createPets(data?: CreatePetsMutationResponse | ((info: Parameters<Parameters<typeof http.post>[1]>[0]) => Response)) {
|
|
4
|
-
return http.post('
|
|
4
|
+
return http.post('/pets', function handler(info) {
|
|
5
5
|
if (typeof data === 'function') return data(info)
|
|
6
6
|
|
|
7
7
|
return new Response(JSON.stringify(data), {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { http } from 'msw'
|
|
2
2
|
|
|
3
3
|
export function deletePetsPetid(data?: DeletePetsPetidMutationResponse | ((info: Parameters<Parameters<typeof http.delete>[1]>[0]) => Response)) {
|
|
4
|
-
return http.delete('
|
|
4
|
+
return http.delete('/pets/:petId', function handler(info) {
|
|
5
5
|
if (typeof data === 'function') return data(info)
|
|
6
6
|
|
|
7
7
|
return new Response(JSON.stringify(data), {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { http } from 'msw'
|
|
2
2
|
|
|
3
3
|
export function listPets(data?: ListPetsQueryResponse | ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Response)) {
|
|
4
|
-
return http.get('
|
|
4
|
+
return http.get('/pets', function handler(info) {
|
|
5
5
|
if (typeof data === 'function') return data(info)
|
|
6
6
|
|
|
7
7
|
return new Response(JSON.stringify(data), {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { http } from 'msw'
|
|
2
2
|
|
|
3
3
|
export function listPets(data?: ListPetsQueryResponse | ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Response)) {
|
|
4
|
-
return http.get('
|
|
4
|
+
return http.get('/pets', function handler(info) {
|
|
5
5
|
if (typeof data === 'function') return data(info)
|
|
6
6
|
|
|
7
7
|
return new Response(JSON.stringify(data || listPetsQueryResponse(data)), {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { http } from 'msw'
|
|
2
2
|
|
|
3
3
|
export function showPetById(data?: ShowPetByIdQueryResponse | ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Response)) {
|
|
4
|
-
return http.get('
|
|
4
|
+
return http.get('/pets/:petId', function handler(info) {
|
|
5
5
|
if (typeof data === 'function') return data(info)
|
|
6
6
|
|
|
7
7
|
return new Response(JSON.stringify(data), {
|
|
@@ -13,7 +13,7 @@ export const mswGenerator = createReactGenerator<PluginMsw>({
|
|
|
13
13
|
Operation({ operation }) {
|
|
14
14
|
const {
|
|
15
15
|
plugin: {
|
|
16
|
-
options: { output, parser },
|
|
16
|
+
options: { output, parser, baseURL },
|
|
17
17
|
},
|
|
18
18
|
} = useApp<PluginMsw>()
|
|
19
19
|
const oas = useOas()
|
|
@@ -49,6 +49,7 @@ export const mswGenerator = createReactGenerator<PluginMsw>({
|
|
|
49
49
|
typeName={type.schemas.response.name}
|
|
50
50
|
fakerName={faker.schemas.response.name}
|
|
51
51
|
method={operation.method}
|
|
52
|
+
baseURL={baseURL}
|
|
52
53
|
url={new URLPath(operation.path).toURLPath()}
|
|
53
54
|
/>
|
|
54
55
|
)}
|
|
@@ -58,6 +59,7 @@ export const mswGenerator = createReactGenerator<PluginMsw>({
|
|
|
58
59
|
typeName={type.schemas.response.name}
|
|
59
60
|
fakerName={faker.schemas.response.name}
|
|
60
61
|
method={operation.method}
|
|
62
|
+
baseURL={baseURL}
|
|
61
63
|
url={new URLPath(operation.path).toURLPath()}
|
|
62
64
|
/>
|
|
63
65
|
)}
|
package/src/plugin.ts
CHANGED
|
@@ -26,6 +26,7 @@ export const pluginMsw = createPlugin<PluginMsw>((options) => {
|
|
|
26
26
|
parser = 'data',
|
|
27
27
|
generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),
|
|
28
28
|
contentType,
|
|
29
|
+
baseURL,
|
|
29
30
|
} = options
|
|
30
31
|
|
|
31
32
|
return {
|
|
@@ -34,6 +35,7 @@ export const pluginMsw = createPlugin<PluginMsw>((options) => {
|
|
|
34
35
|
output,
|
|
35
36
|
parser,
|
|
36
37
|
group,
|
|
38
|
+
baseURL,
|
|
37
39
|
},
|
|
38
40
|
pre: [pluginOasName, pluginTsName, parser === 'faker' ? pluginFakerName : undefined].filter(Boolean),
|
|
39
41
|
resolvePath(baseName, pathMode, options) {
|
package/src/types.ts
CHANGED
|
@@ -14,6 +14,7 @@ export type Options = {
|
|
|
14
14
|
* By default, the first JSON valid mediaType will be used
|
|
15
15
|
*/
|
|
16
16
|
contentType?: contentType
|
|
17
|
+
baseURL?: string
|
|
17
18
|
/**
|
|
18
19
|
* Group the MSW mocks based on the provided name.
|
|
19
20
|
*/
|
|
@@ -57,6 +58,7 @@ type ResolvedOptions = {
|
|
|
57
58
|
output: Output<Oas>
|
|
58
59
|
group: Options['group']
|
|
59
60
|
parser: NonNullable<Options['parser']>
|
|
61
|
+
baseURL: Options['baseURL'] | undefined
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
export type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, never, ResolvePathOptions>
|
|
@@ -1 +0,0 @@
|
|
|
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,I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AA,CAAO,KAAK,CAAA;AAClE,MAAM,MAAA,aAAA,GAAgB,QAAQ,SAAW,EAAA,EAAE,WAAW,MAAO,CAAA,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"]}
|
|
@@ -1 +0,0 @@
|
|
|
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,EAAA;AAE7D,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,MAAM,OAAQ,CAAA,SAAA,EA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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 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources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AM,GAAG,QAAQ,CAAA;AAAA,gDAAA,EAC2B,MAAM,CAAA;AAAA,oBAAA,CAAA;AAAA,MAElD,QAAU,EAAA;AAAA;AACZ,GACD,CAAA;AAED,EACE,uBAAAF,GAACC,CAAAA,IAAAA,CAAK,MAAL,EAAA,EAAY,MAAY,WAAW,EAAA,IAAA,EAAC,YAAY,EAAA,IAAA,EAC/C,QAAAD,kBAAAA,GAAAA,CAACG,UAAA,EAAS,IAAA,EAAY,MAAM,EAAA,IAAA,EAAC,MAAQ,EAAA,MAAA,CAAO,eACzC,EAAA,QAAA,EAAA,CAAA,YAAA,EAAe,MAAM,CAAA,GAAA,EAAM,GAAG,CAAA;AAAA;;AAAA,+CAAA,EAGU,SAAS,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,CAAA,EAMpD,CACF,EAAA,CAAA;AAEJ","file":"chunk-LOYUDIPB.js","sourcesContent":["import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function Mock({ name, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: `${typeName} | ((\n info: Parameters<Parameters<typeof http.${method}>[1]>[0],\n ) => Response)`,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('*${url}', function handler(info) {\n if(typeof data === 'function') return data(info)\n\n return new Response(JSON.stringify(data), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n","import { File } from '@kubb/react'\nimport type { ReactNode } from 'react'\n\ntype HandlersProps = {\n /**\n * Name of the function\n */\n name: string\n // custom\n handlers: string[]\n}\n\nexport function Handlers({ name, handlers }: HandlersProps): ReactNode {\n return (\n <File.Source name={name} isIndexable isExportable>\n {`export const ${name} = ${JSON.stringify(handlers).replaceAll(`\"`, '')} as const`}\n </File.Source>\n )\n}\n","import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function MockWithFaker({ name, fakerName, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: `${typeName} | ((\n info: Parameters<Parameters<typeof http.${method}>[1]>[0],\n ) => Response)`,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('*${url}', function handler(info) {\n if(typeof data === 'function') return data(info)\n\n return new Response(JSON.stringify(data || ${fakerName}(data)), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Mock.tsx","../src/components/Handlers.tsx","../src/components/MockWithFaker.tsx"],"names":["FunctionParams","jsx","File","Function"],"mappings":";;;;;;AAgBO,SAAS,KAAK,EAAE,IAAA,EAAM,QAAU,EAAA,GAAA,EAAK,QAA4B,EAAA;AACtE,EAAM,MAAA,MAAA,GAASA,qBAAe,OAAQ,CAAA;AAAA,IACpC,IAAM,EAAA;AAAA,MACJ,IAAA,EAAM,GAAG,QAAQ,CAAA;AAAA,gDAAA,EAC2B,MAAM,CAAA;AAAA,oBAAA,CAAA;AAAA,MAElD,QAAU,EAAA;AAAA;AACZ,GACD,CAAA;AAED,EACE,uBAAAC,cAAA,CAACC,WAAK,MAAL,EAAA,EAAY,MAAY,WAAW,EAAA,IAAA,EAAC,cAAY,IAC/C,EAAA,QAAA,kBAAAD,cAAA,CAACE,kBAAS,IAAY,EAAA,MAAA,EAAM,MAAC,MAAQ,EAAA,MAAA,CAAO,eACzC,EAAA,QAAA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@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function Mock({ name, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: `${typeName} | ((\n info: Parameters<Parameters<typeof http.${method}>[1]>[0],\n ) => Response)`,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('*${url}', function handler(info) {\n if(typeof data === 'function') return data(info)\n\n return new Response(JSON.stringify(data), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n","import { File } from '@kubb/react'\nimport type { ReactNode } from 'react'\n\ntype HandlersProps = {\n /**\n * Name of the function\n */\n name: string\n // custom\n handlers: string[]\n}\n\nexport function Handlers({ name, handlers }: HandlersProps): ReactNode {\n return (\n <File.Source name={name} isIndexable isExportable>\n {`export const ${name} = ${JSON.stringify(handlers).replaceAll(`\"`, '')} as const`}\n </File.Source>\n )\n}\n","import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function MockWithFaker({ name, fakerName, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: `${typeName} | ((\n info: Parameters<Parameters<typeof http.${method}>[1]>[0],\n ) => Response)`,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('*${url}', function handler(info) {\n if(typeof data === 'function') return data(info)\n\n return new Response(JSON.stringify(data || ${fakerName}(data)), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n"]}
|