@kubb/plugin-msw 5.0.0-alpha.9 → 5.0.0-beta.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.
Files changed (44) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +1 -3
  3. package/dist/components-CLQ77DVn.cjs +584 -0
  4. package/dist/components-CLQ77DVn.cjs.map +1 -0
  5. package/dist/components-vO0FIb2i.js +519 -0
  6. package/dist/components-vO0FIb2i.js.map +1 -0
  7. package/dist/components.cjs +1 -1
  8. package/dist/components.d.ts +17 -21
  9. package/dist/components.js +1 -1
  10. package/dist/generators-BPJCs1x1.js +176 -0
  11. package/dist/generators-BPJCs1x1.js.map +1 -0
  12. package/dist/generators-CrmMwWE4.cjs +186 -0
  13. package/dist/generators-CrmMwWE4.cjs.map +1 -0
  14. package/dist/generators.cjs +1 -1
  15. package/dist/generators.d.ts +4 -500
  16. package/dist/generators.js +1 -1
  17. package/dist/index.cjs +54 -65
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +4 -4
  20. package/dist/index.js +51 -65
  21. package/dist/index.js.map +1 -1
  22. package/dist/types-Dxu0KMQ4.d.ts +89 -0
  23. package/extension.yaml +260 -0
  24. package/package.json +59 -57
  25. package/src/components/Handlers.tsx +3 -3
  26. package/src/components/Mock.tsx +36 -28
  27. package/src/components/MockWithFaker.tsx +36 -24
  28. package/src/components/Response.tsx +23 -17
  29. package/src/generators/handlersGenerator.tsx +18 -18
  30. package/src/generators/mswGenerator.tsx +49 -60
  31. package/src/index.ts +1 -1
  32. package/src/plugin.ts +48 -85
  33. package/src/resolvers/resolverMsw.ts +19 -0
  34. package/src/types.ts +45 -22
  35. package/src/utils.ts +109 -0
  36. package/dist/components-8XBwMbFa.cjs +0 -343
  37. package/dist/components-8XBwMbFa.cjs.map +0 -1
  38. package/dist/components-DgtTZkWX.js +0 -277
  39. package/dist/components-DgtTZkWX.js.map +0 -1
  40. package/dist/generators-CY1SNd5X.cjs +0 -171
  41. package/dist/generators-CY1SNd5X.cjs.map +0 -1
  42. package/dist/generators-CvyZTxOm.js +0 -161
  43. package/dist/generators-CvyZTxOm.js.map +0 -1
  44. package/dist/types-MdHRNpgi.d.ts +0 -68
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { n as PluginMsw, t as Options } from "./types-MdHRNpgi.js";
3
- import * as _kubb_core0 from "@kubb/core";
2
+ import { n as PluginMsw, t as Options } from "./types-Dxu0KMQ4.js";
3
+ import * as _$_kubb_core0 from "@kubb/core";
4
4
 
5
5
  //#region src/plugin.d.ts
6
6
  declare const pluginMswName = "plugin-msw";
7
- declare const pluginMsw: (options?: Options | undefined) => _kubb_core0.UserPluginWithLifeCycle<PluginMsw>;
7
+ declare const pluginMsw: (options?: Options | undefined) => _$_kubb_core0.Plugin<PluginMsw>;
8
8
  //#endregion
9
- export { type PluginMsw, pluginMsw, pluginMswName };
9
+ export { type PluginMsw, pluginMsw as default, pluginMsw, pluginMswName };
10
10
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,84 +1,70 @@
1
1
  import "./chunk--u3MIqq1.js";
2
- import { a as camelCase } from "./components-DgtTZkWX.js";
3
- import { n as handlersGenerator, t as mswGenerator } from "./generators-CvyZTxOm.js";
4
- import path from "node:path";
5
- import { createPlugin, getBarrelFiles, getMode } from "@kubb/core";
2
+ import { l as camelCase } from "./components-vO0FIb2i.js";
3
+ import { n as handlersGenerator, t as mswGenerator } from "./generators-BPJCs1x1.js";
4
+ import { definePlugin, defineResolver } from "@kubb/core";
6
5
  import { pluginFakerName } from "@kubb/plugin-faker";
7
- import { OperationGenerator, pluginOasName } from "@kubb/plugin-oas";
8
6
  import { pluginTsName } from "@kubb/plugin-ts";
