@kubb/plugin-msw 4.4.1 → 4.5.1

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.
@@ -23,11 +23,22 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
23
  //#endregion
24
24
  let __kubb_react_fabric = require("@kubb/react-fabric");
25
25
  __kubb_react_fabric = __toESM(__kubb_react_fabric);
26
- let __kubb_core_utils = require("@kubb/core/utils");
27
- __kubb_core_utils = __toESM(__kubb_core_utils);
28
26
  let __kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
29
27
  __kubb_react_fabric_jsx_runtime = __toESM(__kubb_react_fabric_jsx_runtime);
28
+ let __kubb_core_utils = require("@kubb/core/utils");
29
+ __kubb_core_utils = __toESM(__kubb_core_utils);
30
+
31
+ //#region src/components/Handlers.tsx
32
+ function Handlers({ name, handlers }) {
33
+ return /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Source, {
34
+ name,
35
+ isIndexable: true,
36
+ isExportable: true,
37
+ children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const`
38
+ });
39
+ }
30
40
 
41
+ //#endregion
31
42
  //#region src/components/Mock.tsx
32
43
  function Mock({ baseURL = "", name, typeName, operation }) {
33
44
  const method = operation.method;
@@ -66,17 +77,6 @@ function Mock({ baseURL = "", name, typeName, operation }) {
66
77
  });
67
78
  }
68
79
 
69
- //#endregion
70
- //#region src/components/Handlers.tsx
71
- function Handlers({ name, handlers }) {
72
- return /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Source, {
73
- name,
74
- isIndexable: true,
75
- isExportable: true,
76
- children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const`
77
- });
78
- }
79
-
80
80
  //#endregion
81
81
  //#region src/components/MockWithFaker.tsx
82
82
  function MockWithFaker({ baseURL = "", name, fakerName, typeName, operation }) {
@@ -177,4 +177,4 @@ Object.defineProperty(exports, '__toESM', {
177
177
  return __toESM;
178
178
  }
179
179
  });
180
- //# sourceMappingURL=components-DhZ1MTrg.cjs.map
180
+ //# sourceMappingURL=components-DsnoNtPq.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components-DsnoNtPq.cjs","names":["File","URLPath","FunctionParams","File","Function","URLPath","FunctionParams","File","Function","FunctionParams","File","Function"],"sources":["../src/components/Handlers.tsx","../src/components/Mock.tsx","../src/components/MockWithFaker.tsx","../src/components/Response.tsx"],"sourcesContent":["import { File } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\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): KubbNode {\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'\nimport type { OasTypes, Operation } from '@kubb/oas'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\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): KubbNode {\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 hasResponseSchema = contentType && responseObject?.content?.[contentType]?.schema !== undefined\n\n // If no response schema, uses any type but function to avoid overriding callback\n const dataType = hasResponseSchema ? typeName : 'string | number | boolean | null | object'\n\n const params = FunctionParams.factory({\n data: {\n type: `${dataType} | ((\n info: Parameters<Parameters<typeof http.${method}>[1]>[0],\n ) => Response | Promise<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 { URLPath } from '@kubb/core/utils'\n\nimport type { OasTypes, Operation } from '@kubb/oas'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\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): KubbNode {\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 | Promise<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","import type { OasTypes, Operation } from '@kubb/oas'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\n\ntype Props = {\n typeName: string\n operation: Operation\n name: string\n statusCode: number\n}\n\nexport function Response({ name, typeName, operation, statusCode }: Props): KubbNode {\n const responseObject = operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject\n const contentType = Object.keys(responseObject.content || {})?.[0]\n\n const headers = [contentType ? `'Content-Type': '${contentType}'` : undefined].filter(Boolean)\n\n const hasResponseSchema = contentType && responseObject?.content?.[contentType]?.schema !== undefined\n\n const params = FunctionParams.factory({\n data: {\n type: `${typeName}`,\n optional: !hasResponseSchema,\n },\n })\n\n const responseName = `${name}Response${statusCode}`\n\n return (\n <File.Source name={responseName} isIndexable isExportable>\n <Function name={responseName} export params={params.toConstructor()}>\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 </Function>\n </File.Source>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,SAAgB,SAAS,EAAE,MAAM,YAAqC;AACpE,QACE,yDAACA,yBAAK;EAAa;EAAM;EAAY;YAClC,gBAAgB,KAAK,KAAK,KAAK,UAAU,SAAS,CAAC,WAAW,KAAK,GAAG,CAAC;GAC5D;;;;;ACAlB,SAAgB,KAAK,EAAE,UAAU,IAAI,MAAM,UAAU,aAA8B;CACjF,MAAM,SAAS,UAAU;CACzB,MAAM,qBAAqB,UAAU,wBAAwB,CAAC,QAAQ,SAAS,KAAK,WAAW,IAAI,CAAC;CACpG,MAAM,a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,QAAQ;CAE9F,MAAM,SAASC,mCAAe,QAAQ,EACpC,MAAM;EACJ,MAAM,GAAG,SAAS;kDAC0B,OAAO;;EAEnD,UAAU;EACX,EACF,CAAC;AAEF,QACE,yDAACC,yBAAK;EAAa;EAAM;EAAY;YACnC,yDAACC;GAAe;GAAM;GAAO,QAAQ,OAAO,eAAe;aACxD,eAAe,OAAO,IAAI,UAAU,IAAI,QAAQ,YAAY,UAAU,CAAC;;;iDAG/B,UAAU;gBAC3C,WAAW;QAEnB,QAAQ,SACJ;UACF,QAAQ,KAAK,OAAO,CAAC;YAEnB,GACL;;;IAGU;GACC;;;;;AC5ClB,SAAgB,SAAS,EAAE,MAAM,UAAU,WAAW,cAA+B;CACnF,MAAM,iBAAiB,UAAU,wBAAwB,WAAW;CACpE,MAAM,cAAc,OAAO,KAAK,eAAe,WAAW,EAAE,CAAC,GAAG;CAEhE,MAAM,UAAU,CAAC,cAAc,oBAAoB,YAAY,KAAK,OAAU,CAAC,OAAO,QAAQ;CAE9F,MAAM,oBAAoB,eAAe,gBAAgB,UAAU,cAAc,WAAW;CAE5F,MAAM,SAASC,mCAAe,QAAQ,EACpC,MAAM;EACJ,MAAM,GAAG;EACT,UAAU,CAAC;EACZ,EACF,CAAC;CAEF,MAAM,eAAe,GAAG,KAAK,UAAU;AAEvC,QACE,yDAACC,yBAAK;EAAO,MAAM;EAAc;EAAY;YAC3C,yDAACC;GAAS,MAAM;GAAc;GAAO,QAAQ,OAAO,eAAe;aAChE;;gBAEO,WAAW;QAEnB,QAAQ,SACJ;UACF,QAAQ,KAAK,OAAO,CAAC;YAEnB,GACL;;IAEU;GACC"}
@@ -1,7 +1,18 @@
1
1
  import { File, Function, FunctionParams } from "@kubb/react-fabric";
2
- import { URLPath } from "@kubb/core/utils";
3
2
  import { jsx } from "@kubb/react-fabric/jsx-runtime";
3
+ import { URLPath } from "@kubb/core/utils";
4
+
5
+ //#region src/components/Handlers.tsx
6
+ function Handlers({ name, handlers }) {
7
+ return /* @__PURE__ */ jsx(File.Source, {
8
+ name,
9
+ isIndexable: true,
10
+ isExportable: true,
11
+ children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const`
12
+ });
13
+ }
4
14
 
15
+ //#endregion
5
16
  //#region src/components/Mock.tsx
6
17
  function Mock({ baseURL = "", name, typeName, operation }) {
7
18
  const method = operation.method;
@@ -40,17 +51,6 @@ function Mock({ baseURL = "", name, typeName, operation }) {
40
51
  });
41
52
  }
42
53
 
43
- //#endregion
44
- //#region src/components/Handlers.tsx
45
- function Handlers({ name, handlers }) {
46
- return /* @__PURE__ */ jsx(File.Source, {
47
- name,
48
- isIndexable: true,
49
- isExportable: true,
50
- children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const`
51
- });
52
- }
53
-
54
54
  //#endregion
55
55
  //#region src/components/MockWithFaker.tsx
