@kubb/plugin-msw 3.14.1 → 3.14.4
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-N5C3UG5M.cjs → chunk-6ANKBOX6.cjs} +12 -8
- package/dist/chunk-6ANKBOX6.cjs.map +1 -0
- package/dist/{chunk-MZZLONMV.cjs → chunk-FYUFQXX6.cjs} +8 -6
- package/dist/chunk-FYUFQXX6.cjs.map +1 -0
- package/dist/{chunk-PAT3XAAU.js → chunk-GUSADLEP.js} +9 -5
- package/dist/chunk-GUSADLEP.js.map +1 -0
- package/dist/{chunk-VFRXFST2.js → chunk-HL53J5NZ.js} +8 -6
- package/dist/chunk-HL53J5NZ.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.js +2 -2
- package/dist/index.cjs +3 -3
- package/dist/index.js +2 -2
- package/package.json +9 -9
- package/src/components/Mock.tsx +4 -2
- package/src/components/MockWithFaker.tsx +4 -2
- package/src/generators/__snapshots__/createPet.ts +1 -0
- package/src/generators/__snapshots__/createPetFaker.ts +18 -0
- package/src/generators/__snapshots__/deletePet.ts +1 -0
- package/src/generators/__snapshots__/getPets.ts +1 -0
- package/src/generators/__snapshots__/getPetsFaker.ts +1 -0
- package/src/generators/__snapshots__/showPetById.ts +1 -0
- package/src/generators/mswGenerator.tsx +7 -2
- package/dist/chunk-MZZLONMV.cjs.map +0 -1
- package/dist/chunk-N5C3UG5M.cjs.map +0 -1
- package/dist/chunk-PAT3XAAU.js.map +0 -1
- package/dist/chunk-VFRXFST2.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkFYUFQXX6_cjs = require('./chunk-FYUFQXX6.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');
|
|
@@ -33,6 +33,8 @@ var mswGenerator = pluginOas.createReactGenerator({
|
|
|
33
33
|
file: getFile(operation, { pluginKey: [pluginTs.pluginTsName] }),
|
|
34
34
|
schemas: getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" })
|
|
35
35
|
};
|
|
36
|
+
const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith("2"));
|
|
37
|
+
const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200;
|
|
36
38
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
37
39
|
react.File,
|
|
38
40
|
{
|
|
@@ -47,25 +49,27 @@ var mswGenerator = pluginOas.createReactGenerator({
|
|
|
47
49
|
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [type.schemas.response.name], path: type.file.path, root: mock.file.path, isTypeOnly: true }),
|
|
48
50
|
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 }),
|
|
49
51
|
parser === "faker" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
50
|
-
|
|
52
|
+
chunkFYUFQXX6_cjs.MockWithFaker,
|
|
51
53
|
{
|
|
52
54
|
name: mock.name,
|
|
53
55
|
typeName: type.schemas.response.name,
|
|
54
56
|
fakerName: faker.schemas.response.name,
|
|
55
57
|
method: operation.method,
|
|
56
58
|
baseURL,
|
|
57
|
-
url: new utils$1.URLPath(operation.path).toURLPath()
|
|
59
|
+
url: new utils$1.URLPath(operation.path).toURLPath().replace(/([^/]):/g, "$1\\\\:"),
|
|
60
|
+
statusCode
|
|
58
61
|
}
|
|
59
62
|
),
|
|
60
63
|
parser === "data" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
61
|
-
|
|
64
|
+
chunkFYUFQXX6_cjs.Mock,
|
|
62
65
|
{
|
|
63
66
|
name: mock.name,
|
|
64
67
|
typeName: type.schemas.response.name,
|
|
65
68
|
fakerName: faker.schemas.response.name,
|
|
66
69
|
method: operation.method,
|
|
67
70
|
baseURL,
|
|
68
|
-
url: new utils$1.URLPath(operation.path).toURLPath()
|
|
71
|
+
url: new utils$1.URLPath(operation.path).toURLPath().replace(/([^/]):/g, "$1\\\\:"),
|
|
72
|
+
statusCode
|
|
69
73
|
}
|
|
70
74
|
)
|
|
71
75
|
]
|
|
@@ -96,7 +100,7 @@ var handlersGenerator = pluginOas.createReactGenerator({
|
|
|
96
100
|
footer: utils.getFooter({ oas, output: plugin.options.output }),
|
|
97
101
|
children: [
|
|
98
102
|
imports,
|
|
99
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
103
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkFYUFQXX6_cjs.Handlers, { name: "handlers", handlers })
|
|
100
104
|
]
|
|
101
105
|
}
|
|
102
106
|
);
|
|
@@ -105,5 +109,5 @@ var handlersGenerator = pluginOas.createReactGenerator({
|
|
|
105
109
|
|
|
106
110
|
exports.handlersGenerator = handlersGenerator;
|
|
107
111
|
exports.mswGenerator = mswGenerator;
|
|
108
|
-
//# sourceMappingURL=chunk-
|
|
109
|
-
//# sourceMappingURL=chunk-
|
|
112
|
+
//# sourceMappingURL=chunk-6ANKBOX6.cjs.map
|
|
113
|
+
//# sourceMappingURL=chunk-6ANKBOX6.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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D;AAAA;AAGN,CAAC","file":"chunk-6ANKBOX6.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 pluginManager,\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 const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith('2'))\n const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200\n\n return (\n <File\n baseName={mock.file.baseName}\n path={mock.file.path}\n meta={mock.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\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().replace(/([^/]):/g, '$1\\\\\\\\:')}\n statusCode={statusCode}\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().replace(/([^/]):/g, '$1\\\\\\\\:')}\n statusCode={statusCode}\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, config: pluginManager.config })}\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({ baseURL = "", name, typeName, url, method }) {
|
|
7
|
+
function Mock({ baseURL = "", name, typeName, url, method, statusCode }) {
|
|
8
8
|
const params = react.FunctionParams.factory({
|
|
9
9
|
data: {
|
|
10
10
|
type: `${typeName} | ((
|
|
@@ -13,10 +13,11 @@ function Mock({ baseURL = "", 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}('${baseURL}${url}', function handler(info) {
|
|
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.replace(/([^/]):/g, "$1\\\\:")}', function handler(info) {
|
|
17
17
|
if(typeof data === 'function') return data(info)
|
|
18
18
|
|
|
19
19
|
return new Response(JSON.stringify(data), {
|
|
20
|
+
status: ${statusCode},
|
|
20
21
|
headers: {
|
|
21
22
|
'Content-Type': 'application/json',
|
|
22
23
|
},
|
|
@@ -26,7 +27,7 @@ function Mock({ baseURL = "", name, typeName, url, method }) {
|
|
|
26
27
|
function Handlers({ name, handlers }) {
|
|
27
28
|
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isIndexable: true, isExportable: true, children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const` });
|
|
28
29
|
}
|
|
29
|
-
function MockWithFaker({ baseURL = "", name, fakerName, typeName, url, method }) {
|
|
30
|
+
function MockWithFaker({ baseURL = "", name, fakerName, typeName, url, method, statusCode }) {
|
|
30
31
|
const params = react.FunctionParams.factory({
|
|
31
32
|
data: {
|
|
32
33
|
type: `${typeName} | ((
|
|
@@ -35,10 +36,11 @@ function MockWithFaker({ baseURL = "", name, fakerName, typeName, url, method })
|
|
|
35
36
|
optional: true
|
|
36
37
|
}
|
|
37
38
|
});
|
|
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
|
+
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.replace(/([^/]):/g, "$1\\\\:")}', function handler(info) {
|
|
39
40
|
if(typeof data === 'function') return data(info)
|
|
40
41
|
|
|
41
42
|
return new Response(JSON.stringify(data || ${fakerName}(data)), {
|
|
43
|
+
status: ${statusCode},
|
|
42
44
|
headers: {
|
|
43
45
|
'Content-Type': 'application/json',
|
|
44
46
|
},
|
|
@@ -49,5 +51,5 @@ function MockWithFaker({ baseURL = "", name, fakerName, typeName, url, method })
|
|
|
49
51
|
exports.Handlers = Handlers;
|
|
50
52
|
exports.Mock = Mock;
|
|
51
53
|
exports.MockWithFaker = MockWithFaker;
|
|
52
|
-
//# sourceMappingURL=chunk-
|
|
53
|
-
//# sourceMappingURL=chunk-
|
|
54
|
+
//# sourceMappingURL=chunk-FYUFQXX6.cjs.map
|
|
55
|
+
//# sourceMappingURL=chunk-FYUFQXX6.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":";;;;;;AAkBO,SAAS,IAAA,CAAK,EAAE,OAAU,GAAA,EAAA,EAAI,MAAM,QAAU,EAAA,GAAA,EAAK,MAAQ,EAAA,UAAA,EAAgC,EAAA;AAChG,EAAM,MAAA,MAAA,GAASA,qBAAe,OAAQ,CAAA;AAAA,IACpC,IAAM,EAAA;AA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AAAA,oBAAA,CAAA;AAAA,MAElD,QAAU,EAAA;AAAA;AACZ,GACD,CAAA;AAED,EAAA,uBACEC,cAAAA,CAACC,UAAK,CAAA,MAAA,EAAL,EAAY,IAAA,EAAY,WAAW,EAAA,IAAA,EAAC,YAAY,EAAA,IAAA,EAC/C,QAAAD,kBAAAA,cAAAA,CAACE,gBAAA,EAAS,IAAA,EAAY,MAAM,EAAA,IAAA,EAAC,MAAQ,EAAA,MAAA,CAAO,aAAc,EAAA,EACvD,QAAe,EAAA,CAAA,YAAA,EAAA,MAAM,CAAK,EAAA,EAAA,OAAO,CAAG,EAAA,GAAA,CAAI,OAAQ,CAAA,UAAA,EAAY,SAAS,CAAC,CAAA;AAAA;;AAAA,+CAAA,EAG9B,SAAS,CAAA;AAAA,cAAA,EAC1C,UAAU,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,CAAA,EAMpB,CACF,EAAA,CAAA;AAEJ","file":"chunk-FYUFQXX6.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 statusCode: number\n}\n\nexport function Mock({ baseURL = '', name, typeName, url, method, statusCode }: 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.replace(/([^/]):/g, '$1\\\\\\\\:')}', function handler(info) {\n if(typeof data === 'function') return data(info)\n\n return new Response(JSON.stringify(data), {\n status: ${statusCode},\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 statusCode: number\n}\n\nexport function MockWithFaker({ baseURL = '', name, fakerName, typeName, url, method, statusCode }: 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.replace(/([^/]):/g, '$1\\\\\\\\:')}', function handler(info) {\n if(typeof data === 'function') return data(info)\n\n return new Response(JSON.stringify(data || ${fakerName}(data)), {\n status: ${statusCode},\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MockWithFaker, Mock, Handlers } from './chunk-
|
|
1
|
+
import { MockWithFaker, Mock, Handlers } from './chunk-HL53J5NZ.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';
|
|
@@ -31,6 +31,8 @@ var mswGenerator = createReactGenerator({
|
|
|
31
31
|
file: getFile(operation, { pluginKey: [pluginTsName] }),
|
|
32
32
|
schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: "type" })
|
|
33
33
|
};
|
|
34
|
+
const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith("2"));
|
|
35
|
+
const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200;
|
|
34
36
|
return /* @__PURE__ */ jsxs(
|
|
35
37
|
File,
|
|
36
38
|
{
|
|
@@ -52,7 +54,8 @@ var mswGenerator = createReactGenerator({
|
|
|
52
54
|
fakerName: faker.schemas.response.name,
|
|
53
55
|
method: operation.method,
|
|
54
56
|
baseURL,
|
|
55
|
-
url: new URLPath(operation.path).toURLPath()
|
|
57
|
+
url: new URLPath(operation.path).toURLPath().replace(/([^/]):/g, "$1\\\\:"),
|
|
58
|
+
statusCode
|
|
56
59
|
}
|
|
57
60
|
),
|
|
58
61
|
parser === "data" && /* @__PURE__ */ jsx(
|
|
@@ -63,7 +66,8 @@ var mswGenerator = createReactGenerator({
|
|
|
63
66
|
fakerName: faker.schemas.response.name,
|
|
64
67
|
method: operation.method,
|
|
65
68
|
baseURL,
|
|
66
|
-
url: new URLPath(operation.path).toURLPath()
|
|
69
|
+
url: new URLPath(operation.path).toURLPath().replace(/([^/]):/g, "$1\\\\:"),
|
|
70
|
+
statusCode
|
|
67
71
|
}
|
|
68
72
|
)
|
|
69
73
|
]
|
|
@@ -102,5 +106,5 @@ var handlersGenerator = createReactGenerator({
|
|
|
102
106
|
});
|
|
103
107
|
|
|
104
108
|
export { handlersGenerator, mswGenerator };
|
|
105
|
-
//# sourceMappingURL=chunk-
|
|
106
|
-
//# sourceMappingURL=chunk-
|
|
109
|
+
//# sourceMappingURL=chunk-GUSADLEP.js.map
|
|
110
|
+
//# sourceMappingURL=chunk-GUSADLEP.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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,IAAA,EAAM,YAAY,QAAoB,EAAA;AAAA;AAAA;AAAA,KAClD;AAAA;AAGN,CAAC","file":"chunk-GUSADLEP.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 pluginManager,\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 const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith('2'))\n const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200\n\n return (\n <File\n baseName={mock.file.baseName}\n path={mock.file.path}\n meta={mock.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\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().replace(/([^/]):/g, '$1\\\\\\\\:')}\n statusCode={statusCode}\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().replace(/([^/]):/g, '$1\\\\\\\\:')}\n statusCode={statusCode}\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, config: pluginManager.config })}\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({ baseURL = "", name, typeName, url, method }) {
|
|
5
|
+
function Mock({ baseURL = "", name, typeName, url, method, statusCode }) {
|
|
6
6
|
const params = FunctionParams.factory({
|
|
7
7
|
data: {
|
|
8
8
|
type: `${typeName} | ((
|
|
@@ -11,10 +11,11 @@ function Mock({ baseURL = "", 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}('${baseURL}${url}', function handler(info) {
|
|
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.replace(/([^/]):/g, "$1\\\\:")}', function handler(info) {
|
|
15
15
|
if(typeof data === 'function') return data(info)
|
|
16
16
|
|
|
17
17
|
return new Response(JSON.stringify(data), {
|
|
18
|
+
status: ${statusCode},
|
|
18
19
|
headers: {
|
|
19
20
|
'Content-Type': 'application/json',
|
|
20
21
|
},
|
|
@@ -24,7 +25,7 @@ function Mock({ baseURL = "", name, typeName, url, method }) {
|
|
|
24
25
|
function Handlers({ name, handlers }) {
|
|
25
26
|
return /* @__PURE__ */ jsx(File.Source, { name, isIndexable: true, isExportable: true, children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const` });
|
|
26
27
|
}
|
|
27
|
-
function MockWithFaker({ baseURL = "", name, fakerName, typeName, url, method }) {
|
|
28
|
+
function MockWithFaker({ baseURL = "", name, fakerName, typeName, url, method, statusCode }) {
|
|
28
29
|
const params = FunctionParams.factory({
|
|
29
30
|
data: {
|
|
30
31
|
type: `${typeName} | ((
|
|
@@ -33,10 +34,11 @@ function MockWithFaker({ baseURL = "", name, fakerName, typeName, url, method })
|
|
|
33
34
|
optional: true
|
|
34
35
|
}
|
|
35
36
|
});
|
|
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
|
+
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.replace(/([^/]):/g, "$1\\\\:")}', function handler(info) {
|
|
37
38
|
if(typeof data === 'function') return data(info)
|
|
38
39
|
|
|
39
40
|
return new Response(JSON.stringify(data || ${fakerName}(data)), {
|
|
41
|
+
status: ${statusCode},
|
|
40
42
|
headers: {
|
|
41
43
|
'Content-Type': 'application/json',
|
|
42
44
|
},
|
|
@@ -45,5 +47,5 @@ function MockWithFaker({ baseURL = "", name, fakerName, typeName, url, method })
|
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
export { Handlers, Mock, MockWithFaker };
|
|
48
|
-
//# sourceMappingURL=chunk-
|
|
49
|
-
//# sourceMappingURL=chunk-
|
|
50
|
+
//# sourceMappingURL=chunk-HL53J5NZ.js.map
|
|
51
|
+
//# sourceMappingURL=chunk-HL53J5NZ.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":";;;;AAkBO,SAAS,IAAA,CAAK,EAAE,OAAU,GAAA,EAAA,EAAI,MAAM,QAAU,EAAA,GAAA,EAAK,MAAQ,EAAA,UAAA,EAAgC,EAAA;AAChG,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,CAA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C,IAAK,CAAA,MAAA,EAAL,EAAY,IAAA,EAAY,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,aAAc,EAAA,EACvD,QAAe,EAAA,CAAA,YAAA,EAAA,MAAM,CAAK,EAAA,EAAA,OAAO,CAAG,EAAA,GAAA,CAAI,OAAQ,CAAA,UAAA,EAAY,SAAS,CAAC,CAAA;AAAA;;AAAA,+CAAA,EAG9B,SAAS,CAAA;AAAA,cAAA,EAC1C,UAAU,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,CAAA,EAMpB,CACF,EAAA,CAAA;AAEJ","file":"chunk-HL53J5NZ.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 statusCode: number\n}\n\nexport function Mock({ baseURL = '', name, typeName, url, method, statusCode }: 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.replace(/([^/]):/g, '$1\\\\\\\\:')}', function handler(info) {\n if(typeof data === 'function') return data(info)\n\n return new Response(JSON.stringify(data), {\n status: ${statusCode},\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 statusCode: number\n}\n\nexport function MockWithFaker({ baseURL = '', name, fakerName, typeName, url, method, statusCode }: 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.replace(/([^/]):/g, '$1\\\\\\\\:')}', function handler(info) {\n if(typeof data === 'function') return data(info)\n\n return new Response(JSON.stringify(data || ${fakerName}(data)), {\n status: ${statusCode},\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 chunkFYUFQXX6_cjs = require('./chunk-FYUFQXX6.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 chunkFYUFQXX6_cjs.Handlers; }
|
|
10
10
|
});
|
|
11
11
|
Object.defineProperty(exports, "Mock", {
|
|
12
12
|
enumerable: true,
|
|
13
|
-
get: function () { return
|
|
13
|
+
get: function () { return chunkFYUFQXX6_cjs.Mock; }
|
|
14
14
|
});
|
|
15
15
|
Object.defineProperty(exports, "MockWithFaker", {
|
|
16
16
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
17
|
+
get: function () { return chunkFYUFQXX6_cjs.MockWithFaker; }
|
|
18
18
|
});
|
|
19
19
|
//# sourceMappingURL=components.cjs.map
|
|
20
20
|
//# sourceMappingURL=components.cjs.map
|
package/dist/components.d.cts
CHANGED
|
@@ -11,8 +11,9 @@ type Props$1 = {
|
|
|
11
11
|
url: string;
|
|
12
12
|
baseURL: string | undefined;
|
|
13
13
|
method: HttpMethod;
|
|
14
|
+
statusCode: number;
|
|
14
15
|
};
|
|
15
|
-
declare function Mock({ baseURL, name, typeName, url, method }: Props$1): ReactNode;
|
|
16
|
+
declare function Mock({ baseURL, name, typeName, url, method, statusCode }: Props$1): ReactNode;
|
|
16
17
|
|
|
17
18
|
type HandlersProps = {
|
|
18
19
|
/**
|
|
@@ -33,7 +34,8 @@ type Props = {
|
|
|
33
34
|
baseURL: string | undefined;
|
|
34
35
|
url: string;
|
|
35
36
|
method: HttpMethod;
|
|
37
|
+
statusCode: number;
|
|
36
38
|
};
|
|
37
|
-
declare function MockWithFaker({ baseURL, name, fakerName, typeName, url, method }: Props): ReactNode;
|
|
39
|
+
declare function MockWithFaker({ baseURL, name, fakerName, typeName, url, method, statusCode }: Props): ReactNode;
|
|
38
40
|
|
|
39
41
|
export { Handlers, Mock, MockWithFaker };
|
package/dist/components.d.ts
CHANGED
|
@@ -11,8 +11,9 @@ type Props$1 = {
|
|
|
11
11
|
url: string;
|
|
12
12
|
baseURL: string | undefined;
|
|
13
13
|
method: HttpMethod;
|
|
14
|
+
statusCode: number;
|
|
14
15
|
};
|
|
15
|
-
declare function Mock({ baseURL, name, typeName, url, method }: Props$1): ReactNode;
|
|
16
|
+
declare function Mock({ baseURL, name, typeName, url, method, statusCode }: Props$1): ReactNode;
|
|
16
17
|
|
|
17
18
|
type HandlersProps = {
|
|
18
19
|
/**
|
|
@@ -33,7 +34,8 @@ type Props = {
|
|
|
33
34
|
baseURL: string | undefined;
|
|
34
35
|
url: string;
|
|
35
36
|
method: HttpMethod;
|
|
37
|
+
statusCode: number;
|
|
36
38
|
};
|
|
37
|
-
declare function MockWithFaker({ baseURL, name, fakerName, typeName, url, method }: Props): ReactNode;
|
|
39
|
+
declare function MockWithFaker({ baseURL, name, fakerName, typeName, url, method, statusCode }: Props): ReactNode;
|
|
38
40
|
|
|
39
41
|
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 chunk6ANKBOX6_cjs = require('./chunk-6ANKBOX6.cjs');
|
|
4
|
+
require('./chunk-FYUFQXX6.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 chunk6ANKBOX6_cjs.handlersGenerator; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "mswGenerator", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunk6ANKBOX6_cjs.mswGenerator; }
|
|
15
15
|
});
|
|
16
16
|
//# sourceMappingURL=generators.cjs.map
|
|
17
17
|
//# sourceMappingURL=generators.cjs.map
|
package/dist/generators.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { handlersGenerator, mswGenerator } from './chunk-
|
|
2
|
-
import './chunk-
|
|
1
|
+
export { handlersGenerator, mswGenerator } from './chunk-GUSADLEP.js';
|
|
2
|
+
import './chunk-HL53J5NZ.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 chunk6ANKBOX6_cjs = require('./chunk-6ANKBOX6.cjs');
|
|
4
|
+
require('./chunk-FYUFQXX6.cjs');
|
|
5
5
|
var path = require('path');
|
|
6
6
|
var core = require('@kubb/core');
|
|
7
7
|
var transformers = require('@kubb/core/transformers');
|
|
@@ -24,7 +24,7 @@ var pluginMsw = core.createPlugin((options) => {
|
|
|
24
24
|
transformers: transformers$1 = {},
|
|
25
25
|
handlers = false,
|
|
26
26
|
parser = "data",
|
|
27
|
-
generators = [
|
|
27
|
+
generators = [chunk6ANKBOX6_cjs.mswGenerator, handlers ? chunk6ANKBOX6_cjs.handlersGenerator : void 0].filter(Boolean),
|
|
28
28
|
contentType,
|
|
29
29
|
baseURL
|
|
30
30
|
} = options;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { mswGenerator, handlersGenerator } from './chunk-
|
|
2
|
-
import './chunk-
|
|
1
|
+
import { mswGenerator, handlersGenerator } from './chunk-GUSADLEP.js';
|
|
2
|
+
import './chunk-HL53J5NZ.js';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { createPlugin, PluginManager, FileManager } from '@kubb/core';
|
|
5
5
|
import { camelCase } from '@kubb/core/transformers';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-msw",
|
|
3
|
-
"version": "3.14.
|
|
3
|
+
"version": "3.14.4",
|
|
4
4
|
"description": "Mock Service Worker (MSW) handlers generator plugin for Kubb, creating API mocks from OpenAPI specifications for frontend development and testing.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"msw",
|
|
@@ -80,20 +80,20 @@
|
|
|
80
80
|
"!/**/__tests__/**"
|
|
81
81
|
],
|
|
82
82
|
"dependencies": {
|
|
83
|
-
"@kubb/core": "3.14.
|
|
84
|
-
"@kubb/oas": "3.14.
|
|
85
|
-
"@kubb/plugin-faker": "3.14.
|
|
86
|
-
"@kubb/plugin-oas": "3.14.
|
|
87
|
-
"@kubb/plugin-ts": "3.14.
|
|
88
|
-
"@kubb/react": "3.14.
|
|
83
|
+
"@kubb/core": "3.14.4",
|
|
84
|
+
"@kubb/oas": "3.14.4",
|
|
85
|
+
"@kubb/plugin-faker": "3.14.4",
|
|
86
|
+
"@kubb/plugin-oas": "3.14.4",
|
|
87
|
+
"@kubb/plugin-ts": "3.14.4",
|
|
88
|
+
"@kubb/react": "3.14.4"
|
|
89
89
|
},
|
|
90
90
|
"devDependencies": {
|
|
91
91
|
"@types/react": "^18.3.23",
|
|
92
92
|
"react": "^18.3.1",
|
|
93
93
|
"tsup": "^8.5.0",
|
|
94
94
|
"typescript": "^5.8.3",
|
|
95
|
-
"@kubb/config-ts": "3.14.
|
|
96
|
-
"@kubb/config-tsup": "3.14.
|
|
95
|
+
"@kubb/config-ts": "3.14.4",
|
|
96
|
+
"@kubb/config-tsup": "3.14.4"
|
|
97
97
|
},
|
|
98
98
|
"peerDependencies": {
|
|
99
99
|
"@kubb/react": "^3.0.0"
|
package/src/components/Mock.tsx
CHANGED
|
@@ -13,9 +13,10 @@ type Props = {
|
|
|
13
13
|
url: string
|
|
14
14
|
baseURL: string | undefined
|
|
15
15
|
method: HttpMethod
|
|
16
|
+
statusCode: number
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
export function Mock({ baseURL = '', name, typeName, url, method }: Props): ReactNode {
|
|
19
|
+
export function Mock({ baseURL = '', name, typeName, url, method, statusCode }: Props): ReactNode {
|
|
19
20
|
const params = FunctionParams.factory({
|
|
20
21
|
data: {
|
|
21
22
|
type: `${typeName} | ((
|
|
@@ -28,10 +29,11 @@ export function Mock({ baseURL = '', name, typeName, url, method }: Props): Reac
|
|
|
28
29
|
return (
|
|
29
30
|
<File.Source name={name} isIndexable isExportable>
|
|
30
31
|
<Function name={name} export params={params.toConstructor()}>
|
|
31
|
-
{`return http.${method}('${baseURL}${url}', function handler(info) {
|
|
32
|
+
{`return http.${method}('${baseURL}${url.replace(/([^/]):/g, '$1\\\\:')}', function handler(info) {
|
|
32
33
|
if(typeof data === 'function') return data(info)
|
|
33
34
|
|
|
34
35
|
return new Response(JSON.stringify(data), {
|
|
36
|
+
status: ${statusCode},
|
|
35
37
|
headers: {
|
|
36
38
|
'Content-Type': 'application/json',
|
|
37
39
|
},
|
|
@@ -13,9 +13,10 @@ type Props = {
|
|
|
13
13
|
baseURL: string | undefined
|
|
14
14
|
url: string
|
|
15
15
|
method: HttpMethod
|
|
16
|
+
statusCode: number
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
export function MockWithFaker({ baseURL = '', name, fakerName, typeName, url, method }: Props): ReactNode {
|
|
19
|
+
export function MockWithFaker({ baseURL = '', name, fakerName, typeName, url, method, statusCode }: Props): ReactNode {
|
|
19
20
|
const params = FunctionParams.factory({
|
|
20
21
|
data: {
|
|
21
22
|
type: `${typeName} | ((
|
|
@@ -28,10 +29,11 @@ export function MockWithFaker({ baseURL = '', name, fakerName, typeName, url, me
|
|
|
28
29
|
return (
|
|
29
30
|
<File.Source name={name} isIndexable isExportable>
|
|
30
31
|
<Function name={name} export params={params.toConstructor()}>
|
|
31
|
-
{`return http.${method}('${baseURL}${url}', function handler(info) {
|
|
32
|
+
{`return http.${method}('${baseURL}${url.replace(/([^/]):/g, '$1\\\\:')}', function handler(info) {
|
|
32
33
|
if(typeof data === 'function') return data(info)
|
|
33
34
|
|
|
34
35
|
return new Response(JSON.stringify(data || ${fakerName}(data)), {
|
|
36
|
+
status: ${statusCode},
|
|
35
37
|
headers: {
|
|
36
38
|
'Content-Type': 'application/json',
|
|
37
39
|
},
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by Kubb (https://kubb.dev/).
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import { http } from 'msw'
|
|
6
|
+
|
|
7
|
+
export function createPets(data?: CreatePetsMutationResponse | ((info: Parameters<Parameters<typeof http.post>[1]>[0]) => Response)) {
|
|
8
|
+
return http.post('/pets', function handler(info) {
|
|
9
|
+
if (typeof data === 'function') return data(info)
|
|
10
|
+
|
|
11
|
+
return new Response(JSON.stringify(data || createPetsMutationResponse(data)), {
|
|
12
|
+
status: 201,
|
|
13
|
+
headers: {
|
|
14
|
+
'Content-Type': 'application/json',
|
|
15
|
+
},
|
|
16
|
+
})
|
|
17
|
+
})
|
|
18
|
+
}
|
|
@@ -9,6 +9,7 @@ export function listPets(data?: ListPetsQueryResponse | ((info: Parameters<Param
|
|
|
9
9
|
if (typeof data === 'function') return data(info)
|
|
10
10
|
|
|
11
11
|
return new Response(JSON.stringify(data || listPetsQueryResponse(data)), {
|
|
12
|
+
status: 200,
|
|
12
13
|
headers: {
|
|
13
14
|
'Content-Type': 'application/json',
|
|
14
15
|
},
|
|
@@ -35,6 +35,9 @@ export const mswGenerator = createReactGenerator<PluginMsw>({
|
|
|
35
35
|
schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith('2'))
|
|
39
|
+
const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200
|
|
40
|
+
|
|
38
41
|
return (
|
|
39
42
|
<File
|
|
40
43
|
baseName={mock.file.baseName}
|
|
@@ -57,7 +60,8 @@ export const mswGenerator = createReactGenerator<PluginMsw>({
|
|
|
57
60
|
fakerName={faker.schemas.response.name}
|
|
58
61
|
method={operation.method}
|
|
59
62
|
baseURL={baseURL}
|
|
60
|
-
url={new URLPath(operation.path).toURLPath()}
|
|
63
|
+
url={new URLPath(operation.path).toURLPath().replace(/([^/]):/g, '$1\\\\:')}
|
|
64
|
+
statusCode={statusCode}
|
|
61
65
|
/>
|
|
62
66
|
)}
|
|
63
67
|
{parser === 'data' && (
|
|
@@ -67,7 +71,8 @@ export const mswGenerator = createReactGenerator<PluginMsw>({
|
|
|
67
71
|
fakerName={faker.schemas.response.name}
|
|
68
72
|
method={operation.method}
|
|
69
73
|
baseURL={baseURL}
|
|
70
|
-
url={new URLPath(operation.path).toURLPath()}
|
|
74
|
+
url={new URLPath(operation.path).toURLPath().replace(/([^/]):/g, '$1\\\\:')}
|
|
75
|
+
statusCode={statusCode}
|
|
71
76
|
/>
|
|
72
77
|
)}
|
|
73
78
|
</File>
|
|
@@ -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":";;;;;;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 +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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WAAW,MAAO,CAAA,GAAA,EAAK,IAAM,EAAA,UAAA,EAAY,CAAA;AAEpF,MAAA,uBAAOO,cAACH,CAAAA,UAAAA,CAAK,MAAL,EAAA,EAAqC,MAAM,CAAC,aAAa,CAAG,EAAA,IAAA,EAAM,KAAK,IAAM,EAAA,IAAA,EAAM,aAAc,CAAA,IAAA,EAAA,EAAhF,cAAc,IAAwE,CAAA;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,uBACED,eAAAA;AAAA,MAACC,UAAAA;AAAA,MAAA;AAAA,QACC,UAAU,IAAK,CAAA,QAAA;AAAA,QACf,MAAM,IAAK,CAAA,IAAA;AAAA,QACX,MAAM,IAAK,CAAA,IAAA;AAAA,QACX,MAAA,EAAQC,eAAU,CAAA,EAAE,GAAK,EAAA,MAAA,EAAQ,MAAO,CAAA,OAAA,CAAQ,MAAQ,EAAA,MAAA,EAAQ,aAAc,CAAA,MAAA,EAAQ,CAAA;AAAA,QACtF,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-N5C3UG5M.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 pluginManager,\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\n baseName={mock.file.baseName}\n path={mock.file.path}\n meta={mock.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\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, config: pluginManager.config })}\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","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,aAAA;AAAA,MACA,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,GA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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,SAAU,CAAA,EAAE,GAAK,EAAA,MAAA,EAAQ,MAAO,CAAA,OAAA,CAAQ,MAAQ,EAAA,MAAA,EAAQ,aAAc,CAAA,MAAA,EAAQ,CAAA;AAAA,QACtF,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-PAT3XAAU.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 pluginManager,\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\n baseName={mock.file.baseName}\n path={mock.file.path}\n meta={mock.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\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, config: pluginManager.config })}\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/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"]}
|