@kubb/plugin-cypress 0.0.0-canary-20250324220231
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/LICENSE +21 -0
- package/README.md +53 -0
- package/dist/chunk-G5BC6NQG.cjs +74 -0
- package/dist/chunk-G5BC6NQG.cjs.map +1 -0
- package/dist/chunk-O3CFCJRV.js +24 -0
- package/dist/chunk-O3CFCJRV.js.map +1 -0
- package/dist/chunk-Q34V6XN5.js +72 -0
- package/dist/chunk-Q34V6XN5.js.map +1 -0
- package/dist/chunk-QRUN5SOO.cjs +26 -0
- package/dist/chunk-QRUN5SOO.cjs.map +1 -0
- package/dist/components.cjs +12 -0
- package/dist/components.cjs.map +1 -0
- package/dist/components.d.cts +20 -0
- package/dist/components.d.ts +20 -0
- package/dist/components.js +3 -0
- package/dist/components.js.map +1 -0
- package/dist/generators.cjs +13 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +8 -0
- package/dist/generators.d.ts +8 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +106 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +99 -0
- package/dist/index.js.map +1 -0
- package/dist/types-C2ke2hnU.d.cts +59 -0
- package/dist/types-C2ke2hnU.d.ts +59 -0
- package/package.json +113 -0
- package/src/components/Request.tsx +45 -0
- package/src/components/index.ts +1 -0
- package/src/generators/__snapshots__/createPet.ts +3 -0
- package/src/generators/__snapshots__/deletePet.ts +3 -0
- package/src/generators/__snapshots__/getPets.ts +3 -0
- package/src/generators/__snapshots__/showPetById.ts +3 -0
- package/src/generators/cypressGenerator.tsx +63 -0
- package/src/generators/index.ts +1 -0
- package/src/index.ts +2 -0
- package/src/plugin.ts +118 -0
- package/src/types.ts +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Stijn Van Hulle
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<!-- <img src="assets/logo.png" alt="logo" width="200" height="auto" /> -->
|
|
4
|
+
<h1>@kubb/plugin-cypress</h1>
|
|
5
|
+
|
|
6
|
+
<p>
|
|
7
|
+
Swagger integration to create Cypress requests commands.
|
|
8
|
+
</p>
|
|
9
|
+
<img src="https://raw.githubusercontent.com/kubb-labs/kubb/main/assets/banner.png" alt="logo" height="auto" />
|
|
10
|
+
|
|
11
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
12
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
13
|
+
[![Coverage][coverage-src]][coverage-href]
|
|
14
|
+
[![License][license-src]][license-href]
|
|
15
|
+
|
|
16
|
+
<h4>
|
|
17
|
+
<a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/main//examples/typescript" target="_blank">View Demo</a>
|
|
18
|
+
<span> · </span>
|
|
19
|
+
<a href="https://kubb.dev/" target="_blank">Documentation</a>
|
|
20
|
+
<span> · </span>
|
|
21
|
+
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
|
|
22
|
+
<span> · </span>
|
|
23
|
+
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Request Feature</a>
|
|
24
|
+
</h4>
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
## Supporting Kubb
|
|
28
|
+
|
|
29
|
+
Kubb uses an MIT-licensed open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider:
|
|
30
|
+
|
|
31
|
+
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
|
|
32
|
+
|
|
33
|
+
<p align="center">
|
|
34
|
+
<a href="https://github.com/sponsors/stijnvanhulle">
|
|
35
|
+
<img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" />
|
|
36
|
+
</a>
|
|
37
|
+
</p>
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
<!-- Badges -->
|
|
41
|
+
|
|
42
|
+
[npm-version-src]: https://img.shields.io/npm/v/@kubb/plugin-msw?flat&colorA=18181B&colorB=f58517
|
|
43
|
+
[npm-version-href]: https://npmjs.com/package/@kubb/plugin-msw
|
|
44
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/@kubb/plugin-msw?flat&colorA=18181B&colorB=f58517
|
|
45
|
+
[npm-downloads-href]: https://npmjs.com/package/@kubb/plugin-msw
|
|
46
|
+
[license-src]: https://img.shields.io/github/license/kubb-labs/kubb.svg?flat&colorA=18181B&colorB=f58517
|
|
47
|
+
[license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
|
|
48
|
+
[build-src]: https://img.shields.io/github/actions/workflow/status/kubb-labs/kubb/ci.yaml?style=flat&colorA=18181B&colorB=f58517
|
|
49
|
+
[build-href]: https://www.npmjs.com/package/@kubb/plugin-msw
|
|
50
|
+
[minified-src]: https://img.shields.io/bundlephobia/min/@kubb/plugin-msw?style=flat&colorA=18181B&colorB=f58517
|
|
51
|
+
[minified-href]: https://www.npmjs.com/package/@kubb/plugin-msw
|
|
52
|
+
[coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
|
|
53
|
+
[coverage-href]: https://www.npmjs.com/package/@kubb/plugin-msw
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkQRUN5SOO_cjs = require('./chunk-QRUN5SOO.cjs');
|
|
4
|
+
var utils$1 = require('@kubb/core/utils');
|
|
5
|
+
var pluginOas = require('@kubb/plugin-oas');
|
|
6
|
+
var hooks = require('@kubb/plugin-oas/hooks');
|
|
7
|
+
var utils = require('@kubb/plugin-oas/utils');
|
|
8
|
+
var pluginTs = require('@kubb/plugin-ts');
|
|
9
|
+
var react = require('@kubb/react');
|
|
10
|
+
var jsxRuntime = require('@kubb/react/jsx-runtime');
|
|
11
|
+
|
|
12
|
+
var cypressGenerator = pluginOas.createReactGenerator({
|
|
13
|
+
name: "cypress",
|
|
14
|
+
Operation({ operation }) {
|
|
15
|
+
const {
|
|
16
|
+
plugin: {
|
|
17
|
+
options: { output, baseURL, dataReturnType }
|
|
18
|
+
}
|
|
19
|
+
} = react.useApp();
|
|
20
|
+
const oas = hooks.useOas();
|
|
21
|
+
const { getSchemas, getName, getFile } = hooks.useOperationManager();
|
|
22
|
+
const request = {
|
|
23
|
+
name: getName(operation, { type: "function" }),
|
|
24
|
+
file: getFile(operation)
|
|
25
|
+
};
|
|
26
|
+
const type = {
|
|
27
|
+
file: getFile(operation, { pluginKey: [pluginTs.pluginTsName] }),
|
|
28
|
+
schemas: getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" })
|
|
29
|
+
};
|
|
30
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
31
|
+
react.File,
|
|
32
|
+
{
|
|
33
|
+
baseName: request.file.baseName,
|
|
34
|
+
path: request.file.path,
|
|
35
|
+
meta: request.file.meta,
|
|
36
|
+
banner: utils.getBanner({ oas, output }),
|
|
37
|
+
footer: utils.getFooter({ oas, output }),
|
|
38
|
+
children: [
|
|
39
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
40
|
+
react.File.Import,
|
|
41
|
+
{
|
|
42
|
+
name: [
|
|
43
|
+
type.schemas.request?.name,
|
|
44
|
+
type.schemas.response.name,
|
|
45
|
+
type.schemas.pathParams?.name,
|
|
46
|
+
type.schemas.queryParams?.name,
|
|
47
|
+
type.schemas.headerParams?.name,
|
|
48
|
+
...type.schemas.statusCodes?.map((item) => item.name) || []
|
|
49
|
+
].filter(Boolean),
|
|
50
|
+
root: request.file.path,
|
|
51
|
+
path: type.file.path,
|
|
52
|
+
isTypeOnly: true
|
|
53
|
+
}
|
|
54
|
+
),
|
|
55
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
56
|
+
chunkQRUN5SOO_cjs.Request,
|
|
57
|
+
{
|
|
58
|
+
name: request.name,
|
|
59
|
+
dataReturnType,
|
|
60
|
+
typeSchemas: type.schemas,
|
|
61
|
+
method: operation.method,
|
|
62
|
+
baseURL,
|
|
63
|
+
url: new utils$1.URLPath(operation.path).toURLPath()
|
|
64
|
+
}
|
|
65
|
+
)
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
exports.cypressGenerator = cypressGenerator;
|
|
73
|
+
//# sourceMappingURL=chunk-G5BC6NQG.cjs.map
|
|
74
|
+
//# sourceMappingURL=chunk-G5BC6NQG.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generators/cypressGenerator.tsx"],"names":["createReactGenerator","useApp","useOas","useOperationManager","pluginTsName","jsxs","File","getBanner","getFooter","jsx","Request","URLPath"],"mappings":";;;;;;;;;;;AASO,IAAM,mBAAmBA,8BAAoC,CAAA;AAAA,EAClE,IAAM,EAAA,SAAA;AAAA,EACN,SAAA,CAAU,EAAE,SAAA,EAAa,EAAA;AACvB,IAAM,MAAA;AAAA,MACJ,MAAQ,EAAA;AAAA,QACN,OAAS,EAAA,EAAE,MAAQ,EAAA,OAAA,EAAS,cAAe;AAAA;AAC7C,QACEC,YAAsB,EAAA;AAC1B,IAAA,MAAM,MAAMC,YAAO,EAAA;AACnB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAYC,yBAAoB,EAAA;AAE7D,IAAA,MAAM,OAAU,GAAA;AAAA,MACd,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA;AAAA,MAC7C,IAAA,EAAM,QAAQ,SAAS;AAAA,KACzB;AAEA,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,IAAA,EAAM,QAAQ,SAAW,EAAA,EAAE,WAAW,CAACC,qBAAY,GAAG,CAAA;AAAA,MACtD,OAAA,EAAS,UAAW,CAAA,SAAA,EAAW,EAAE,SAAA,EAAW,CAACA,qBAAY,CAAA,EAAG,IAAM,EAAA,MAAA,EAAQ;AAAA,KAC5E;AAEA,IACE,uBAAAC,eAAA;AAAA,MAACC,UAAA;AAAA,MAAA;AAAA,QACC,QAAA,EAAU,QAAQ,IAAK,CAAA,QAAA;AAAA,QACvB,IAAA,EAAM,QAAQ,IAAK,CAAA,IAAA;AAAA,QACnB,IAAA,EAAM,QAAQ,IAAK,CAAA,IAAA;AAAA,QACnB,MAAQ,EAAAC,eAAA,CAAU,EAAE,GAAA,EAAK,QAAQ,CAAA;AAAA,QACjC,MAAQ,EAAAC,eAAA,CAAU,EAAE,GAAA,EAAK,QAAQ,CAAA;AAAA,QAEjC,QAAA,EAAA;AAAA,0BAAAC,cAAA;AAAA,YAACH,UAAK,CAAA,MAAA;AAAA,YAAL;AAAA,cACC,IAAM,EAAA;AAAA,gBACJ,IAAA,CAAK,QAAQ,OAAS,EAAA,IAAA;AAAA,gBACtB,IAAA,CAAK,QAAQ,QAAS,CAAA,IAAA;AAAA,gBACtB,IAAA,CAAK,QAAQ,UAAY,EAAA,IAAA;AAAA,gBACzB,IAAA,CAAK,QAAQ,WAAa,EAAA,IAAA;AAAA,gBAC1B,IAAA,CAAK,QAAQ,YAAc,EAAA,IAAA;AAAA,gBAC3B,GAAI,IAAK,CAAA,OAAA,CAAQ,WAAa,EAAA,GAAA,CAAI,CAAC,IAAS,KAAA,IAAA,CAAK,IAAI,CAAA,IAAK;AAAC,eAC7D,CAAE,OAAO,OAAO,CAAA;AAAA,cAChB,IAAA,EAAM,QAAQ,IAAK,CAAA,IAAA;AAAA,cACnB,IAAA,EAAM,KAAK,IAAK,CAAA,IAAA;AAAA,cAChB,UAAU,EAAA;AAAA;AAAA,WACZ;AAAA,0BACAG,cAAA;AAAA,YAACC,yBAAA;AAAA,YAAA;AAAA,cACC,MAAM,OAAQ,CAAA,IAAA;AAAA,cACd,cAAA;AAAA,cACA,aAAa,IAAK,CAAA,OAAA;AAAA,cAClB,QAAQ,SAAU,CAAA,MAAA;AAAA,cAClB,OAAA;AAAA,cACA,KAAK,IAAIC,eAAA,CAAQ,SAAU,CAAA,IAAI,EAAE,SAAU;AAAA;AAAA;AAC7C;AAAA;AAAA,KACF;AAAA;AAGN,CAAC","file":"chunk-G5BC6NQG.cjs","sourcesContent":["import { URLPath } from '@kubb/core/utils'\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, useApp } from '@kubb/react'\nimport { Request } from '../components'\nimport type { PluginCypress } from '../types'\n\nexport const cypressGenerator = createReactGenerator<PluginCypress>({\n name: 'cypress',\n Operation({ operation }) {\n const {\n plugin: {\n options: { output, baseURL, dataReturnType },\n },\n } = useApp<PluginCypress>()\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const request = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n return (\n <File\n baseName={request.file.baseName}\n path={request.file.path}\n meta={request.file.meta}\n banner={getBanner({ oas, output })}\n footer={getFooter({ oas, output })}\n >\n <File.Import\n name={[\n type.schemas.request?.name,\n type.schemas.response.name,\n type.schemas.pathParams?.name,\n type.schemas.queryParams?.name,\n type.schemas.headerParams?.name,\n ...(type.schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={request.file.path}\n path={type.file.path}\n isTypeOnly\n />\n <Request\n name={request.name}\n dataReturnType={dataReturnType}\n typeSchemas={type.schemas}\n method={operation.method}\n baseURL={baseURL}\n url={new URLPath(operation.path).toURLPath()}\n />\n </File>\n )\n },\n})\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { FunctionParams, File, Function } from '@kubb/react';
|
|
2
|
+
import { isOptional } from '@kubb/oas';
|
|
3
|
+
import { URLPath } from '@kubb/core/utils';
|
|
4
|
+
import { jsx, jsxs } from '@kubb/react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
// src/components/Request.tsx
|
|
7
|
+
function Request({ baseURL = "", name, dataReturnType, typeSchemas, url, method }) {
|
|
8
|
+
const params = FunctionParams.factory({
|
|
9
|
+
data: typeSchemas.request?.name ? {
|
|
10
|
+
type: typeSchemas.request?.name,
|
|
11
|
+
optional: isOptional(typeSchemas.request?.schema)
|
|
12
|
+
} : void 0
|
|
13
|
+
});
|
|
14
|
+
const returnType = dataReturnType === "data" ? `Cypress.Chainable<${typeSchemas.response.name}>` : `Cypress.Chainable<Cypress.Response<${typeSchemas.response.name}>>`;
|
|
15
|
+
const body = typeSchemas.request?.name ? "data" : void 0;
|
|
16
|
+
return /* @__PURE__ */ jsx(File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsxs(Function, { name, export: true, params: params.toConstructor(), returnType, children: [
|
|
17
|
+
dataReturnType === "data" && `return cy.request('${method}', '${new URLPath(`${baseURL ?? ""}${url}`).toURLPath()}', ${body}).then((res: Cypress.Response<${typeSchemas.response.name}>) => res.body)`,
|
|
18
|
+
dataReturnType === "full" && `return cy.request('${method}', '${new URLPath(`${baseURL ?? ""}${url}`).toURLPath()}', ${body})`
|
|
19
|
+
] }) });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { Request };
|
|
23
|
+
//# sourceMappingURL=chunk-O3CFCJRV.js.map
|
|
24
|
+
//# sourceMappingURL=chunk-O3CFCJRV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/Request.tsx"],"names":[],"mappings":";;;;;;AAoBO,SAAS,OAAA,CAAQ,EAAE,OAAU,GAAA,EAAA,EAAI,MAAM,cAAgB,EAAA,WAAA,EAAa,GAAK,EAAA,MAAA,EAA4B,EAAA;AAC1G,EAAM,MAAA,MAAA,GAAS,eAAe,OAAQ,CAAA;AAAA,IACpC,IAAA,EAAM,WAAY,CAAA,OAAA,EAAS,IACvB,GAAA;AAAA,MACE,IAAA,EAAM,YAAY,OAAS,EAAA,IAAA;AAAA,MAC3B,QAAU,EAAA,UAAA,CAAW,WAAY,CAAA,OAAA,EAAS,MAAM;AAAA,KAElD,GAAA;AAAA,GACL,CAAA;AAED,EAAM,MAAA,UAAA,GACJ,cAAmB,KAAA,MAAA,GAAS,CAAqB,kBAAA,EAAA,WAAA,CAAY,QAAS,CAAA,IAAI,CAAM,CAAA,CAAA,GAAA,CAAA,mCAAA,EAAsC,WAAY,CAAA,QAAA,CAAS,IAAI,CAAA,EAAA,CAAA;AAEjJ,EAAA,MAAM,IAAO,GAAA,WAAA,CAAY,OAAS,EAAA,IAAA,GAAO,MAAS,GAAA,MAAA;AAElD,EAAA,2BACG,IAAK,CAAA,MAAA,EAAL,EAAY,IAAY,EAAA,WAAA,EAAW,MAAC,YAAY,EAAA,IAAA,EAC/C,QAAC,kBAAA,IAAA,CAAA,QAAA,EAAA,EAAS,MAAY,MAAM,EAAA,IAAA,EAAC,QAAQ,MAAO,CAAA,aAAA,IAAiB,UAC1D,EAAA,QAAA,EAAA;AAAA,IAAmB,cAAA,KAAA,MAAA,IAClB,sBAAsB,MAAM,CAAA,IAAA,EAAO,IAAI,OAAQ,CAAA,CAAA,EAAG,WAAW,EAAE,CAAA,EAAG,GAAG,CAAE,CAAA,CAAA,CAAE,WAAW,CAAA,GAAA,EAAM,IAAI,CAAiC,8BAAA,EAAA,WAAA,CAAY,SAAS,IAAI,CAAA,eAAA,CAAA;AAAA,IACzJ,mBAAmB,MAAU,IAAA,CAAA,mBAAA,EAAsB,MAAM,CAAA,IAAA,EAAO,IAAI,OAAQ,CAAA,CAAA,EAAG,OAAW,IAAA,EAAE,GAAG,GAAG,CAAA,CAAE,EAAE,SAAU,EAAC,MAAM,IAAI,CAAA,CAAA;AAAA,GAAA,EAC9H,CACF,EAAA,CAAA;AAEJ","file":"chunk-O3CFCJRV.js","sourcesContent":["import { File, Function, FunctionParams } from '@kubb/react'\n\nimport { type HttpMethod, isOptional } from '@kubb/oas'\nimport type { ReactNode } from 'react'\nimport { URLPath } from '@kubb/core/utils'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport type { PluginCypress } from '../types.ts'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeSchemas: OperationSchemas\n url: string\n baseURL: string | undefined\n dataReturnType: PluginCypress['resolvedOptions']['dataReturnType']\n method: HttpMethod\n}\n\nexport function Request({ baseURL = '', name, dataReturnType, typeSchemas, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n })\n\n const returnType =\n dataReturnType === 'data' ? `Cypress.Chainable<${typeSchemas.response.name}>` : `Cypress.Chainable<Cypress.Response<${typeSchemas.response.name}>>`\n\n const body = typeSchemas.request?.name ? 'data' : undefined\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()} returnType={returnType}>\n {dataReturnType === 'data' &&\n `return cy.request('${method}', '${new URLPath(`${baseURL ?? ''}${url}`).toURLPath()}', ${body}).then((res: Cypress.Response<${typeSchemas.response.name}>) => res.body)`}\n {dataReturnType === 'full' && `return cy.request('${method}', '${new URLPath(`${baseURL ?? ''}${url}`).toURLPath()}', ${body})`}\n </Function>\n </File.Source>\n )\n}\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Request } from './chunk-O3CFCJRV.js';
|
|
2
|
+
import { URLPath } from '@kubb/core/utils';
|
|
3
|
+
import { createReactGenerator } from '@kubb/plugin-oas';
|
|
4
|
+
import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks';
|
|
5
|
+
import { getFooter, getBanner } from '@kubb/plugin-oas/utils';
|
|
6
|
+
import { pluginTsName } from '@kubb/plugin-ts';
|
|
7
|
+
import { useApp, File } from '@kubb/react';
|
|
8
|
+
import { jsxs, jsx } from '@kubb/react/jsx-runtime';
|
|
9
|
+
|
|
10
|
+
var cypressGenerator = createReactGenerator({
|
|
11
|
+
name: "cypress",
|
|
12
|
+
Operation({ operation }) {
|
|
13
|
+
const {
|
|
14
|
+
plugin: {
|
|
15
|
+
options: { output, baseURL, dataReturnType }
|
|
16
|
+
}
|
|
17
|
+
} = useApp();
|
|
18
|
+
const oas = useOas();
|
|
19
|
+
const { getSchemas, getName, getFile } = useOperationManager();
|
|
20
|
+
const request = {
|
|
21
|
+
name: getName(operation, { type: "function" }),
|
|
22
|
+
file: getFile(operation)
|
|
23
|
+
};
|
|
24
|
+
const type = {
|
|
25
|
+
file: getFile(operation, { pluginKey: [pluginTsName] }),
|
|
26
|
+
schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: "type" })
|
|
27
|
+
};
|
|
28
|
+
return /* @__PURE__ */ jsxs(
|
|
29
|
+
File,
|
|
30
|
+
{
|
|
31
|
+
baseName: request.file.baseName,
|
|
32
|
+
path: request.file.path,
|
|
33
|
+
meta: request.file.meta,
|
|
34
|
+
banner: getBanner({ oas, output }),
|
|
35
|
+
footer: getFooter({ oas, output }),
|
|
36
|
+
children: [
|
|
37
|
+
/* @__PURE__ */ jsx(
|
|
38
|
+
File.Import,
|
|
39
|
+
{
|
|
40
|
+
name: [
|
|
41
|
+
type.schemas.request?.name,
|
|
42
|
+
type.schemas.response.name,
|
|
43
|
+
type.schemas.pathParams?.name,
|
|
44
|
+
type.schemas.queryParams?.name,
|
|
45
|
+
type.schemas.headerParams?.name,
|
|
46
|
+
...type.schemas.statusCodes?.map((item) => item.name) || []
|
|
47
|
+
].filter(Boolean),
|
|
48
|
+
root: request.file.path,
|
|
49
|
+
path: type.file.path,
|
|
50
|
+
isTypeOnly: true
|
|
51
|
+
}
|
|
52
|
+
),
|
|
53
|
+
/* @__PURE__ */ jsx(
|
|
54
|
+
Request,
|
|
55
|
+
{
|
|
56
|
+
name: request.name,
|
|
57
|
+
dataReturnType,
|
|
58
|
+
typeSchemas: type.schemas,
|
|
59
|
+
method: operation.method,
|
|
60
|
+
baseURL,
|
|
61
|
+
url: new URLPath(operation.path).toURLPath()
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export { cypressGenerator };
|
|
71
|
+
//# sourceMappingURL=chunk-Q34V6XN5.js.map
|
|
72
|
+
//# sourceMappingURL=chunk-Q34V6XN5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generators/cypressGenerator.tsx"],"names":[],"mappings":";;;;;;;;;AASO,IAAM,mBAAmB,oBAAoC,CAAA;AAAA,EAClE,IAAM,EAAA,SAAA;AAAA,EACN,SAAA,CAAU,EAAE,SAAA,EAAa,EAAA;AACvB,IAAM,MAAA;AAAA,MACJ,MAAQ,EAAA;AAAA,QACN,OAAS,EAAA,EAAE,MAAQ,EAAA,OAAA,EAAS,cAAe;AAAA;AAC7C,QACE,MAAsB,EAAA;AAC1B,IAAA,MAAM,MAAM,MAAO,EAAA;AACnB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAY,mBAAoB,EAAA;AAE7D,IAAA,MAAM,OAAU,GAAA;AAAA,MACd,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA;AAAA,MAC7C,IAAA,EAAM,QAAQ,SAAS;AAAA,KACzB;AAEA,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,IAAA,EAAM,QAAQ,SAAW,EAAA,EAAE,WAAW,CAAC,YAAY,GAAG,CAAA;AAAA,MACtD,OAAA,EAAS,UAAW,CAAA,SAAA,EAAW,EAAE,SAAA,EAAW,CAAC,YAAY,CAAA,EAAG,IAAM,EAAA,MAAA,EAAQ;AAAA,KAC5E;AAEA,IACE,uBAAA,IAAA;AAAA,MAAC,IAAA;AAAA,MAAA;AAAA,QACC,QAAA,EAAU,QAAQ,IAAK,CAAA,QAAA;AAAA,QACvB,IAAA,EAAM,QAAQ,IAAK,CAAA,IAAA;AAAA,QACnB,IAAA,EAAM,QAAQ,IAAK,CAAA,IAAA;AAAA,QACnB,MAAQ,EAAA,SAAA,CAAU,EAAE,GAAA,EAAK,QAAQ,CAAA;AAAA,QACjC,MAAQ,EAAA,SAAA,CAAU,EAAE,GAAA,EAAK,QAAQ,CAAA;AAAA,QAEjC,QAAA,EAAA;AAAA,0BAAA,GAAA;AAAA,YAAC,IAAK,CAAA,MAAA;AAAA,YAAL;AAAA,cACC,IAAM,EAAA;AAAA,gBACJ,IAAA,CAAK,QAAQ,OAAS,EAAA,IAAA;AAAA,gBACtB,IAAA,CAAK,QAAQ,QAAS,CAAA,IAAA;AAAA,gBACtB,IAAA,CAAK,QAAQ,UAAY,EAAA,IAAA;AAAA,gBACzB,IAAA,CAAK,QAAQ,WAAa,EAAA,IAAA;AAAA,gBAC1B,IAAA,CAAK,QAAQ,YAAc,EAAA,IAAA;AAAA,gBAC3B,GAAI,IAAK,CAAA,OAAA,CAAQ,WAAa,EAAA,GAAA,CAAI,CAAC,IAAS,KAAA,IAAA,CAAK,IAAI,CAAA,IAAK;AAAC,eAC7D,CAAE,OAAO,OAAO,CAAA;AAAA,cAChB,IAAA,EAAM,QAAQ,IAAK,CAAA,IAAA;AAAA,cACnB,IAAA,EAAM,KAAK,IAAK,CAAA,IAAA;AAAA,cAChB,UAAU,EAAA;AAAA;AAAA,WACZ;AAAA,0BACA,GAAA;AAAA,YAAC,OAAA;AAAA,YAAA;AAAA,cACC,MAAM,OAAQ,CAAA,IAAA;AAAA,cACd,cAAA;AAAA,cACA,aAAa,IAAK,CAAA,OAAA;AAAA,cAClB,QAAQ,SAAU,CAAA,MAAA;AAAA,cAClB,OAAA;AAAA,cACA,KAAK,IAAI,OAAA,CAAQ,SAAU,CAAA,IAAI,EAAE,SAAU;AAAA;AAAA;AAC7C;AAAA;AAAA,KACF;AAAA;AAGN,CAAC","file":"chunk-Q34V6XN5.js","sourcesContent":["import { URLPath } from '@kubb/core/utils'\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, useApp } from '@kubb/react'\nimport { Request } from '../components'\nimport type { PluginCypress } from '../types'\n\nexport const cypressGenerator = createReactGenerator<PluginCypress>({\n name: 'cypress',\n Operation({ operation }) {\n const {\n plugin: {\n options: { output, baseURL, dataReturnType },\n },\n } = useApp<PluginCypress>()\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const request = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n return (\n <File\n baseName={request.file.baseName}\n path={request.file.path}\n meta={request.file.meta}\n banner={getBanner({ oas, output })}\n footer={getFooter({ oas, output })}\n >\n <File.Import\n name={[\n type.schemas.request?.name,\n type.schemas.response.name,\n type.schemas.pathParams?.name,\n type.schemas.queryParams?.name,\n type.schemas.headerParams?.name,\n ...(type.schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={request.file.path}\n path={type.file.path}\n isTypeOnly\n />\n <Request\n name={request.name}\n dataReturnType={dataReturnType}\n typeSchemas={type.schemas}\n method={operation.method}\n baseURL={baseURL}\n url={new URLPath(operation.path).toURLPath()}\n />\n </File>\n )\n },\n})\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('@kubb/react');
|
|
4
|
+
var oas = require('@kubb/oas');
|
|
5
|
+
var utils = require('@kubb/core/utils');
|
|
6
|
+
var jsxRuntime = require('@kubb/react/jsx-runtime');
|
|
7
|
+
|
|
8
|
+
// src/components/Request.tsx
|
|
9
|
+
function Request({ baseURL = "", name, dataReturnType, typeSchemas, url, method }) {
|
|
10
|
+
const params = react.FunctionParams.factory({
|
|
11
|
+
data: typeSchemas.request?.name ? {
|
|
12
|
+
type: typeSchemas.request?.name,
|
|
13
|
+
optional: oas.isOptional(typeSchemas.request?.schema)
|
|
14
|
+
} : void 0
|
|
15
|
+
});
|
|
16
|
+
const returnType = dataReturnType === "data" ? `Cypress.Chainable<${typeSchemas.response.name}>` : `Cypress.Chainable<Cypress.Response<${typeSchemas.response.name}>>`;
|
|
17
|
+
const body = typeSchemas.request?.name ? "data" : void 0;
|
|
18
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsxRuntime.jsxs(react.Function, { name, export: true, params: params.toConstructor(), returnType, children: [
|
|
19
|
+
dataReturnType === "data" && `return cy.request('${method}', '${new utils.URLPath(`${baseURL ?? ""}${url}`).toURLPath()}', ${body}).then((res: Cypress.Response<${typeSchemas.response.name}>) => res.body)`,
|
|
20
|
+
dataReturnType === "full" && `return cy.request('${method}', '${new utils.URLPath(`${baseURL ?? ""}${url}`).toURLPath()}', ${body})`
|
|
21
|
+
] }) });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
exports.Request = Request;
|
|
25
|
+
//# sourceMappingURL=chunk-QRUN5SOO.cjs.map
|
|
26
|
+
//# sourceMappingURL=chunk-QRUN5SOO.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/Request.tsx"],"names":["FunctionParams","isOptional","File","jsxs","Function","URLPath"],"mappings":";;;;;;;;AAoBO,SAAS,OAAA,CAAQ,EAAE,OAAU,GAAA,EAAA,EAAI,MAAM,cAAgB,EAAA,WAAA,EAAa,GAAK,EAAA,MAAA,EAA4B,EAAA;AAC1G,EAAM,MAAA,MAAA,GAASA,qBAAe,OAAQ,CAAA;AAAA,IACpC,IAAA,EAAM,WAAY,CAAA,OAAA,EAAS,IACvB,GAAA;AAAA,MACE,IAAA,EAAM,YAAY,OAAS,EAAA,IAAA;AAAA,MAC3B,QAAU,EAAAC,cAAA,CAAW,WAAY,CAAA,OAAA,EAAS,MAAM;AAAA,KAElD,GAAA;AAAA,GACL,CAAA;AAED,EAAM,MAAA,UAAA,GACJ,cAAmB,KAAA,MAAA,GAAS,CAAqB,kBAAA,EAAA,WAAA,CAAY,QAAS,CAAA,IAAI,CAAM,CAAA,CAAA,GAAA,CAAA,mCAAA,EAAsC,WAAY,CAAA,QAAA,CAAS,IAAI,CAAA,EAAA,CAAA;AAEjJ,EAAA,MAAM,IAAO,GAAA,WAAA,CAAY,OAAS,EAAA,IAAA,GAAO,MAAS,GAAA,MAAA;AAElD,EAAA,sCACGC,UAAK,CAAA,MAAA,EAAL,EAAY,IAAY,EAAA,WAAA,EAAW,MAAC,YAAY,EAAA,IAAA,EAC/C,QAAC,kBAAAC,eAAA,CAAAC,cAAA,EAAA,EAAS,MAAY,MAAM,EAAA,IAAA,EAAC,QAAQ,MAAO,CAAA,aAAA,IAAiB,UAC1D,EAAA,QAAA,EAAA;AAAA,IAAmB,cAAA,KAAA,MAAA,IAClB,sBAAsB,MAAM,CAAA,IAAA,EAAO,IAAIC,aAAQ,CAAA,CAAA,EAAG,WAAW,EAAE,CAAA,EAAG,GAAG,CAAE,CAAA,CAAA,CAAE,WAAW,CAAA,GAAA,EAAM,IAAI,CAAiC,8BAAA,EAAA,WAAA,CAAY,SAAS,IAAI,CAAA,eAAA,CAAA;AAAA,IACzJ,mBAAmB,MAAU,IAAA,CAAA,mBAAA,EAAsB,MAAM,CAAA,IAAA,EAAO,IAAIA,aAAQ,CAAA,CAAA,EAAG,OAAW,IAAA,EAAE,GAAG,GAAG,CAAA,CAAE,EAAE,SAAU,EAAC,MAAM,IAAI,CAAA,CAAA;AAAA,GAAA,EAC9H,CACF,EAAA,CAAA;AAEJ","file":"chunk-QRUN5SOO.cjs","sourcesContent":["import { File, Function, FunctionParams } from '@kubb/react'\n\nimport { type HttpMethod, isOptional } from '@kubb/oas'\nimport type { ReactNode } from 'react'\nimport { URLPath } from '@kubb/core/utils'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport type { PluginCypress } from '../types.ts'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeSchemas: OperationSchemas\n url: string\n baseURL: string | undefined\n dataReturnType: PluginCypress['resolvedOptions']['dataReturnType']\n method: HttpMethod\n}\n\nexport function Request({ baseURL = '', name, dataReturnType, typeSchemas, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n })\n\n const returnType =\n dataReturnType === 'data' ? `Cypress.Chainable<${typeSchemas.response.name}>` : `Cypress.Chainable<Cypress.Response<${typeSchemas.response.name}>>`\n\n const body = typeSchemas.request?.name ? 'data' : undefined\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()} returnType={returnType}>\n {dataReturnType === 'data' &&\n `return cy.request('${method}', '${new URLPath(`${baseURL ?? ''}${url}`).toURLPath()}', ${body}).then((res: Cypress.Response<${typeSchemas.response.name}>) => res.body)`}\n {dataReturnType === 'full' && `return cy.request('${method}', '${new URLPath(`${baseURL ?? ''}${url}`).toURLPath()}', ${body})`}\n </Function>\n </File.Source>\n )\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkQRUN5SOO_cjs = require('./chunk-QRUN5SOO.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "Request", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return chunkQRUN5SOO_cjs.Request; }
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=components.cjs.map
|
|
12
|
+
//# sourceMappingURL=components.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"components.cjs"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { HttpMethod } from '@kubb/oas';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { OperationSchemas } from '@kubb/plugin-oas';
|
|
4
|
+
import { P as PluginCypress } from './types-C2ke2hnU.cjs';
|
|
5
|
+
import '@kubb/core';
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
/**
|
|
9
|
+
* Name of the function
|
|
10
|
+
*/
|
|
11
|
+
name: string;
|
|
12
|
+
typeSchemas: OperationSchemas;
|
|
13
|
+
url: string;
|
|
14
|
+
baseURL: string | undefined;
|
|
15
|
+
dataReturnType: PluginCypress['resolvedOptions']['dataReturnType'];
|
|
16
|
+
method: HttpMethod;
|
|
17
|
+
};
|
|
18
|
+
declare function Request({ baseURL, name, dataReturnType, typeSchemas, url, method }: Props): ReactNode;
|
|
19
|
+
|
|
20
|
+
export { Request };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { HttpMethod } from '@kubb/oas';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { OperationSchemas } from '@kubb/plugin-oas';
|
|
4
|
+
import { P as PluginCypress } from './types-C2ke2hnU.js';
|
|
5
|
+
import '@kubb/core';
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
/**
|
|
9
|
+
* Name of the function
|
|
10
|
+
*/
|
|
11
|
+
name: string;
|
|
12
|
+
typeSchemas: OperationSchemas;
|
|
13
|
+
url: string;
|
|
14
|
+
baseURL: string | undefined;
|
|
15
|
+
dataReturnType: PluginCypress['resolvedOptions']['dataReturnType'];
|
|
16
|
+
method: HttpMethod;
|
|
17
|
+
};
|
|
18
|
+
declare function Request({ baseURL, name, dataReturnType, typeSchemas, url, method }: Props): ReactNode;
|
|
19
|
+
|
|
20
|
+
export { Request };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"components.js"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkG5BC6NQG_cjs = require('./chunk-G5BC6NQG.cjs');
|
|
4
|
+
require('./chunk-QRUN5SOO.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, "cypressGenerator", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return chunkG5BC6NQG_cjs.cypressGenerator; }
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=generators.cjs.map
|
|
13
|
+
//# sourceMappingURL=generators.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"generators.cjs"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as _kubb_plugin_oas from '@kubb/plugin-oas';
|
|
2
|
+
import { P as PluginCypress } from './types-C2ke2hnU.cjs';
|
|
3
|
+
import '@kubb/core';
|
|
4
|
+
import '@kubb/oas';
|
|
5
|
+
|
|
6
|
+
declare const cypressGenerator: _kubb_plugin_oas.Generator<PluginCypress>;
|
|
7
|
+
|
|
8
|
+
export { cypressGenerator };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as _kubb_plugin_oas from '@kubb/plugin-oas';
|
|
2
|
+
import { P as PluginCypress } from './types-C2ke2hnU.js';
|
|
3
|
+
import '@kubb/core';
|
|
4
|
+
import '@kubb/oas';
|
|
5
|
+
|
|
6
|
+
declare const cypressGenerator: _kubb_plugin_oas.Generator<PluginCypress>;
|
|
7
|
+
|
|
8
|
+
export { cypressGenerator };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"generators.js"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkG5BC6NQG_cjs = require('./chunk-G5BC6NQG.cjs');
|
|
4
|
+
require('./chunk-QRUN5SOO.cjs');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var core = require('@kubb/core');
|
|
7
|
+
var transformers = require('@kubb/core/transformers');
|
|
8
|
+
var pluginOas = require('@kubb/plugin-oas');
|
|
9
|
+
var pluginTs = require('@kubb/plugin-ts');
|
|
10
|
+
|
|
11
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
|
|
13
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
14
|
+
|
|
15
|
+
var pluginCypressName = "plugin-cypress";
|
|
16
|
+
var pluginCypress = core.createPlugin((options) => {
|
|
17
|
+
const {
|
|
18
|
+
output = { path: "cypress", barrelType: "named" },
|
|
19
|
+
group,
|
|
20
|
+
dataReturnType = "data",
|
|
21
|
+
exclude = [],
|
|
22
|
+
include,
|
|
23
|
+
override = [],
|
|
24
|
+
transformers: transformers$1 = {},
|
|
25
|
+
generators = [chunkG5BC6NQG_cjs.cypressGenerator].filter(Boolean),
|
|
26
|
+
contentType,
|
|
27
|
+
baseURL
|
|
28
|
+
} = options;
|
|
29
|
+
return {
|
|
30
|
+
name: pluginCypressName,
|
|
31
|
+
options: {
|
|
32
|
+
output,
|
|
33
|
+
dataReturnType,
|
|
34
|
+
group,
|
|
35
|
+
baseURL
|
|
36
|
+
},
|
|
37
|
+
pre: [pluginOas.pluginOasName, pluginTs.pluginTsName].filter(Boolean),
|
|
38
|
+
resolvePath(baseName, pathMode, options2) {
|
|
39
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
40
|
+
const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
41
|
+
if (mode === "single") {
|
|
42
|
+
return path__default.default.resolve(root, output.path);
|
|
43
|
+
}
|
|
44
|
+
if (group && (options2?.group?.path || options2?.group?.tag)) {
|
|
45
|
+
const groupName = group?.name ? group.name : (ctx) => {
|
|
46
|
+
if (group?.type === "path") {
|
|
47
|
+
return `${ctx.group.split("/")[1]}`;
|
|
48
|
+
}
|
|
49
|
+
return `${transformers.camelCase(ctx.group)}Requests`;
|
|
50
|
+
};
|
|
51
|
+
return path__default.default.resolve(
|
|
52
|
+
root,
|
|
53
|
+
output.path,
|
|
54
|
+
groupName({
|
|
55
|
+
group: group.type === "path" ? options2.group.path : options2.group.tag
|
|
56
|
+
}),
|
|
57
|
+
baseName
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
return path__default.default.resolve(root, output.path, baseName);
|
|
61
|
+
},
|
|
62
|
+
resolveName(name, type) {
|
|
63
|
+
const resolvedName = transformers.camelCase(name, {
|
|
64
|
+
isFile: type === "file"
|
|
65
|
+
});
|
|
66
|
+
if (type) {
|
|
67
|
+
return transformers$1?.name?.(resolvedName, type) || resolvedName;
|
|
68
|
+
}
|
|
69
|
+
return resolvedName;
|
|
70
|
+
},
|
|
71
|
+
async buildStart() {
|
|
72
|
+
const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
|
|
73
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
74
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
75
|
+
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
76
|
+
const operationGenerator = new pluginOas.OperationGenerator(this.plugin.options, {
|
|
77
|
+
oas,
|
|
78
|
+
pluginManager: this.pluginManager,
|
|
79
|
+
plugin: this.plugin,
|
|
80
|
+
contentType,
|
|
81
|
+
exclude,
|
|
82
|
+
include,
|
|
83
|
+
override,
|
|
84
|
+
mode
|
|
85
|
+
});
|
|
86
|
+
const files = await operationGenerator.build(...generators);
|
|
87
|
+
await this.addFile(...files);
|
|
88
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
89
|
+
type: output.barrelType ?? "named",
|
|
90
|
+
root,
|
|
91
|
+
output,
|
|
92
|
+
files: this.fileManager.files,
|
|
93
|
+
meta: {
|
|
94
|
+
pluginKey: this.plugin.key
|
|
95
|
+
},
|
|
96
|
+
logger: this.logger
|
|
97
|
+
});
|
|
98
|
+
await this.addFile(...barrelFiles);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
exports.pluginCypress = pluginCypress;
|
|
104
|
+
exports.pluginCypressName = pluginCypressName;
|
|
105
|
+
//# sourceMappingURL=index.cjs.map
|
|
106
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","cypressGenerator","pluginOasName","pluginTsName","options","path","FileManager","camelCase","PluginManager","OperationGenerator"],"mappings":"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","file":"index.cjs","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { cypressGenerator } from './generators'\nimport type { PluginCypress } from './types.ts'\n\nexport const pluginCypressName = 'plugin-cypress' satisfies PluginCypress['name']\n\nexport const pluginCypress = createPlugin<PluginCypress>((options) => {\n const {\n output = { path: 'cypress', barrelType: 'named' },\n group,\n dataReturnType = 'data',\n exclude = [],\n include,\n override = [],\n transformers = {},\n generators = [cypressGenerator].filter(Boolean),\n contentType,\n baseURL,\n } = options\n\n return {\n name: pluginCypressName,\n options: {\n output,\n dataReturnType,\n group,\n baseURL,\n },\n pre: [pluginOasName, pluginTsName].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.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)}Requests`\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 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 = FileManager.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 this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as _kubb_core from '@kubb/core';
|
|
2
|
+
import { O as Options, P as PluginCypress } from './types-C2ke2hnU.cjs';
|
|
3
|
+
import '@kubb/oas';
|
|
4
|
+
import '@kubb/plugin-oas';
|
|
5
|
+
|
|
6
|
+
declare const pluginCypressName = "plugin-cypress";
|
|
7
|
+
declare const pluginCypress: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginCypress>;
|
|
8
|
+
|
|
9
|
+
export { PluginCypress, pluginCypress, pluginCypressName };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as _kubb_core from '@kubb/core';
|
|
2
|
+
import { O as Options, P as PluginCypress } from './types-C2ke2hnU.js';
|
|
3
|
+
import '@kubb/oas';
|
|
4
|
+
import '@kubb/plugin-oas';
|
|
5
|
+
|
|
6
|
+
declare const pluginCypressName = "plugin-cypress";
|
|
7
|
+
declare const pluginCypress: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginCypress>;
|
|
8
|
+
|
|
9
|
+
export { PluginCypress, pluginCypress, pluginCypressName };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { cypressGenerator } from './chunk-Q34V6XN5.js';
|
|
2
|
+
import './chunk-O3CFCJRV.js';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { createPlugin, PluginManager, FileManager } from '@kubb/core';
|
|
5
|
+
import { camelCase } from '@kubb/core/transformers';
|
|
6
|
+
import { pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
|
|
7
|
+
import { pluginTsName } from '@kubb/plugin-ts';
|
|
8
|
+
|
|
9
|
+
var pluginCypressName = "plugin-cypress";
|
|
10
|
+
var pluginCypress = createPlugin((options) => {
|
|
11
|
+
const {
|
|
12
|
+
output = { path: "cypress", barrelType: "named" },
|
|
13
|
+
group,
|
|
14
|
+
dataReturnType = "data",
|
|
15
|
+
exclude = [],
|
|
16
|
+
include,
|
|
17
|
+
override = [],
|
|
18
|
+
transformers = {},
|
|
19
|
+
generators = [cypressGenerator].filter(Boolean),
|
|
20
|
+
contentType,
|
|
21
|
+
baseURL
|
|
22
|
+
} = options;
|
|
23
|
+
return {
|
|
24
|
+
name: pluginCypressName,
|
|
25
|
+
options: {
|
|
26
|
+
output,
|
|
27
|
+
dataReturnType,
|
|
28
|
+
group,
|
|
29
|
+
baseURL
|
|
30
|
+
},
|
|
31
|
+
pre: [pluginOasName, pluginTsName].filter(Boolean),
|
|
32
|
+
resolvePath(baseName, pathMode, options2) {
|
|
33
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
34
|
+
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
35
|
+
if (mode === "single") {
|
|
36
|
+
return path.resolve(root, output.path);
|
|
37
|
+
}
|
|
38
|
+
if (group && (options2?.group?.path || options2?.group?.tag)) {
|
|
39
|
+
const groupName = group?.name ? group.name : (ctx) => {
|
|
40
|
+
if (group?.type === "path") {
|
|
41
|
+
return `${ctx.group.split("/")[1]}`;
|
|
42
|
+
}
|
|
43
|
+
return `${camelCase(ctx.group)}Requests`;
|
|
44
|
+
};
|
|
45
|
+
return path.resolve(
|
|
46
|
+
root,
|
|
47
|
+
output.path,
|
|
48
|
+
groupName({
|
|
49
|
+
group: group.type === "path" ? options2.group.path : options2.group.tag
|
|
50
|
+
}),
|
|
51
|
+
baseName
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
return path.resolve(root, output.path, baseName);
|
|
55
|
+
},
|
|
56
|
+
resolveName(name, type) {
|
|
57
|
+
const resolvedName = camelCase(name, {
|
|
58
|
+
isFile: type === "file"
|
|
59
|
+
});
|
|
60
|
+
if (type) {
|
|
61
|
+
return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
62
|
+
}
|
|
63
|
+
return resolvedName;
|
|
64
|
+
},
|
|
65
|
+
async buildStart() {
|
|
66
|
+
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
67
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
68
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
69
|
+
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
70
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
71
|
+
oas,
|
|
72
|
+
pluginManager: this.pluginManager,
|
|
73
|
+
plugin: this.plugin,
|
|
74
|
+
contentType,
|
|
75
|
+
exclude,
|
|
76
|
+
include,
|
|
77
|
+
override,
|
|
78
|
+
mode
|
|
79
|
+
});
|
|
80
|
+
const files = await operationGenerator.build(...generators);
|
|
81
|
+
await this.addFile(...files);
|
|
82
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
83
|
+
type: output.barrelType ?? "named",
|
|
84
|
+
root,
|
|
85
|
+
output,
|
|
86
|
+
files: this.fileManager.files,
|
|
87
|
+
meta: {
|
|
88
|
+
pluginKey: this.plugin.key
|
|
89
|
+
},
|
|
90
|
+
logger: this.logger
|
|
91
|
+
});
|
|
92
|
+
await this.addFile(...barrelFiles);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
export { pluginCypress, pluginCypressName };
|
|
98
|
+
//# sourceMappingURL=index.js.map
|
|
99
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"names":["options"],"mappings":";;;;;;;;AAYO,IAAM,iBAAoB,GAAA;AAEpB,IAAA,aAAA,GAAgB,YAA4B,CAAA,CAAC,OAAY,KAAA;AACpE,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,SAAA,EAAW,YAAY,OAAQ,EAAA;AAAA,IAChD,KAAA;AAAA,IACA,cAAiB,GAAA,MAAA;AAAA,IACjB,UAAU,EAAC;AAAA,IACX,OAAA;AAAA,IACA,WAAW,EAAC;AAAA,IACZ,eAAe,EAAC;AAAA,IAChB,UAAa,GAAA,CAAC,gBAAgB,CAAA,CAAE,OAAO,OAAO,CAAA;AAAA,IAC9C,WAAA;AAAA,IACA;AAAA,GACE,GAAA,OAAA;AAEJ,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,iBAAA;AAAA,IACN,OAAS,EAAA;AAAA,MACP,MAAA;AAAA,MACA,cAAA;AAAA,MACA,KAAA;AAAA,MACA;AAAA,KACF;AAAA,IACA,KAAK,CAAC,aAAA,EAAe,YAAY,CAAA,CAAE,OAAO,OAAO,CAAA;AAAA,IACjD,WAAA,CAAY,QAAU,EAAA,QAAA,EAAUA,QAAS,EAAA;AACvC,MAAM,MAAA,IAAA,GAAO,KAAK,OAAQ,CAAA,IAAA,CAAK,OAAO,IAAM,EAAA,IAAA,CAAK,MAAO,CAAA,MAAA,CAAO,IAAI,CAAA;AACnE,MAAM,MAAA,IAAA,GAAO,YAAY,WAAY,CAAA,OAAA,CAAQ,KAAK,OAAQ,CAAA,IAAA,EAAM,MAAO,CAAA,IAAI,CAAC,CAAA;AAE5E,MAAA,IAAI,SAAS,QAAU,EAAA;AAKrB,QAAA,OAAO,IAAK,CAAA,OAAA,CAAQ,IAAM,EAAA,MAAA,CAAO,IAAI,CAAA;AAAA;AAGvC,MAAA,IAAI,UAAUA,QAAS,EAAA,KAAA,EAAO,IAAQA,IAAAA,QAAAA,EAAS,OAAO,GAAM,CAAA,EAAA;AAC1D,QAAA,MAAM,YAA2B,KAAO,EAAA,IAAA,GACpC,KAAM,CAAA,IAAA,GACN,CAAC,GAAQ,KAAA;AACP,UAAI,IAAA,KAAA,EAAO,SAAS,MAAQ,EAAA;AAC1B,YAAA,OAAO,GAAG,GAAI,CAAA,KAAA,CAAM,MAAM,GAAG,CAAA,CAAE,CAAC,CAAC,CAAA,CAAA;AAAA;AAEnC,UAAA,OAAO,CAAG,EAAA,SAAA,CAAU,GAAI,CAAA,KAAK,CAAC,CAAA,QAAA,CAAA;AAAA,SAChC;AAEJ,QAAA,OAAO,IAAK,CAAA,OAAA;AAAA,UACV,IAAA;AAAA,UACA,MAAO,CAAA,IAAA;AAAA,UACP,SAAU,CAAA;AAAA,YACR,KAAA,EAAO,MAAM,IAAS,KAAA,MAAA,GAASA,SAAQ,KAAM,CAAA,IAAA,GAAQA,SAAQ,KAAM,CAAA;AAAA,WACpE,CAAA;AAAA,UACD;AAAA,SACF;AAAA;AAGF,MAAA,OAAO,IAAK,CAAA,OAAA,CAAQ,IAAM,EAAA,MAAA,CAAO,MAAM,QAAQ,CAAA;AAAA,KACjD;AAAA,IACA,WAAA,CAAY,MAAM,IAAM,EAAA;AACtB,MAAM,MAAA,YAAA,GAAe,UAAU,IAAM,EAAA;AAAA,QACnC,QAAQ,IAAS,KAAA;AAAA,OAClB,CAAA;AAED,MAAA,IAAI,IAAM,EAAA;AACR,QAAA,OAAO,YAAc,EAAA,IAAA,GAAO,YAAc,EAAA,IAAI,CAAK,IAAA,YAAA;AAAA;AAGrD,MAAO,OAAA,YAAA;AAAA,KACT;AAAA,IACA,MAAM,UAAa,GAAA;AACjB,MAAM,MAAA,CAAC,aAAa,CAAoC,GAAA,aAAA,CAAc,mBAAyC,IAAK,CAAA,OAAA,EAAS,CAAC,aAAa,CAAC,CAAA;AAE5I,MAAA,MAAM,GAAM,GAAA,MAAM,aAAc,CAAA,OAAA,CAAQ,MAAO,EAAA;AAC/C,MAAM,MAAA,IAAA,GAAO,KAAK,OAAQ,CAAA,IAAA,CAAK,OAAO,IAAM,EAAA,IAAA,CAAK,MAAO,CAAA,MAAA,CAAO,IAAI,CAAA;AACnE,MAAM,MAAA,IAAA,GAAO,YAAY,OAAQ,CAAA,IAAA,CAAK,QAAQ,IAAM,EAAA,MAAA,CAAO,IAAI,CAAC,CAAA;AAEhE,MAAA,MAAM,kBAAqB,GAAA,IAAI,kBAAmB,CAAA,IAAA,CAAK,OAAO,OAAS,EAAA;AAAA,QACrE,GAAA;AAAA,QACA,eAAe,IAAK,CAAA,aAAA;AAAA,QACpB,QAAQ,IAAK,CAAA,MAAA;AAAA,QACb,WAAA;AAAA,QACA,OAAA;AAAA,QACA,OAAA;AAAA,QACA,QAAA;AAAA,QACA;AAAA,OACD,CAAA;AAED,MAAA,MAAM,KAAQ,GAAA,MAAM,kBAAmB,CAAA,KAAA,CAAM,GAAG,UAAU,CAAA;AAC1D,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,KAAK,CAAA;AAE3B,MAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,QACxD,IAAA,EAAM,OAAO,UAAc,IAAA,OAAA;AAAA,QAC3B,IAAA;AAAA,QACA,MAAA;AAAA,QACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,QACxB,IAAM,EAAA;AAAA,UACJ,SAAA,EAAW,KAAK,MAAO,CAAA;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA;AAAA,OACd,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAAA;AACnC,GACF;AACF,CAAC","file":"index.js","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { cypressGenerator } from './generators'\nimport type { PluginCypress } from './types.ts'\n\nexport const pluginCypressName = 'plugin-cypress' satisfies PluginCypress['name']\n\nexport const pluginCypress = createPlugin<PluginCypress>((options) => {\n const {\n output = { path: 'cypress', barrelType: 'named' },\n group,\n dataReturnType = 'data',\n exclude = [],\n include,\n override = [],\n transformers = {},\n generators = [cypressGenerator].filter(Boolean),\n contentType,\n baseURL,\n } = options\n\n return {\n name: pluginCypressName,\n options: {\n output,\n dataReturnType,\n group,\n baseURL,\n },\n pre: [pluginOasName, pluginTsName].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.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)}Requests`\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 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 = FileManager.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 this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Output, Group, ResolveNameParams, PluginFactoryOptions } from '@kubb/core';
|
|
2
|
+
import { Oas, contentType } from '@kubb/oas';
|
|
3
|
+
import { Exclude, Include, Override, Generator, ResolvePathOptions } from '@kubb/plugin-oas';
|
|
4
|
+
|
|
5
|
+
type Options = {
|
|
6
|
+
/**
|
|
7
|
+
* Specify the export location for the files and define the behavior of the output
|
|
8
|
+
* @default { path: 'cypress', barrelType: 'named' }
|
|
9
|
+
*/
|
|
10
|
+
output?: Output<Oas>;
|
|
11
|
+
/**
|
|
12
|
+
* Define which contentType should be used.
|
|
13
|
+
* By default, the first JSON valid mediaType will be used
|
|
14
|
+
*/
|
|
15
|
+
contentType?: contentType;
|
|
16
|
+
/**
|
|
17
|
+
* ReturnType that will be used when calling cy.request.
|
|
18
|
+
* - 'data' will return ResponseConfig[data].
|
|
19
|
+
* - 'full' will return ResponseConfig.
|
|
20
|
+
* @default 'data'
|
|
21
|
+
*/
|
|
22
|
+
dataReturnType?: 'data' | 'full';
|
|
23
|
+
baseURL?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Group the Cypress requests based on the provided name.
|
|
26
|
+
*/
|
|
27
|
+
group?: Group;
|
|
28
|
+
/**
|
|
29
|
+
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
30
|
+
*/
|
|
31
|
+
exclude?: Array<Exclude>;
|
|
32
|
+
/**
|
|
33
|
+
* Array containing include parameters to include tags/operations/methods/paths.
|
|
34
|
+
*/
|
|
35
|
+
include?: Array<Include>;
|
|
36
|
+
/**
|
|
37
|
+
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
38
|
+
*/
|
|
39
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
40
|
+
transformers?: {
|
|
41
|
+
/**
|
|
42
|
+
* Customize the names based on the type that is provided by the plugin.
|
|
43
|
+
*/
|
|
44
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Define some generators next to the Cypress generators.
|
|
48
|
+
*/
|
|
49
|
+
generators?: Array<Generator<PluginCypress>>;
|
|
50
|
+
};
|
|
51
|
+
type ResolvedOptions = {
|
|
52
|
+
output: Output<Oas>;
|
|
53
|
+
group: Options['group'];
|
|
54
|
+
baseURL: Options['baseURL'] | undefined;
|
|
55
|
+
dataReturnType: NonNullable<Options['dataReturnType']>;
|
|
56
|
+
};
|
|
57
|
+
type PluginCypress = PluginFactoryOptions<'plugin-cypress', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
58
|
+
|
|
59
|
+
export type { Options as O, PluginCypress as P };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Output, Group, ResolveNameParams, PluginFactoryOptions } from '@kubb/core';
|
|
2
|
+
import { Oas, contentType } from '@kubb/oas';
|
|
3
|
+
import { Exclude, Include, Override, Generator, ResolvePathOptions } from '@kubb/plugin-oas';
|
|
4
|
+
|
|
5
|
+
type Options = {
|
|
6
|
+
/**
|
|
7
|
+
* Specify the export location for the files and define the behavior of the output
|
|
8
|
+
* @default { path: 'cypress', barrelType: 'named' }
|
|
9
|
+
*/
|
|
10
|
+
output?: Output<Oas>;
|
|
11
|
+
/**
|
|
12
|
+
* Define which contentType should be used.
|
|
13
|
+
* By default, the first JSON valid mediaType will be used
|
|
14
|
+
*/
|
|
15
|
+
contentType?: contentType;
|
|
16
|
+
/**
|
|
17
|
+
* ReturnType that will be used when calling cy.request.
|
|
18
|
+
* - 'data' will return ResponseConfig[data].
|
|
19
|
+
* - 'full' will return ResponseConfig.
|
|
20
|
+
* @default 'data'
|
|
21
|
+
*/
|
|
22
|
+
dataReturnType?: 'data' | 'full';
|
|
23
|
+
baseURL?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Group the Cypress requests based on the provided name.
|
|
26
|
+
*/
|
|
27
|
+
group?: Group;
|
|
28
|
+
/**
|
|
29
|
+
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
30
|
+
*/
|
|
31
|
+
exclude?: Array<Exclude>;
|
|
32
|
+
/**
|
|
33
|
+
* Array containing include parameters to include tags/operations/methods/paths.
|
|
34
|
+
*/
|
|
35
|
+
include?: Array<Include>;
|
|
36
|
+
/**
|
|
37
|
+
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
38
|
+
*/
|
|
39
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
40
|
+
transformers?: {
|
|
41
|
+
/**
|
|
42
|
+
* Customize the names based on the type that is provided by the plugin.
|
|
43
|
+
*/
|
|
44
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Define some generators next to the Cypress generators.
|
|
48
|
+
*/
|
|
49
|
+
generators?: Array<Generator<PluginCypress>>;
|
|
50
|
+
};
|
|
51
|
+
type ResolvedOptions = {
|
|
52
|
+
output: Output<Oas>;
|
|
53
|
+
group: Options['group'];
|
|
54
|
+
baseURL: Options['baseURL'] | undefined;
|
|
55
|
+
dataReturnType: NonNullable<Options['dataReturnType']>;
|
|
56
|
+
};
|
|
57
|
+
type PluginCypress = PluginFactoryOptions<'plugin-cypress', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
58
|
+
|
|
59
|
+
export type { Options as O, PluginCypress as P };
|
package/package.json
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kubb/plugin-cypress",
|
|
3
|
+
"version": "0.0.0-canary-20250324220231",
|
|
4
|
+
"description": "Generator cypress",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"typescript",
|
|
7
|
+
"plugins",
|
|
8
|
+
"kubb",
|
|
9
|
+
"codegen",
|
|
10
|
+
"cypress",
|
|
11
|
+
"openapi"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git://github.com/kubb-labs/kubb.git",
|
|
16
|
+
"directory": "packages/plugin-cypress"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "Stijn Van Hulle <stijn@stijnvanhulle.be",
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"import": "./dist/index.js",
|
|
25
|
+
"require": "./dist/index.cjs",
|
|
26
|
+
"default": "./dist/index.cjs"
|
|
27
|
+
},
|
|
28
|
+
"./utils": {
|
|
29
|
+
"import": "./dist/utils.js",
|
|
30
|
+
"require": "./dist/utils.cjs",
|
|
31
|
+
"default": "./dist/utils.cjs"
|
|
32
|
+
},
|
|
33
|
+
"./hooks": {
|
|
34
|
+
"import": "./dist/hooks.js",
|
|
35
|
+
"require": "./dist/hooks.cjs",
|
|
36
|
+
"default": "./dist/hooks.cjs"
|
|
37
|
+
},
|
|
38
|
+
"./components": {
|
|
39
|
+
"import": "./dist/components.js",
|
|
40
|
+
"require": "./dist/components.cjs",
|
|
41
|
+
"default": "./dist/components.cjs"
|
|
42
|
+
},
|
|
43
|
+
"./generators": {
|
|
44
|
+
"import": "./dist/generators.js",
|
|
45
|
+
"require": "./dist/generators.cjs",
|
|
46
|
+
"default": "./dist/generators.cjs"
|
|
47
|
+
},
|
|
48
|
+
"./package.json": "./package.json",
|
|
49
|
+
"./*": "./*"
|
|
50
|
+
},
|
|
51
|
+
"main": "dist/index.cjs",
|
|
52
|
+
"module": "dist/index.js",
|
|
53
|
+
"types": "./dist/index.d.ts",
|
|
54
|
+
"typesVersions": {
|
|
55
|
+
"*": {
|
|
56
|
+
"utils": [
|
|
57
|
+
"./dist/utils.d.ts"
|
|
58
|
+
],
|
|
59
|
+
"hooks": [
|
|
60
|
+
"./dist/hooks.d.ts"
|
|
61
|
+
],
|
|
62
|
+
"components": [
|
|
63
|
+
"./dist/components.d.ts"
|
|
64
|
+
],
|
|
65
|
+
"generators": [
|
|
66
|
+
"./dist/generators.d.ts"
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"files": [
|
|
71
|
+
"src",
|
|
72
|
+
"dist",
|
|
73
|
+
"!/**/**.test.**",
|
|
74
|
+
"!/**/__tests__/**"
|
|
75
|
+
],
|
|
76
|
+
"dependencies": {
|
|
77
|
+
"@kubb/core": "0.0.0-canary-20250324220231",
|
|
78
|
+
"@kubb/fs": "0.0.0-canary-20250324220231",
|
|
79
|
+
"@kubb/oas": "0.0.0-canary-20250324220231",
|
|
80
|
+
"@kubb/plugin-oas": "0.0.0-canary-20250324220231",
|
|
81
|
+
"@kubb/plugin-ts": "0.0.0-canary-20250324220231",
|
|
82
|
+
"@kubb/react": "0.0.0-canary-20250324220231"
|
|
83
|
+
},
|
|
84
|
+
"devDependencies": {
|
|
85
|
+
"@types/react": "^18.3.20",
|
|
86
|
+
"react": "^18.3.1",
|
|
87
|
+
"tsup": "^8.4.0",
|
|
88
|
+
"typescript": "^5.8.2",
|
|
89
|
+
"@kubb/config-ts": "0.0.0-canary-20250324220231",
|
|
90
|
+
"@kubb/config-tsup": "0.0.0-canary-20250324220231"
|
|
91
|
+
},
|
|
92
|
+
"peerDependencies": {
|
|
93
|
+
"@kubb/react": "0.0.0-canary-20250324220231"
|
|
94
|
+
},
|
|
95
|
+
"engines": {
|
|
96
|
+
"node": ">=20"
|
|
97
|
+
},
|
|
98
|
+
"publishConfig": {
|
|
99
|
+
"access": "public",
|
|
100
|
+
"registry": "https://registry.npmjs.org/"
|
|
101
|
+
},
|
|
102
|
+
"scripts": {
|
|
103
|
+
"build": "tsup",
|
|
104
|
+
"clean": "npx rimraf ./dist",
|
|
105
|
+
"lint": "bun biome lint .",
|
|
106
|
+
"lint:fix": "bun biome lint --apply-unsafe .",
|
|
107
|
+
"release": "pnpm publish --no-git-check",
|
|
108
|
+
"release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
|
|
109
|
+
"start": "tsup --watch",
|
|
110
|
+
"test": "vitest --passWithNoTests",
|
|
111
|
+
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { File, Function, FunctionParams } from '@kubb/react'
|
|
2
|
+
|
|
3
|
+
import { type HttpMethod, isOptional } from '@kubb/oas'
|
|
4
|
+
import type { ReactNode } from 'react'
|
|
5
|
+
import { URLPath } from '@kubb/core/utils'
|
|
6
|
+
import type { OperationSchemas } from '@kubb/plugin-oas'
|
|
7
|
+
import type { PluginCypress } from '../types.ts'
|
|
8
|
+
|
|
9
|
+
type Props = {
|
|
10
|
+
/**
|
|
11
|
+
* Name of the function
|
|
12
|
+
*/
|
|
13
|
+
name: string
|
|
14
|
+
typeSchemas: OperationSchemas
|
|
15
|
+
url: string
|
|
16
|
+
baseURL: string | undefined
|
|
17
|
+
dataReturnType: PluginCypress['resolvedOptions']['dataReturnType']
|
|
18
|
+
method: HttpMethod
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function Request({ baseURL = '', name, dataReturnType, typeSchemas, url, method }: Props): ReactNode {
|
|
22
|
+
const params = FunctionParams.factory({
|
|
23
|
+
data: typeSchemas.request?.name
|
|
24
|
+
? {
|
|
25
|
+
type: typeSchemas.request?.name,
|
|
26
|
+
optional: isOptional(typeSchemas.request?.schema),
|
|
27
|
+
}
|
|
28
|
+
: undefined,
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const returnType =
|
|
32
|
+
dataReturnType === 'data' ? `Cypress.Chainable<${typeSchemas.response.name}>` : `Cypress.Chainable<Cypress.Response<${typeSchemas.response.name}>>`
|
|
33
|
+
|
|
34
|
+
const body = typeSchemas.request?.name ? 'data' : undefined
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<File.Source name={name} isIndexable isExportable>
|
|
38
|
+
<Function name={name} export params={params.toConstructor()} returnType={returnType}>
|
|
39
|
+
{dataReturnType === 'data' &&
|
|
40
|
+
`return cy.request('${method}', '${new URLPath(`${baseURL ?? ''}${url}`).toURLPath()}', ${body}).then((res: Cypress.Response<${typeSchemas.response.name}>) => res.body)`}
|
|
41
|
+
{dataReturnType === 'full' && `return cy.request('${method}', '${new URLPath(`${baseURL ?? ''}${url}`).toURLPath()}', ${body})`}
|
|
42
|
+
</Function>
|
|
43
|
+
</File.Source>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Request } from './Request.tsx'
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { URLPath } from '@kubb/core/utils'
|
|
2
|
+
import { createReactGenerator } from '@kubb/plugin-oas'
|
|
3
|
+
import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
4
|
+
import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
|
|
5
|
+
import { pluginTsName } from '@kubb/plugin-ts'
|
|
6
|
+
import { File, useApp } from '@kubb/react'
|
|
7
|
+
import { Request } from '../components'
|
|
8
|
+
import type { PluginCypress } from '../types'
|
|
9
|
+
|
|
10
|
+
export const cypressGenerator = createReactGenerator<PluginCypress>({
|
|
11
|
+
name: 'cypress',
|
|
12
|
+
Operation({ operation }) {
|
|
13
|
+
const {
|
|
14
|
+
plugin: {
|
|
15
|
+
options: { output, baseURL, dataReturnType },
|
|
16
|
+
},
|
|
17
|
+
} = useApp<PluginCypress>()
|
|
18
|
+
const oas = useOas()
|
|
19
|
+
const { getSchemas, getName, getFile } = useOperationManager()
|
|
20
|
+
|
|
21
|
+
const request = {
|
|
22
|
+
name: getName(operation, { type: 'function' }),
|
|
23
|
+
file: getFile(operation),
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const type = {
|
|
27
|
+
file: getFile(operation, { pluginKey: [pluginTsName] }),
|
|
28
|
+
schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<File
|
|
33
|
+
baseName={request.file.baseName}
|
|
34
|
+
path={request.file.path}
|
|
35
|
+
meta={request.file.meta}
|
|
36
|
+
banner={getBanner({ oas, output })}
|
|
37
|
+
footer={getFooter({ oas, output })}
|
|
38
|
+
>
|
|
39
|
+
<File.Import
|
|
40
|
+
name={[
|
|
41
|
+
type.schemas.request?.name,
|
|
42
|
+
type.schemas.response.name,
|
|
43
|
+
type.schemas.pathParams?.name,
|
|
44
|
+
type.schemas.queryParams?.name,
|
|
45
|
+
type.schemas.headerParams?.name,
|
|
46
|
+
...(type.schemas.statusCodes?.map((item) => item.name) || []),
|
|
47
|
+
].filter(Boolean)}
|
|
48
|
+
root={request.file.path}
|
|
49
|
+
path={type.file.path}
|
|
50
|
+
isTypeOnly
|
|
51
|
+
/>
|
|
52
|
+
<Request
|
|
53
|
+
name={request.name}
|
|
54
|
+
dataReturnType={dataReturnType}
|
|
55
|
+
typeSchemas={type.schemas}
|
|
56
|
+
method={operation.method}
|
|
57
|
+
baseURL={baseURL}
|
|
58
|
+
url={new URLPath(operation.path).toURLPath()}
|
|
59
|
+
/>
|
|
60
|
+
</File>
|
|
61
|
+
)
|
|
62
|
+
},
|
|
63
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { cypressGenerator } from './cypressGenerator.tsx'
|
package/src/index.ts
ADDED
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
|
|
3
|
+
import { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'
|
|
4
|
+
import { camelCase } from '@kubb/core/transformers'
|
|
5
|
+
import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
|
|
6
|
+
import { pluginTsName } from '@kubb/plugin-ts'
|
|
7
|
+
|
|
8
|
+
import type { Plugin } from '@kubb/core'
|
|
9
|
+
import type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'
|
|
10
|
+
import { cypressGenerator } from './generators'
|
|
11
|
+
import type { PluginCypress } from './types.ts'
|
|
12
|
+
|
|
13
|
+
export const pluginCypressName = 'plugin-cypress' satisfies PluginCypress['name']
|
|
14
|
+
|
|
15
|
+
export const pluginCypress = createPlugin<PluginCypress>((options) => {
|
|
16
|
+
const {
|
|
17
|
+
output = { path: 'cypress', barrelType: 'named' },
|
|
18
|
+
group,
|
|
19
|
+
dataReturnType = 'data',
|
|
20
|
+
exclude = [],
|
|
21
|
+
include,
|
|
22
|
+
override = [],
|
|
23
|
+
transformers = {},
|
|
24
|
+
generators = [cypressGenerator].filter(Boolean),
|
|
25
|
+
contentType,
|
|
26
|
+
baseURL,
|
|
27
|
+
} = options
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
name: pluginCypressName,
|
|
31
|
+
options: {
|
|
32
|
+
output,
|
|
33
|
+
dataReturnType,
|
|
34
|
+
group,
|
|
35
|
+
baseURL,
|
|
36
|
+
},
|
|
37
|
+
pre: [pluginOasName, pluginTsName].filter(Boolean),
|
|
38
|
+
resolvePath(baseName, pathMode, options) {
|
|
39
|
+
const root = path.resolve(this.config.root, this.config.output.path)
|
|
40
|
+
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))
|
|
41
|
+
|
|
42
|
+
if (mode === 'single') {
|
|
43
|
+
/**
|
|
44
|
+
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
45
|
+
* Other plugins then need to call addOrAppend instead of just add from the fileManager class
|
|
46
|
+
*/
|
|
47
|
+
return path.resolve(root, output.path)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (group && (options?.group?.path || options?.group?.tag)) {
|
|
51
|
+
const groupName: Group['name'] = group?.name
|
|
52
|
+
? group.name
|
|
53
|
+
: (ctx) => {
|
|
54
|
+
if (group?.type === 'path') {
|
|
55
|
+
return `${ctx.group.split('/')[1]}`
|
|
56
|
+
}
|
|
57
|
+
return `${camelCase(ctx.group)}Requests`
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return path.resolve(
|
|
61
|
+
root,
|
|
62
|
+
output.path,
|
|
63
|
+
groupName({
|
|
64
|
+
group: group.type === 'path' ? options.group.path! : options.group.tag!,
|
|
65
|
+
}),
|
|
66
|
+
baseName,
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return path.resolve(root, output.path, baseName)
|
|
71
|
+
},
|
|
72
|
+
resolveName(name, type) {
|
|
73
|
+
const resolvedName = camelCase(name, {
|
|
74
|
+
isFile: type === 'file',
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
if (type) {
|
|
78
|
+
return transformers?.name?.(resolvedName, type) || resolvedName
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return resolvedName
|
|
82
|
+
},
|
|
83
|
+
async buildStart() {
|
|
84
|
+
const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])
|
|
85
|
+
|
|
86
|
+
const oas = await swaggerPlugin.context.getOas()
|
|
87
|
+
const root = path.resolve(this.config.root, this.config.output.path)
|
|
88
|
+
const mode = FileManager.getMode(path.resolve(root, output.path))
|
|
89
|
+
|
|
90
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
91
|
+
oas,
|
|
92
|
+
pluginManager: this.pluginManager,
|
|
93
|
+
plugin: this.plugin,
|
|
94
|
+
contentType,
|
|
95
|
+
exclude,
|
|
96
|
+
include,
|
|
97
|
+
override,
|
|
98
|
+
mode,
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
const files = await operationGenerator.build(...generators)
|
|
102
|
+
await this.addFile(...files)
|
|
103
|
+
|
|
104
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
105
|
+
type: output.barrelType ?? 'named',
|
|
106
|
+
root,
|
|
107
|
+
output,
|
|
108
|
+
files: this.fileManager.files,
|
|
109
|
+
meta: {
|
|
110
|
+
pluginKey: this.plugin.key,
|
|
111
|
+
},
|
|
112
|
+
logger: this.logger,
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
await this.addFile(...barrelFiles)
|
|
116
|
+
},
|
|
117
|
+
}
|
|
118
|
+
})
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
|
2
|
+
|
|
3
|
+
import type { Oas, contentType } from '@kubb/oas'
|
|
4
|
+
import type { Exclude, Include, Override, ResolvePathOptions, Generator } from '@kubb/plugin-oas'
|
|
5
|
+
|
|
6
|
+
export type Options = {
|
|
7
|
+
/**
|
|
8
|
+
* Specify the export location for the files and define the behavior of the output
|
|
9
|
+
* @default { path: 'cypress', barrelType: 'named' }
|
|
10
|
+
*/
|
|
11
|
+
output?: Output<Oas>
|
|
12
|
+
/**
|
|
13
|
+
* Define which contentType should be used.
|
|
14
|
+
* By default, the first JSON valid mediaType will be used
|
|
15
|
+
*/
|
|
16
|
+
contentType?: contentType
|
|
17
|
+
/**
|
|
18
|
+
* ReturnType that will be used when calling cy.request.
|
|
19
|
+
* - 'data' will return ResponseConfig[data].
|
|
20
|
+
* - 'full' will return ResponseConfig.
|
|
21
|
+
* @default 'data'
|
|
22
|
+
*/
|
|
23
|
+
dataReturnType?: 'data' | 'full'
|
|
24
|
+
baseURL?: string
|
|
25
|
+
/**
|
|
26
|
+
* Group the Cypress requests based on the provided name.
|
|
27
|
+
*/
|
|
28
|
+
group?: Group
|
|
29
|
+
/**
|
|
30
|
+
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
31
|
+
*/
|
|
32
|
+
exclude?: Array<Exclude>
|
|
33
|
+
/**
|
|
34
|
+
* Array containing include parameters to include tags/operations/methods/paths.
|
|
35
|
+
*/
|
|
36
|
+
include?: Array<Include>
|
|
37
|
+
/**
|
|
38
|
+
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
39
|
+
*/
|
|
40
|
+
override?: Array<Override<ResolvedOptions>>
|
|
41
|
+
transformers?: {
|
|
42
|
+
/**
|
|
43
|
+
* Customize the names based on the type that is provided by the plugin.
|
|
44
|
+
*/
|
|
45
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Define some generators next to the Cypress generators.
|
|
49
|
+
*/
|
|
50
|
+
generators?: Array<Generator<PluginCypress>>
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
type ResolvedOptions = {
|
|
54
|
+
output: Output<Oas>
|
|
55
|
+
group: Options['group']
|
|
56
|
+
baseURL: Options['baseURL'] | undefined
|
|
57
|
+
dataReturnType: NonNullable<Options['dataReturnType']>
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type PluginCypress = PluginFactoryOptions<'plugin-cypress', Options, ResolvedOptions, never, ResolvePathOptions>
|