56
56
  function MockWithFaker({ baseURL = "", name, fakerName, typeName, operation }) {
@@ -121,5 +121,5 @@ function Response({ name, typeName, operation, statusCode }) {
121
121
  }
122
122
 
123
123
  //#endregion
124
- export { Mock as i, MockWithFaker as n, Handlers as r, Response as t };
125
- //# sourceMappingURL=components-C1RVylIl.js.map
124
+ export { Handlers as i, MockWithFaker as n, Mock as r, Response as t };
125
+ //# sourceMappingURL=components-IvRPRy3j.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components-IvRPRy3j.js","names":[],"sources":["../src/components/Handlers.tsx","../src/components/Mock.tsx","../src/components/MockWithFaker.tsx","../src/components/Response.tsx"],"sourcesContent":["import { File } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\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): KubbNode {\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'\nimport type { OasTypes, Operation } from '@kubb/oas'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\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): KubbNode {\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 hasResponseSchema = contentType && responseObject?.content?.[contentType]?.schema !== undefined\n\n // If no response schema, uses any type but function to avoid overriding callback\n const dataType = hasResponseSchema ? typeName : 'string | number | boolean | null | object'\n\n const params = FunctionParams.factory({\n data: {\n type: `${dataType} | ((\n info: Parameters<Parameters<typeof http.${method}>[1]>[0],\n ) => Response | Promise<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 { URLPath } from '@kubb/core/utils'\n\nimport type { OasTypes, Operation } from '@kubb/oas'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\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): KubbNode {\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 | Promise<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","import type { OasTypes, Operation } from '@kubb/oas'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\n\ntype Props = {\n typeName: string\n operation: Operation\n name: string\n statusCode: number\n}\n\nexport function Response({ name, typeName, operation, statusCode }: Props): KubbNode {\n const responseObject = operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject\n const contentType = Object.keys(responseObject.content || {})?.[0]\n\n const headers = [contentType ? `'Content-Type': '${contentType}'` : undefined].filter(Boolean)\n\n const hasResponseSchema = contentType && responseObject?.content?.[contentType]?.schema !== undefined\n\n const params = FunctionParams.factory({\n data: {\n type: `${typeName}`,\n optional: !hasResponseSchema,\n },\n })\n\n const responseName = `${name}Response${statusCode}`\n\n return (\n <File.Source name={responseName} isIndexable isExportable>\n <Function name={responseName} export params={params.toConstructor()}>\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 </Function>\n </File.Source>\n )\n}\n"],"mappings":";;;;;AAYA,SAAgB,SAAS,EAAE,MAAM,YAAqC;AACpE,QACE,oBAAC,KAAK;EAAa;EAAM;EAAY;YAClC,gBAAgB,KAAK,KAAK,KAAK,UAAU,SAAS,CAAC,WAAW,KAAK,GAAG,CAAC;GAC5D;;;;;ACAlB,SAAgB,KAAK,EAAE,UAAU,IAAI,MAAM,UAAU,aAA8B;CACjF,MAAM,SAAS,UAAU;CACzB,MAAM,qBAAqB,UAAU,wBAAwB,CAAC,QAAQ,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,EAAE,CAAC,GAAG;CAChE,MAAM,MAAM,IAAI,QAAQ,UAAU,KAAK,CAAC,WAAW,CAAC,QAAQ,YAAY,UAAU;CAElF,MAAM,UAAU,CAAC,cAAc,oBAAoB,YAAY,KAAK,OAAU,CAAC,OAAO,QAAQ;CAK9F,MAAM,WAHoB,eAAe,gBAAgB,UAAU,cAAc,WAAW,SAGvD,WAAW;CAEhD,MAAM,SAAS,eAAe,QAAQ,EACpC,MAAM;EACJ,MAAM,GAAG,SAAS;kDAC0B,OAAO;;EAEnD,UAAU;EACX,EACF,CAAC;AAEF,QACE,oBAAC,KAAK;EAAa;EAAM;EAAY;YACnC,oBAAC;GAAe;GAAM;GAAO,QAAQ,OAAO,eAAe;aACxD,eAAe,OAAO,IAAI,UAAU,IAAI,QAAQ,YAAY,UAAU,CAAC;;;;gBAIhE,WAAW;QAEnB,QAAQ,SACJ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AS,eAAe,QAAQ,EACpC,MAAM;EACJ,MAAM,GAAG;EACT,UAAU,CAAC;EACZ,EACF,CAAC;CAEF,MAAM,eAAe,GAAG,KAAK,UAAU;AAEvC,QACE,oBAAC,KAAK;EAAO,MAAM;EAAc;EAAY;YAC3C,oBAAC;GAAS,MAAM;GAAc;GAAO,QAAQ,OAAO,eAAe;aAChE;;gBAEO,WAAW;QAEnB,QAAQ,SACJ;UACF,QAAQ,KAAK,OAAO,CAAC;YAEnB,GACL;;IAEU;GACC"}
@@ -1,4 +1,4 @@
1
- const require_components = require('./components-DhZ1MTrg.cjs');
1
+ const require_components = require('./components-DsnoNtPq.cjs');
2
2
 
3
3
  exports.Handlers = require_components.Handlers;
4
4
  exports.Mock = require_components.Mock;
@@ -1,6 +1,19 @@
1
1
  import { r as Operation } from "./types-8ZXwr93_.cjs";
2
2
  import { KubbNode } from "@kubb/react-fabric/types";
3
3
 
4
+ //#region src/components/Handlers.d.ts
5
+ type HandlersProps = {
6
+ /**
7
+ * Name of the function
8
+ */
9
+ name: string;
10
+ handlers: string[];
11
+ };
12
+ declare function Handlers({
13
+ name,
14
+ handlers
15
+ }: HandlersProps): KubbNode;
16
+ //#endregion
4
17
  //#region src/components/Mock.d.ts
5
18
  type Props$2 = {
6
19
  /**
@@ -19,19 +32,6 @@ declare function Mock({
19
32
  operation
20
33
  }: Props$2): KubbNode;
21
34
  //#endregion
22
- //#region src/components/Handlers.d.ts
23
- type HandlersProps = {
24
- /**
25
- * Name of the function
26
- */
27
- name: string;
28
- handlers: string[];
29
- };
30
- declare function Handlers({
31
- name,
32
- handlers
33
- }: HandlersProps): KubbNode;
34
- //#endregion
35
35
  //#region src/components/MockWithFaker.d.ts
36
36
  type Props$1 = {
37
37
  /**
@@ -1,6 +1,19 @@
1
1
  import { r as Operation } from "./types-D0JuaurR.js";
2
2
  import { KubbNode } from "@kubb/react-fabric/types";
3
3
 
4
+ //#region src/components/Handlers.d.ts
5
+ type HandlersProps = {
6
+ /**
7
+ * Name of the function
8
+ */
9
+ name: string;
10
+ handlers: string[];
11
+ };
12
+ declare function Handlers({
13
+ name,
14
+ handlers
15
+ }: HandlersProps): KubbNode;
16
+ //#endregion
4
17
  //#region src/components/Mock.d.ts
5
18
  type Props$2 = {
6
19
  /**
@@ -19,19 +32,6 @@ declare function Mock({
19
32
  operation
20
33
  }: Props$2): KubbNode;
21
34
  //#endregion
22
- //#region src/components/Handlers.d.ts
23
- type HandlersProps = {
24
- /**
25
- * Name of the function
26
- */
27
- name: string;
28
- handlers: string[];
29
- };
30
- declare function Handlers({
31
- name,
32
- handlers
33
- }: HandlersProps): KubbNode;
34
- //#endregion
35
35
  //#region src/components/MockWithFaker.d.ts
36
36
  type Props$1 = {
37
37
  /**
@@ -1,3 +1,3 @@
1
- import { i as Mock, n as MockWithFaker, r as Handlers, t as Response } from "./components-C1RVylIl.js";
1
+ import { i as Handlers, n as MockWithFaker, r as Mock, t as Response } from "./components-IvRPRy3j.js";
2
2
 
3
3
  export { Handlers, Mock, MockWithFaker, Response };
@@ -1,12 +1,12 @@
1
- const require_components = require('./components-DhZ1MTrg.cjs');
1
+ const require_components = require('./components-DsnoNtPq.cjs');
2
2
  let __kubb_plugin_faker = require("@kubb/plugin-faker");
3
3
  __kubb_plugin_faker = require_components.__toESM(__kubb_plugin_faker);
4
- let __kubb_plugin_oas = require("@kubb/plugin-oas");
5
- __kubb_plugin_oas = require_components.__toESM(__kubb_plugin_oas);
6
4
  let __kubb_plugin_ts = require("@kubb/plugin-ts");
7
5
  __kubb_plugin_ts = require_components.__toESM(__kubb_plugin_ts);
8
6
  let __kubb_core_hooks = require("@kubb/core/hooks");
9
7
  __kubb_core_hooks = require_components.__toESM(__kubb_core_hooks);
8
+ let __kubb_plugin_oas_generators = require("@kubb/plugin-oas/generators");
9
+ __kubb_plugin_oas_generators = require_components.__toESM(__kubb_plugin_oas_generators);
10
10
  let __kubb_plugin_oas_hooks = require("@kubb/plugin-oas/hooks");
11
11
  __kubb_plugin_oas_hooks = require_components.__toESM(__kubb_plugin_oas_hooks);
12
12
  let __kubb_plugin_oas_utils = require("@kubb/plugin-oas/utils");
@@ -16,14 +16,64 @@ __kubb_react_fabric = require_components.__toESM(__kubb_react_fabric);
16
16
  let __kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
17
17
  __kubb_react_fabric_jsx_runtime = require_components.__toESM(__kubb_react_fabric_jsx_runtime);
18
18
 
19
+ //#region src/generators/handlersGenerator.tsx
20
+ const handlersGenerator = (0, __kubb_plugin_oas_generators.createReactGenerator)({
21
+ name: "plugin-msw",
22
+ Operations({ operations, generator, plugin }) {
23
+ const pluginManager = (0, __kubb_core_hooks.usePluginManager)();
24
+ const oas = (0, __kubb_plugin_oas_hooks.useOas)();
25
+ const { getName, getFile } = (0, __kubb_plugin_oas_hooks.useOperationManager)(generator);
26
+ const file = pluginManager.getFile({
27
+ name: "handlers",
28
+ extname: ".ts",
29
+ pluginKey: plugin.key
30
+ });
31
+ const imports = operations.map((operation) => {
32
+ const operationFile = getFile(operation, { pluginKey: plugin.key });
33
+ const operationName = getName(operation, {
34
+ pluginKey: plugin.key,
35
+ type: "function"
36
+ });
37
+ return /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
38
+ name: [operationName],
39
+ root: file.path,
40
+ path: operationFile.path
41
+ }, operationFile.path);
42
+ });
43
+ const handlers = operations.map((operation) => `${getName(operation, {
44
+ type: "function",
45
+ pluginKey: plugin.key
46
+ })}()`);
47
+ return /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsxs)(__kubb_react_fabric.File, {
48
+ baseName: file.baseName,
49
+ path: file.path,
50
+ meta: file.meta,
51
+ banner: (0, __kubb_plugin_oas_utils.getBanner)({
52
+ oas,
53
+ output: plugin.options.output,
54
+ config: pluginManager.config
55
+ }),
56
+ footer: (0, __kubb_plugin_oas_utils.getFooter)({
57
+ oas,
58
+ output: plugin.options.output
59
+ }),
60
+ children: [imports, /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(require_components.Handlers, {
61
+ name: "handlers",
62
+ handlers
63
+ })]
64
+ });
65
+ }
66
+ });
67
+
68
+ //#endregion
19
69
  //#region src/generators/mswGenerator.tsx
20
- const mswGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
70
+ const mswGenerator = (0, __kubb_plugin_oas_generators.createReactGenerator)({
21
71
  name: "msw",
22
- Operation({ operation }) {
23
- const { options: { output, parser, baseURL } } = (0, __kubb_core_hooks.usePlugin)();
72
+ Operation({ operation, generator, plugin }) {
73
+ const { options: { output, parser, baseURL } } = plugin;
24
74
  const pluginManager = (0, __kubb_core_hooks.usePluginManager)();
25
75
  const oas = (0, __kubb_plugin_oas_hooks.useOas)();
26
- const { getSchemas, getName, getFile } = (0, __kubb_plugin_oas_hooks.useOperationManager)();
76
+ const { getSchemas, getName, getFile } = (0, __kubb_plugin_oas_hooks.useOperationManager)(generator);
27
77
  const mock = {
28
78
  name: getName(operation, { type: "function" }),
29
79
  file: getFile(operation)
@@ -115,57 +165,6 @@ const mswGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
115
165
  }
116
166
  });
117
167
 
118
- //#endregion
119
- //#region src/generators/handlersGenerator.tsx
120
- const handlersGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
121
- name: "plugin-msw",
122
- Operations({ operations }) {
123
- const plugin = (0, __kubb_core_hooks.usePlugin)();
124
- const pluginManager = (0, __kubb_core_hooks.usePluginManager)();
125
- const oas = (0, __kubb_plugin_oas_hooks.useOas)();
126
- const { getName, getFile } = (0, __kubb_plugin_oas_hooks.useOperationManager)();
127
- const file = pluginManager.getFile({
128
- name: "handlers",
129
- extname: ".ts",
130
- pluginKey: plugin.key
131
- });
132
- const imports = operations.map((operation) => {
133
- const operationFile = getFile(operation, { pluginKey: plugin.key });
134
- const operationName = getName(operation, {
135
- pluginKey: plugin.key,
136
- type: "function"
137
- });
138
- return /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
139
- name: [operationName],
140
- root: file.path,
141
- path: operationFile.path
142
- }, operationFile.path);
143
- });
144
- const handlers = operations.map((operation) => `${getName(operation, {
145
- type: "function",
146
- pluginKey: plugin.key
147
- })}()`);
148
- return /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsxs)(__kubb_react_fabric.File, {
149
- baseName: file.baseName,
150
- path: file.path,
151
- meta: file.meta,
152
- banner: (0, __kubb_plugin_oas_utils.getBanner)({
153
- oas,
154
- output: plugin.options.output,
155
- config: pluginManager.config
156
- }),
157
- footer: (0, __kubb_plugin_oas_utils.getFooter)({
158
- oas,
159
- output: plugin.options.output
160
- }),
161
- children: [imports, /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(require_components.Handlers, {
162
- name: "handlers",
163
- handlers
164
- })]
165
- });
166
- }
167
- });
168
-
169
168
  //#endregion
170
169
  Object.defineProperty(exports, 'handlersGenerator', {
171
170
  enumerable: true,
@@ -179,4 +178,4 @@ Object.defineProperty(exports, 'mswGenerator', {
179
178
  return mswGenerator;
180
179
  }
181
180
  });
182
- //# sourceMappingURL=generators-CNRKORe8.cjs.map
181
+ //# sourceMappingURL=generators-BMD5TEc2.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generators-BMD5TEc2.cjs","names":["File","Handlers","pluginFakerName","pluginTsName","types: [statusCode: number | 'default', typeName: string][]","File","Response","MockWithFaker","Mock"],"sources":["../src/generators/handlersGenerator.tsx","../src/generators/mswGenerator.tsx"],"sourcesContent":["import { usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport { Handlers } from '../components/Handlers.tsx'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations, generator, plugin }) {\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getName, getFile } = useOperationManager(generator)\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","import { usePluginManager } from '@kubb/core/hooks'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } from '@kubb/react-fabric'\nimport { Mock, MockWithFaker, Response } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation, generator, plugin }) {\n const {\n options: { output, parser, baseURL },\n } = plugin\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager(generator)\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginFakerName], type: 'function' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n const responseStatusCodes = operation.getResponseStatusCodes()\n\n const types: [statusCode: number | 'default', typeName: string][] = []\n\n for (const code of responseStatusCodes) {\n if (code === 'default') {\n types.push(['default', type.schemas.response.name])\n continue\n }\n\n if (code.startsWith('2')) {\n types.push([Number(code), type.schemas.response.name])\n continue\n }\n\n const codeType = type.schemas.errors?.find((err) => err.statusCode === Number(code))\n if (codeType) types.push([Number(code), codeType.name])\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\n name={Array.from(new Set([type.schemas.response.name, ...types.map((t) => t[1])]))}\n path={type.file.path}\n root={mock.file.path}\n isTypeOnly\n />\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 {types\n .filter(([code]) => code !== 'default')\n .map(([code, typeName]) => (\n <Response typeName={typeName} operation={operation} name={mock.name} statusCode={code as number} />\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"],"mappings":";;;;;;;;;;;;;;;;;;;AAQA,MAAa,2EAAoD;CAC/D,MAAM;CACN,WAAW,EAAE,YAAY,WAAW,UAAU;EAC5C,MAAM,yDAAkC;EAExC,MAAM,2CAAc;EACpB,MAAM,EAAE,SAAS,6DAAgC,UAAU;EAE3D,MAAM,OAAO,cAAc,QAAQ;GAAE,MAAM;GAAY,SAAS;GAAO,WAAW,OAAO;GAAK,CAAC;EAE/F,MAAM,UAAU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AAC,UAAU,SAAS,UAAU,CACtC,KAAK,CAAC,MAAM,cACX,yDAACC;KAAmB;KAAqB;KAAW,MAAM,KAAK;KAAM,YAAY;MAAkB,CACnG;IACH,WAAW,WACV,yDAACC;KACC,MAAM,KAAK;KACX,UAAU,KAAK,QAAQ,SAAS;KAChC,WAAW,MAAM,QAAQ,SAAS;KACvB;KACF;MACT;IAEH,WAAW,UACV,yDAACC;KAAK,MAAM,KAAK;KAAM,UAAU,KAAK,QAAQ,SAAS;KAAM,WAAW,MAAM,QAAQ,SAAS;KAAiB;KAAoB;MAAW;;IAE5I;;CAGZ,CAAC"}
@@ -1,21 +1,71 @@
1
- import { i as Mock, n as MockWithFaker, r as Handlers, t as Response } from "./components-C1RVylIl.js";
1
+ import { i as Handlers, n as MockWithFaker, r as Mock, t as Response } from "./components-IvRPRy3j.js";
2
2
  import { pluginFakerName } from "@kubb/plugin-faker";
3
- import { createReactGenerator } from "@kubb/plugin-oas";
4
3
  import { pluginTsName } from "@kubb/plugin-ts";
5
- import { usePlugin, usePluginManager } from "@kubb/core/hooks";
4
+ import { usePluginManager } from "@kubb/core/hooks";
5
+ import { createReactGenerator } from "@kubb/plugin-oas/generators";
6
6
  import { useOas, useOperationManager } from "@kubb/plugin-oas/hooks";
7
7
  import { getBanner, getFooter } from "@kubb/plugin-oas/utils";
8
8
  import { File } from "@kubb/react-fabric";
9
9
  import { jsx, jsxs } from "@kubb/react-fabric/jsx-runtime";
10
10
 
11
+ //#region src/generators/handlersGenerator.tsx
12
+ const handlersGenerator = createReactGenerator({
13
+ name: "plugin-msw",
14
+ Operations({ operations, generator, plugin }) {
15
+ const pluginManager = usePluginManager();
16
+ const oas = useOas();
17
+ const { getName, getFile } = useOperationManager(generator);
18
+ const file = pluginManager.getFile({
19
+ name: "handlers",
20
+ extname: ".ts",
21
+ pluginKey: plugin.key
22
+ });
23
+ const imports = operations.map((operation) => {
24
+ const operationFile = getFile(operation, { pluginKey: plugin.key });
25
+ const operationName = getName(operation, {
26
+ pluginKey: plugin.key,
27
+ type: "function"
28
+ });
29
+ return /* @__PURE__ */ jsx(File.Import, {
30
+ name: [operationName],
31
+ root: file.path,
32
+ path: operationFile.path
33
+ }, operationFile.path);
34
+ });
35
+ const handlers = operations.map((operation) => `${getName(operation, {
36
+ type: "function",
37
+ pluginKey: plugin.key
38
+ })}()`);
39
+ return /* @__PURE__ */ jsxs(File, {
40
+ baseName: file.baseName,
41
+ path: file.path,
42
+ meta: file.meta,
43
+ banner: getBanner({
44
+ oas,
45
+ output: plugin.options.output,
46
+ config: pluginManager.config
47
+ }),
48
+ footer: getFooter({
49
+ oas,
50
+ output: plugin.options.output
51
+ }),
52
+ children: [imports, /* @__PURE__ */ jsx(Handlers, {
53
+ name: "handlers",
54
+ handlers
55
+ })]
56
+ });
57
+ }
58
+ });
59
+
60
+ //#endregion
11
61
  //#region src/generators/mswGenerator.tsx
