@kubb/plugin-msw 3.16.2 → 3.16.3
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/components-ByUOezvw.js +93 -0
- package/dist/components-ByUOezvw.js.map +1 -0
- package/dist/components-Bz0C7Qrg.cjs +139 -0
- package/dist/components-Bz0C7Qrg.cjs.map +1 -0
- package/dist/components.cjs +4 -19
- package/dist/components.d.cts +47 -33
- package/dist/components.d.ts +47 -33
- package/dist/components.js +3 -3
- package/dist/generators-BjQcx0SS.js +140 -0
- package/dist/generators-BjQcx0SS.js.map +1 -0
- package/dist/generators-DQ6KjdAH.cjs +151 -0
- package/dist/generators-DQ6KjdAH.cjs.map +1 -0
- package/dist/generators.cjs +4 -16
- package/dist/generators.d.cts +9 -8
- package/dist/generators.d.ts +9 -8
- package/dist/generators.js +4 -4
- package/dist/index.cjs +82 -102
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +82 -96
- package/dist/index.js.map +1 -1
- package/dist/types-BOMj2hjt.d.ts +13 -0
- package/dist/types-CxxnBHOU.d.cts +1164 -0
- package/dist/types-DYAniEBx.d.cts +13 -0
- package/dist/types-Dte4R-vh.d.ts +1164 -0
- package/package.json +19 -34
- package/src/components/Mock.tsx +21 -9
- package/src/components/MockWithFaker.tsx +22 -9
- package/src/generators/__snapshots__/createPet.ts +0 -3
- package/src/generators/__snapshots__/createPetFaker.ts +0 -3
- package/src/generators/__snapshots__/deletePet.ts +0 -3
- package/src/generators/mswGenerator.tsx +2 -16
- package/dist/chunk-6ANKBOX6.cjs +0 -113
- package/dist/chunk-6ANKBOX6.cjs.map +0 -1
- package/dist/chunk-FYUFQXX6.cjs +0 -55
- package/dist/chunk-FYUFQXX6.cjs.map +0 -1
- package/dist/chunk-GUSADLEP.js +0 -110
- package/dist/chunk-GUSADLEP.js.map +0 -1
- package/dist/chunk-HL53J5NZ.js +0 -51
- package/dist/chunk-HL53J5NZ.js.map +0 -1
- package/dist/components.cjs.map +0 -1
- package/dist/components.js.map +0 -1
- package/dist/generators.cjs.map +0 -1
- package/dist/generators.js.map +0 -1
- package/dist/types-CzI_io_g.d.cts +0 -64
- package/dist/types-CzI_io_g.d.ts +0 -64
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { File, Function, FunctionParams } from "@kubb/react";
|
|
2
|
+
import { URLPath } from "@kubb/core/utils";
|
|
3
|
+
import { jsx } from "@kubb/react/jsx-runtime";
|
|
4
|
+
|
|
5
|
+
//#region src/components/Mock.tsx
|
|
6
|
+
function Mock({ baseURL = "", name, typeName, operation }) {
|
|
7
|
+
const method = operation.method;
|
|
8
|
+
const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith("2"));
|
|
9
|
+
const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200;
|
|
10
|
+
const responseObject = operation.getResponseByStatusCode(statusCode);
|
|
11
|
+
const contentType = Object.keys(responseObject.content || {})?.[0];
|
|
12
|
+
const url = new URLPath(operation.path).toURLPath().replace(/([^/]):/g, "$1\\\\:");
|
|
13
|
+
const headers = [contentType ? `'Content-Type': '${contentType}'` : void 0].filter(Boolean);
|
|
14
|
+
const params = FunctionParams.factory({ data: {
|
|
15
|
+
type: `${typeName} | ((
|
|
16
|
+
info: Parameters<Parameters<typeof http.${method}>[1]>[0],
|
|
17
|
+
) => Response)`,
|
|
18
|
+
optional: true
|
|
19
|
+
} });
|
|
20
|
+
return /* @__PURE__ */ jsx(File.Source, {
|
|
21
|
+
name,
|
|
22
|
+
isIndexable: true,
|
|
23
|
+
isExportable: true,
|
|
24
|
+
children: /* @__PURE__ */ jsx(Function, {
|
|
25
|
+
name,
|
|
26
|
+
export: true,
|
|
27
|
+
params: params.toConstructor(),
|
|
28
|
+
children: `return http.${method}('${baseURL}${url.replace(/([^/]):/g, "$1\\\\:")}', function handler(info) {
|
|
29
|
+
if(typeof data === 'function') return data(info)
|
|
30
|
+
|
|
31
|
+
return new Response(JSON.stringify(data), {
|
|
32
|
+
status: ${statusCode},
|
|
33
|
+
${headers.length ? ` headers: {
|
|
34
|
+
${headers.join(", \n")}
|
|
35
|
+
},` : ""}
|
|
36
|
+
})
|
|
37
|
+
})`
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/components/Handlers.tsx
|
|
44
|
+
function Handlers({ name, handlers }) {
|
|
45
|
+
return /* @__PURE__ */ jsx(File.Source, {
|
|
46
|
+
name,
|
|
47
|
+
isIndexable: true,
|
|
48
|
+
isExportable: true,
|
|
49
|
+
children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const`
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/components/MockWithFaker.tsx
|
|
55
|
+
function MockWithFaker({ baseURL = "", name, fakerName, typeName, operation }) {
|
|
56
|
+
const method = operation.method;
|
|
57
|
+
const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith("2"));
|
|
58
|
+
const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200;
|
|
59
|
+
const responseObject = operation.getResponseByStatusCode(statusCode);
|
|
60
|
+
const contentType = Object.keys(responseObject.content || {})?.[0];
|
|
61
|
+
const url = new URLPath(operation.path).toURLPath().replace(/([^/]):/g, "$1\\\\:");
|
|
62
|
+
const headers = [contentType ? `'Content-Type': '${contentType}'` : void 0].filter(Boolean);
|
|
63
|
+
const params = FunctionParams.factory({ data: {
|
|
64
|
+
type: `${typeName} | ((
|
|
65
|
+
info: Parameters<Parameters<typeof http.${method}>[1]>[0],
|
|
66
|
+
) => Response)`,
|
|
67
|
+
optional: true
|
|
68
|
+
} });
|
|
69
|
+
return /* @__PURE__ */ jsx(File.Source, {
|
|
70
|
+
name,
|
|
71
|
+
isIndexable: true,
|
|
72
|
+
isExportable: true,
|
|
73
|
+
children: /* @__PURE__ */ jsx(Function, {
|
|
74
|
+
name,
|
|
75
|
+
export: true,
|
|
76
|
+
params: params.toConstructor(),
|
|
77
|
+
children: `return http.${method}('${baseURL}${url.replace(/([^/]):/g, "$1\\\\:")}', function handler(info) {
|
|
78
|
+
if(typeof data === 'function') return data(info)
|
|
79
|
+
|
|
80
|
+
return new Response(JSON.stringify(data || ${fakerName}(data)), {
|
|
81
|
+
status: ${statusCode},
|
|
82
|
+
${headers.length ? ` headers: {
|
|
83
|
+
${headers.join(", \n")}
|
|
84
|
+
},` : ""}
|
|
85
|
+
})
|
|
86
|
+
})`
|
|
87
|
+
})
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
//#endregion
|
|
92
|
+
export { Handlers, Mock, MockWithFaker };
|
|
93
|
+
//# sourceMappingURL=components-ByUOezvw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components-ByUOezvw.js","names":[],"sources":["../src/components/Mock.tsx","../src/components/Handlers.tsx","../src/components/MockWithFaker.tsx"],"sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport type { OasTypes, Operation } from '@kubb/oas'\nimport { File, Function, FunctionParams } from '@kubb/react'\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 operation: Operation\n}\n\nexport function Mock({ baseURL = '', name, typeName, operation }: Props): ReactNode {\n const method = operation.method\n const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith('2'))\n const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200\n\n const responseObject = operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject\n const contentType = Object.keys(responseObject.content || {})?.[0]\n const url = new URLPath(operation.path).toURLPath().replace(/([^/]):/g, '$1\\\\\\\\:')\n\n const headers = [contentType ? `'Content-Type': '${contentType}'` : undefined].filter(Boolean)\n\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 ${\n headers.length\n ? ` headers: {\n ${headers.join(', \\n')}\n },`\n : ''\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 { URLPath } from '@kubb/core/utils'\n\nimport type { OasTypes, Operation } from '@kubb/oas'\nimport { File, Function, FunctionParams } from '@kubb/react'\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 operation: Operation\n}\n\nexport function MockWithFaker({ baseURL = '', name, fakerName, typeName, operation }: Props): ReactNode {\n const method = operation.method\n const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith('2'))\n const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200\n\n const responseObject = operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject\n const contentType = Object.keys(responseObject.content || {})?.[0]\n const url = new URLPath(operation.path).toURLPath().replace(/([^/]):/g, '$1\\\\\\\\:')\n\n const headers = [contentType ? `'Content-Type': '${contentType}'` : undefined].filter(Boolean)\n\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 ${\n headers.length\n ? ` headers: {\n ${headers.join(', \\n')}\n },`\n : ''\n }\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n"],"mappings":";;;;;AAgBA,SAAgB,KAAK,EAAE,UAAU,IAAI,MAAM,UAAU,WAAkB,EAAa;CAClF,MAAM,SAAS,UAAU;CACzB,MAAM,qBAAqB,UAAU,wBAAwB,CAAC,OAAO,CAAC,SAAS,KAAK,WAAW,IAAI,CAAC;CACpG,MAAM,aAAa,mBAAmB,SAAS,IAAI,OAAO,mBAAmB,GAAG,GAAG;CAEnF,MAAM,iBAAiB,UAAU,wBAAwB,WAAW;CACpE,MAAM,cAAc,OAAO,KAAK,eAAe,WAAW,CAAE,EAAC,GAAG;CAChE,MAAM,MAAM,IAAI,QAAQ,UAAU,MAAM,WAAW,CAAC,QAAQ,YAAY,UAAU;CAElF,MAAM,UAAU,CAAC,cAAc,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC,GAAG,MAAU,EAAC,OAAO,QAAQ;CAE9F,MAAM,SAAS,eAAe,QAAQ,EACpC,MAAM;EACJ,MAAM,GAAG,SAAS;gDACwB,EAAE,OAAO;oBACrC,CAAC;EACf,UAAU;CACX,EACF,EAAC;AAEF,4BACG,KAAK;EAAa;EAAM;EAAY;gCAClC;GAAe;GAAM;GAAO,QAAQ,OAAO,eAAe;aACxD,CAAC,YAAY,EAAE,OAAO,EAAE,EAAE,UAAU,IAAI,QAAQ,YAAY,UAAU,CAAC;;;;cAIlE,EAAE,WAAW;MACrB,EACE,QAAQ,SACJ,CAAC;QACL,EAAE,QAAQ,KAAK,OAAO,CAAC;QACvB,CAAC,GAC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@@ -0,0 +1,139 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
const __kubb_react = __toESM(require("@kubb/react"));
|
|
25
|
+
const __kubb_core_utils = __toESM(require("@kubb/core/utils"));
|
|
26
|
+
const __kubb_react_jsx_runtime = __toESM(require("@kubb/react/jsx-runtime"));
|
|
27
|
+
|
|
28
|
+
//#region src/components/Mock.tsx
|
|
29
|
+
function Mock({ baseURL = "", name, typeName, operation }) {
|
|
30
|
+
const method = operation.method;
|
|
31
|
+
const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith("2"));
|
|
32
|
+
const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200;
|
|
33
|
+
const responseObject = operation.getResponseByStatusCode(statusCode);
|
|
34
|
+
const contentType = Object.keys(responseObject.content || {})?.[0];
|
|
35
|
+
const url = new __kubb_core_utils.URLPath(operation.path).toURLPath().replace(/([^/]):/g, "$1\\\\:");
|
|
36
|
+
const headers = [contentType ? `'Content-Type': '${contentType}'` : void 0].filter(Boolean);
|
|
37
|
+
const params = __kubb_react.FunctionParams.factory({ data: {
|
|
38
|
+
type: `${typeName} | ((
|
|
39
|
+
info: Parameters<Parameters<typeof http.${method}>[1]>[0],
|
|
40
|
+
) => Response)`,
|
|
41
|
+
optional: true
|
|
42
|
+
} });
|
|
43
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
|
|
44
|
+
name,
|
|
45
|
+
isIndexable: true,
|
|
46
|
+
isExportable: true,
|
|
47
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.Function, {
|
|
48
|
+
name,
|
|
49
|
+
export: true,
|
|
50
|
+
params: params.toConstructor(),
|
|
51
|
+
children: `return http.${method}('${baseURL}${url.replace(/([^/]):/g, "$1\\\\:")}', function handler(info) {
|
|
52
|
+
if(typeof data === 'function') return data(info)
|
|
53
|
+
|
|
54
|
+
return new Response(JSON.stringify(data), {
|
|
55
|
+
status: ${statusCode},
|
|
56
|
+
${headers.length ? ` headers: {
|
|
57
|
+
${headers.join(", \n")}
|
|
58
|
+
},` : ""}
|
|
59
|
+
})
|
|
60
|
+
})`
|
|
61
|
+
})
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/components/Handlers.tsx
|
|
67
|
+
function Handlers({ name, handlers }) {
|
|
68
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
|
|
69
|
+
name,
|
|
70
|
+
isIndexable: true,
|
|
71
|
+
isExportable: true,
|
|
72
|
+
children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const`
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/components/MockWithFaker.tsx
|
|
78
|
+
function MockWithFaker({ baseURL = "", name, fakerName, typeName, operation }) {
|
|
79
|
+
const method = operation.method;
|
|
80
|
+
const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith("2"));
|
|
81
|
+
const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200;
|
|
82
|
+
const responseObject = operation.getResponseByStatusCode(statusCode);
|
|
83
|
+
const contentType = Object.keys(responseObject.content || {})?.[0];
|
|
84
|
+
const url = new __kubb_core_utils.URLPath(operation.path).toURLPath().replace(/([^/]):/g, "$1\\\\:");
|
|
85
|
+
const headers = [contentType ? `'Content-Type': '${contentType}'` : void 0].filter(Boolean);
|
|
86
|
+
const params = __kubb_react.FunctionParams.factory({ data: {
|
|
87
|
+
type: `${typeName} | ((
|
|
88
|
+
info: Parameters<Parameters<typeof http.${method}>[1]>[0],
|
|
89
|
+
) => Response)`,
|
|
90
|
+
optional: true
|
|
91
|
+
} });
|
|
92
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
|
|
93
|
+
name,
|
|
94
|
+
isIndexable: true,
|
|
95
|
+
isExportable: true,
|
|
96
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.Function, {
|
|
97
|
+
name,
|
|
98
|
+
export: true,
|
|
99
|
+
params: params.toConstructor(),
|
|
100
|
+
children: `return http.${method}('${baseURL}${url.replace(/([^/]):/g, "$1\\\\:")}', function handler(info) {
|
|
101
|
+
if(typeof data === 'function') return data(info)
|
|
102
|
+
|
|
103
|
+
return new Response(JSON.stringify(data || ${fakerName}(data)), {
|
|
104
|
+
status: ${statusCode},
|
|
105
|
+
${headers.length ? ` headers: {
|
|
106
|
+
${headers.join(", \n")}
|
|
107
|
+
},` : ""}
|
|
108
|
+
})
|
|
109
|
+
})`
|
|
110
|
+
})
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
Object.defineProperty(exports, 'Handlers', {
|
|
116
|
+
enumerable: true,
|
|
117
|
+
get: function () {
|
|
118
|
+
return Handlers;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
Object.defineProperty(exports, 'Mock', {
|
|
122
|
+
enumerable: true,
|
|
123
|
+
get: function () {
|
|
124
|
+
return Mock;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
Object.defineProperty(exports, 'MockWithFaker', {
|
|
128
|
+
enumerable: true,
|
|
129
|
+
get: function () {
|
|
130
|
+
return MockWithFaker;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
Object.defineProperty(exports, '__toESM', {
|
|
134
|
+
enumerable: true,
|
|
135
|
+
get: function () {
|
|
136
|
+
return __toESM;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
//# sourceMappingURL=components-Bz0C7Qrg.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components-Bz0C7Qrg.cjs","names":["URLPath","FunctionParams","File","Function","File","URLPath","FunctionParams","File","Function"],"sources":["../src/components/Mock.tsx","../src/components/Handlers.tsx","../src/components/MockWithFaker.tsx"],"sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport type { OasTypes, Operation } from '@kubb/oas'\nimport { File, Function, FunctionParams } from '@kubb/react'\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 operation: Operation\n}\n\nexport function Mock({ baseURL = '', name, typeName, operation }: Props): ReactNode {\n const method = operation.method\n const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith('2'))\n const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200\n\n const responseObject = operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject\n const contentType = Object.keys(responseObject.content || {})?.[0]\n const url = new URLPath(operation.path).toURLPath().replace(/([^/]):/g, '$1\\\\\\\\:')\n\n const headers = [contentType ? `'Content-Type': '${contentType}'` : undefined].filter(Boolean)\n\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 ${\n headers.length\n ? ` headers: {\n ${headers.join(', \\n')}\n },`\n : ''\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 { URLPath } from '@kubb/core/utils'\n\nimport type { OasTypes, Operation } from '@kubb/oas'\nimport { File, Function, FunctionParams } from '@kubb/react'\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 operation: Operation\n}\n\nexport function MockWithFaker({ baseURL = '', name, fakerName, typeName, operation }: Props): ReactNode {\n const method = operation.method\n const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith('2'))\n const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200\n\n const responseObject = operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject\n const contentType = Object.keys(responseObject.content || {})?.[0]\n const url = new URLPath(operation.path).toURLPath().replace(/([^/]):/g, '$1\\\\\\\\:')\n\n const headers = [contentType ? `'Content-Type': '${contentType}'` : undefined].filter(Boolean)\n\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 ${\n headers.length\n ? ` headers: {\n ${headers.join(', \\n')}\n },`\n : ''\n }\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,SAAgB,KAAK,EAAE,UAAU,IAAI,MAAM,UAAU,WAAkB,EAAa;CAClF,MAAM,SAAS,UAAU;CACzB,MAAM,qBAAqB,UAAU,wBAAwB,CAAC,OAAO,CAAC,SAAS,KAAK,WAAW,IAAI,CAAC;CACpG,MAAM,aAAa,mBAAmB,SAAS,IAAI,OAAO,mBAAmB,GAAG,GAAG;CAEnF,MAAM,iBAAiB,UAAU,wBAAwB,WAAW;CACpE,MAAM,cAAc,OAAO,KAAK,eAAe,WAAW,CAAE,EAAC,GAAG;CAChE,MAAM,MAAM,IAAIA,0BAAQ,UAAU,MAAM,WAAW,CAAC,QAAQ,YAAY,UAAU;CAElF,MAAM,UAAU,CAAC,cAAc,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC,GAAG,MAAU,EAAC,OAAO,QAAQ;CAE9F,MAAM,SAASC,4BAAe,QAAQ,EACpC,MAAM;EACJ,MAAM,GAAG,SAAS;gDACwB,EAAE,OAAO;oBACrC,CAAC;EACf,UAAU;CACX,EACF,EAAC;AAEF,0DACGC,kBAAK;EAAa;EAAM;EAAY;8DAClCC;GAAe;GAAM;GAAO,QAAQ,O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AAU,IAAI,QAAQ,YAAY,UAAU,CAAC;;;+CAGjC,EAAE,UAAU;cAC7C,EAAE,WAAW;MACrB,EACE,QAAQ,SACJ,CAAC;QACL,EAAE,QAAQ,KAAK,OAAO,CAAC;QACvB,CAAC,GACG,GACL;;IAEH,CAAC;IACY;GACC;AAEjB"}
|
package/dist/components.cjs
CHANGED
|
@@ -1,20 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
const require_components = require('./components-Bz0C7Qrg.cjs');
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "Handlers", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () { return chunkFYUFQXX6_cjs.Handlers; }
|
|
10
|
-
});
|
|
11
|
-
Object.defineProperty(exports, "Mock", {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function () { return chunkFYUFQXX6_cjs.Mock; }
|
|
14
|
-
});
|
|
15
|
-
Object.defineProperty(exports, "MockWithFaker", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: function () { return chunkFYUFQXX6_cjs.MockWithFaker; }
|
|
18
|
-
});
|
|
19
|
-
//# sourceMappingURL=components.cjs.map
|
|
20
|
-
//# sourceMappingURL=components.cjs.map
|
|
3
|
+
exports.Handlers = require_components.Handlers;
|
|
4
|
+
exports.Mock = require_components.Mock;
|
|
5
|
+
exports.MockWithFaker = require_components.MockWithFaker;
|
package/dist/components.d.cts
CHANGED
|
@@ -1,41 +1,55 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ReactNode } from
|
|
1
|
+
import { Operation } from "./types-DYAniEBx.cjs";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
3
|
|
|
4
|
+
//#region src/components/Mock.d.ts
|
|
4
5
|
type Props$1 = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
method: HttpMethod;
|
|
14
|
-
statusCode: number;
|
|
6
|
+
/**
|
|
7
|
+
* Name of the function
|
|
8
|
+
*/
|
|
9
|
+
name: string;
|
|
10
|
+
typeName: string;
|
|
11
|
+
fakerName: string;
|
|
12
|
+
baseURL: string | undefined;
|
|
13
|
+
operation: Operation;
|
|
15
14
|
};
|
|
16
|
-
declare function Mock({
|
|
17
|
-
|
|
15
|
+
declare function Mock({
|
|
16
|
+
baseURL,
|
|
17
|
+
name,
|
|
18
|
+
typeName,
|
|
19
|
+
operation
|
|
20
|
+
}: Props$1): ReactNode;
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/components/Handlers.d.ts
|
|
18
23
|
type HandlersProps = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Name of the function
|
|
26
|
+
*/
|
|
27
|
+
name: string;
|
|
28
|
+
handlers: string[];
|
|
24
29
|
};
|
|
25
|
-
declare function Handlers({
|
|
26
|
-
|
|
30
|
+
declare function Handlers({
|
|
31
|
+
name,
|
|
32
|
+
handlers
|
|
33
|
+
}: HandlersProps): ReactNode;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/components/MockWithFaker.d.ts
|
|
27
36
|
type Props = {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
method: HttpMethod;
|
|
37
|
-
statusCode: number;
|
|
37
|
+
/**
|
|
38
|
+
* Name of the function
|
|
39
|
+
*/
|
|
40
|
+
name: string;
|
|
41
|
+
typeName: string;
|
|
42
|
+
fakerName: string;
|
|
43
|
+
baseURL: string | undefined;
|
|
44
|
+
operation: Operation;
|
|
38
45
|
};
|
|
39
|
-
declare function MockWithFaker({
|
|
40
|
-
|
|
46
|
+
declare function MockWithFaker({
|
|
47
|
+
baseURL,
|
|
48
|
+
name,
|
|
49
|
+
fakerName,
|
|
50
|
+
typeName,
|
|
51
|
+
operation
|
|
52
|
+
}: Props): ReactNode;
|
|
53
|
+
//#endregion
|
|
41
54
|
export { Handlers, Mock, MockWithFaker };
|
|
55
|
+
//# sourceMappingURL=components.d.cts.map
|
package/dist/components.d.ts
CHANGED
|
@@ -1,41 +1,55 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ReactNode } from
|
|
1
|
+
import { Operation } from "./types-BOMj2hjt.js";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
3
|
|
|
4
|
+
//#region src/components/Mock.d.ts
|
|
4
5
|
type Props$1 = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
method: HttpMethod;
|
|
14
|
-
statusCode: number;
|
|
6
|
+
/**
|
|
7
|
+
* Name of the function
|
|
8
|
+
*/
|
|
9
|
+
name: string;
|
|
10
|
+
typeName: string;
|
|
11
|
+
fakerName: string;
|
|
12
|
+
baseURL: string | undefined;
|
|
13
|
+
operation: Operation;
|
|
15
14
|
};
|
|
16
|
-
declare function Mock({
|
|
17
|
-
|
|
15
|
+
declare function Mock({
|
|
16
|
+
baseURL,
|
|
17
|
+
name,
|
|
18
|
+
typeName,
|
|
19
|
+
operation
|
|
20
|
+
}: Props$1): ReactNode;
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/components/Handlers.d.ts
|
|
18
23
|
type HandlersProps = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Name of the function
|
|
26
|
+
*/
|
|
27
|
+
name: string;
|
|
28
|
+
handlers: string[];
|
|
24
29
|
};
|
|
25
|
-
declare function Handlers({
|
|
26
|
-
|
|
30
|
+
declare function Handlers({
|
|
31
|
+
name,
|
|
32
|
+
handlers
|
|
33
|
+
}: HandlersProps): ReactNode;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/components/MockWithFaker.d.ts
|
|
27
36
|
type Props = {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
method: HttpMethod;
|
|
37
|
-
statusCode: number;
|
|
37
|
+
/**
|
|
38
|
+
* Name of the function
|
|
39
|
+
*/
|
|
40
|
+
name: string;
|
|
41
|
+
typeName: string;
|
|
42
|
+
fakerName: string;
|
|
43
|
+
baseURL: string | undefined;
|
|
44
|
+
operation: Operation;
|
|
38
45
|
};
|
|
39
|
-
declare function MockWithFaker({
|
|
40
|
-
|
|
46
|
+
declare function MockWithFaker({
|
|
47
|
+
baseURL,
|
|
48
|
+
name,
|
|
49
|
+
fakerName,
|
|
50
|
+
typeName,
|
|
51
|
+
operation
|
|
52
|
+
}: Props): ReactNode;
|
|
53
|
+
//#endregion
|
|
41
54
|
export { Handlers, Mock, MockWithFaker };
|
|
55
|
+
//# sourceMappingURL=components.d.ts.map
|
package/dist/components.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Handlers, Mock, MockWithFaker } from "./components-ByUOezvw.js";
|
|
2
|
+
|
|
3
|
+
export { Handlers, Mock, MockWithFaker };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { Handlers, Mock, MockWithFaker } from "./components-ByUOezvw.js";
|
|
2
|
+
import { createReactGenerator } from "@kubb/plugin-oas";
|
|
3
|
+
import { pluginFakerName } from "@kubb/plugin-faker";
|
|
4
|
+
import { pluginTsName } from "@kubb/plugin-ts";
|
|
5
|
+
import { useOas, useOperationManager } from "@kubb/plugin-oas/hooks";
|
|
6
|
+
import { getBanner, getFooter } from "@kubb/plugin-oas/utils";
|
|
7
|
+
import { File, useApp } from "@kubb/react";
|
|
8
|
+
import { jsx, jsxs } from "@kubb/react/jsx-runtime";
|
|
9
|
+
|
|
10
|
+
//#region src/generators/mswGenerator.tsx
|
|
11
|
+
const mswGenerator = createReactGenerator({
|
|
12
|
+
name: "msw",
|
|
13
|
+
Operation({ operation }) {
|
|
14
|
+
const { pluginManager, plugin: { options: { output, parser, baseURL } } } = useApp();
|
|
15
|
+
const oas = useOas();
|
|
16
|
+
const { getSchemas, getName, getFile } = useOperationManager();
|
|
17
|
+
const mock = {
|
|
18
|
+
name: getName(operation, { type: "function" }),
|
|
19
|
+
file: getFile(operation)
|
|
20
|
+
};
|
|
21
|
+
const faker = {
|
|
22
|
+
file: getFile(operation, { pluginKey: [pluginFakerName] }),
|
|
23
|
+
schemas: getSchemas(operation, {
|
|
24
|
+
pluginKey: [pluginFakerName],
|
|
25
|
+
type: "function"
|
|
26
|
+
})
|
|
27
|
+
};
|
|
28
|
+
const type = {
|
|
29
|
+
file: getFile(operation, { pluginKey: [pluginTsName] }),
|
|
30
|
+
schemas: getSchemas(operation, {
|
|
31
|
+
pluginKey: [pluginTsName],
|
|
32
|
+
type: "type"
|
|
33
|
+
})
|
|
34
|
+
};
|
|
35
|
+
return /* @__PURE__ */ jsxs(File, {
|
|
36
|
+
baseName: mock.file.baseName,
|
|
37
|
+
path: mock.file.path,
|
|
38
|
+
meta: mock.file.meta,
|
|
39
|
+
banner: getBanner({
|
|
40
|
+
oas,
|
|
41
|
+
output,
|
|
42
|
+
config: pluginManager.config
|
|
43
|
+
}),
|
|
44
|
+
footer: getFooter({
|
|
45
|
+
oas,
|
|
46
|
+
output
|
|
47
|
+
}),
|
|
48
|
+
children: [
|
|
49
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
50
|
+
name: ["http"],
|
|
51
|
+
path: "msw"
|
|
52
|
+
}),
|
|
53
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
54
|
+
name: ["ResponseResolver"],
|
|
55
|
+
isTypeOnly: true,
|
|
56
|
+
path: "msw"
|
|
57
|
+
}),
|
|
58
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
59
|
+
name: [type.schemas.response.name],
|
|
60
|
+
path: type.file.path,
|
|
61
|
+
root: mock.file.path,
|
|
62
|
+
isTypeOnly: true
|
|
63
|
+
}),
|
|
64
|
+
parser === "faker" && faker.file && faker.schemas.response && /* @__PURE__ */ jsx(File.Import, {
|
|
65
|
+
name: [faker.schemas.response.name],
|
|
66
|
+
root: mock.file.path,
|
|
67
|
+
path: faker.file.path
|
|
68
|
+
}),
|
|
69
|
+
parser === "faker" && /* @__PURE__ */ jsx(MockWithFaker, {
|
|
70
|
+
name: mock.name,
|
|
71
|
+
typeName: type.schemas.response.name,
|
|
72
|
+
fakerName: faker.schemas.response.name,
|
|
73
|
+
operation,
|
|
74
|
+
baseURL
|
|
75
|
+
}),
|
|
76
|
+
parser === "data" && /* @__PURE__ */ jsx(Mock, {
|
|
77
|
+
name: mock.name,
|
|
78
|
+
typeName: type.schemas.response.name,
|
|
79
|
+
fakerName: faker.schemas.response.name,
|
|
80
|
+
operation,
|
|
81
|
+
baseURL
|
|
82
|
+
})
|
|
83
|
+
]
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/generators/handlersGenerator.tsx
|
|
90
|
+
const handlersGenerator = createReactGenerator({
|
|
91
|
+
name: "plugin-msw",
|
|
92
|
+
Operations({ operations }) {
|
|
93
|
+
const { pluginManager, plugin } = useApp();
|
|
94
|
+
const oas = useOas();
|
|
95
|
+
const { getName, getFile } = useOperationManager();
|
|
96
|
+
const file = pluginManager.getFile({
|
|
97
|
+
name: "handlers",
|
|
98
|
+
extname: ".ts",
|
|
99
|
+
pluginKey: plugin.key
|
|
100
|
+
});
|
|
101
|
+
const imports = operations.map((operation) => {
|
|
102
|
+
const operationFile = getFile(operation, { pluginKey: plugin.key });
|
|
103
|
+
const operationName = getName(operation, {
|
|
104
|
+
pluginKey: plugin.key,
|
|
105
|
+
type: "function"
|
|
106
|
+
});
|
|
107
|
+
return /* @__PURE__ */ jsx(File.Import, {
|
|
108
|
+
name: [operationName],
|
|
109
|
+
root: file.path,
|
|
110
|
+
path: operationFile.path
|
|
111
|
+
}, operationFile.path);
|
|
112
|
+
});
|
|
113
|
+
const handlers = operations.map((operation) => `${getName(operation, {
|
|
114
|
+
type: "function",
|
|
115
|
+
pluginKey: plugin.key
|
|
116
|
+
})}()`);
|
|
117
|
+
return /* @__PURE__ */ jsxs(File, {
|
|
118
|
+
baseName: file.baseName,
|
|
119
|
+
path: file.path,
|
|
120
|
+
meta: file.meta,
|
|
121
|
+
banner: getBanner({
|
|
122
|
+
oas,
|
|
123
|
+
output: plugin.options.output,
|
|
124
|
+
config: pluginManager.config
|
|
125
|
+
}),
|
|
126
|
+
footer: getFooter({
|
|
127
|
+
oas,
|
|
128
|
+
output: plugin.options.output
|
|
129
|
+
}),
|
|
130
|
+
children: [imports, /* @__PURE__ */ jsx(Handlers, {
|
|
131
|
+
name: "handlers",
|
|
132
|
+
handlers
|
|
133
|
+
})]
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
//#endregion
|
|
139
|
+
export { handlersGenerator, mswGenerator };
|
|
140
|
+
//# sourceMappingURL=generators-BjQcx0SS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-BjQcx0SS.js","names":[],"sources":["../src/generators/mswGenerator.tsx","../src/generators/handlersGenerator.tsx"],"sourcesContent":["import { 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 operation={operation}\n baseURL={baseURL}\n />\n )}\n {parser === 'data' && (\n <Mock name={mock.name} typeName={type.schemas.response.name} fakerName={faker.schemas.response.name} operation={operation} baseURL={baseURL} />\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"],"mappings":";;;;;;;;;;AASA,MAAa,eAAe,qBAAgC;CAC1D,MAAM;CACN,UAAU,EAAE,WAAW,EAAE;EACvB,MAAM,EACJ,eACA,QAAQ,EACN,SAAS,EAAE,QAAQ,QAAQ,SAAS,EACrC,EACF,GAAG,QAAmB;EACvB,MAAM,MAAM,QAAQ;EACpB,MAAM,EAAE,YAAY,SAAS,SAAS,GAAG,qBAAqB;EAE9D,MAAM,OAAO;GACX,MAAM,QAAQ,WAAW,EAAE,MAAM,WAAY,EAAC;GAC9C,MAAM,QAAQ,UAAU;EACzB;EAED,MAAM,QAAQ;GACZ,MAAM,QAAQ,WAAW,EAAE,WAAW,CAAC,eAAgB,EAAE,EAAC;GAC1D,SAAS,WAAW,WAAW;IAAE,WAAW,CAAC,eAAgB;IAAE,MAAM;GAAY,EAAC;EACnF;EAED,MAAM,OAAO;GACX,MAAM,QAAQ,WAAW,EAAE,WAAW,CAAC,YAAa,EAAE,EAAC;GACvD,SAAS,WAAW,WAAW;IAAE,WAAW,CAAC,YAAa;IAAE,MAAM;GAAQ,EAAC;EAC5E;AAED,8BACG;GACC,UAAU,KAAK,KAAK;GACpB,MAAM,KAAK,KAAK;GAChB,MAAM,KAAK,KAAK;GAChB,QAAQ,UAAU;IAAE;IAAK;IAAQ,QAAQ,cAAc;GAAQ,EAAC;GAChE,QAAQ,UAAU;IAAE;I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