@kubb/plugin-msw 4.1.4 → 4.2.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.
- package/dist/{components-Bcz4mvn3.cjs → components-CULOceYX.cjs} +34 -1
- package/dist/components-CULOceYX.cjs.map +1 -0
- package/dist/{components-Ba13vW1_.js → components-DcRndqwD.js} +29 -2
- package/dist/components-DcRndqwD.js.map +1 -0
- package/dist/components.cjs +3 -2
- package/dist/components.d.cts +21 -8
- package/dist/components.d.ts +21 -8
- package/dist/components.js +2 -2
- package/dist/{generators-DgwpklSC.cjs → generators-BpCsxN0-.cjs} +31 -7
- package/dist/generators-BpCsxN0-.cjs.map +1 -0
- package/dist/{generators-lMP39igU.js → generators-itHERcU2.js} +31 -8
- package/dist/generators-itHERcU2.js.map +1 -0
- package/dist/generators.cjs +2 -2
- package/dist/generators.d.cts +2 -2
- package/dist/generators.d.ts +2 -2
- package/dist/generators.js +2 -2
- package/dist/index.cjs +7 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +7 -7
- package/dist/index.js.map +1 -1
- package/dist/{types-BOMj2hjt.d.ts → types-8ZXwr93_.d.cts} +2 -2
- package/dist/{types-BdC96j80.d.ts → types-BB6ZV1EN.d.cts} +79 -123
- package/dist/{types-DLxzBV0T.d.cts → types-BLiYk9M7.d.ts} +79 -123
- package/dist/{types-DYAniEBx.d.cts → types-IbHKcY02.d.ts} +2 -2
- package/package.json +8 -10
- package/src/components/Handlers.tsx +1 -2
- package/src/components/Mock.tsx +1 -2
- package/src/components/MockWithFaker.tsx +1 -2
- package/src/components/Response.tsx +42 -0
- package/src/components/index.ts +1 -0
- package/src/generators/__snapshots__/createPet.ts +6 -0
- package/src/generators/__snapshots__/createPetFaker.ts +6 -0
- package/src/generators/__snapshots__/getPets.ts +15 -0
- package/src/generators/__snapshots__/getPetsFaker.ts +15 -0
- package/src/generators/__snapshots__/showPetById.ts +9 -0
- package/src/generators/handlersGenerator.tsx +5 -2
- package/src/generators/mswGenerator.tsx +37 -8
- package/src/plugin.ts +6 -9
- package/dist/components-Ba13vW1_.js.map +0 -1
- package/dist/components-Bcz4mvn3.cjs.map +0 -1
- package/dist/generators-DgwpklSC.cjs.map +0 -1
- package/dist/generators-lMP39igU.js.map +0 -1
|
@@ -114,6 +114,33 @@ function MockWithFaker({ baseURL = "", name, fakerName, typeName, operation }) {
|
|
|
114
114
|
});
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/components/Response.tsx
|
|
119
|
+
function Response({ name, typeName, operation, statusCode }) {
|
|
120
|
+
const responseObject = operation.getResponseByStatusCode(statusCode);
|
|
121
|
+
const contentType = Object.keys(responseObject.content || {})?.[0];
|
|
122
|
+
const headers = [contentType ? `'Content-Type': '${contentType}'` : void 0].filter(Boolean);
|
|
123
|
+
const params = __kubb_react.FunctionParams.factory({ data: { type: `${typeName}` } });
|
|
124
|
+
const responseName = `${name}Response${statusCode}`;
|
|
125
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
|
|
126
|
+
name: responseName,
|
|
127
|
+
isIndexable: true,
|
|
128
|
+
isExportable: true,
|
|
129
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.Function, {
|
|
130
|
+
name: responseName,
|
|
131
|
+
export: true,
|
|
132
|
+
params: params.toConstructor(),
|
|
133
|
+
children: `
|
|
134
|
+
return new Response(JSON.stringify(data), {
|
|
135
|
+
status: ${statusCode},
|
|
136
|
+
${headers.length ? ` headers: {
|
|
137
|
+
${headers.join(", \n")}
|
|
138
|
+
},` : ""}
|
|
139
|
+
})`
|
|
140
|
+
})
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
117
144
|
//#endregion
|
|
118
145
|
Object.defineProperty(exports, 'Handlers', {
|
|
119
146
|
enumerable: true,
|
|
@@ -133,10 +160,16 @@ Object.defineProperty(exports, 'MockWithFaker', {
|
|
|
133
160
|
return MockWithFaker;
|
|
134
161
|
}
|
|
135
162
|
});
|
|
163
|
+
Object.defineProperty(exports, 'Response', {
|
|
164
|
+
enumerable: true,
|
|
165
|
+
get: function () {
|
|
166
|
+
return Response;
|
|
167
|
+
}
|
|
168
|
+
});
|
|
136
169
|
Object.defineProperty(exports, '__toESM', {
|
|
137
170
|
enumerable: true,
|
|
138
171
|
get: function () {
|
|
139
172
|
return __toESM;
|
|
140
173
|
}
|
|
141
174
|
});
|
|
142
|
-
//# sourceMappingURL=components-
|
|
175
|
+
//# sourceMappingURL=components-CULOceYX.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components-CULOceYX.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'\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) {\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), {\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'\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) {\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'\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) {\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'\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) {\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 params = FunctionParams.factory({\n data: {\n type: `${typeName}`,\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,SAAgB,KAAK,EAAE,UAAU,IAAI,MAAM,UAAU,aAAoB;CACvE,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,IAAIA,0BAAQ,UAAU,KAAK,CAAC,WAAW,CAAC,QAAQ,YAAY,UAAU;CAElF,MAAM,UAAU,CAAC,c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M;EAAY;YACnC,kDAACC;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,cAAqB;CACzE,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,SAASC,4BAAe,QAAQ,EACpC,MAAM,EACJ,MAAM,GAAG,YACV,EACF,CAAC;CAEF,MAAM,eAAe,GAAG,KAAK,UAAU;AAEvC,QACE,kDAACC,kBAAK;EAAO,MAAM;EAAc;EAAY;YAC3C,kDAACC;GAAS,MAAM;GAAc;GAAO,QAAQ,OAAO,eAAe;aAChE;;gBAEO,WAAW;QAEnB,QAAQ,SACJ;UACF,QAAQ,KAAK,OAAO,CAAC;YAEnB,GACL;;IAEU;GACC"}
|
|
@@ -89,5 +89,32 @@ function MockWithFaker({ baseURL = "", name, fakerName, typeName, operation }) {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
//#endregion
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
//#region src/components/Response.tsx
|
|
93
|
+
function Response({ name, typeName, operation, statusCode }) {
|
|
94
|
+
const responseObject = operation.getResponseByStatusCode(statusCode);
|
|
95
|
+
const contentType = Object.keys(responseObject.content || {})?.[0];
|
|
96
|
+
const headers = [contentType ? `'Content-Type': '${contentType}'` : void 0].filter(Boolean);
|
|
97
|
+
const params = FunctionParams.factory({ data: { type: `${typeName}` } });
|
|
98
|
+
const responseName = `${name}Response${statusCode}`;
|
|
99
|
+
return /* @__PURE__ */ jsx(File.Source, {
|
|
100
|
+
name: responseName,
|
|
101
|
+
isIndexable: true,
|
|
102
|
+
isExportable: true,
|
|
103
|
+
children: /* @__PURE__ */ jsx(Function, {
|
|
104
|
+
name: responseName,
|
|
105
|
+
export: true,
|
|
106
|
+
params: params.toConstructor(),
|
|
107
|
+
children: `
|
|
108
|
+
return new Response(JSON.stringify(data), {
|
|
109
|
+
status: ${statusCode},
|
|
110
|
+
${headers.length ? ` headers: {
|
|
111
|
+
${headers.join(", \n")}
|
|
112
|
+
},` : ""}
|
|
113
|
+
})`
|
|
114
|
+
})
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
//#endregion
|
|
119
|
+
export { Mock as i, MockWithFaker as n, Handlers as r, Response as t };
|
|
120
|
+
//# sourceMappingURL=components-DcRndqwD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components-DcRndqwD.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'\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) {\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), {\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'\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) {\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'\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) {\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'\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) {\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 params = FunctionParams.factory({\n data: {\n type: `${typeName}`,\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":";;;;;AAeA,SAAgB,KAAK,EAAE,UAAU,IAAI,MAAM,UAAU,aAAoB;CACvE,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,UAA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AM;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,cAAqB;CACzE,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,SAAS,eAAe,QAAQ,EACpC,MAAM,EACJ,MAAM,GAAG,YACV,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
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
const require_components = require('./components-
|
|
1
|
+
const require_components = require('./components-CULOceYX.cjs');
|
|
2
2
|
|
|
3
3
|
exports.Handlers = require_components.Handlers;
|
|
4
4
|
exports.Mock = require_components.Mock;
|
|
5
|
-
exports.MockWithFaker = require_components.MockWithFaker;
|
|
5
|
+
exports.MockWithFaker = require_components.MockWithFaker;
|
|
6
|
+
exports.Response = require_components.Response;
|
package/dist/components.d.cts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { Operation } from "./types-
|
|
2
|
-
import { ReactNode } from "react";
|
|
1
|
+
import { r as Operation } from "./types-8ZXwr93_.cjs";
|
|
3
2
|
|
|
4
3
|
//#region src/components/Mock.d.ts
|
|
5
|
-
type Props$
|
|
4
|
+
type Props$2 = {
|
|
6
5
|
/**
|
|
7
6
|
* Name of the function
|
|
8
7
|
*/
|
|
@@ -17,7 +16,7 @@ declare function Mock({
|
|
|
17
16
|
name,
|
|
18
17
|
typeName,
|
|
19
18
|
operation
|
|
20
|
-
}: Props$
|
|
19
|
+
}: Props$2): any;
|
|
21
20
|
//#endregion
|
|
22
21
|
//#region src/components/Handlers.d.ts
|
|
23
22
|
type HandlersProps = {
|
|
@@ -30,10 +29,10 @@ type HandlersProps = {
|
|
|
30
29
|
declare function Handlers({
|
|
31
30
|
name,
|
|
32
31
|
handlers
|
|
33
|
-
}: HandlersProps):
|
|
32
|
+
}: HandlersProps): any;
|
|
34
33
|
//#endregion
|
|
35
34
|
//#region src/components/MockWithFaker.d.ts
|
|
36
|
-
type Props = {
|
|
35
|
+
type Props$1 = {
|
|
37
36
|
/**
|
|
38
37
|
* Name of the function
|
|
39
38
|
*/
|
|
@@ -49,7 +48,21 @@ declare function MockWithFaker({
|
|
|
49
48
|
fakerName,
|
|
50
49
|
typeName,
|
|
51
50
|
operation
|
|
52
|
-
}: Props):
|
|
51
|
+
}: Props$1): any;
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/components/Response.d.ts
|
|
54
|
+
type Props = {
|
|
55
|
+
typeName: string;
|
|
56
|
+
operation: Operation;
|
|
57
|
+
name: string;
|
|
58
|
+
statusCode: number;
|
|
59
|
+
};
|
|
60
|
+
declare function Response({
|
|
61
|
+
name,
|
|
62
|
+
typeName,
|
|
63
|
+
operation,
|
|
64
|
+
statusCode
|
|
65
|
+
}: Props): any;
|
|
53
66
|
//#endregion
|
|
54
|
-
export { Handlers, Mock, MockWithFaker };
|
|
67
|
+
export { Handlers, Mock, MockWithFaker, Response };
|
|
55
68
|
//# sourceMappingURL=components.d.cts.map
|
package/dist/components.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { Operation } from "./types-
|
|
2
|
-
import { ReactNode } from "react";
|
|
1
|
+
import { r as Operation } from "./types-IbHKcY02.js";
|
|
3
2
|
|
|
4
3
|
//#region src/components/Mock.d.ts
|
|
5
|
-
type Props$
|
|
4
|
+
type Props$2 = {
|
|
6
5
|
/**
|
|
7
6
|
* Name of the function
|
|
8
7
|
*/
|
|
@@ -17,7 +16,7 @@ declare function Mock({
|
|
|
17
16
|
name,
|
|
18
17
|
typeName,
|
|
19
18
|
operation
|
|
20
|
-
}: Props$
|
|
19
|
+
}: Props$2): any;
|
|
21
20
|
//#endregion
|
|
22
21
|
//#region src/components/Handlers.d.ts
|
|
23
22
|
type HandlersProps = {
|
|
@@ -30,10 +29,10 @@ type HandlersProps = {
|
|
|
30
29
|
declare function Handlers({
|
|
31
30
|
name,
|
|
32
31
|
handlers
|
|
33
|
-
}: HandlersProps):
|
|
32
|
+
}: HandlersProps): any;
|
|
34
33
|
//#endregion
|
|
35
34
|
//#region src/components/MockWithFaker.d.ts
|
|
36
|
-
type Props = {
|
|
35
|
+
type Props$1 = {
|
|
37
36
|
/**
|
|
38
37
|
* Name of the function
|
|
39
38
|
*/
|
|
@@ -49,7 +48,21 @@ declare function MockWithFaker({
|
|
|
49
48
|
fakerName,
|
|
50
49
|
typeName,
|
|
51
50
|
operation
|
|
52
|
-
}: Props):
|
|
51
|
+
}: Props$1): any;
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/components/Response.d.ts
|
|
54
|
+
type Props = {
|
|
55
|
+
typeName: string;
|
|
56
|
+
operation: Operation;
|
|
57
|
+
name: string;
|
|
58
|
+
statusCode: number;
|
|
59
|
+
};
|
|
60
|
+
declare function Response({
|
|
61
|
+
name,
|
|
62
|
+
typeName,
|
|
63
|
+
operation,
|
|
64
|
+
statusCode
|
|
65
|
+
}: Props): any;
|
|
53
66
|
//#endregion
|
|
54
|
-
export { Handlers, Mock, MockWithFaker };
|
|
67
|
+
export { Handlers, Mock, MockWithFaker, Response };
|
|
55
68
|
//# sourceMappingURL=components.d.ts.map
|
package/dist/components.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as Mock, n as MockWithFaker, r as Handlers, t as Response } from "./components-DcRndqwD.js";
|
|
2
2
|
|
|
3
|
-
export { Handlers, Mock, MockWithFaker };
|
|
3
|
+
export { Handlers, Mock, MockWithFaker, Response };
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
const require_components = require('./components-
|
|
2
|
-
let __kubb_plugin_oas = require("@kubb/plugin-oas");
|
|
3
|
-
__kubb_plugin_oas = require_components.__toESM(__kubb_plugin_oas);
|
|
1
|
+
const require_components = require('./components-CULOceYX.cjs');
|
|
4
2
|
let __kubb_plugin_faker = require("@kubb/plugin-faker");
|
|
5
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
6
|
let __kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
7
7
|
__kubb_plugin_ts = require_components.__toESM(__kubb_plugin_ts);
|
|
8
|
+
let __kubb_core_hooks = require("@kubb/core/hooks");
|
|
9
|
+
__kubb_core_hooks = require_components.__toESM(__kubb_core_hooks);
|
|
8
10
|
let __kubb_plugin_oas_hooks = require("@kubb/plugin-oas/hooks");
|
|
9
11
|
__kubb_plugin_oas_hooks = require_components.__toESM(__kubb_plugin_oas_hooks);
|
|
10
12
|
let __kubb_plugin_oas_utils = require("@kubb/plugin-oas/utils");
|
|
@@ -18,7 +20,8 @@ __kubb_react_jsx_runtime = require_components.__toESM(__kubb_react_jsx_runtime);
|
|
|
18
20
|
const mswGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
|
|
19
21
|
name: "msw",
|
|
20
22
|
Operation({ operation }) {
|
|
21
|
-
const {
|
|
23
|
+
const { options: { output, parser, baseURL } } = (0, __kubb_core_hooks.usePlugin)();
|
|
24
|
+
const pluginManager = (0, __kubb_core_hooks.usePluginManager)();
|
|
22
25
|
const oas = (0, __kubb_plugin_oas_hooks.useOas)();
|
|
23
26
|
const { getSchemas, getName, getFile } = (0, __kubb_plugin_oas_hooks.useOperationManager)();
|
|
24
27
|
const mock = {
|
|
@@ -39,6 +42,20 @@ const mswGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
|
|
|
39
42
|
type: "type"
|
|
40
43
|
})
|
|
41
44
|
};
|
|
45
|
+
const responseStatusCodes = operation.getResponseStatusCodes();
|
|
46
|
+
const types = [];
|
|
47
|
+
for (const code of responseStatusCodes) {
|
|
48
|
+
if (code === "default") {
|
|
49
|
+
types.push(["default", type.schemas.response.name]);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (code.startsWith("2")) {
|
|
53
|
+
types.push([Number(code), type.schemas.response.name]);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const codeType = type.schemas.errors?.find((err) => err.statusCode === Number(code));
|
|
57
|
+
if (codeType) types.push([Number(code), codeType.name]);
|
|
58
|
+
}
|
|
42
59
|
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react.File, {
|
|
43
60
|
baseName: mock.file.baseName,
|
|
44
61
|
path: mock.file.path,
|
|
@@ -63,7 +80,7 @@ const mswGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
|
|
|
63
80
|
path: "msw"
|
|
64
81
|
}),
|
|
65
82
|
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
66
|
-
name: [type.schemas.response.name],
|
|
83
|
+
name: Array.from(new Set([type.schemas.response.name, ...types.map((t) => t[1])])),
|
|
67
84
|
path: type.file.path,
|
|
68
85
|
root: mock.file.path,
|
|
69
86
|
isTypeOnly: true
|
|
@@ -73,6 +90,12 @@ const mswGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
|
|
|
73
90
|
root: mock.file.path,
|
|
74
91
|
path: faker.file.path
|
|
75
92
|
}),
|
|
93
|
+
types.filter(([code]) => code !== "default").map(([code, typeName]) => /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.Response, {
|
|
94
|
+
typeName,
|
|
95
|
+
operation,
|
|
96
|
+
name: mock.name,
|
|
97
|
+
statusCode: code
|
|
98
|
+
})),
|
|
76
99
|
parser === "faker" && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.MockWithFaker, {
|
|
77
100
|
name: mock.name,
|
|
78
101
|
typeName: type.schemas.response.name,
|
|
@@ -97,7 +120,8 @@ const mswGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
|
|
|
97
120
|
const handlersGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
|
|
98
121
|
name: "plugin-msw",
|
|
99
122
|
Operations({ operations }) {
|
|
100
|
-
const
|
|
123
|
+
const plugin = (0, __kubb_core_hooks.usePlugin)();
|
|
124
|
+
const pluginManager = (0, __kubb_core_hooks.usePluginManager)();
|
|
101
125
|
const oas = (0, __kubb_plugin_oas_hooks.useOas)();
|
|
102
126
|
const { getName, getFile } = (0, __kubb_plugin_oas_hooks.useOperationManager)();
|
|
103
127
|
const file = pluginManager.getFile({
|
|
@@ -155,4 +179,4 @@ Object.defineProperty(exports, 'mswGenerator', {
|
|
|
155
179
|
return mswGenerator;
|
|
156
180
|
}
|
|
157
181
|
});
|
|
158
|
-
//# sourceMappingURL=generators-
|
|
182
|
+
//# sourceMappingURL=generators-BpCsxN0-.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-BpCsxN0-.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'\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'\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,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QAAQ,WAAW;IAAE,WAAW,OAAO;IAAK,MAAM;IAAY,CAAC;AAErF,UAAO,kDAACC,kBAAK;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,mDAACA;GACC,UAAU,KAAK;GACf,MAAM,KAAK;GACX,MAAM,KAAK;GACX,+CAAkB;IAAE;IAAK,QAAQ,OAAO,QAAQ;IAAQ,QAAQ,cAAc;IAAQ,CAAC;GACvF,+CAAkB;IAAE;IAAK,QAAQ,OAAO,QAAQ;IAAQ,CAAC;cAExD,SACD,kDAACC;IAAS,MAAM;IAAsB;KAAY;IAC7C;;CAGZ,CAAC"}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createReactGenerator } from "@kubb/plugin-oas";
|
|
1
|
+
import { i as Mock, n as MockWithFaker, r as Handlers, t as Response } from "./components-DcRndqwD.js";
|
|
3
2
|
import { pluginFakerName } from "@kubb/plugin-faker";
|
|
3
|
+
import { createReactGenerator } from "@kubb/plugin-oas";
|
|
4
4
|
import { pluginTsName } from "@kubb/plugin-ts";
|
|
5
|
+
import { usePlugin, usePluginManager } from "@kubb/core/hooks";
|
|
5
6
|
import { useOas, useOperationManager } from "@kubb/plugin-oas/hooks";
|
|
6
7
|
import { getBanner, getFooter } from "@kubb/plugin-oas/utils";
|
|
7
|
-
import { File
|
|
8
|
+
import { File } from "@kubb/react";
|
|
8
9
|
import { jsx, jsxs } from "@kubb/react/jsx-runtime";
|
|
9
10
|
|
|
10
11
|
//#region src/generators/mswGenerator.tsx
|
|
11
12
|
const mswGenerator = createReactGenerator({
|
|
12
13
|
name: "msw",
|
|
13
14
|
Operation({ operation }) {
|
|
14
|
-
const {
|
|
15
|
+
const { options: { output, parser, baseURL } } = usePlugin();
|
|
16
|
+
const pluginManager = usePluginManager();
|
|
15
17
|
const oas = useOas();
|
|
16
18
|
const { getSchemas, getName, getFile } = useOperationManager();
|
|
17
19
|
const mock = {
|
|
@@ -32,6 +34,20 @@ const mswGenerator = createReactGenerator({
|
|
|
32
34
|
type: "type"
|
|
33
35
|
})
|
|
34
36
|
};
|
|
37
|
+
const responseStatusCodes = operation.getResponseStatusCodes();
|
|
38
|
+
const types = [];
|
|
39
|
+
for (const code of responseStatusCodes) {
|
|
40
|
+
if (code === "default") {
|
|
41
|
+
types.push(["default", type.schemas.response.name]);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (code.startsWith("2")) {
|
|
45
|
+
types.push([Number(code), type.schemas.response.name]);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const codeType = type.schemas.errors?.find((err) => err.statusCode === Number(code));
|
|
49
|
+
if (codeType) types.push([Number(code), codeType.name]);
|
|
50
|
+
}
|
|
35
51
|
return /* @__PURE__ */ jsxs(File, {
|
|
36
52
|
baseName: mock.file.baseName,
|
|
37
53
|
path: mock.file.path,
|
|
@@ -56,7 +72,7 @@ const mswGenerator = createReactGenerator({
|
|
|
56
72
|
path: "msw"
|
|
57
73
|
}),
|
|
58
74
|
/* @__PURE__ */ jsx(File.Import, {
|
|
59
|
-
name: [type.schemas.response.name],
|
|
75
|
+
name: Array.from(new Set([type.schemas.response.name, ...types.map((t) => t[1])])),
|
|
60
76
|
path: type.file.path,
|
|
61
77
|
root: mock.file.path,
|
|
62
78
|
isTypeOnly: true
|
|
@@ -66,6 +82,12 @@ const mswGenerator = createReactGenerator({
|
|
|
66
82
|
root: mock.file.path,
|
|
67
83
|
path: faker.file.path
|
|
68
84
|
}),
|
|
85
|
+
types.filter(([code]) => code !== "default").map(([code, typeName]) => /* @__PURE__ */ jsx(Response, {
|
|
86
|
+
typeName,
|
|
87
|
+
operation,
|
|
88
|
+
name: mock.name,
|
|
89
|
+
statusCode: code
|
|
90
|
+
})),
|
|
69
91
|
parser === "faker" && /* @__PURE__ */ jsx(MockWithFaker, {
|
|
70
92
|
name: mock.name,
|
|
71
93
|
typeName: type.schemas.response.name,
|
|
@@ -90,7 +112,8 @@ const mswGenerator = createReactGenerator({
|
|
|
90
112
|
const handlersGenerator = createReactGenerator({
|
|
91
113
|
name: "plugin-msw",
|
|
92
114
|
Operations({ operations }) {
|
|
93
|
-
const
|
|
115
|
+
const plugin = usePlugin();
|
|
116
|
+
const pluginManager = usePluginManager();
|
|
94
117
|
const oas = useOas();
|
|
95
118
|
const { getName, getFile } = useOperationManager();
|
|
96
119
|
const file = pluginManager.getFile({
|
|
@@ -136,5 +159,5 @@ const handlersGenerator = createReactGenerator({
|
|
|
136
159
|
});
|
|
137
160
|
|
|
138
161
|
//#endregion
|
|
139
|
-
export {
|
|
140
|
-
//# sourceMappingURL=generators-
|
|
162
|
+
export { mswGenerator as n, handlersGenerator as t };
|
|
163
|
+
//# sourceMappingURL=generators-itHERcU2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-itHERcU2.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'\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'\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,CA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AAK;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"}
|
package/dist/generators.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
require('./components-
|
|
2
|
-
const require_generators = require('./generators-
|
|
1
|
+
require('./components-CULOceYX.cjs');
|
|
2
|
+
const require_generators = require('./generators-BpCsxN0-.cjs');
|
|
3
3
|
|
|
4
4
|
exports.handlersGenerator = require_generators.handlersGenerator;
|
|
5
5
|
exports.mswGenerator = require_generators.mswGenerator;
|
package/dist/generators.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./types-
|
|
2
|
-
import {
|
|
1
|
+
import "./types-8ZXwr93_.cjs";
|
|
2
|
+
import { n as PluginMsw, r as Generator } from "./types-BB6ZV1EN.cjs";
|
|
3
3
|
|
|
4
4
|
//#region src/generators/mswGenerator.d.ts
|
|
5
5
|
declare const mswGenerator: Generator<PluginMsw>;
|
package/dist/generators.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./types-
|
|
2
|
-
import {
|
|
1
|
+
import "./types-IbHKcY02.js";
|
|
2
|
+
import { n as PluginMsw, r as Generator } from "./types-BLiYk9M7.js";
|
|
3
3
|
|
|
4
4
|
//#region src/generators/mswGenerator.d.ts
|
|
5
5
|
declare const mswGenerator: Generator<PluginMsw>;
|
package/dist/generators.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./components-
|
|
2
|
-
import {
|
|
1
|
+
import "./components-DcRndqwD.js";
|
|
2
|
+
import { n as mswGenerator, t as handlersGenerator } from "./generators-itHERcU2.js";
|
|
3
3
|
|
|
4
4
|
export { handlersGenerator, mswGenerator };
|
package/dist/index.cjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
const require_components = require('./components-
|
|
2
|
-
const require_generators = require('./generators-
|
|
1
|
+
const require_components = require('./components-CULOceYX.cjs');
|
|
2
|
+
const require_generators = require('./generators-BpCsxN0-.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");
|
|
6
6
|
__kubb_core = require_components.__toESM(__kubb_core);
|
|
7
7
|
let __kubb_core_transformers = require("@kubb/core/transformers");
|
|
8
8
|
__kubb_core_transformers = require_components.__toESM(__kubb_core_transformers);
|
|
9
|
-
let __kubb_plugin_oas = require("@kubb/plugin-oas");
|
|
10
|
-
__kubb_plugin_oas = require_components.__toESM(__kubb_plugin_oas);
|
|
11
9
|
let __kubb_plugin_faker = require("@kubb/plugin-faker");
|
|
12
10
|
__kubb_plugin_faker = require_components.__toESM(__kubb_plugin_faker);
|
|
11
|
+
let __kubb_plugin_oas = require("@kubb/plugin-oas");
|
|
12
|
+
__kubb_plugin_oas = require_components.__toESM(__kubb_plugin_oas);
|
|
13
13
|
let __kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
14
14
|
__kubb_plugin_ts = require_components.__toESM(__kubb_plugin_ts);
|
|
15
15
|
|
|
@@ -35,7 +35,7 @@ const pluginMsw = (0, __kubb_core.createPlugin)((options) => {
|
|
|
35
35
|
].filter(Boolean),
|
|
36
36
|
resolvePath(baseName, pathMode, options$1) {
|
|
37
37
|
const root = node_path.default.resolve(this.config.root, this.config.output.path);
|
|
38
|
-
if ((pathMode ?? __kubb_core.
|
|
38
|
+
if ((pathMode ?? (0, __kubb_core.getMode)(node_path.default.resolve(root, output.path))) === "single")
|
|
39
39
|
/**
|
|
40
40
|
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
41
41
|
* Other plugins then need to call addOrAppend instead of just add from the fileManager class
|
|
@@ -62,7 +62,7 @@ const pluginMsw = (0, __kubb_core.createPlugin)((options) => {
|
|
|
62
62
|
const [swaggerPlugin] = __kubb_core.PluginManager.getDependedPlugins(this.plugins, [__kubb_plugin_oas.pluginOasName]);
|
|
63
63
|
const oas = await swaggerPlugin.context.getOas();
|
|
64
64
|
const root = node_path.default.resolve(this.config.root, this.config.output.path);
|
|
65
|
-
const mode = __kubb_core.
|
|
65
|
+
const mode = (0, __kubb_core.getMode)(node_path.default.resolve(root, output.path));
|
|
66
66
|
const files = await new __kubb_plugin_oas.OperationGenerator(this.plugin.options, {
|
|
67
67
|
oas,
|
|
68
68
|
pluginManager: this.pluginManager,
|
|
@@ -74,7 +74,7 @@ const pluginMsw = (0, __kubb_core.createPlugin)((options) => {
|
|
|
74
74
|
mode
|
|
75
75
|
}).build(...generators);
|
|
76
76
|
await this.addFile(...files);
|
|
77
|
-
const barrelFiles = await this.fileManager.
|
|
77
|
+
const barrelFiles = await (0, __kubb_core.getBarrelFiles)(this.fileManager.files, {
|
|
78
78
|
type: output.barrelType ?? "named",
|
|
79
79
|
root,
|
|
80
80
|
output,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["mswGenerator","handlersGenerator","pluginOasName","pluginTsName","pluginFakerName","path","
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["mswGenerator","handlersGenerator","pluginOasName","pluginTsName","pluginFakerName","path","options","groupName: Group['name']","PluginManager","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { createPlugin, type Group, getBarrelFiles, getMode, type Plugin, PluginManager } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = createPlugin<PluginMsw>((options) => {\n const {\n output = { path: 'handlers', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n handlers = false,\n parser = 'data',\n generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),\n contentType,\n baseURL,\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n parser,\n group,\n baseURL,\n },\n pre: [pluginOasName, pluginTsName, parser === 'faker' ? pluginFakerName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\n })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.addFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fileManager.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;;AAWA,MAAa,gBAAgB;AAE7B,MAAa,2CAAqC,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAY,YAAY;EAAS,EAClD,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,eAAe,EAAE,EACjB,WAAW,OACX,SAAS,QACT,aAAa,CAACA,iCAAc,WAAWC,uCAAoB,OAAU,CAAC,OAAO,QAAQ,EACrF,aACA,YACE;AAEJ,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA;GACA;GACA;GACD;EACD,KAAK;GAACC;GAAeC;GAAc,WAAW,UAAUC,sCAAkB;GAAU,CAAC,OAAO,QAAQ;EACpG,YAAY,UAAU,UAAU,WAAS;GACvC,MAAM,OAAOC,kBAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;AAGpE,QAFa,qCAAoBA,kBAAK,QAAQ,MAAM,OAAO,KAAK,CAAC,MAEpD;;;;;AAKX,UAAOA,kBAAK,QAAQ,MAAM,OAAO,KAAK;AAGxC,OAAI,UAAUC,WAAS,OAAO,QAAQA,WAAS,OAAO,MAAM;IAC1D,MAAMC,YAA2B,OAAO,OACpC,MAAM,QACL,QAAQ;AACP,SAAI,OAAO,SAAS,OAClB,QAAO,GAAG,IAAI,MAAM,MAAM,IAAI,CAAC;AAEjC,YAAO,2CAAa,IAAI,MAAM,CAAC;;AAGrC,WAAOF,kBAAK,QACV,MACA,OAAO,MACP,UAAU,EACR,OAAO,MAAM,SAAS,SAASC,UAAQ,MAAM,OAAQA,UAAQ,MAAM,KACpE,CAAC,EACF,SACD;;AAGH,UAAOD,kBAAK,QAAQ,MAAM,OAAO,MAAM,SAAS;;EAElD,YAAY,MAAM,MAAM;GACtB,MAAM,uDAAyB,MAAM;IACnC,QAAQ,OAAO,YAAY;IAC3B,QAAQ,SAAS;IAClB,CAAC;AAEF,OAAI,KACF,QAAO,cAAc,OAAO,cAAc,KAAK,IAAI;AAGrD,UAAO;;EAET,MAAM,aAAa;GACjB,MAAM,CAAC,iBAAiDG,0BAAc,mBAAyC,KAAK,SAAS,CAACN,gCAAc,CAAC;GAE7I,MAAM,MAAM,MAAM,cAAc,QAAQ,QAAQ;GAChD,MAAM,OAAOG,kBAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;GACpE,MAAM,gCAAeA,kBAAK,QAAQ,MAAM,OAAO,KAAK,CAAC;GAarD,MAAM,QAAQ,MAXa,IAAII,qCAAmB,KAAK,OAAO,SAAS;IACrE;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAEqC,MAAM,GAAG,WAAW;AAC3D,SAAM,KAAK,QAAQ,GAAG,MAAM;GAE5B,MAAM,cAAc,sCAAqB,KAAK,YAAY,OAAO;IAC/D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACD,QAAQ,KAAK;IACd,CAAC;AAEF,SAAM,KAAK,QAAQ,GAAG,YAAY;;EAErC;EACD"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./types-
|
|
2
|
-
import {
|
|
1
|
+
import "./types-8ZXwr93_.cjs";
|
|
2
|
+
import { i as UserPluginWithLifeCycle, n as PluginMsw, t as Options } from "./types-BB6ZV1EN.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
|
-
import "./types-
|
|
2
|
-
import {
|
|
1
|
+
import "./types-IbHKcY02.js";
|
|
2
|
+
import { i as UserPluginWithLifeCycle, n as PluginMsw, t as Options } from "./types-BLiYk9M7.js";
|
|
3
3
|
|
|
4
4
|
//#region src/plugin.d.ts
|
|
5
5
|
declare const pluginMswName = "plugin-msw";
|