@kubb/plugin-msw 5.0.0-beta.4 → 5.0.0-beta.56
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/README.md +39 -22
- package/dist/{components-vO0FIb2i.js → components-Bi7cN-ws.js} +111 -199
- package/dist/components-Bi7cN-ws.js.map +1 -0
- package/dist/{components-CLQ77DVn.cjs → components-Bp69JYOt.cjs} +113 -213
- package/dist/components-Bp69JYOt.cjs.map +1 -0
- package/dist/components.cjs +1 -2
- package/dist/components.d.ts +6 -19
- package/dist/components.js +2 -2
- package/dist/{generators-BPJCs1x1.js → generators-BnEvTy3q.js} +71 -39
- package/dist/generators-BnEvTy3q.js.map +1 -0
- package/dist/{generators-CrmMwWE4.cjs → generators-d22_s2UN.cjs} +69 -37
- package/dist/generators-d22_s2UN.cjs.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +16 -5
- package/dist/generators.js +1 -1
- package/dist/index.cjs +112 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +33 -4
- package/dist/index.js +113 -18
- package/dist/index.js.map +1 -1
- package/dist/types-B1yTWOfj.d.ts +99 -0
- package/package.json +13 -23
- package/src/components/Mock.tsx +7 -6
- package/src/components/MockWithFaker.tsx +7 -6
- package/src/components/Response.tsx +1 -1
- package/src/components/index.ts +0 -1
- package/src/generators/handlersGenerator.ts +49 -0
- package/src/generators/index.ts +1 -1
- package/src/generators/mswGenerator.tsx +27 -16
- package/src/plugin.ts +35 -19
- package/src/resolvers/resolverMsw.ts +21 -5
- package/src/types.ts +36 -26
- package/src/utils.ts +26 -61
- package/dist/components-CLQ77DVn.cjs.map +0 -1
- package/dist/components-vO0FIb2i.js.map +0 -1
- package/dist/generators-BPJCs1x1.js.map +0 -1
- package/dist/generators-CrmMwWE4.cjs.map +0 -1
- package/dist/types-Dxu0KMQ4.d.ts +0 -89
- package/extension.yaml +0 -260
- package/src/components/Handlers.tsx +0 -19
- package/src/generators/handlersGenerator.tsx +0 -41
- /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
|
@@ -1,27 +1,33 @@
|
|
|
1
|
-
import "./chunk
|
|
2
|
-
import { a as
|
|
3
|
-
import { defineGenerator } from "@kubb/core";
|
|
1
|
+
import "./chunk-C0LytTxp.js";
|
|
2
|
+
import { a as getOperationSuccessResponses, i as resolveFakerMeta, n as MockWithFaker, o as resolveResponseTypes, r as Mock, t as Response } from "./components-Bi7cN-ws.js";
|
|
3
|
+
import { ast, defineGenerator } from "@kubb/core";
|
|
4
4
|
import { pluginFakerName } from "@kubb/plugin-faker";
|
|
5
5
|
import { pluginTsName } from "@kubb/plugin-ts";
|
|
6
6
|
import { File, jsxRenderer } from "@kubb/renderer-jsx";
|
|
7
7
|
import { jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
|
|
8
|
-
//#region src/generators/handlersGenerator.
|
|
8
|
+
//#region src/generators/handlersGenerator.ts
|
|
9
|
+
/**
|
|
10
|
+
* Aggregate generator enabled by `pluginMsw({ handlers: true })`. Emits a
|
|
11
|
+
* `handlers.ts` file that re-exports every generated handler grouped by HTTP
|
|
12
|
+
* method, ready to spread into `setupServer(...handlers)` or
|
|
13
|
+
* `setupWorker(...handlers)`.
|
|
14
|
+
*/
|
|
9
15
|
const handlersGenerator = defineGenerator({
|
|
10
16
|
name: "plugin-msw",
|
|
11
|
-
renderer: jsxRenderer,
|
|
12
17
|
operations(nodes, ctx) {
|
|
13
|
-
const { resolver, config, root
|
|
14
|
-
const { output, group
|
|
18
|
+
const { resolver, config, root } = ctx;
|
|
19
|
+
const { output, group } = ctx.options;
|
|
20
|
+
const handlersName = resolver.resolveHandlersName();
|
|
15
21
|
const file = resolver.resolveFile({
|
|
16
|
-
name: "
|
|
22
|
+
name: resolver.resolvePathName(handlersName, "file"),
|
|
17
23
|
extname: ".ts"
|
|
18
24
|
}, {
|
|
19
25
|
root,
|
|
20
26
|
output,
|
|
21
|
-
group
|
|
27
|
+
group: group ?? void 0
|
|
22
28
|
});
|
|
23
29
|
const imports = nodes.map((node) => {
|
|
24
|
-
const operationName =
|
|
30
|
+
const operationName = resolver.resolveHandlerName(node);
|
|
25
31
|
const operationFile = resolver.resolveFile({
|
|
26
32
|
name: resolver.resolveName(node.operationId),
|
|
27
33
|
extname: ".ts",
|
|
@@ -30,45 +36,63 @@ const handlersGenerator = defineGenerator({
|
|
|
30
36
|
}, {
|
|
31
37
|
root,
|
|
32
38
|
output,
|
|
33
|
-
group
|
|
39
|
+
group: group ?? void 0
|
|
34
40
|
});
|
|
35
|
-
return
|
|
41
|
+
return ast.createImport({
|
|
36
42
|
name: [operationName],
|
|
37
43
|
root: file.path,
|
|
38
44
|
path: operationFile.path
|
|
39
|
-
}
|
|
45
|
+
});
|
|
40
46
|
});
|
|
41
|
-
const handlers = nodes.map((node) => `${
|
|
42
|
-
return
|
|
47
|
+
const handlers = nodes.map((node) => `${resolver.resolveHandlerName(node)}()`);
|
|
48
|
+
return [ast.createFile({
|
|
43
49
|
baseName: file.baseName,
|
|
44
50
|
path: file.path,
|
|
45
51
|
meta: file.meta,
|
|
46
|
-
banner: resolver.resolveBanner(
|
|
52
|
+
banner: resolver.resolveBanner(ctx.meta, {
|
|
47
53
|
output,
|
|
48
|
-
config
|
|
54
|
+
config,
|
|
55
|
+
file: {
|
|
56
|
+
path: file.path,
|
|
57
|
+
baseName: file.baseName
|
|
58
|
+
}
|
|
49
59
|
}),
|
|
50
|
-
footer: resolver.resolveFooter(
|
|
60
|
+
footer: resolver.resolveFooter(ctx.meta, {
|
|
51
61
|
output,
|
|
52
|
-
config
|
|
62
|
+
config,
|
|
63
|
+
file: {
|
|
64
|
+
path: file.path,
|
|
65
|
+
baseName: file.baseName
|
|
66
|
+
}
|
|
53
67
|
}),
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
68
|
+
imports,
|
|
69
|
+
sources: [ast.createSource({
|
|
70
|
+
name: handlersName,
|
|
71
|
+
isIndexable: true,
|
|
72
|
+
isExportable: true,
|
|
73
|
+
nodes: [ast.createText(`export const ${handlersName} = ${JSON.stringify(handlers).replaceAll("\"", "")} as const`)]
|
|
57
74
|
})]
|
|
58
|
-
});
|
|
75
|
+
})];
|
|
59
76
|
}
|
|
60
77
|
});
|
|
61
78
|
//#endregion
|
|
62
79
|
//#region src/generators/mswGenerator.tsx
|
|
80
|
+
/**
|
|
81
|
+
* Built-in operation generator for `@kubb/plugin-msw`. Emits one MSW handler
|
|
82
|
+
* per OpenAPI operation. With `parser: 'faker'` the handler returns a value
|
|
83
|
+
* from `@kubb/plugin-faker`; with `parser: 'data'` it returns a typed empty
|
|
84
|
+
* payload for tests to fill in.
|
|
85
|
+
*/
|
|
63
86
|
const mswGenerator = defineGenerator({
|
|
64
87
|
name: "msw",
|
|
65
88
|
renderer: jsxRenderer,
|
|
66
89
|
operation(node, ctx) {
|
|
67
|
-
|
|
68
|
-
const {
|
|
90
|
+
if (!ast.isHttpOperationNode(node)) return null;
|
|
91
|
+
const { driver, resolver, config, root } = ctx;
|
|
92
|
+
const { output, parser, baseURL, group } = ctx.options;
|
|
69
93
|
const fileName = resolver.resolveName(node.operationId);
|
|
70
94
|
const mock = {
|
|
71
|
-
name:
|
|
95
|
+
name: resolver.resolveHandlerName(node),
|
|
72
96
|
file: resolver.resolveFile({
|
|
73
97
|
name: fileName,
|
|
74
98
|
extname: ".ts",
|
|
@@ -77,16 +101,16 @@ const mswGenerator = defineGenerator({
|
|
|
77
101
|
}, {
|
|
78
102
|
root,
|
|
79
103
|
output,
|
|
80
|
-
group
|
|
104
|
+
group: group ?? void 0
|
|
81
105
|
})
|
|
82
106
|
};
|
|
83
|
-
const fakerPlugin = parser === "faker" ? driver.getPlugin(pluginFakerName) :
|
|
107
|
+
const fakerPlugin = parser === "faker" ? driver.getPlugin(pluginFakerName) : null;
|
|
84
108
|
const faker = parser === "faker" && fakerPlugin ? resolveFakerMeta(node, {
|
|
85
109
|
root,
|
|
86
110
|
fakerResolver: driver.getResolver(pluginFakerName),
|
|
87
111
|
fakerOutput: fakerPlugin.options?.output ?? output,
|
|
88
|
-
fakerGroup: fakerPlugin.options?.group
|
|
89
|
-
}) :
|
|
112
|
+
fakerGroup: fakerPlugin.options?.group ?? null
|
|
113
|
+
}) : null;
|
|
90
114
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
91
115
|
if (!pluginTs) return null;
|
|
92
116
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
@@ -99,24 +123,32 @@ const mswGenerator = defineGenerator({
|
|
|
99
123
|
}, {
|
|
100
124
|
root,
|
|
101
125
|
output: pluginTs.options?.output ?? output,
|
|
102
|
-
group: pluginTs.options?.group
|
|
126
|
+
group: pluginTs.options?.group ?? void 0
|
|
103
127
|
}),
|
|
104
128
|
responseName: tsResolver.resolveResponseName(node)
|
|
105
129
|
};
|
|
106
|
-
const types =
|
|
107
|
-
const hasSuccessSchema =
|
|
108
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) :
|
|
130
|
+
const types = resolveResponseTypes(node, tsResolver);
|
|
131
|
+
const hasSuccessSchema = getOperationSuccessResponses(node).some((response) => !!response.content?.[0]?.schema);
|
|
132
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) : null;
|
|
109
133
|
return /* @__PURE__ */ jsxs(File, {
|
|
110
134
|
baseName: mock.file.baseName,
|
|
111
135
|
path: mock.file.path,
|
|
112
136
|
meta: mock.file.meta,
|
|
113
|
-
banner: resolver.resolveBanner(
|
|
137
|
+
banner: resolver.resolveBanner(ctx.meta, {
|
|
114
138
|
output,
|
|
115
|
-
config
|
|
139
|
+
config,
|
|
140
|
+
file: {
|
|
141
|
+
path: mock.file.path,
|
|
142
|
+
baseName: mock.file.baseName
|
|
143
|
+
}
|
|
116
144
|
}),
|
|
117
|
-
footer: resolver.resolveFooter(
|
|
145
|
+
footer: resolver.resolveFooter(ctx.meta, {
|
|
118
146
|
output,
|
|
119
|
-
config
|
|
147
|
+
config,
|
|
148
|
+
file: {
|
|
149
|
+
path: mock.file.path,
|
|
150
|
+
baseName: mock.file.baseName
|
|
151
|
+
}
|
|
120
152
|
}),
|
|
121
153
|
children: [
|
|
122
154
|
/* @__PURE__ */ jsx(File.Import, {
|
|
@@ -173,4 +205,4 @@ const mswGenerator = defineGenerator({
|
|
|
173
205
|
//#endregion
|
|
174
206
|
export { handlersGenerator as n, mswGenerator as t };
|
|
175
207
|
|
|
176
|
-
//# sourceMappingURL=generators-
|
|
208
|
+
//# sourceMappingURL=generators-BnEvTy3q.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-BnEvTy3q.js","names":[],"sources":["../src/generators/handlersGenerator.ts","../src/generators/mswGenerator.tsx"],"sourcesContent":["import { ast, defineGenerator } from '@kubb/core'\nimport type { PluginMsw } from '../types'\n\n/**\n * Aggregate generator enabled by `pluginMsw({ handlers: true })`. Emits a\n * `handlers.ts` file that re-exports every generated handler grouped by HTTP\n * method, ready to spread into `setupServer(...handlers)` or\n * `setupWorker(...handlers)`.\n */\nexport const handlersGenerator = defineGenerator<PluginMsw>({\n name: 'plugin-msw',\n operations(nodes, ctx) {\n const { resolver, config, root } = ctx\n const { output, group } = ctx.options\n\n const handlersName = resolver.resolveHandlersName()\n const file = resolver.resolveFile({ name: resolver.resolvePathName(handlersName, 'file'), extname: '.ts' }, { root, output, group: group ?? undefined })\n\n const imports = nodes.map((node) => {\n const operationName = resolver.resolveHandlerName(node)\n const operationFile = resolver.resolveFile(\n { name: resolver.resolveName(node.operationId), extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },\n { root, output, group: group ?? undefined },\n )\n return ast.createImport({ name: [operationName], root: file.path, path: operationFile.path })\n })\n\n const handlers = nodes.map((node) => `${resolver.resolveHandlerName(node)}()`)\n\n return [\n ast.createFile({\n baseName: file.baseName,\n path: file.path,\n meta: file.meta,\n banner: resolver.resolveBanner(ctx.meta, { output, config, file: { path: file.path, baseName: file.baseName } }),\n footer: resolver.resolveFooter(ctx.meta, { output, config, file: { path: file.path, baseName: file.baseName } }),\n imports,\n sources: [\n ast.createSource({\n name: handlersName,\n isIndexable: true,\n isExportable: true,\n nodes: [ast.createText(`export const ${handlersName} = ${JSON.stringify(handlers).replaceAll('\"', '')} as const`)],\n }),\n ],\n }),\n ]\n },\n})\n","import { getOperationSuccessResponses, resolveResponseTypes } from '@internals/shared'\nimport { ast, defineGenerator } from '@kubb/core'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, jsxRenderer } from '@kubb/renderer-jsx'\nimport { Mock, MockWithFaker, Response } from '../components'\nimport type { PluginMsw } from '../types'\nimport { resolveFakerMeta } from '../utils.ts'\n\n/**\n * Built-in operation generator for `@kubb/plugin-msw`. Emits one MSW handler\n * per OpenAPI operation. With `parser: 'faker'` the handler returns a value\n * from `@kubb/plugin-faker`; with `parser: 'data'` it returns a typed empty\n * payload for tests to fill in.\n */\nexport const mswGenerator = defineGenerator<PluginMsw>({\n name: 'msw',\n renderer: jsxRenderer,\n operation(node, ctx) {\n if (!ast.isHttpOperationNode(node)) return null\n const { driver, resolver, config, root } = ctx\n const { output, parser, baseURL, group } = ctx.options\n\n const fileName = resolver.resolveName(node.operationId)\n const mock = {\n name: resolver.resolveHandlerName(node),\n file: resolver.resolveFile(\n { name: fileName, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },\n { root, output, group: group ?? undefined },\n ),\n }\n\n const fakerPlugin = parser === 'faker' ? driver.getPlugin(pluginFakerName) : null\n const faker =\n parser === 'faker' && fakerPlugin\n ? resolveFakerMeta(node, {\n root,\n fakerResolver: driver.getResolver(pluginFakerName),\n fakerOutput: fakerPlugin.options?.output ?? output,\n fakerGroup: fakerPlugin.options?.group ?? null,\n })\n : null\n\n const pluginTs = driver.getPlugin(pluginTsName)\n if (!pluginTs) return null\n const tsResolver = driver.getResolver(pluginTsName)\n\n const type = {\n file: tsResolver.resolveFile(\n { name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },\n { root, output: pluginTs.options?.output ?? output, group: pluginTs.options?.group ?? undefined },\n ),\n responseName: tsResolver.resolveResponseName(node),\n }\n\n const types = resolveResponseTypes(node, tsResolver)\n const successResponses = getOperationSuccessResponses(node)\n const hasSuccessSchema = successResponses.some((response) => !!response.content?.[0]?.schema)\n\n const requestName = node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) : null\n\n return (\n <File\n baseName={mock.file.baseName}\n path={mock.file.path}\n meta={mock.file.meta}\n banner={resolver.resolveBanner(ctx.meta, { output, config, file: { path: mock.file.path, baseName: mock.file.baseName } })}\n footer={resolver.resolveFooter(ctx.meta, { output, config, file: { path: mock.file.path, baseName: mock.file.baseName } })}\n >\n <File.Import name={['http']} path=\"msw\" />\n <File.Import name={['HttpResponseResolver']} isTypeOnly path=\"msw\" />\n <File.Import\n name={Array.from(new Set([type.responseName, ...types.map((t) => t[1]), ...(requestName ? [requestName] : [])]))}\n path={type.file.path}\n root={mock.file.path}\n isTypeOnly\n />\n {parser === 'faker' && faker && <File.Import name={[faker.name]} root={mock.file.path} path={faker.file.path} />}\n\n {types\n .filter(([code]) => code !== 'default')\n .map(([code, typeName]) => {\n const response = node.responses.find((item) => item.statusCode === String(code))\n if (!response) return null\n return <Response key={typeName} typeName={typeName} response={response} name={mock.name} />\n })}\n\n {parser === 'faker' && faker && hasSuccessSchema ? (\n <MockWithFaker name={mock.name} typeName={type.responseName} requestTypeName={requestName} fakerName={faker.name} node={node} baseURL={baseURL} />\n ) : (\n <Mock name={mock.name} typeName={type.responseName} requestTypeName={requestName} node={node} baseURL={baseURL} />\n )}\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;;AASA,MAAa,oBAAoB,gBAA2B;CAC1D,MAAM;CACN,WAAW,OAAO,KAAK;EACrB,MAAM,EAAE,UAAU,QAAQ,SAAS;EACnC,MAAM,EAAE,QAAQ,UAAU,IAAI;EAE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AAK;KAAM,UAAU,KAAK;KAAc,iBAAiB;KAAa,WAAW,MAAM;KAAY;KAAe;IAAU,CAAA,IAEjJ,oBAAC,MAAD;KAAM,MAAM,KAAK;KAAM,UAAU,KAAK;KAAc,iBAAiB;KAAmB;KAAe;IAAU,CAAA;GAE/G;;CAEV;AACF,CAAC"}
|
|
@@ -1,26 +1,32 @@
|
|
|
1
|
-
const require_components = require("./components-
|
|
1
|
+
const require_components = require("./components-Bp69JYOt.cjs");
|
|
2
2
|
let _kubb_core = require("@kubb/core");
|
|
3
3
|
let _kubb_plugin_faker = require("@kubb/plugin-faker");
|
|
4
4
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
5
5
|
let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
|
|
6
6
|
let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
7
|
-
//#region src/generators/handlersGenerator.
|
|
7
|
+
//#region src/generators/handlersGenerator.ts
|
|
8
|
+
/**
|
|
9
|
+
* Aggregate generator enabled by `pluginMsw({ handlers: true })`. Emits a
|
|
10
|
+
* `handlers.ts` file that re-exports every generated handler grouped by HTTP
|
|
11
|
+
* method, ready to spread into `setupServer(...handlers)` or
|
|
12
|
+
* `setupWorker(...handlers)`.
|
|
13
|
+
*/
|
|
8
14
|
const handlersGenerator = (0, _kubb_core.defineGenerator)({
|
|
9
15
|
name: "plugin-msw",
|
|
10
|
-
renderer: _kubb_renderer_jsx.jsxRenderer,
|
|
11
16
|
operations(nodes, ctx) {
|
|
12
|
-
const { resolver, config, root
|
|
13
|
-
const { output, group
|
|
17
|
+
const { resolver, config, root } = ctx;
|
|
18
|
+
const { output, group } = ctx.options;
|
|
19
|
+
const handlersName = resolver.resolveHandlersName();
|
|
14
20
|
const file = resolver.resolveFile({
|
|
15
|
-
name: "
|
|
21
|
+
name: resolver.resolvePathName(handlersName, "file"),
|
|
16
22
|
extname: ".ts"
|
|
17
23
|
}, {
|
|
18
24
|
root,
|
|
19
25
|
output,
|
|
20
|
-
group
|
|
26
|
+
group: group ?? void 0
|
|
21
27
|
});
|
|
22
28
|
const imports = nodes.map((node) => {
|
|
23
|
-
const operationName =
|
|
29
|
+
const operationName = resolver.resolveHandlerName(node);
|
|
24
30
|
const operationFile = resolver.resolveFile({
|
|
25
31
|
name: resolver.resolveName(node.operationId),
|
|
26
32
|
extname: ".ts",
|
|
@@ -29,45 +35,63 @@ const handlersGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
29
35
|
}, {
|
|
30
36
|
root,
|
|
31
37
|
output,
|
|
32
|
-
group
|
|
38
|
+
group: group ?? void 0
|
|
33
39
|
});
|
|
34
|
-
return
|
|
40
|
+
return _kubb_core.ast.createImport({
|
|
35
41
|
name: [operationName],
|
|
36
42
|
root: file.path,
|
|
37
43
|
path: operationFile.path
|
|
38
|
-
}
|
|
44
|
+
});
|
|
39
45
|
});
|
|
40
|
-
const handlers = nodes.map((node) => `${
|
|
41
|
-
return
|
|
46
|
+
const handlers = nodes.map((node) => `${resolver.resolveHandlerName(node)}()`);
|
|
47
|
+
return [_kubb_core.ast.createFile({
|
|
42
48
|
baseName: file.baseName,
|
|
43
49
|
path: file.path,
|
|
44
50
|
meta: file.meta,
|
|
45
|
-
banner: resolver.resolveBanner(
|
|
51
|
+
banner: resolver.resolveBanner(ctx.meta, {
|
|
46
52
|
output,
|
|
47
|
-
config
|
|
53
|
+
config,
|
|
54
|
+
file: {
|
|
55
|
+
path: file.path,
|
|
56
|
+
baseName: file.baseName
|
|
57
|
+
}
|
|
48
58
|
}),
|
|
49
|
-
footer: resolver.resolveFooter(
|
|
59
|
+
footer: resolver.resolveFooter(ctx.meta, {
|
|
50
60
|
output,
|
|
51
|
-
config
|
|
61
|
+
config,
|
|
62
|
+
file: {
|
|
63
|
+
path: file.path,
|
|
64
|
+
baseName: file.baseName
|
|
65
|
+
}
|
|
52
66
|
}),
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
67
|
+
imports,
|
|
68
|
+
sources: [_kubb_core.ast.createSource({
|
|
69
|
+
name: handlersName,
|
|
70
|
+
isIndexable: true,
|
|
71
|
+
isExportable: true,
|
|
72
|
+
nodes: [_kubb_core.ast.createText(`export const ${handlersName} = ${JSON.stringify(handlers).replaceAll("\"", "")} as const`)]
|
|
56
73
|
})]
|
|
57
|
-
});
|
|
74
|
+
})];
|
|
58
75
|
}
|
|
59
76
|
});
|
|
60
77
|
//#endregion
|
|
61
78
|
//#region src/generators/mswGenerator.tsx
|
|
79
|
+
/**
|
|
80
|
+
* Built-in operation generator for `@kubb/plugin-msw`. Emits one MSW handler
|
|
81
|
+
* per OpenAPI operation. With `parser: 'faker'` the handler returns a value
|
|
82
|
+
* from `@kubb/plugin-faker`; with `parser: 'data'` it returns a typed empty
|
|
83
|
+
* payload for tests to fill in.
|
|
84
|
+
*/
|
|
62
85
|
const mswGenerator = (0, _kubb_core.defineGenerator)({
|
|
63
86
|
name: "msw",
|
|
64
87
|
renderer: _kubb_renderer_jsx.jsxRenderer,
|
|
65
88
|
operation(node, ctx) {
|
|
66
|
-
|
|
67
|
-
const {
|
|
89
|
+
if (!_kubb_core.ast.isHttpOperationNode(node)) return null;
|
|
90
|
+
const { driver, resolver, config, root } = ctx;
|
|
91
|
+
const { output, parser, baseURL, group } = ctx.options;
|
|
68
92
|
const fileName = resolver.resolveName(node.operationId);
|
|
69
93
|
const mock = {
|
|
70
|
-
name:
|
|
94
|
+
name: resolver.resolveHandlerName(node),
|
|
71
95
|
file: resolver.resolveFile({
|
|
72
96
|
name: fileName,
|
|
73
97
|
extname: ".ts",
|
|
@@ -76,16 +100,16 @@ const mswGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
76
100
|
}, {
|
|
77
101
|
root,
|
|
78
102
|
output,
|
|
79
|
-
group
|
|
103
|
+
group: group ?? void 0
|
|
80
104
|
})
|
|
81
105
|
};
|
|
82
|
-
const fakerPlugin = parser === "faker" ? driver.getPlugin(_kubb_plugin_faker.pluginFakerName) :
|
|
106
|
+
const fakerPlugin = parser === "faker" ? driver.getPlugin(_kubb_plugin_faker.pluginFakerName) : null;
|
|
83
107
|
const faker = parser === "faker" && fakerPlugin ? require_components.resolveFakerMeta(node, {
|
|
84
108
|
root,
|
|
85
109
|
fakerResolver: driver.getResolver(_kubb_plugin_faker.pluginFakerName),
|
|
86
110
|
fakerOutput: fakerPlugin.options?.output ?? output,
|
|
87
|
-
fakerGroup: fakerPlugin.options?.group
|
|
88
|
-
}) :
|
|
111
|
+
fakerGroup: fakerPlugin.options?.group ?? null
|
|
112
|
+
}) : null;
|
|
89
113
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
90
114
|
if (!pluginTs) return null;
|
|
91
115
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
@@ -98,24 +122,32 @@ const mswGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
98
122
|
}, {
|
|
99
123
|
root,
|
|
100
124
|
output: pluginTs.options?.output ?? output,
|
|
101
|
-
group: pluginTs.options?.group
|
|
125
|
+
group: pluginTs.options?.group ?? void 0
|
|
102
126
|
}),
|
|
103
127
|
responseName: tsResolver.resolveResponseName(node)
|
|
104
128
|
};
|
|
105
|
-
const types = require_components.
|
|
106
|
-
const hasSuccessSchema = require_components.
|
|
107
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) :
|
|
129
|
+
const types = require_components.resolveResponseTypes(node, tsResolver);
|
|
130
|
+
const hasSuccessSchema = require_components.getOperationSuccessResponses(node).some((response) => !!response.content?.[0]?.schema);
|
|
131
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) : null;
|
|
108
132
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
109
133
|
baseName: mock.file.baseName,
|
|
110
134
|
path: mock.file.path,
|
|
111
135
|
meta: mock.file.meta,
|
|
112
|
-
banner: resolver.resolveBanner(
|
|
136
|
+
banner: resolver.resolveBanner(ctx.meta, {
|
|
113
137
|
output,
|
|
114
|
-
config
|
|
138
|
+
config,
|
|
139
|
+
file: {
|
|
140
|
+
path: mock.file.path,
|
|
141
|
+
baseName: mock.file.baseName
|
|
142
|
+
}
|
|
115
143
|
}),
|
|
116
|
-
footer: resolver.resolveFooter(
|
|
144
|
+
footer: resolver.resolveFooter(ctx.meta, {
|
|
117
145
|
output,
|
|
118
|
-
config
|
|
146
|
+
config,
|
|
147
|
+
file: {
|
|
148
|
+
path: mock.file.path,
|
|
149
|
+
baseName: mock.file.baseName
|
|
150
|
+
}
|
|
119
151
|
}),
|
|
120
152
|
children: [
|
|
121
153
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
@@ -183,4 +215,4 @@ Object.defineProperty(exports, "mswGenerator", {
|
|
|
183
215
|
}
|
|
184
216
|
});
|
|
185
217
|
|
|
186
|
-
//# sourceMappingURL=generators-
|
|
218
|
+
//# sourceMappingURL=generators-d22_s2UN.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-d22_s2UN.cjs","names":["ast","jsxRenderer","ast","pluginFakerName","resolveFakerMeta","pluginTsName","resolveResponseTypes","getOperationSuccessResponses","File","Response","MockWithFaker","Mock"],"sources":["../src/generators/handlersGenerator.ts","../src/generators/mswGenerator.tsx"],"sourcesContent":["import { ast, defineGenerator } from '@kubb/core'\nimport type { PluginMsw } from '../types'\n\n/**\n * Aggregate generator enabled by `pluginMsw({ handlers: true })`. Emits a\n * `handlers.ts` file that re-exports every generated handler grouped by HTTP\n * method, ready to spread into `setupServer(...handlers)` or\n * `setupWorker(...handlers)`.\n */\nexport const handlersGenerator = defineGenerator<PluginMsw>({\n name: 'plugin-msw',\n operations(nodes, ctx) {\n const { resolver, config, root } = ctx\n const { output, group } = ctx.options\n\n const handlersName = resolver.resolveHandlersName()\n const file = resolver.resolveFile({ name: resolver.resolvePathName(handlersName, 'file'), extname: '.ts' }, { root, output, group: group ?? undefined })\n\n const imports = nodes.map((node) => {\n const operationName = resolver.resolveHandlerName(node)\n const operationFile = resolver.resolveFile(\n { name: resolver.resolveName(node.operationId), extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },\n { root, output, group: group ?? undefined },\n )\n return ast.createImport({ name: [operationName], root: file.path, path: operationFile.path })\n })\n\n const handlers = nodes.map((node) => `${resolver.resolveHandlerName(node)}()`)\n\n return [\n ast.createFile({\n baseName: file.baseName,\n path: file.path,\n meta: file.meta,\n banner: resolver.resolveBanner(ctx.meta, { output, config, file: { path: file.path, baseName: file.baseName } }),\n footer: resolver.resolveFooter(ctx.meta, { output, config, file: { path: file.path, baseName: file.baseName } }),\n imports,\n sources: [\n ast.createSource({\n name: handlersName,\n isIndexable: true,\n isExportable: true,\n nodes: [ast.createText(`export const ${handlersName} = ${JSON.stringify(handlers).replaceAll('\"', '')} as const`)],\n }),\n ],\n }),\n ]\n },\n})\n","import { getOperationSuccessResponses, resolveResponseTypes } from '@internals/shared'\nimport { ast, defineGenerator } from '@kubb/core'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, jsxRenderer } from '@kubb/renderer-jsx'\nimport { Mock, MockWithFaker, Response } from '../components'\nimport type { PluginMsw } from '../types'\nimport { resolveFakerMeta } from '../utils.ts'\n\n/**\n * Built-in operation generator for `@kubb/plugin-msw`. Emits one MSW handler\n * per OpenAPI operation. With `parser: 'faker'` the handler returns a value\n * from `@kubb/plugin-faker`; with `parser: 'data'` it returns a typed empty\n * payload for tests to fill in.\n */\nexport const mswGenerator = defineGenerator<PluginMsw>({\n name: 'msw',\n renderer: jsxRenderer,\n operation(node, ctx) {\n if (!ast.isHttpOperationNode(node)) return null\n const { driver, resolver, config, root } = ctx\n const { output, parser, baseURL, group } = ctx.options\n\n const fileName = resolver.resolveName(node.operationId)\n const mock = {\n name: resolver.resolveHandlerName(node),\n file: resolver.resolveFile(\n { name: fileName, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },\n { root, output, group: group ?? undefined },\n ),\n }\n\n const fakerPlugin = parser === 'faker' ? driver.getPlugin(pluginFakerName) : null\n const faker =\n parser === 'faker' && fakerPlugin\n ? resolveFakerMeta(node, {\n root,\n fakerResolver: driver.getResolver(pluginFakerName),\n fakerOutput: fakerPlugin.options?.output ?? output,\n fakerGroup: fakerPlugin.options?.group ?? null,\n })\n : null\n\n const pluginTs = driver.getPlugin(pluginTsName)\n if (!pluginTs) return null\n const tsResolver = driver.getResolver(pluginTsName)\n\n const type = {\n file: tsResolver.resolveFile(\n { name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },\n { root, output: pluginTs.options?.output ?? output, group: pluginTs.options?.group ?? undefined },\n ),\n responseName: tsResolver.resolveResponseName(node),\n }\n\n const types = resolveResponseTypes(node, tsResolver)\n const successResponses = getOperationSuccessResponses(node)\n const hasSuccessSchema = successResponses.some((response) => !!response.content?.[0]?.schema)\n\n const requestName = node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) : null\n\n return (\n <File\n baseName={mock.file.baseName}\n path={mock.file.path}\n meta={mock.file.meta}\n banner={resolver.resolveBanner(ctx.meta, { output, config, file: { path: mock.file.path, baseName: mock.file.baseName } })}\n footer={resolver.resolveFooter(ctx.meta, { output, config, file: { path: mock.file.path, baseName: mock.file.baseName } })}\n >\n <File.Import name={['http']} path=\"msw\" />\n <File.Import name={['HttpResponseResolver']} isTypeOnly path=\"msw\" />\n <File.Import\n name={Array.from(new Set([type.responseName, ...types.map((t) => t[1]), ...(requestName ? [requestName] : [])]))}\n path={type.file.path}\n root={mock.file.path}\n isTypeOnly\n />\n {parser === 'faker' && faker && <File.Import name={[faker.name]} root={mock.file.path} path={faker.file.path} />}\n\n {types\n .filter(([code]) => code !== 'default')\n .map(([code, typeName]) => {\n const response = node.responses.find((item) => item.statusCode === String(code))\n if (!response) return null\n return <Response key={typeName} typeName={typeName} response={response} name={mock.name} />\n })}\n\n {parser === 'faker' && faker && hasSuccessSchema ? (\n <MockWithFaker name={mock.name} typeName={type.responseName} requestTypeName={requestName} fakerName={faker.name} node={node} baseURL={baseURL} />\n ) : (\n <Mock name={mock.name} typeName={type.responseName} requestTypeName={requestName} node={node} baseURL={baseURL} />\n )}\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;AASA,MAAa,qBAAA,GAAA,WAAA,gBAAA,CAA+C;CAC1D,MAAM;CACN,WAAW,OAAO,KAAK;EACrB,MAAM,EAAE,UAAU,QAAQ,SAAS;EACnC,MAAM,EAAE,QAAQ,UAAU,IAAI;EAE9B,MAAM,eAAe,SAAS,oBAAoB;EAClD,MAAM,OAAO,SAAS,YAAY;GAAE,MAAM,SAAS,gBAAgB,cAAc,MAAM;GAAG,SAAS;EAAM,GAAG;GAAE;GAAM;GAAQ,OAAO,SAAS,KAAA;EAAU,CAAC;EAEvJ,MAAM,UAAU,MAAM,KAAK,SAAS;GAClC,MAAM,gBAAgB,SAAS,mBAAmB,IAAI;GACtD,MAAM,gBAAgB,SAAS,YAC7B;IAAE,MAAM,SAAS,YAAY,KAAK,WAAW;IAAG,SAAS;IAAO,KAAK,KAAK,KAAK,MAAM;IAAW,MAAM,KAAK;GAAK,GAChH;IAAE;IAAM;IAAQ,OAAO,SAAS,KAAA;GAAU,CAC5C;GACA,OAAOA,WAAAA,IAAI,aAAa;IAAE,MAAM,CAAC,aAAa;IAAG,MAAM,KAAK;IAAM,MAAM,cAAc;GAAK,CAAC;EAC9F,CAAC;EAED,MAAM,WAAW,MAAM,KAAK,SAAS,GAAG,SAAS,mBAAmB,IAAI,EAAE,GAAG;EAE7E,OAAO,CACLA,WAAAA,IAAI,WAAW;GACb,UAAU,KAAK;GACf,MAAM,KAAK;GACX,MAAM,KAAK;GACX,QAAQ,SAAS,cAAc,IAAI,MAAM;IAAE;IAAQ;IAAQ,MAAM;KAAE,MAAM,KAAK;KAAM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,QAAN;KACE,MAAM,MAAM,KAAK,IAAI,IAAI;MAAC,KAAK;MAAc,GAAG,MAAM,KAAK,MAAM,EAAE,EAAE;MAAG,GAAI,cAAc,CAAC,WAAW,IAAI,CAAC;KAAE,CAAC,CAAC;KAC/G,MAAM,KAAK,KAAK;KAChB,MAAM,KAAK,KAAK;KAChB,YAAA;IACD,CAAA;IACA,WAAW,WAAW,SAAS,iBAAA,GAAA,+BAAA,IAAA,CAACA,mBAAAA,KAAK,QAAN;KAAa,MAAM,CAAC,MAAM,IAAI;KAAG,MAAM,KAAK,KAAK;KAAM,MAAM,MAAM,KAAK;IAAO,CAAA;IAE9G,MACE,QAAQ,CAAC,UAAU,SAAS,SAAS,CAAC,CACtC,KAAK,CAAC,MAAM,cAAc;KACzB,MAAM,WAAW,KAAK,UAAU,MAAM,SAAS,KAAK,eAAe,OAAO,IAAI,CAAC;KAC/E,IAAI,CAAC,UAAU,OAAO;KACtB,OAAO,iBAAA,GAAA,+BAAA,IAAA,CAACC,mBAAAA,UAAD;MAAmC;MAAoB;MAAU,MAAM,KAAK;KAAO,GAApE,QAAoE;IAC5F,CAAC;IAEF,WAAW,WAAW,SAAS,mBAC9B,iBAAA,GAAA,+BAAA,IAAA,CAACC,mBAAAA,eAAD;KAAe,MAAM,KAAK;KAAM,UAAU,KAAK;KAAc,iBAAiB;KAAa,WAAW,MAAM;KAAY;KAAe;IAAU,CAAA,IAEjJ,iBAAA,GAAA,+BAAA,IAAA,CAACC,mBAAAA,MAAD;KAAM,MAAM,KAAK;KAAM,UAAU,KAAK;KAAc,iBAAiB;KAAmB;KAAe;IAAU,CAAA;GAE/G;;CAEV;AACF,CAAC"}
|
package/dist/generators.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_generators = require("./generators-
|
|
2
|
+
const require_generators = require("./generators-d22_s2UN.cjs");
|
|
3
3
|
exports.handlersGenerator = require_generators.handlersGenerator;
|
|
4
4
|
exports.mswGenerator = require_generators.mswGenerator;
|
package/dist/generators.d.ts
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
|
-
import { t as __name } from "./chunk
|
|
2
|
-
import { n as PluginMsw } from "./types-
|
|
3
|
-
import * as _$_kubb_core0 from "@kubb/core";
|
|
1
|
+
import { t as __name } from "./chunk-C0LytTxp.js";
|
|
2
|
+
import { n as PluginMsw } from "./types-B1yTWOfj.js";
|
|
4
3
|
|
|
5
4
|
//#region src/generators/handlersGenerator.d.ts
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Aggregate generator enabled by `pluginMsw({ handlers: true })`. Emits a
|
|
7
|
+
* `handlers.ts` file that re-exports every generated handler grouped by HTTP
|
|
8
|
+
* method, ready to spread into `setupServer(...handlers)` or
|
|
9
|
+
* `setupWorker(...handlers)`.
|
|
10
|
+
*/
|
|
11
|
+
declare const handlersGenerator: import("@kubb/core").Generator<PluginMsw, unknown>;
|
|
7
12
|
//#endregion
|
|
8
13
|
//#region src/generators/mswGenerator.d.ts
|
|
9
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Built-in operation generator for `@kubb/plugin-msw`. Emits one MSW handler
|
|
16
|
+
* per OpenAPI operation. With `parser: 'faker'` the handler returns a value
|
|
17
|
+
* from `@kubb/plugin-faker`; with `parser: 'data'` it returns a typed empty
|
|
18
|
+
* payload for tests to fill in.
|
|
19
|
+
*/
|
|
20
|
+
declare const mswGenerator: import("@kubb/core").Generator<PluginMsw, unknown>;
|
|
10
21
|
//#endregion
|
|
11
22
|
export { handlersGenerator, mswGenerator };
|
|
12
23
|
//# sourceMappingURL=generators.d.ts.map
|
package/dist/generators.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as handlersGenerator, t as mswGenerator } from "./generators-
|
|
1
|
+
import { n as handlersGenerator, t as mswGenerator } from "./generators-BnEvTy3q.js";
|
|
2
2
|
export { handlersGenerator, mswGenerator };
|
package/dist/index.cjs
CHANGED
|
@@ -2,46 +2,142 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
const require_components = require("./components-
|
|
6
|
-
const require_generators = require("./generators-
|
|
5
|
+
const require_components = require("./components-Bp69JYOt.cjs");
|
|
6
|
+
const require_generators = require("./generators-d22_s2UN.cjs");
|
|
7
7
|
let _kubb_core = require("@kubb/core");
|
|
8
8
|
let _kubb_plugin_faker = require("@kubb/plugin-faker");
|
|
9
9
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
10
|
+
//#region ../../internals/utils/src/fs.ts
|
|
11
|
+
/**
|
|
12
|
+
* Builds a nested file path from a dotted name. Splits on dots that precede a letter
|
|
13
|
+
* (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases
|
|
14
|
+
* every earlier segment, applies `caseLast` to the final segment, and joins with `/`.
|
|
15
|
+
*
|
|
16
|
+
* Empty segments are dropped before joining. They arise when the name starts with a dot
|
|
17
|
+
* followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to
|
|
18
|
+
* an empty string). Without this a leading `/` would form, which `path.resolve` reads as an
|
|
19
|
+
* absolute path, letting generated files escape the configured output directory.
|
|
20
|
+
*
|
|
21
|
+
* @example Nested path from a dotted name
|
|
22
|
+
* `toFilePath('pet.petId') // 'pet/petId'`
|
|
23
|
+
*
|
|
24
|
+
* @example PascalCase the final segment
|
|
25
|
+
* `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`
|
|
26
|
+
*
|
|
27
|
+
* @example Suffix applied to the final segment only
|
|
28
|
+
* `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`
|
|
29
|
+
*/
|
|
30
|
+
function toFilePath(name, caseLast = require_components.camelCase) {
|
|
31
|
+
const parts = name.split(/\.(?=[a-zA-Z])/);
|
|
32
|
+
return parts.map((part, i) => i === parts.length - 1 ? caseLast(part) : require_components.camelCase(part)).filter(Boolean).join("/");
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region ../../internals/shared/src/group.ts
|
|
36
|
+
/**
|
|
37
|
+
* Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
|
|
38
|
+
* shared default naming so every plugin groups output consistently:
|
|
39
|
+
*
|
|
40
|
+
* - `path` groups use the second path segment (`/pet/findByStatus` → `pet`).
|
|
41
|
+
* - other groups use the camelCased group (`pet store` → `petStore`).
|
|
42
|
+
*
|
|
43
|
+
* A user-provided `group.name` always wins over the default namer, so callers stay in
|
|
44
|
+
* control of their output folders. Returns `null` when grouping is disabled, matching the
|
|
45
|
+
* per-plugin convention.
|
|
46
|
+
*
|
|
47
|
+
* @param group - The user-supplied group option, or `undefined` to disable grouping.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* createGroupConfig(group) // shared across every plugin
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
function createGroupConfig(group) {
|
|
55
|
+
if (!group) return null;
|
|
56
|
+
const defaultName = (ctx) => {
|
|
57
|
+
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
58
|
+
return require_components.camelCase(ctx.group);
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
...group,
|
|
62
|
+
name: group.name ? group.name : defaultName
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
10
66
|
//#region src/resolvers/resolverMsw.ts
|
|
11
67
|
/**
|
|
12
|
-
*
|
|
68
|
+
* Default resolver used by `@kubb/plugin-msw`. Decides the names and file
|
|
69
|
+
* paths for every generated MSW handler. Function names get a `Handler`
|
|
70
|
+
* suffix; the aggregate export is always `handlers`.
|
|
71
|
+
*
|
|
72
|
+
* @example Resolve a handler name
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { resolverMsw } from '@kubb/plugin-msw'
|
|
13
75
|
*
|
|
14
|
-
*
|
|
76
|
+
* resolverMsw.resolveName('addPet') // 'addPetHandler'
|
|
77
|
+
* ```
|
|
15
78
|
*/
|
|
16
|
-
const resolverMsw = (0, _kubb_core.defineResolver)((
|
|
79
|
+
const resolverMsw = (0, _kubb_core.defineResolver)(() => ({
|
|
17
80
|
name: "default",
|
|
18
81
|
pluginName: "plugin-msw",
|
|
19
82
|
default(name, type) {
|
|
20
|
-
return
|
|
83
|
+
return type === "file" ? toFilePath(name) : require_components.camelCase(name);
|
|
21
84
|
},
|
|
22
85
|
resolveName(name) {
|
|
23
86
|
return require_components.camelCase(name, { suffix: "handler" });
|
|
87
|
+
},
|
|
88
|
+
resolvePathName(name, type) {
|
|
89
|
+
return this.default(name, type);
|
|
90
|
+
},
|
|
91
|
+
resolveHandlerName(node) {
|
|
92
|
+
return this.resolveName(node.operationId);
|
|
93
|
+
},
|
|
94
|
+
resolveHandlersName() {
|
|
95
|
+
return "handlers";
|
|
24
96
|
}
|
|
25
97
|
}));
|
|
26
98
|
//#endregion
|
|
27
99
|
//#region src/plugin.ts
|
|
100
|
+
/**
|
|
101
|
+
* Canonical plugin name for `@kubb/plugin-msw`. Used for driver lookups and
|
|
102
|
+
* cross-plugin dependency references.
|
|
103
|
+
*/
|
|
28
104
|
const pluginMswName = "plugin-msw";
|
|
105
|
+
/**
|
|
106
|
+
* Generates MSW request handlers from an OpenAPI spec. Drop them into your
|
|
107
|
+
* test setup or service worker to mock the API end-to-end. Request path,
|
|
108
|
+
* method, status, and response body all stay in sync with the spec. Combine
|
|
109
|
+
* with `@kubb/plugin-faker` (via `parser: 'faker'`) to seed handlers with
|
|
110
|
+
* realistic data.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* import { defineConfig } from 'kubb'
|
|
115
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
116
|
+
* import { pluginMsw } from '@kubb/plugin-msw'
|
|
117
|
+
*
|
|
118
|
+
* export default defineConfig({
|
|
119
|
+
* input: { path: './petStore.yaml' },
|
|
120
|
+
* output: { path: './src/gen' },
|
|
121
|
+
* plugins: [
|
|
122
|
+
* pluginTs(),
|
|
123
|
+
* pluginMsw({
|
|
124
|
+
* output: { path: './handlers' },
|
|
125
|
+
* handlers: true,
|
|
126
|
+
* }),
|
|
127
|
+
* ],
|
|
128
|
+
* })
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
29
131
|
const pluginMsw = (0, _kubb_core.definePlugin)((options) => {
|
|
30
132
|
const { output = {
|
|
31
133
|
path: "handlers",
|
|
32
|
-
|
|
33
|
-
}, group, exclude = [], include, override = [],
|
|
34
|
-
const groupConfig = group
|
|
35
|
-
...group,
|
|
36
|
-
name: group.name ? group.name : (ctx) => {
|
|
37
|
-
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
38
|
-
return `${require_components.camelCase(ctx.group)}Controller`;
|
|
39
|
-
}
|
|
40
|
-
} : void 0;
|
|
134
|
+
barrel: { type: "named" }
|
|
135
|
+
}, group, exclude = [], include, override = [], handlers = false, parser = "data", baseURL, resolver: userResolver, transformer: userTransformer, generators: userGenerators = [] } = options;
|
|
136
|
+
const groupConfig = createGroupConfig(group);
|
|
41
137
|
return {
|
|
42
138
|
name: pluginMswName,
|
|
43
139
|
options,
|
|
44
|
-
dependencies: [_kubb_plugin_ts.pluginTsName, parser === "faker" ? _kubb_plugin_faker.pluginFakerName :
|
|
140
|
+
dependencies: [_kubb_plugin_ts.pluginTsName, parser === "faker" ? _kubb_plugin_faker.pluginFakerName : null].filter((dependency) => Boolean(dependency)),
|
|
45
141
|
hooks: { "kubb:plugin:setup"(ctx) {
|
|
46
142
|
const resolver = userResolver ? {
|
|
47
143
|
...resolverMsw,
|
|
@@ -56,7 +152,6 @@ const pluginMsw = (0, _kubb_core.definePlugin)((options) => {
|
|
|
56
152
|
include,
|
|
57
153
|
override,
|
|
58
154
|
handlers,
|
|
59
|
-
transformers,
|
|
60
155
|
resolver
|
|
61
156
|
});
|
|
62
157
|
ctx.setResolver(resolver);
|