12
62
  const mswGenerator = createReactGenerator({
13
63
  name: "msw",
14
- Operation({ operation }) {
15
- const { options: { output, parser, baseURL } } = usePlugin();
64
+ Operation({ operation, generator, plugin }) {
65
+ const { options: { output, parser, baseURL } } = plugin;
16
66
  const pluginManager = usePluginManager();
17
67
  const oas = useOas();
18
- const { getSchemas, getName, getFile } = useOperationManager();
68
+ const { getSchemas, getName, getFile } = useOperationManager(generator);
19
69
  const mock = {
20
70
  name: getName(operation, { type: "function" }),
21
71
  file: getFile(operation)
@@ -108,56 +158,5 @@ const mswGenerator = createReactGenerator({
108
158
  });
109
159
 
110
160
  //#endregion
111
- //#region src/generators/handlersGenerator.tsx
112
- const handlersGenerator = createReactGenerator({
113
- name: "plugin-msw",
114
- Operations({ operations }) {
115
- const plugin = usePlugin();
116
- const pluginManager = usePluginManager();
117
- const oas = useOas();
118
- const { getName, getFile } = useOperationManager();
119
- const file = pluginManager.getFile({
120
- name: "handlers",
121
- extname: ".ts",
122
- pluginKey: plugin.key
123
- });
124
- const imports = operations.map((operation) => {
125
- const operationFile = getFile(operation, { pluginKey: plugin.key });
126
- const operationName = getName(operation, {
127
- pluginKey: plugin.key,
128
- type: "function"
129
- });
130
- return /* @__PURE__ */ jsx(File.Import, {
131
- name: [operationName],
132
- root: file.path,
133
- path: operationFile.path
134
- }, operationFile.path);
135
- });
136
- const handlers = operations.map((operation) => `${getName(operation, {
137
- type: "function",
138
- pluginKey: plugin.key
139
- })}()`);
140
- return /* @__PURE__ */ jsxs(File, {
141
- baseName: file.baseName,
142
- path: file.path,
143
- meta: file.meta,
144
- banner: getBanner({
145
- oas,
146
- output: plugin.options.output,
147
- config: pluginManager.config
148
- }),
149
- footer: getFooter({
150
- oas,
151
- output: plugin.options.output
152
- }),
153
- children: [imports, /* @__PURE__ */ jsx(Handlers, {
154
- name: "handlers",
155
- handlers
156
- })]
157
- });
158
- }
159
- });
160
-
161
- //#endregion
162
- export { mswGenerator as n, handlersGenerator as t };
163
- //# sourceMappingURL=generators-BvLpjRZi.js.map
161
+ export { handlersGenerator as n, mswGenerator as t };
162
+ //# sourceMappingURL=generators-ubi6QbfX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generators-ubi6QbfX.js","names":["types: [statusCode: number | 'default', typeName: string][]"],"sources":["../src/generators/handlersGenerator.tsx","../src/generators/mswGenerator.tsx"],"sourcesContent":["import { usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport { Handlers } from '../components/Handlers.tsx'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations, generator, plugin }) {\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getName, getFile } = useOperationManager(generator)\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","import { usePluginManager } from '@kubb/core/hooks'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } from '@kubb/react-fabric'\nimport { Mock, MockWithFaker, Response } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation, generator, plugin }) {\n const {\n options: { output, parser, baseURL },\n } = plugin\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager(generator)\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginFakerName], type: 'function' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n const responseStatusCodes = operation.getResponseStatusCodes()\n\n const types: [statusCode: number | 'default', typeName: string][] = []\n\n for (const code of responseStatusCodes) {\n if (code === 'default') {\n types.push(['default', type.schemas.response.name])\n continue\n }\n\n if (code.startsWith('2')) {\n types.push([Number(code), type.schemas.response.name])\n continue\n }\n\n const codeType = type.schemas.errors?.find((err) => err.statusCode === Number(code))\n if (codeType) types.push([Number(code), codeType.name])\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\n name={Array.from(new Set([type.schemas.response.name, ...types.map((t) => t[1])]))}\n path={type.file.path}\n root={mock.file.path}\n isTypeOnly\n />\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 {types\n .filter(([code]) => code !== 'default')\n .map(([code, typeName]) => (\n <Response typeName={typeName} operation={operation} name={mock.name} statusCode={code as number} />\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"],"mappings":";;;;;;;;;;;AAQA,MAAa,oBAAoB,qBAAgC;CAC/D,MAAM;CACN,WAAW,EAAE,YAAY,WAAW,UAAU;EAC5C,MAAM,gBAAgB,kBAAkB;EAExC,MAAM,MAAM,QAAQ;EACpB,MAAM,EAAE,SAAS,YAAY,oBAAoB,UAAU;EAE3D,MAAM,OAAO,cAAc,QAAQ;GAAE,MAAM;GAAY,SAAS;GAAO,WAAW,OAAO;GAAK,CAAC;EAE/F,MAAM,UAAU,WAAW,KAAK,cAAc;GAC5C,MAAM,gBAAgB,QAAQ,WAAW,EAAE,WAAW,OAAO,KAAK,CAAC;GACnE,MAAM,gBAAgB,QAAQ,WAAW;IAAE,WAAW,OAAO;IAAK,MAAM;IAAY,CAAC;AAErF,UAAO,oBAAC,K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,MAAM,KAAK;KACX,UAAU,KAAK,QAAQ,SAAS;KAChC,WAAW,MAAM,QAAQ,SAAS;KACvB;KACF;MACT;IAEH,WAAW,UACV,oBAAC;KAAK,MAAM,KAAK;KAAM,UAAU,KAAK,QAAQ,SAAS;KAAM,WAAW,MAAM,QAAQ,SAAS;KAAiB;KAAoB;MAAW;;IAE5I;;CAGZ,CAAC"}
@@ -1,5 +1,5 @@
1
- require('./components-DhZ1MTrg.cjs');
2
- const require_generators = require('./generators-CNRKORe8.cjs');
1
+ require('./components-DsnoNtPq.cjs');
2
+ const require_generators = require('./generators-BMD5TEc2.cjs');
3
3
 
4
4
  exports.handlersGenerator = require_generators.handlersGenerator;
5
5
  exports.mswGenerator = require_generators.mswGenerator;
@@ -1,11 +1,11 @@
1
1
  import "./types-8ZXwr93_.cjs";
2
- import { n as PluginMsw, r as ReactGenerator } from "./types-CvyuqqRp.cjs";
2
+ import { n as PluginMsw, r as ReactGenerator } from "./types-C9Jm40mM.cjs";
3
3
 
4
- //#region src/generators/mswGenerator.d.ts
5
- declare const mswGenerator: ReactGenerator<PluginMsw>;
6
- //#endregion
7
4
  //#region src/generators/handlersGenerator.d.ts
8
5
  declare const handlersGenerator: ReactGenerator<PluginMsw>;
9
6
  //#endregion
7
+ //#region src/generators/mswGenerator.d.ts
8
+ declare const mswGenerator: ReactGenerator<PluginMsw>;
9
+ //#endregion
10
10
  export { handlersGenerator, mswGenerator };
11
11
  //# sourceMappingURL=generators.d.cts.map
@@ -1,11 +1,11 @@
1
1
  import "./types-D0JuaurR.js";
2
- import { n as PluginMsw, r as ReactGenerator } from "./types-BKFpz20w.js";
2
+ import { n as PluginMsw, r as ReactGenerator } from "./types-DSnvepCr.js";
3
3
 
4
- //#region src/generators/mswGenerator.d.ts
5
- declare const mswGenerator: ReactGenerator<PluginMsw>;
6
- //#endregion
7
4
  //#region src/generators/handlersGenerator.d.ts
8
5
  declare const handlersGenerator: ReactGenerator<PluginMsw>;
9
6
  //#endregion
7
+ //#region src/generators/mswGenerator.d.ts
8
+ declare const mswGenerator: ReactGenerator<PluginMsw>;
9
+ //#endregion
10
10
  export { handlersGenerator, mswGenerator };
11
11
  //# sourceMappingURL=generators.d.ts.map
@@ -1,4 +1,4 @@
1
- import "./components-C1RVylIl.js";
2
- import { n as mswGenerator, t as handlersGenerator } from "./generators-BvLpjRZi.js";
1
+ import "./components-IvRPRy3j.js";
2
+ import { n as handlersGenerator, t as mswGenerator } from "./generators-ubi6QbfX.js";
3
3
 
4
4
  export { handlersGenerator, mswGenerator };
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
- const require_components = require('./components-DhZ1MTrg.cjs');
2
- const require_generators = require('./generators-CNRKORe8.cjs');
1
+ const require_components = require('./components-DsnoNtPq.cjs');
2
+ const require_generators = require('./generators-BMD5TEc2.cjs');
3
3
  let node_path = require("node:path");
4
4
  node_path = require_components.__toESM(node_path);
5
5
  let __kubb_core = require("@kubb/core");
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./types-8ZXwr93_.cjs";
2
- import { i as UserPluginWithLifeCycle, n as PluginMsw, t as Options } from "./types-CvyuqqRp.cjs";
2
+ import { i as UserPluginWithLifeCycle, n as PluginMsw, t as Options } from "./types-C9Jm40mM.cjs";
3
3
 
4
4
  //#region src/plugin.d.ts
5
5
  declare const pluginMswName = "plugin-msw";
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./types-D0JuaurR.js";
2
- import { i as UserPluginWithLifeCycle, n as PluginMsw, t as Options } from "./types-BKFpz20w.js";
2
+ import { i as UserPluginWithLifeCycle, n as PluginMsw, t as Options } from "./types-DSnvepCr.js";
3
3
 
4
4
  //#region src/plugin.d.ts
5
5
  declare const pluginMswName = "plugin-msw";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./components-C1RVylIl.js";
2
- import { n as mswGenerator, t as handlersGenerator } from "./generators-BvLpjRZi.js";
1
+ import "./components-IvRPRy3j.js";
2
+ import { n as handlersGenerator, t as mswGenerator } from "./generators-ubi6QbfX.js";
3
3
  import path from "node:path";
4
4
  import { PluginManager, createPlugin, getBarrelFiles, getMode } from "@kubb/core";
5
5
  import { camelCase } from "@kubb/core/transformers";
@@ -1,10 +1,10 @@
1
1
  import { a as contentType, i as SchemaObject$1, n as OasTypes, r as Operation$1, t as HttpMethod } from "./types-8ZXwr93_.cjs";
2
+ import { KubbNode } from "@kubb/react-fabric/types";
2
3
  import { OASDocument, SchemaObject, User } from "oas/types";
3
4
  import { Operation } from "oas/operation";
4
5
  import { OpenAPIV3 } from "openapi-types";
5
6
  import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
6
7
  import BaseOas from "oas";
7
- import { KubbNode } from "@kubb/react-fabric/types";
8
8
  import { KubbFile } from "@kubb/fabric-core/types";
9
9
  import { Fabric, FileManager } from "@kubb/react-fabric";
10
10
  import { ConsolaInstance, LogLevel } from "consola";
@@ -549,15 +549,6 @@ type FileMetaBase = {
549
549
  pluginKey?: Plugin['key'];
550
550
  };
551
551
  //#endregion
552
- //#region ../plugin-oas/src/generators/createGenerator.d.ts
553
- type CoreGenerator<TOptions extends PluginFactoryOptions> = {
554
- name: string;
555
- type: 'core';
556
- operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
557
- operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
558
- schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
559
- };
560
- //#endregion
561
552
  //#region ../plugin-oas/src/types.d.ts
562
553
  type ResolvePathOptions = {
563
554
  pluginKey?: Plugin['key'];
@@ -944,35 +935,38 @@ declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGe
944
935
  * optionally adds a union with null.
945
936
  */
946
937
  parse(props: SchemaProps$1): Schema[];
947
- deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]>;
948
- find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
949
938
  static deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]>;
950
- static findInObject<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
951
939
  static find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
952
940
  static combineObjects(tree: Schema[] | undefined): Schema[];
953
941
  build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
954
942
  }
955
943
  //#endregion
944
+ //#region ../plugin-oas/src/generators/createGenerator.d.ts
945
+ type CoreGenerator<TOptions extends PluginFactoryOptions> = {
946
+ name: string;
947
+ type: 'core';
948
+ operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
949
+ operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
950
+ schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
951
+ };
952
+ //#endregion
956
953
  //#region ../plugin-oas/src/generators/types.d.ts
957
954
  type OperationsProps<TOptions extends PluginFactoryOptions> = {
958
- /**
959
- * @deprecated
960
- */
961
- instance: Omit<OperationGenerator<TOptions>, 'build'>;
962
- options: TOptions['resolvedOptions'];
955
+ config: Config;
956
+ generator: Omit<OperationGenerator<TOptions>, 'build'>;
957
+ plugin: Plugin<TOptions>;
963
958
  operations: Array<Operation$1>;
964
959
  };
965
960
  type OperationProps<TOptions extends PluginFactoryOptions> = {
966
- /**
967
- * @deprecated
968
- */
969
- instance: Omit<OperationGenerator<TOptions>, 'build'>;
970
- options: TOptions['resolvedOptions'];
961
+ config: Config;
962
+ generator: Omit<OperationGenerator<TOptions>, 'build'>;
963
+ plugin: Plugin<TOptions>;
971
964
  operation: Operation$1;
972
965
  };
973
966
  type SchemaProps<TOptions extends PluginFactoryOptions> = {
974
- instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
975
- options: TOptions['resolvedOptions'];
967
+ config: Config;
968
+ generator: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
969
+ plugin: Plugin<TOptions>;
976
970
  schema: {
977
971
  name: string;
978
972
  tree: Array<Schema>;
@@ -1051,4 +1045,4 @@ type ResolvedOptions = {
1051
1045
  type PluginMsw = PluginFactoryOptions<'plugin-msw', Options$1, ResolvedOptions, never, ResolvePathOptions>;
1052
1046
  //#endregion
1053
1047
  export { UserPluginWithLifeCycle as i, PluginMsw as n, ReactGenerator as r, Options$1 as t };
1054
- //# sourceMappingURL=types-CvyuqqRp.d.cts.map
1048
+ //# sourceMappingURL=types-C9Jm40mM.d.cts.map
@@ -1,11 +1,11 @@
1
1
  import { a as contentType, i as SchemaObject$1, n as OasTypes, r as Operation$1, t as HttpMethod } from "./types-D0JuaurR.js";
2
2
  import { Fabric, FileManager } from "@kubb/react-fabric";
3
+ import { KubbNode } from "@kubb/react-fabric/types";
3
4
  import { OASDocument, SchemaObject, User } from "oas/types";
4
5
  import { Operation } from "oas/operation";
5
6
  import { OpenAPIV3 } from "openapi-types";
6
7
  import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
7
8
  import BaseOas from "oas";
8
- import { KubbNode } from "@kubb/react-fabric/types";
9
9
  import { KubbFile } from "@kubb/fabric-core/types";
10
10
  import { ConsolaInstance, LogLevel } from "consola";
11
11
 
@@ -549,15 +549,6 @@ type FileMetaBase = {
549
549
  pluginKey?: Plugin['key'];
550
550
  };
551
551
  //#endregion
552
- //#region ../plugin-oas/src/generators/createGenerator.d.ts
553
- type CoreGenerator<TOptions extends PluginFactoryOptions> = {
554
- name: string;
555
- type: 'core';
556
- operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
557
- operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
558
- schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
559
- };
560
- //#endregion
561
552
  //#region ../plugin-oas/src/types.d.ts
562
553
  type ResolvePathOptions = {
563
554
  pluginKey?: Plugin['key'];
@@ -944,35 +935,38 @@ declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGe
944
935
  * optionally adds a union with null.
945
936
  */
946
937
  parse(props: SchemaProps$1): Schema[];
947
- deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]>;
948
- find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
949
938
  static deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]>;
950
- static findInObject<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
951
939
  static find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
952
940
  static combineObjects(tree: Schema[] | undefined): Schema[];
953
941
  build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
954
942
  }
955
943
  //#endregion
944
+ //#region ../plugin-oas/src/generators/createGenerator.d.ts
945
+ type CoreGenerator<TOptions extends PluginFactoryOptions> = {
946
+ name: string;
947
+ type: 'core';
948
+ operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
949
+ operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
950
+ schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
951
+ };
952
+ //#endregion
956
953
  //#region ../plugin-oas/src/generators/types.d.ts
957
954
  type OperationsProps<TOptions extends PluginFactoryOptions> = {
958
- /**
959
- * @deprecated
960
- */
961
- instance: Omit<OperationGenerator<TOptions>, 'build'>;
962
- options: TOptions['resolvedOptions'];
955
+ config: Config;
956
+ generator: Omit<OperationGenerator<TOptions>, 'build'>;
957
+ plugin: Plugin<TOptions>;
963
958
  operations: Array<Operation$1>;
964
959
  };
965
960
  type OperationProps<TOptions extends PluginFactoryOptions> = {
966
- /**
967
- * @deprecated
968
- */
969
- instance: Omit<OperationGenerator<TOptions>, 'build'>;
970
- options: TOptions['resolvedOptions'];
961
+ config: Config;
962
+ generator: Omit<OperationGenerator<TOptions>, 'build'>;
963
+ plugin: Plugin<TOptions>;
971
964
  operation: Operation$1;
972
965
  };
973
966
  type SchemaProps<TOptions extends PluginFactoryOptions> = {
974
- instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
975
- options: TOptions['resolvedOptions'];
967
+ config: Config;
968
+ generator: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
969
+ plugin: Plugin<TOptions>;
976
970
  schema: {
977
971
  name: string;
978
972
  tree: Array<Schema>;
@@ -1051,4 +1045,4 @@ type ResolvedOptions = {
1051
1045
  type PluginMsw = PluginFactoryOptions<'plugin-msw', Options$1, ResolvedOptions, never, ResolvePathOptions>;
1052
1046
  //#endregion
1053
1047
  export { UserPluginWithLifeCycle as i, PluginMsw as n, ReactGenerator as r, Options$1 as t };
1054
- //# sourceMappingURL=types-BKFpz20w.d.ts.map
1048
+ //# sourceMappingURL=types-DSnvepCr.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-msw",
3
- "version": "4.4.1",
3
+ "version": "4.5.1",
4
4
  "description": "Mock Service Worker (MSW) handlers generator plugin for Kubb, creating API mocks from OpenAPI specifications for frontend development and testing.",
5
5
  "keywords": [
6
6
  "msw",
@@ -73,16 +73,16 @@
73
73
  }
74
74
  ],
75
75
  "dependencies": {
76
- "@kubb/react-fabric": "0.2.10",
77
- "@kubb/core": "4.4.1",
78
- "@kubb/oas": "4.4.1",
79
- "@kubb/plugin-faker": "4.4.1",
80
- "@kubb/plugin-oas": "4.4.1",
81
- "@kubb/plugin-ts": "4.4.1"
76
+ "@kubb/react-fabric": "0.2.14",
77
+ "@kubb/core": "4.5.1",
78
+ "@kubb/oas": "4.5.1",
79
+ "@kubb/plugin-faker": "4.5.1",
80
+ "@kubb/plugin-oas": "4.5.1",
81
+ "@kubb/plugin-ts": "4.5.1"
82
82
  },
83
83
  "devDependencies": {},
84
84
  "peerDependencies": {
85
- "@kubb/react-fabric": "0.2.10"
85
+ "@kubb/react-fabric": "0.2.14"
86
86
  },
87
87
  "engines": {
88
88
  "node": ">=20"
@@ -1,4 +1,4 @@
1
- export { Mock } from './Mock.tsx'
2
1
  export { Handlers } from './Handlers.tsx'
2
+ export { Mock } from './Mock.tsx'
3
3
  export { MockWithFaker } from './MockWithFaker.tsx'
4
4
  export { Response } from './Response.tsx'
@@ -1,5 +1,5 @@
1
- import { usePlugin, usePluginManager } from '@kubb/core/hooks'
2
- import { createReactGenerator } from '@kubb/plugin-oas'
1
+ import { usePluginManager } from '@kubb/core/hooks'
2
+ import { createReactGenerator } from '@kubb/plugin-oas/generators'
3
3
  import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
4
4
  import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
5
5
  import { File } from '@kubb/react-fabric'
@@ -8,12 +8,11 @@ import type { PluginMsw } from '../types'
8
8
 
9
9
  export const handlersGenerator = createReactGenerator<PluginMsw>({
10
10
  name: 'plugin-msw',
11
- Operations({ operations }) {
12
- const plugin = usePlugin<PluginMsw>()
11
+ Operations({ operations, generator, plugin }) {
13
12
  const pluginManager = usePluginManager()
14
13
 
15
14
  const oas = useOas()
16
- const { getName, getFile } = useOperationManager()
15
+ const { getName, getFile } = useOperationManager(generator)
17
16
 
18
17
  const file = pluginManager.getFile({ name: 'handlers', extname: '.ts', pluginKey: plugin.key })
19
18
 
@@ -1,2 +1,2 @@
1
- export { mswGenerator } from './mswGenerator.tsx'
2
1
  export { handlersGenerator } from './handlersGenerator.tsx'
2
+ export { mswGenerator } from './mswGenerator.tsx'
@@ -1,6 +1,6 @@
1
- import { usePlugin, usePluginManager } from '@kubb/core/hooks'
1
+ import { usePluginManager } from '@kubb/core/hooks'
2
2
  import { pluginFakerName } from '@kubb/plugin-faker'
3
- import { createReactGenerator } from '@kubb/plugin-oas'
3
+ import { createReactGenerator } from '@kubb/plugin-oas/generators'
4
4
  import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
5
5
  import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
6
6
  import { pluginTsName } from '@kubb/plugin-ts'
@@ -10,14 +10,14 @@ import type { PluginMsw } from '../types'
10
10
 
11
11
  export const mswGenerator = createReactGenerator<PluginMsw>({
12
12
  name: 'msw',
13
- Operation({ operation }) {
13
+ Operation({ operation, generator, plugin }) {
14
14
  const {
15
15
  options: { output, parser, baseURL },
16
- } = usePlugin<PluginMsw>()
16
+ } = plugin
17
17
  const pluginManager = usePluginManager()
18
18
 
19
19
  const oas = useOas()
20
- const { getSchemas, getName, getFile } = useOperationManager()
20
+ const { getSchemas, getName, getFile } = useOperationManager(generator)
21
21
 
22
22
  const mock = {
23
23
  name: getName(operation, { type: 'function' }),
package/src/types.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
2
2
 
3
3
  import type { contentType, Oas } from '@kubb/oas'
4
- import type { Exclude, Generator, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
4
+ import type { Exclude, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
5
+ import type { Generator } from '@kubb/plugin-oas/generators'
5
6
 
6
7
  export type Options = {
7
8
  /**
@@ -1 +0,0 @@
1
- {"version":3,"file":"components-C1RVylIl.js","names":[],"sources":["../src/components/Mock.tsx","../src/components/Handlers.tsx","../src/components/MockWithFaker.tsx","../src/components/Response.tsx"],"sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport type { OasTypes, Operation } from '@kubb/oas'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\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): KubbNode {\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 hasResponseSchema = contentType && responseObject?.content?.[contentType]?.schema !== undefined\n\n // If no response schema, uses any type but function to avoid overriding callback\n const dataType = hasResponseSchema ? typeName : 'string | number | boolean | null | object'\n\n const params = FunctionParams.factory({\n data: {\n type: `${dataType} | ((\n info: Parameters<Parameters<typeof http.${method}>[1]>[0],\n ) => Response | Promise<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-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\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): KubbNode {\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-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\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): KubbNode {\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 | Promise<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","import type { OasTypes, Operation } from '@kubb/oas'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\n\ntype Props = {\n typeName: string\n operation: Operation\n name: string\n statusCode: number\n}\n\nexport function Response({ name, typeName, operation, statusCode }: Props): KubbNode {\n const responseObject = operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject\n const contentType = Object.keys(responseObject.content || {})?.[0]\n\n const headers = [contentType ? `'Content-Type': '${contentType}'` : undefined].filter(Boolean)\n\n const hasResponseSchema = contentType && responseObject?.content?.[contentType]?.schema !== undefined\n\n const params = FunctionParams.factory({\n data: {\n type: `${typeName}`,\n optional: !hasResponseSchema,\n },\n })\n\n const responseName = `${name}Response${statusCode}`\n\n return (\n <File.Source name={responseName} isIndexable isExportable>\n <Function name={responseName} export params={params.toConstructor()}>\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 </Function>\n </File.Source>\n )\n}\n"],"mappings":";;;;;AAgBA,SAAgB,KAAK,EAAE,UAAU,IAAI,MAAM,UAAU,aAA8B;CACjF,MAAM,SAAS,UAAU;CACzB,MAAM,qBAAqB,UAAU,wBAAwB,CAAC,QAAQ,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,EAAE,CAAC,GAAG;CAChE,MAAM,MAAM,IAAI,QAAQ,UAAU,KAAK,CAAC,WAAW,CAAC,QAAQ,YAAY,UAAU;CAElF,MAAM,UAAU,CAAC,cAAc,oBAAoB,YAAY,KAAK,OAAU,CAAC,OAAO,QAAQ;CAK9F,MAAM,WAHoB,eAAe,gBAAgB,UAAU,cAAc,WAAW,SAGvD,WAAW;CAEhD,MAAM,SAAS,eAAe,QAAQ,EACpC,MAAM;EACJ,MAAM,GAAG,SAAS;kDAC0B,OAAO;;EAEnD,UAAU;EACX,EACF,CAAC;AAEF,QACE,oBAAC,KAAK;EAAa;EAAM;EAAY;YACnC,oBAAC;GAAe;GAAM;GAAO,QAAQ,OAAO,eAAe;aACxD,eAAe,OAAO,IAAI,UAAU,IAAI,QAAQ,YAAY,UAAU,CAAC;;;;gBAIhE,WAAW;QAEnB,QAAQ,SACJ;UACF,QAAQ,KAAK,OAAO,CAAC;YAEnB,GACL;;;IAGU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,oBAAoB,YAAY,KAAK,OAAU,CAAC,OAAO,QAAQ;CAE9F,MAAM,oBAAoB,eAAe,gBAAgB,UAAU,cAAc,WAAW;CAE5F,MAAM,SAAS,eAAe,QAAQ,EACpC,MAAM;EACJ,MAAM,GAAG;EACT,UAAU,CAAC;EACZ,EACF,CAAC;CAEF,MAAM,eAAe,GAAG,KAAK,UAAU;AAEvC,QACE,oBAAC,KAAK;EAAO,MAAM;EAAc;EAAY;YAC3C,oBAAC;GAAS,MAAM;GAAc;GAAO,QAAQ,OAAO,eAAe;aAChE;;gBAEO,WAAW;QAEnB,QAAQ,SACJ;UACF,QAAQ,KAAK,OAAO,CAAC;YAEnB,GACL;;IAEU;GACC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"components-DhZ1MTrg.cjs","names":["URLPath","FunctionParams","File","Function","File","URLPath","FunctionParams","File","Function","FunctionParams","File","Function"],"sources":["../src/components/Mock.tsx","../src/components/Handlers.tsx","../src/components/MockWithFaker.tsx","../src/components/Response.tsx"],"sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport type { OasTypes, Operation } from '@kubb/oas'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\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): KubbNode {\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 hasResponseSchema = contentType && responseObject?.content?.[contentType]?.schema !== undefined\n\n // If no response schema, uses any type but function to avoid overriding callback\n const dataType = hasResponseSchema ? typeName : 'string | number | boolean | null | object'\n\n const params = FunctionParams.factory({\n data: {\n type: `${dataType} | ((\n info: Parameters<Parameters<typeof http.${method}>[1]>[0],\n ) => Response | Promise<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-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\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): KubbNode {\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-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\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): KubbNode {\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 | Promise<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","import type { OasTypes, Operation } from '@kubb/oas'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\n\ntype Props = {\n typeName: string\n operation: Operation\n name: string\n statusCode: number\n}\n\nexport function Response({ name, typeName, operation, statusCode }: Props): KubbNode {\n const responseObject = operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject\n const contentType = Object.keys(responseObject.content || {})?.[0]\n\n const headers = [contentType ? `'Content-Type': '${contentType}'` : undefined].filter(Boolean)\n\n const hasResponseSchema = contentType && responseObject?.content?.[contentType]?.schema !== undefined\n\n const params = FunctionParams.factory({\n data: {\n type: `${typeName}`,\n optional: !hasResponseSchema,\n },\n })\n\n const responseName = `${name}Response${statusCode}`\n\n return (\n <File.Source name={responseName} isIndexable isExportable>\n <Function name={responseName} export params={params.toConstructor()}>\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 </Function>\n </File.Source>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,SAAgB,KAAK,EAAE,UAAU,IAAI,MAAM,UAAU,aAA8B;CACjF,MAAM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ACF,QAAQ,KAAK,OAAO,CAAC;YAEnB,GACL;;IAEU;GACC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"generators-BvLpjRZi.js","names":["types: [statusCode: number | 'default', typeName: string][]"],"sources":["../src/generators/mswGenerator.tsx","../src/generators/handlersGenerator.tsx"],"sourcesContent":["import { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } from '@kubb/react-fabric'\nimport { Mock, MockWithFaker, Response } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation }) {\n const {\n options: { output, parser, baseURL },\n } = usePlugin<PluginMsw>()\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginFakerName], type: 'function' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n const responseStatusCodes = operation.getResponseStatusCodes()\n\n const types: [statusCode: number | 'default', typeName: string][] = []\n\n for (const code of responseStatusCodes) {\n if (code === 'default') {\n types.push(['default', type.schemas.response.name])\n continue\n }\n\n if (code.startsWith('2')) {\n types.push([Number(code), type.schemas.response.name])\n continue\n }\n\n const codeType = type.schemas.errors?.find((err) => err.statusCode === Number(code))\n if (codeType) types.push([Number(code), codeType.name])\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\n name={Array.from(new Set([type.schemas.response.name, ...types.map((t) => t[1])]))}\n path={type.file.path}\n root={mock.file.path}\n isTypeOnly\n />\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 {types\n .filter(([code]) => code !== 'default')\n .map(([code, typeName]) => (\n <Response typeName={typeName} operation={operation} name={mock.name} statusCode={code as number} />\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 { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\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 plugin = usePlugin<PluginMsw>()\n const pluginManager = usePluginManager()\n\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":";;;;;;;;;;;AAUA,MAAa,eAAe,qBAAgC;CAC1D,MAAM;CACN,UAAU,EAAE,aAAa;EACvB,MAAM,EACJ,SAAS,EAAE,QAAQ,QAAQ,cACzB,WAAsB;EAC1B,MAAM,gBAAgB,kBAAkB;EAExC,MAAM,MAAM,QAAQ;EACpB,MAAM,EAAE,YAAY,SAAS,YAAY,qBAAqB;EAE9D,MAAM,OAAO;GACX,MAAM,QAAQ,WAAW,EAAE,MAAM,YAAY,CAAC;GAC9C,MAAM,QAAQ,UAAU;GACzB;EAED,MAAM,QAAQ;GACZ,MAAM,QAAQ,WAAW,EAAE,WAAW,CAAC,gBAAgB,EAAE,CAAC;GAC1D,SAAS,WAAW,WAAW;IAAE,WAAW,CAAC,gBAAgB;IAAE,MAAM;IAAY,CAAC;GACnF;EAED,MAAM,OAAO;GACX,MAAM,QAAQ,WAAW,EAAE,WAAW,CAAC,aAAa,EAAE,CAAC;GACvD,SAAS,WAAW,WAAW;IAAE,WAAW,CAAC,aAAa;IAAE,MAAM;IAAQ,CAAC;GAC5E;EAED,MAAM,sBAAsB,UAAU,wBAAwB;EAE9D,MAAMA,QAA8D,EAAE;AAEtE,OAAK,MAAM,QAAQ,qBAAqB;AACtC,OAAI,SAAS,WAAW;AACtB,UAAM,KAAK,CAAC,WAAW,KAAK,QAAQ,SAAS,KAAK,CAAC;AACnD;;AAGF,OAAI,KAAK,WAAW,IAAI,EAAE;AACxB,UAAM,KAAK,CAAC,OAAO,KAAK,EAAE,KAAK,QAAQ,SAAS,KAAK,CAAC;AACtD;;GAGF,MAAM,WAAW,KAAK,QAAQ,QAAQ,MAAM,QAAQ,IAAI,eAAe,OAAO,KAAK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AAW,EAAE,cAAc;EACzB,MAAM,SAAS,WAAsB;EACrC,MAAM,gBAAgB,kBAAkB;EAExC,MAAM,MAAM,QAAQ;EACpB,MAAM,EAAE,SAAS,YAAY,qBAAqB;EAElD,MAAM,OAAO,cAAc,QAAQ;GAAE,MAAM;GAAY,SAAS;GAAO,WAAW,OAAO;GAAK,CAAC;EAE/F,MAAM,UAAU,WAAW,KAAK,cAAc;GAC5C,MAAM,gBAAgB,QAAQ,WAAW,EAAE,WAAW,OAAO,KAAK,CAAC;GACnE,MAAM,gBAAgB,QAAQ,WAAW;IAAE,WAAW,OAAO;IAAK,MAAM;IAAY,CAAC;AAErF,UAAO,oBAAC,KAAK;IAAgC,MAAM,CAAC,cAAc;IAAE,MAAM,KAAK;IAAM,MAAM,cAAc;MAAhF,cAAc,KAA0E;IACjH;EAEF,MAAM,WAAW,WAAW,KAAK,cAAc,GAAG,QAAQ,WAAW;GAAE,MAAM;GAAY,WAAW,OAAO;GAAK,CAAC,CAAC,IAAI;AAEtH,SACE,qBAAC;GACC,UAAU,KAAK;GACf,MAAM,KAAK;GACX,MAAM,KAAK;GACX,QAAQ,UAAU;IAAE;IAAK,QAAQ,OAAO,QAAQ;IAAQ,QAAQ,cAAc;IAAQ,CAAC;GACvF,QAAQ,UAAU;IAAE;IAAK,QAAQ,OAAO,QAAQ;IAAQ,CAAC;cAExD,SACD,oBAAC;IAAS,MAAM;IAAsB;KAAY;IAC7C;;CAGZ,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"generators-CNRKORe8.cjs","names":["pluginFakerName","pluginTsName","types: [statusCode: number | 'default', typeName: string][]","File","Response","MockWithFaker","Mock","File","Handlers"],"sources":["../src/generators/mswGenerator.tsx","../src/generators/handlersGenerator.tsx"],"sourcesContent":["import { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } from '@kubb/react-fabric'\nimport { Mock, MockWithFaker, Response } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation }) {\n const {\n options: { output, parser, baseURL },\n } = usePlugin<PluginMsw>()\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginFakerName], type: 'function' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n const responseStatusCodes = operation.getResponseStatusCodes()\n\n const types: [statusCode: number | 'default', typeName: string][] = []\n\n for (const code of responseStatusCodes) {\n if (code === 'default') {\n types.push(['default', type.schemas.response.name])\n continue\n }\n\n if (code.startsWith('2')) {\n types.push([Number(code), type.schemas.response.name])\n continue\n }\n\n const codeType = type.schemas.errors?.find((err) => err.statusCode === Number(code))\n if (codeType) types.push([Number(code), codeType.name])\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\n name={Array.from(new Set([type.schemas.response.name, ...types.map((t) => t[1])]))}\n path={type.file.path}\n root={mock.file.path}\n isTypeOnly\n />\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 {types\n .filter(([code]) => code !== 'default')\n .map(([code, typeName]) => (\n <Response typeName={typeName} operation={operation} name={mock.name} statusCode={code as number} />\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 { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\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 plugin = usePlugin<PluginMsw>()\n const pluginManager = usePluginManager()\n\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":";;;;;;;;;;;;;;;;;;;AAUA,MAAa,2DAA+C;CAC1D,MAAM;CACN,UAAU,EAAE,aAAa;EACvB,MAAM,EACJ,SAAS,EAAE,QAAQ,QAAQ,gDACH;EAC1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