7
+ //#region src/resolvers/resolverMsw.ts
8
+ /**
9
+ * Naming convention resolver for MSW plugin.
10
+ *
11
+ * Provides default naming helpers using camelCase with a `handler` suffix.
12
+ */
13
+ const resolverMsw = defineResolver((_ctx) => ({
14
+ name: "default",
15
+ pluginName: "plugin-msw",
16
+ default(name, type) {
17
+ return camelCase(name, { isFile: type === "file" });
18
+ },
19
+ resolveName(name) {
20
+ return camelCase(name, { suffix: "handler" });
21
+ }
22
+ }));
23
+ //#endregion
9
24
  //#region src/plugin.ts
10
25
  const pluginMswName = "plugin-msw";
11
- const pluginMsw = createPlugin((options) => {
26
+ const pluginMsw = definePlugin((options) => {
12
27
  const { output = {
13
28
  path: "handlers",
14
29
  barrelType: "named"
15
- }, group, exclude = [], include, override = [], transformers = {}, handlers = false, parser = "data", generators = [mswGenerator, handlers ? handlersGenerator : void 0].filter(Boolean), contentType, baseURL } = options;
30
+ }, group, exclude = [], include, override = [], transformers = {}, handlers = false, parser = "data", baseURL, resolver: userResolver, transformer: userTransformer, generators: userGenerators = [] } = options;
31
+ const groupConfig = group ? {
32
+ ...group,
33
+ name: group.name ? group.name : (ctx) => {
34
+ if (group.type === "path") return `${ctx.group.split("/")[1]}`;
35
+ return `${camelCase(ctx.group)}Controller`;
36
+ }
37
+ } : void 0;
16
38
  return {
17
39
  name: pluginMswName,
18
- options: {
19
- output,
20
- parser,
21
- group,
22
- baseURL
23
- },
24
- pre: [
25
- pluginOasName,
26
- pluginTsName,
27
- parser === "faker" ? pluginFakerName : void 0
28
- ].filter(Boolean),
29
- resolvePath(baseName, pathMode, options) {
30
- const root = path.resolve(this.config.root, this.config.output.path);
31
- if ((pathMode ?? getMode(path.resolve(root, output.path))) === "single")
32
- /**
33
- * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
34
- * Other plugins then need to call addOrAppend instead of just add from the fileManager class
35
- */
36
- return path.resolve(root, output.path);
37
- if (group && (options?.group?.path || options?.group?.tag)) {
38
- const groupName = group?.name ? group.name : (ctx) => {
39
- if (group?.type === "path") return `${ctx.group.split("/")[1]}`;
40
- return `${camelCase(ctx.group)}Controller`;
41
- };
42
- return path.resolve(root, output.path, groupName({ group: group.type === "path" ? options.group.path : options.group.tag }), baseName);
43
- }
44
- return path.resolve(root, output.path, baseName);
45
- },
46
- resolveName(name, type) {
47
- const resolvedName = camelCase(name, {
48
- suffix: type ? "handler" : void 0,
49
- isFile: type === "file"
50
- });
51
- if (type) return transformers?.name?.(resolvedName, type) || resolvedName;
52
- return resolvedName;
53
- },
54
- async install() {
55
- const root = path.resolve(this.config.root, this.config.output.path);
56
- const mode = getMode(path.resolve(root, output.path));
57
- const oas = await this.getOas();
58
- const files = await new OperationGenerator(this.plugin.options, {
59
- fabric: this.fabric,
60
- oas,
61
- driver: this.driver,
62
- events: this.events,
63
- plugin: this.plugin,
64
- contentType,
40
+ options,
41
+ dependencies: [pluginTsName, parser === "faker" ? pluginFakerName : void 0].filter(Boolean),
42
+ hooks: { "kubb:plugin:setup"(ctx) {
43
+ const resolver = userResolver ? {
44
+ ...resolverMsw,
45
+ ...userResolver
46
+ } : resolverMsw;
47
+ ctx.setOptions({
48
+ output,
49
+ parser,
50
+ baseURL,
51
+ group: groupConfig,
65
52
  exclude,
66
53
  include,
67
54
  override,
68
- mode
69
- }).build(...generators);
70
- await this.upsertFile(...files);
71
- const barrelFiles = await getBarrelFiles(this.fabric.files, {
72
- type: output.barrelType ?? "named",
73
- root,
74
- output,
75
- meta: { pluginName: this.plugin.name }
55
+ handlers,
56
+ transformers,
57
+ resolver
76
58
  });
77
- await this.upsertFile(...barrelFiles);
78
- }
59
+ ctx.setResolver(resolver);
60
+ if (userTransformer) ctx.setTransformer(userTransformer);
61
+ ctx.addGenerator(mswGenerator);
62
+ if (handlers) ctx.addGenerator(handlersGenerator);
63
+ for (const gen of userGenerators) ctx.addGenerator(gen);
64
+ } }
79
65
  };
80
66
  });
81
67
  //#endregion
82
- export { pluginMsw, pluginMswName };
68
+ export { pluginMsw as default, pluginMsw, pluginMswName };
83
69
 
84
70
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport { createPlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = createPlugin<PluginMsw>((options) => {\n const {\n output = { path: 'handlers', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n handlers = false,\n parser = 'data',\n generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),\n contentType,\n baseURL,\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n parser,\n group,\n baseURL,\n },\n pre: [pluginOasName, pluginTsName, parser === 'faker' ? pluginFakerName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\n })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n driver: this.driver,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.upsertFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginName: this.plugin.name,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;AASA,MAAa,gBAAgB;AAE7B,MAAa,YAAY,cAAyB,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAY,YAAY;EAAS,EAClD,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,eAAe,EAAE,EACjB,WAAW,OACX,SAAS,QACT,aAAa,CAAC,cAAc,WAAW,oBAAoB,KAAA,EAAU,CAAC,OAAO,QAAQ,EACrF,aACA,YACE;AAEJ,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA;GACA;GACA;GACD;EACD,KAAK;GAAC;GAAe;GAAc,WAAW,UAAU,kBAAkB,KAAA;GAAU,CAAC,OAAO,QAAQ;EACpG,YAAY,UAAU,UAAU,SAAS;GACvC,MAAM,OAAO,KAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;AAGpE,QAFa,YAAY,QAAQ,KAAK,QAAQ,MAAM,OAAO,KAAK,CAAC,MAEpD;;;;;AAKX,UAAO,KAAK,QAAQ,MAAM,OAAO,KAAK;AAGxC,OAAI,UAAU,SAAS,OAAO,QAAQ,SAAS,OAAO,MAAM;IAC1D,MAAM,YAA2B,OAAO,OACpC,MAAM,QACL,QAAQ;AACP,SAAI,OAAO,SAAS,OAClB,QAAO,GAAG,IAAI,MAAM,MAAM,IAAI,CAAC;AAEjC,YAAO,GAAG,UAAU,IAAI,MAAM,CAAC;;AAGrC,WAAO,KAAK,QACV,MACA,OAAO,MACP,UAAU,EACR,OAAO,MAAM,SAAS,SAAS,QAAQ,MAAM,OAAQ,QAAQ,MAAM,KACpE,CAAC,EACF,SACD;;AAGH,UAAO,KAAK,QAAQ,MAAM,OAAO,MAAM,SAAS;;EAElD,YAAY,MAAM,MAAM;GACtB,MAAM,eAAe,UAAU,MAAM;IACnC,QAAQ,OAAO,YAAY,KAAA;IAC3B,QAAQ,SAAS;IAClB,CAAC;AAEF,OAAI,KACF,QAAO,cAAc,OAAO,cAAc,KAAK,IAAI;AAGrD,UAAO;;EAET,MAAM,UAAU;GACd,MAAM,OAAO,KAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;GACpE,MAAM,OAAO,QAAQ,KAAK,QAAQ,MAAM,OAAO,KAAK,CAAC;GACrD,MAAM,MAAM,MAAM,KAAK,QAAQ;GAe/B,MAAM,QAAQ,MAba,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAEqC,MAAM,GAAG,WAAW;AAC3D,SAAM,KAAK,WAAW,GAAG,MAAM;GAE/B,MAAM,cAAc,MAAM,eAAe,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,YAAY,KAAK,OAAO,MACzB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/resolvers/resolverMsw.ts","../src/plugin.ts"],"sourcesContent":["import { camelCase } from '@internals/utils'\nimport { defineResolver } from '@kubb/core'\nimport type { PluginMsw } from '../types.ts'\n\n/**\n * Naming convention resolver for MSW plugin.\n *\n * Provides default naming helpers using camelCase with a `handler` suffix.\n */\nexport const resolverMsw = defineResolver<PluginMsw>((_ctx) => ({\n name: 'default',\n pluginName: 'plugin-msw',\n default(name, type) {\n return camelCase(name, { isFile: type === 'file' })\n },\n resolveName(name) {\n return camelCase(name, { suffix: 'handler' })\n },\n}))\n","import { camelCase } from '@internals/utils'\nimport { definePlugin, type Group } from '@kubb/core'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport { resolverMsw } from './resolvers/resolverMsw.ts'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = definePlugin<PluginMsw>((options) => {\n const {\n output = { path: 'handlers', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n handlers = false,\n parser = 'data',\n baseURL,\n resolver: userResolver,\n transformer: userTransformer,\n generators: userGenerators = [],\n } = options\n\n const groupConfig = group\n ? ({\n ...group,\n name: group.name\n ? group.name\n : (ctx: { group: string }) => {\n if (group.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n },\n } satisfies Group)\n : undefined\n\n return {\n name: pluginMswName,\n options,\n dependencies: [pluginTsName, parser === 'faker' ? pluginFakerName : undefined].filter(Boolean),\n hooks: {\n 'kubb:plugin:setup'(ctx) {\n const resolver = userResolver ? { ...resolverMsw, ...userResolver } : resolverMsw\n\n ctx.setOptions({\n output,\n parser,\n baseURL,\n group: groupConfig,\n exclude,\n include,\n override,\n handlers,\n transformers,\n resolver,\n })\n ctx.setResolver(resolver)\n if (userTransformer) {\n ctx.setTransformer(userTransformer)\n }\n\n ctx.addGenerator(mswGenerator)\n if (handlers) {\n ctx.addGenerator(handlersGenerator)\n }\n for (const gen of userGenerators) {\n ctx.addGenerator(gen)\n }\n },\n },\n }\n})\n\nexport default pluginMsw\n"],"mappings":";;;;;;;;;;;;AASA,MAAa,cAAc,gBAA2B,UAAU;CAC9D,MAAM;CACN,YAAY;CACZ,QAAQ,MAAM,MAAM;AAClB,SAAO,UAAU,MAAM,EAAE,QAAQ,SAAS,QAAQ,CAAC;;CAErD,YAAY,MAAM;AAChB,SAAO,UAAU,MAAM,EAAE,QAAQ,WAAW,CAAC;;CAEhD,EAAE;;;ACVH,MAAa,gBAAgB;AAE7B,MAAa,YAAY,cAAyB,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAY,YAAY;EAAS,EAClD,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,eAAe,EAAE,EACjB,WAAW,OACX,SAAS,QACT,SACA,UAAU,cACV,aAAa,iBACb,YAAY,iBAAiB,EAAE,KAC7B;CAEJ,MAAM,cAAc,QACf;EACC,GAAG;EACH,MAAM,MAAM,OACR,MAAM,QACL,QAA2B;AAC1B,OAAI,MAAM,SAAS,OACjB,QAAO,GAAG,IAAI,MAAM,MAAM,IAAI,CAAC;AAEjC,UAAO,GAAG,UAAU,IAAI,MAAM,CAAC;;EAEtC,GACD,KAAA;AAEJ,QAAO;EACL,MAAM;EACN;EACA,cAAc,CAAC,cAAc,WAAW,UAAU,kBAAkB,KAAA,EAAU,CAAC,OAAO,QAAQ;EAC9F,OAAO,EACL,oBAAoB,KAAK;GACvB,MAAM,WAAW,eAAe;IAAE,GAAG;IAAa,GAAG;IAAc,GAAG;AAEtE,OAAI,WAAW;IACb;IACA;IACA;IACA,OAAO;IACP;IACA;IACA;IACA;IACA;IACA;IACD,CAAC;AACF,OAAI,YAAY,SAAS;AACzB,OAAI,gBACF,KAAI,eAAe,gBAAgB;AAGrC,OAAI,aAAa,aAAa;AAC9B,OAAI,SACF,KAAI,aAAa,kBAAkB;AAErC,QAAK,MAAM,OAAO,eAChB,KAAI,aAAa,IAAI;KAG1B;EACF;EACD"}
@@ -0,0 +1,89 @@
1
+ import { t as __name } from "./chunk--u3MIqq1.js";
2
+ import { Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, ResolveNameParams, Resolver, ast } from "@kubb/core";
3
+
4
+ //#region src/types.d.ts
5
+ /**
6
+ * Resolver for MSW that provides naming methods for handler functions.
7
+ */
8
+ type ResolverMsw = Resolver & {
9
+ /**
10
+ * Resolves the handler function name for an operation.
11
+ */
12
+ resolveName(this: ResolverMsw, name: string): string;
13
+ };
14
+ type Options = {
15
+ /**
16
+ * Specify the export location for the files and define the behavior of the output
17
+ * @default { path: 'handlers', barrelType: 'named' }
18
+ */
19
+ output?: Output;
20
+ baseURL?: string;
21
+ /**
22
+ * Group the MSW mocks based on the provided name.
23
+ */
24
+ group?: Group;
25
+ /**
26
+ * Tags, operations, or paths to exclude from generation.
27
+ */
28
+ exclude?: Array<Exclude>;
29
+ /**
30
+ * Tags, operations, or paths to include in generation.
31
+ */
32
+ include?: Array<Include>;
33
+ /**
34
+ * Override options for specific tags, operations, or paths.
35
+ */
36
+ override?: Array<Override<ResolvedOptions>>;
37
+ transformers?: {
38
+ /**
39
+ * Override the default naming for handlers.
40
+ */
41
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
42
+ };
43
+ /**
44
+ * Override naming conventions for function names and types.
45
+ */
46
+ resolver?: Partial<ResolverMsw> & ThisType<ResolverMsw>;
47
+ /**
48
+ * AST visitor to transform generated nodes.
49
+ */
50
+ transformer?: ast.Visitor;
51
+ /**
52
+ * Create `handlers.ts` file with all handlers grouped by methods.
53
+ * @default false
54
+ */
55
+ handlers?: boolean;
56
+ /**
57
+ * Which parser to use for generating response data.
58
+ *
59
+ * @default 'data'
60
+ */
61
+ parser?: 'data' | 'faker';
62
+ /**
63
+ * Additional generators alongside the default generators.
64
+ */
65
+ generators?: Array<Generator<PluginMsw>>;
66
+ };
67
+ type ResolvedOptions = {
68
+ output: Output;
69
+ group: Group | undefined;
70
+ exclude: NonNullable<Options['exclude']>;
71
+ include: Options['include'];
72
+ override: NonNullable<Options['override']>;
73
+ parser: NonNullable<Options['parser']>;
74
+ baseURL: Options['baseURL'] | undefined;
75
+ handlers: boolean;
76
+ transformers: NonNullable<Options['transformers']>;
77
+ resolver: ResolverMsw;
78
+ };
79
+ type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, ResolverMsw>;
80
+ declare global {
81
+ namespace Kubb {
82
+ interface PluginRegistry {
83
+ 'plugin-msw': PluginMsw;
84
+ }
85
+ }
86
+ }
87
+ //#endregion
88
+ export { PluginMsw as n, Options as t };
89
+ //# sourceMappingURL=types-Dxu0KMQ4.d.ts.map
package/extension.yaml ADDED
@@ -0,0 +1,260 @@
1
+ $schema: https://kubb.dev/schemas/extension.json
2
+ kind: plugin
3
+ id: plugin-msw
4
+ name: MSW
5
+ description: Generate Mock Service Worker (MSW) handlers from OpenAPI specifications.
6
+ category: mocks
7
+ type: official
8
+ npmPackage: "@kubb/plugin-msw"
9
+ docsPath: /plugins/plugin-msw
10
+ repo: https://github.com/kubb-labs/plugins
11
+ maintainers:
12
+ - name: Stijn Van Hulle
13
+ github: stijnvanhulle
14
+ compatibility:
15
+ kubb: ">=5.0.0"
16
+ node: ">=22"
17
+ tags:
18
+ - msw
19
+ - mock-service-worker
20
+ - api-mocking
21
+ - mocks
22
+ - testing
23
+ - codegen
24
+ - openapi
25
+ dependencies:
26
+ - plugin-ts
27
+ - plugin-faker
28
+ resources:
29
+ documentation: https://kubb.dev/plugins/plugin-msw
30
+ repository: https://github.com/kubb-labs/plugins
31
+ issues: https://github.com/kubb-labs/plugins/issues
32
+ changelog: https://github.com/kubb-labs/plugins/blob/main/packages/plugin-msw/CHANGELOG.md
33
+ codesandbox: https://codesandbox.io/p/github/kubb-labs/plugins/main/examples/msw
34
+ featured: false
35
+ icon:
36
+ light: https://kubb.dev/feature/msw.svg
37
+ intro: |
38
+ # @kubb/plugin-msw
39
+
40
+ Generate [MSW](https://mswjs.io/) API mock handlers from your OpenAPI schema. Mock API requests in development and tests with type-safe handlers.
41
+ options:
42
+ - name: output
43
+ type: Output
44
+ required: false
45
+ default: "{ path: 'handlers', barrelType: 'named' }"
46
+ description: Specify the export location for the files and define the behavior of the output.
47
+ properties:
48
+ - name: path
49
+ type: string
50
+ required: true
51
+ description: Output directory or file for the generated code, relative to the global `output.path`.
52
+ tip: |
53
+ if `output.path` is a file, `group` cannot be used.
54
+ default: "'handlers'"
55
+ - name: barrelType
56
+ type: "'all' | 'named' | 'propagate' | false"
57
+ required: false
58
+ default: "'named'"
59
+ description: Specify what to export and optionally disable barrel-file generation.
60
+ tip: |
61
+ Using `propagate` will prevent a plugin from creating a barrel file, but it will still propagate, allowing [`output.barrelType`](https://kubb.dev/docs/5.x/configuration#output-barreltype) to export the specific function or type.
62
+ examples:
63
+ - name: all
64
+ files:
65
+ - lang: typescript
66
+ code: |
67
+ export * from './gen/petService.ts'
68
+ twoslash: false
69
+ - name: named
70
+ files:
71
+ - lang: typescript
72
+ code: |
73
+ export { PetService } from './gen/petService.ts'
74
+ twoslash: false
75
+ - name: propagate
76
+ files:
77
+ - lang: typescript
78
+ code: ""
79
+ twoslash: false
80
+ - name: "false"
81
+ files:
82
+ - lang: typescript
83
+ code: ""
84
+ twoslash: false
85
+ - name: banner
86
+ type: "string | ((node: RootNode) => string)"
87
+ required: false
88
+ description: Add a banner comment at the top of every generated file. Accepts a static string or a function that receives the `RootNode` and returns a string.
89
+ - name: footer
90
+ type: "string | ((node: RootNode) => string)"
91
+ required: false
92
+ description: Add a footer comment at the end of every generated file. Accepts a static string or a function that receives the `RootNode` and returns a string.
93
+ - name: override
94
+ type: boolean
95
+ required: false
96
+ default: "false"
97
+ description: Whether Kubb overrides existing external files that can be generated if they already exist.
98
+ - name: handlers
99
+ type: boolean
100
+ required: false
101
+ default: "false"
102
+ description: Create a `handlers.ts` file with all handlers grouped by methods.
103
+ - name: contentType
104
+ type: "'application/json' | (string & {})"
105
+ required: false
106
+ description: |
107
+ Define which content type to use.
108
+
109
+ By default, Kubb uses the first JSON-valid media type.
110
+ - name: baseURL
111
+ type: string
112
+ required: false
113
+ description: Sets a custom base URL for all generated calls. When not set, the base URL is automatically taken from the OAS spec via the adapter (e.g. the `servers[0].url` field).
114
+ - name: group
115
+ type: Group
116
+ required: false
117
+ description: |
118
+ Grouping combines files in a folder based on a specific `type`.
119
+ examples:
120
+ - name: kubb.config.ts
121
+ files:
122
+ - lang: typescript
123
+ code: |
124
+ group: {
125
+ type: 'tag',
126
+ name({ group }) {
127
+ return `${group}Controller`
128
+ }
129
+ }
130
+ twoslash: false
131
+ body: |
132
+ With the configuration above, the generator emits:
133
+
134
+ ```text
135
+ .
136
+ ├── src/
137
+ │ └── petController/
138
+ │ │ ├── addPet.ts
139
+ │ │ └── getPet.ts
140
+ │ └── storeController/
141
+ │ ├── createStore.ts
142
+ │ └── getStoreById.ts
143
+ ├── petStore.yaml
144
+ ├── kubb.config.ts
145
+ └── package.json
146
+ ```
147
+ properties:
148
+ - name: type
149
+ type: "'tag'"
150
+ required: true
151
+ description: Specify the property to group files by. Required when `group` is defined.
152
+ note: |
153
+ `Required: true*` means this is required only when the `group` option is used. The `group` option itself is optional.
154
+ body: |
155
+ - `'tag'`: Uses the first tag from `operation.getTags().at(0)?.name`
156
+ - name: name
157
+ type: "(context: GroupContext) => string"
158
+ required: false
159
+ default: (ctx) => `${ctx.group}Controller`
160
+ description: Return the name of a group based on the group name. This is used for file and identifier generation.
161
+ - name: parser
162
+ type: "'data' | 'faker'"
163
+ required: false
164
+ default: "'data'"
165
+ description: Choose which parser to use when generating response data.
166
+ body: |
167
+ - `'faker'` will use `@kubb/plugin-faker` to generate the data for the response.
168
+ - `'data'` will use your custom data to generate the data for the response.
169
+ - name: include
170
+ type: Array<Include>
171
+ required: false
172
+ description: Array containing include parameters to include tags, operations, methods, paths, or content types.
173
+ codeBlock:
174
+ lang: typescript
175
+ title: Include
176
+ code: |
177
+ export type Include = {
178
+ type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
179
+ pattern: string | RegExp
180
+ }
181
+ - name: exclude
182
+ type: Array<Exclude>
183
+ required: false
184
+ description: Array containing exclude parameters to exclude or skip tags, operations, methods, paths, or content types.
185
+ codeBlock:
186
+ lang: typescript
187
+ title: Exclude
188
+ code: |
189
+ export type Exclude = {
190
+ type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
191
+ pattern: string | RegExp
192
+ }
193
+ - name: override
194
+ type: Array<Override>
195
+ required: false
196
+ description: Array containing override parameters to override `options` based on tags, operations, methods, paths, or content types.
197
+ codeBlock:
198
+ lang: typescript
199
+ title: Override
200
+ code: |
201
+ export type Override = {
202
+ type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
203
+ pattern: string | RegExp
204
+ options: PluginOptions
205
+ }
206
+ - name: generators
207
+ type: Array<Generator<PluginMsw>>
208
+ required: false
209
+ experimental: true
210
+ description: |
211
+ Define additional generators next to the built-in generators.
212
+
213
+ See [Generators](https://kubb.dev/docs/5.x/guides/creating-plugins) for more information on how to use generators.
214
+ - name: transformers
215
+ type: object
216
+ required: false
217
+ description: Customize the generated names based on the type provided by the plugin.
218
+ properties:
219
+ - name: name
220
+ type: "(name: string, type?: ResolveType) => string"
221
+ required: false
222
+ description: Customize the names based on the type that is provided by the plugin.
223
+ codeBlock:
224
+ lang: typescript
225
+ code: |
226
+ type ResolveType = 'file' | 'function' | 'type' | 'const'
227
+ examples:
228
+ - name: kubb.config.ts
229
+ files:
230
+ - lang: typescript
231
+ code: |
232
+ import { defineConfig } from 'kubb'
233
+ import { pluginMsw } from '@kubb/plugin-msw'
234
+ import { pluginTs } from '@kubb/plugin-ts'
235
+
236
+ export default defineConfig({
237
+ input: {
238
+ path: './petStore.yaml',
239
+ },
240
+ output: {
241
+ path: './src/gen',
242
+ },
243
+ plugins: [
244
+ pluginTs(),
245
+ pluginMsw({
246
+ output: {
247
+ path: './mocks',
248
+ barrelType: 'named',
249
+ banner: '/* eslint-disable no-alert, no-console */',
250
+ footer: '',
251
+ },
252
+ group: {
253
+ type: 'tag',
254
+ name: ({ group }) => `${group}Service`,
255
+ },
256
+ handlers: true,
257
+ }),
258
+ ],
259
+ })
260
+ twoslash: false