@kubb/plugin-msw 4.12.0 → 4.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{components-CDRldAv7.cjs → components-ATPc-lQH.cjs} +2 -2
- package/dist/components-ATPc-lQH.cjs.map +1 -0
- package/dist/{components-DK6Olrp_.js → components-C5_yzPIo.js} +2 -2
- package/dist/components-C5_yzPIo.js.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.js +1 -1
- package/dist/{generators-BFHTvRSh.cjs → generators-Cz0z5DBg.cjs} +2 -2
- package/dist/{generators-BFHTvRSh.cjs.map → generators-Cz0z5DBg.cjs.map} +1 -1
- package/dist/{generators-DmpieAeS.js → generators-D36jd0kA.js} +2 -2
- package/dist/{generators-DmpieAeS.js.map → generators-D36jd0kA.js.map} +1 -1
- package/dist/generators.cjs +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +6 -6
- package/src/components/Mock.tsx +1 -1
- package/src/generators/__snapshots__/createPet.ts +1 -1
- package/src/generators/__snapshots__/deletePet.ts +1 -1
- package/src/generators/__snapshots__/getPets.ts +1 -1
- package/src/generators/__snapshots__/getPetsTemplateBaseUrl.ts +33 -0
- package/src/generators/__snapshots__/showPetById.ts +1 -1
- package/dist/components-CDRldAv7.cjs.map +0 -1
- package/dist/components-DK6Olrp_.js.map +0 -1
|
@@ -38,7 +38,7 @@ function Mock({ baseURL = "", name, typeName, operation }) {
|
|
|
38
38
|
name,
|
|
39
39
|
export: true,
|
|
40
40
|
params: params.toConstructor(),
|
|
41
|
-
children: `return http.${method}(
|
|
41
|
+
children: `return http.${method}(\`${baseURL}${url.replace(/([^/]):/g, "$1\\\\:")}\`, function handler(info) {
|
|
42
42
|
if(typeof data === 'function') return data(info)
|
|
43
43
|
|
|
44
44
|
return new Response(JSON.stringify(data), {
|
|
@@ -146,4 +146,4 @@ Object.defineProperty(exports, 'Response', {
|
|
|
146
146
|
return Response;
|
|
147
147
|
}
|
|
148
148
|
});
|
|
149
|
-
//# sourceMappingURL=components-
|
|
149
|
+
//# sourceMappingURL=components-ATPc-lQH.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components-ATPc-lQH.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,aAAa,mBAAmB,SAAS,IAAI,OAAO,mBAAmB,GAAG,GAAG;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M;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"}
|
|
@@ -37,7 +37,7 @@ function Mock({ baseURL = "", name, typeName, operation }) {
|
|
|
37
37
|
name,
|
|
38
38
|
export: true,
|
|
39
39
|
params: params.toConstructor(),
|
|
40
|
-
children: `return http.${method}(
|
|
40
|
+
children: `return http.${method}(\`${baseURL}${url.replace(/([^/]):/g, "$1\\\\:")}\`, function handler(info) {
|
|
41
41
|
if(typeof data === 'function') return data(info)
|
|
42
42
|
|
|
43
43
|
return new Response(JSON.stringify(data), {
|
|
@@ -122,4 +122,4 @@ function Response({ name, typeName, operation, statusCode }) {
|
|
|
122
122
|
|
|
123
123
|
//#endregion
|
|
124
124
|
export { Handlers as i, MockWithFaker as n, Mock as r, Response as t };
|
|
125
|
-
//# sourceMappingURL=components-
|
|
125
|
+
//# sourceMappingURL=components-C5_yzPIo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components-C5_yzPIo.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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E9F,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;;;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,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"}
|
package/dist/components.cjs
CHANGED
package/dist/components.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_components = require('./components-
|
|
1
|
+
const require_components = require('./components-ATPc-lQH.cjs');
|
|
2
2
|
const require_index = require('./index.cjs');
|
|
3
3
|
let __kubb_plugin_faker = require("@kubb/plugin-faker");
|
|
4
4
|
let __kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
@@ -171,4 +171,4 @@ Object.defineProperty(exports, 'mswGenerator', {
|
|
|
171
171
|
return mswGenerator;
|
|
172
172
|
}
|
|
173
173
|
});
|
|
174
|
-
//# sourceMappingURL=generators-
|
|
174
|
+
//# sourceMappingURL=generators-Cz0z5DBg.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generators-
|
|
1
|
+
{"version":3,"file":"generators-Cz0z5DBg.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,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,yDAACA,yBAAK;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,0DAACA;GACC,UAAU,KAAK;GACf,MAAM,KAAK;GACX,MAAM,KAAK;GACX,+CAAkB;IAAE;IAAK,QAAQ,OAAO,QAAQ;IAAQ,QAAQ,cAAc;IAAQ,CAAC;GACvF,+CAAkB;I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,KAAK,KAAK;GACpB,MAAM,KAAK,KAAK;GAChB,MAAM,KAAK,KAAK;GAChB,+CAAkB;IAAE;IAAK;IAAQ,QAAQ,cAAc;IAAQ,CAAC;GAChE,+CAAkB;IAAE;IAAK;IAAQ,CAAC;;IAElC,yDAACA,yBAAK;KAAO,MAAM,CAAC,OAAO;KAAE,MAAK;MAAQ;IAC1C,yDAACA,yBAAK;KAAO,MAAM,CAAC,mBAAmB;KAAE;KAAW,MAAK;MAAQ;IACjE,yDAACA,yBAAK;KACJ,MAAM,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,QAAQ,SAAS,MAAM,GAAG,MAAM,KAAK,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;KAClF,MAAM,KAAK,KAAK;KAChB,MAAM,KAAK,KAAK;KAChB;MACA;IACD,WAAW,WAAW,MAAM,QAAQ,MAAM,QAAQ,YACjD,yDAACA,yBAAK;KAAO,MAAM,CAAC,MAAM,QAAQ,SAAS,KAAK;KAAE,MAAM,KAAK,KAAK;KAAM,MAAM,MAAM,KAAK;MAAQ;IAGlG,MACE,QAAQ,CAAC,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,4 +1,4 @@
|
|
|
1
|
-
import { i as Handlers, n as MockWithFaker, r as Mock, t as Response } from "./components-
|
|
1
|
+
import { i as Handlers, n as MockWithFaker, r as Mock, t as Response } from "./components-C5_yzPIo.js";
|
|
2
2
|
import { pluginFakerName } from "@kubb/plugin-faker";
|
|
3
3
|
import { pluginTsName } from "@kubb/plugin-ts";
|
|
4
4
|
import { usePluginManager } from "@kubb/core/hooks";
|
|
@@ -159,4 +159,4 @@ const mswGenerator = createReactGenerator({
|
|
|
159
159
|
|
|
160
160
|
//#endregion
|
|
161
161
|
export { handlersGenerator as n, mswGenerator as t };
|
|
162
|
-
//# sourceMappingURL=generators-
|
|
162
|
+
//# sourceMappingURL=generators-D36jd0kA.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generators-
|
|
1
|
+
{"version":3,"file":"generators-D36jd0kA.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,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;I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CHANGED
|
@@ -25,7 +25,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
}) : target, mod));
|
|
26
26
|
|
|
27
27
|
//#endregion
|
|
28
|
-
const require_generators = require('./generators-
|
|
28
|
+
const require_generators = require('./generators-Cz0z5DBg.cjs');
|
|
29
29
|
let node_path = require("node:path");
|
|
30
30
|
node_path = __toESM(node_path);
|
|
31
31
|
let __kubb_core = require("@kubb/core");
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as handlersGenerator, t as mswGenerator } from "./generators-
|
|
1
|
+
import { n as handlersGenerator, t as mswGenerator } from "./generators-D36jd0kA.js";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { definePlugin, getBarrelFiles, getMode } from "@kubb/core";
|
|
4
4
|
import { camelCase } from "@kubb/core/transformers";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-msw",
|
|
3
|
-
"version": "4.12.
|
|
3
|
+
"version": "4.12.2",
|
|
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",
|
|
@@ -74,11 +74,11 @@
|
|
|
74
74
|
],
|
|
75
75
|
"dependencies": {
|
|
76
76
|
"@kubb/react-fabric": "0.7.0",
|
|
77
|
-
"@kubb/core": "4.12.
|
|
78
|
-
"@kubb/oas": "4.12.
|
|
79
|
-
"@kubb/plugin-faker": "4.12.
|
|
80
|
-
"@kubb/plugin-oas": "4.12.
|
|
81
|
-
"@kubb/plugin-ts": "4.12.
|
|
77
|
+
"@kubb/core": "4.12.2",
|
|
78
|
+
"@kubb/oas": "4.12.2",
|
|
79
|
+
"@kubb/plugin-faker": "4.12.2",
|
|
80
|
+
"@kubb/plugin-oas": "4.12.2",
|
|
81
|
+
"@kubb/plugin-ts": "4.12.2"
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {},
|
|
84
84
|
"engines": {
|
package/src/components/Mock.tsx
CHANGED
|
@@ -42,7 +42,7 @@ export function Mock({ baseURL = '', name, typeName, operation }: Props): KubbNo
|
|
|
42
42
|
return (
|
|
43
43
|
<File.Source name={name} isIndexable isExportable>
|
|
44
44
|
<Function name={name} export params={params.toConstructor()}>
|
|
45
|
-
{`return http.${method}(
|
|
45
|
+
{`return http.${method}(\`${baseURL}${url.replace(/([^/]):/g, '$1\\\\:')}\`, function handler(info) {
|
|
46
46
|
if(typeof data === 'function') return data(info)
|
|
47
47
|
|
|
48
48
|
return new Response(JSON.stringify(data), {
|
|
@@ -13,7 +13,7 @@ export function createPetsResponse201(data?: CreatePetsMutationResponse) {
|
|
|
13
13
|
export function createPets(
|
|
14
14
|
data?: string | number | boolean | null | object | ((info: Parameters<Parameters<typeof http.post>[1]>[0]) => Response | Promise<Response>),
|
|
15
15
|
) {
|
|
16
|
-
return http.post(
|
|
16
|
+
return http.post(`/pets`, function handler(info) {
|
|
17
17
|
if (typeof data === 'function') return data(info)
|
|
18
18
|
|
|
19
19
|
return new Response(JSON.stringify(data), {
|
|
@@ -7,7 +7,7 @@ import { http } from 'msw'
|
|
|
7
7
|
export function deletePetsPetid(
|
|
8
8
|
data?: string | number | boolean | null | object | ((info: Parameters<Parameters<typeof http.delete>[1]>[0]) => Response | Promise<Response>),
|
|
9
9
|
) {
|
|
10
|
-
return http.delete(
|
|
10
|
+
return http.delete(`/pets/:petId`, function handler(info) {
|
|
11
11
|
if (typeof data === 'function') return data(info)
|
|
12
12
|
|
|
13
13
|
return new Response(JSON.stringify(data), {
|
|
@@ -20,7 +20,7 @@ export function listPetsResponse400(data?: ListPets400) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export function listPets(data?: ListPetsQueryResponse | ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Response | Promise<Response>)) {
|
|
23
|
-
return http.get(
|
|
23
|
+
return http.get(`/pets`, function handler(info) {
|
|
24
24
|
if (typeof data === 'function') return data(info)
|
|
25
25
|
|
|
26
26
|
return new Response(JSON.stringify(data), {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by Kubb (https://kubb.dev/).
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import { http } from 'msw'
|
|
6
|
+
|
|
7
|
+
export function listPetsResponse200(data: ListPetsQueryResponse) {
|
|
8
|
+
return new Response(JSON.stringify(data), {
|
|
9
|
+
status: 200,
|
|
10
|
+
headers: {
|
|
11
|
+
'Content-Type': 'application/json',
|
|
12
|
+
},
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function listPetsResponse400(data?: ListPets400) {
|
|
17
|
+
return new Response(JSON.stringify(data), {
|
|
18
|
+
status: 400,
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function listPets(data?: ListPetsQueryResponse | ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Response | Promise<Response>)) {
|
|
23
|
+
return http.get(`${123456}/pets`, function handler(info) {
|
|
24
|
+
if (typeof data === 'function') return data(info)
|
|
25
|
+
|
|
26
|
+
return new Response(JSON.stringify(data), {
|
|
27
|
+
status: 200,
|
|
28
|
+
headers: {
|
|
29
|
+
'Content-Type': 'application/json',
|
|
30
|
+
},
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
}
|
|
@@ -14,7 +14,7 @@ export function showPetByIdResponse200(data: ShowPetByIdQueryResponse) {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function showPetById(data?: ShowPetByIdQueryResponse | ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Response | Promise<Response>)) {
|
|
17
|
-
return http.get(
|
|
17
|
+
return http.get(`/pets/:petId`, function handler(info) {
|
|
18
18
|
if (typeof data === 'function') return data(info)
|
|
19
19
|
|
|
20
20
|
return new Response(JSON.stringify(data), {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"components-CDRldAv7.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,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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,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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"components-DK6Olrp_.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,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