@kubb/plugin-cypress 5.0.0-beta.4 → 5.0.0-beta.42
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/README.md +39 -22
- package/dist/index.cjs +161 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +62 -35
- package/dist/index.js +163 -59
- package/dist/index.js.map +1 -1
- package/extension.yaml +635 -168
- package/package.json +9 -13
- package/src/components/Request.tsx +9 -10
- package/src/generators/cypressGenerator.tsx +19 -23
- package/src/plugin.ts +19 -24
- package/src/resolvers/resolverCypress.ts +13 -6
- package/src/types.ts +29 -17
- /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
package/README.md
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<h1>Plugin Cypress</h1>
|
|
3
2
|
<a href="https://kubb.dev" target="_blank" rel="noopener noreferrer">
|
|
4
|
-
<img
|
|
3
|
+
<img src="https://kubb.dev/og.png" alt="Kubb banner">
|
|
5
4
|
</a>
|
|
6
5
|
|
|
7
6
|
[![npm version][npm-version-src]][npm-version-href]
|
|
8
7
|
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
9
|
-
[![
|
|
8
|
+
[![Stars][stars-src]][stars-href]
|
|
10
9
|
[![License][license-src]][license-href]
|
|
11
|
-
[![
|
|
10
|
+
[![Node][node-src]][node-href]
|
|
12
11
|
|
|
13
12
|
<h4>
|
|
14
|
-
<a href="https://
|
|
15
|
-
<span> · </span>
|
|
16
|
-
<a href="https://kubb.dev/" target="_blank">Documentation</a>
|
|
13
|
+
<a href="https://kubb.dev/plugins/cypress" target="_blank">Documentation</a>
|
|
17
14
|
<span> · </span>
|
|
18
15
|
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
|
|
19
16
|
<span> · </span>
|
|
@@ -21,11 +18,31 @@
|
|
|
21
18
|
</h4>
|
|
22
19
|
</div>
|
|
23
20
|
|
|
24
|
-
|
|
21
|
+
<br />
|
|
22
|
+
|
|
23
|
+
# @kubb/plugin-cypress
|
|
24
|
+
|
|
25
|
+
### Generate Cypress commands from OpenAPI
|
|
26
|
+
|
|
27
|
+
`@kubb/plugin-cypress` generates Cypress request commands from your OpenAPI specification. Each operation in the spec becomes a typed Cypress command, ready to use in your test files.
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
bun add @kubb/plugin-cypress
|
|
33
|
+
# or
|
|
34
|
+
pnpm add @kubb/plugin-cypress
|
|
35
|
+
# or
|
|
36
|
+
npm install @kubb/plugin-cypress
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Documentation
|
|
40
|
+
|
|
41
|
+
See the [full documentation](https://kubb.dev/plugins/cypress) for configuration options and examples.
|
|
25
42
|
|
|
26
43
|
## Supporting Kubb
|
|
27
44
|
|
|
28
|
-
Kubb
|
|
45
|
+
Kubb is an open source project, and its development is funded entirely by sponsors. If you would like to become a sponsor, please consider:
|
|
29
46
|
|
|
30
47
|
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
|
|
31
48
|
|
|
@@ -35,19 +52,19 @@ Kubb uses an MIT-licensed open source project with its ongoing development made
|
|
|
35
52
|
</a>
|
|
36
53
|
</p>
|
|
37
54
|
|
|
55
|
+
## License
|
|
56
|
+
|
|
57
|
+
[MIT](https://github.com/kubb-labs/plugins/blob/main/LICENSE)
|
|
58
|
+
|
|
38
59
|
<!-- Badges -->
|
|
39
60
|
|
|
40
|
-
[npm-version-src]: https://
|
|
41
|
-
[npm-version-href]: https://
|
|
42
|
-
[npm-downloads-src]: https://
|
|
43
|
-
[npm-downloads-href]: https://
|
|
44
|
-
[
|
|
61
|
+
[npm-version-src]: https://shieldcn.dev/npm/v/@kubb/plugin-cypress.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
62
|
+
[npm-version-href]: https://npmx.dev/package/@kubb/plugin-cypress
|
|
63
|
+
[npm-downloads-src]: https://shieldcn.dev/npm/dm/@kubb/plugin-cypress.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
64
|
+
[npm-downloads-href]: https://npmx.dev/package/@kubb/plugin-cypress
|
|
65
|
+
[stars-src]: https://shieldcn.dev/github/stars/kubb-labs/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
66
|
+
[stars-href]: https://github.com/kubb-labs/kubb
|
|
67
|
+
[license-src]: https://shieldcn.dev/npm/license/@kubb/plugin-cypress.svg?variant=secondary&size=xs&theme=zinc
|
|
45
68
|
[license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
|
|
46
|
-
[
|
|
47
|
-
[
|
|
48
|
-
[minified-src]: https://img.shields.io/bundlephobia/min/@kubb/plugin-cypress?style=flat&colorA=18181B&colorB=f58517
|
|
49
|
-
[minified-href]: https://www.npmjs.com/package/@kubb/plugin-cypress
|
|
50
|
-
[coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
|
|
51
|
-
[coverage-href]: https://www.npmjs.com/package/@kubb/plugin-cypress
|
|
52
|
-
[sponsors-src]: https://img.shields.io/github/sponsors/stijnvanhulle?style=flat&colorA=18181B&colorB=f58517
|
|
53
|
-
[sponsors-href]: https://github.com/sponsors/stijnvanhulle/
|
|
69
|
+
[node-src]: https://shieldcn.dev/npm/node/@kubb/plugin-cypress.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
70
|
+
[node-href]: https://npmx.dev/package/@kubb/plugin-cypress
|
package/dist/index.cjs
CHANGED
|
@@ -218,16 +218,16 @@ var URLPath = class {
|
|
|
218
218
|
get object() {
|
|
219
219
|
return this.toObject();
|
|
220
220
|
}
|
|
221
|
-
/** Returns a map of path parameter names, or `
|
|
221
|
+
/** Returns a map of path parameter names, or `null` when the path has no parameters.
|
|
222
222
|
*
|
|
223
223
|
* @example
|
|
224
224
|
* ```ts
|
|
225
225
|
* new URLPath('/pet/{petId}').params // { petId: 'petId' }
|
|
226
|
-
* new URLPath('/pet').params //
|
|
226
|
+
* new URLPath('/pet').params // null
|
|
227
227
|
* ```
|
|
228
228
|
*/
|
|
229
229
|
get params() {
|
|
230
|
-
return this.
|
|
230
|
+
return this.toParamsObject();
|
|
231
231
|
}
|
|
232
232
|
#transformParam(raw) {
|
|
233
233
|
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
@@ -245,7 +245,7 @@ var URLPath = class {
|
|
|
245
245
|
toObject({ type = "path", replacer, stringify } = {}) {
|
|
246
246
|
const object = {
|
|
247
247
|
url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
|
|
248
|
-
params: this.
|
|
248
|
+
params: this.toParamsObject()
|
|
249
249
|
};
|
|
250
250
|
if (stringify) {
|
|
251
251
|
if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
@@ -261,12 +261,13 @@ var URLPath = class {
|
|
|
261
261
|
* @example
|
|
262
262
|
* new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
|
|
263
263
|
*/
|
|
264
|
-
toTemplateString({ prefix
|
|
265
|
-
|
|
264
|
+
toTemplateString({ prefix, replacer } = {}) {
|
|
265
|
+
const result = this.path.split(/\{([^}]+)\}/).map((part, i) => {
|
|
266
266
|
if (i % 2 === 0) return part;
|
|
267
267
|
const param = this.#transformParam(part);
|
|
268
268
|
return `\${${replacer ? replacer(param) : param}}`;
|
|
269
|
-
}).join("")
|
|
269
|
+
}).join("");
|
|
270
|
+
return `\`${prefix ?? ""}${result}\``;
|
|
270
271
|
}
|
|
271
272
|
/**
|
|
272
273
|
* Extracts all `{param}` segments from the path and returns them as a key-value map.
|
|
@@ -275,17 +276,17 @@ var URLPath = class {
|
|
|
275
276
|
*
|
|
276
277
|
* @example
|
|
277
278
|
* ```ts
|
|
278
|
-
* new URLPath('/pet/{petId}/tag/{tagId}').
|
|
279
|
+
* new URLPath('/pet/{petId}/tag/{tagId}').toParamsObject()
|
|
279
280
|
* // { petId: 'petId', tagId: 'tagId' }
|
|
280
281
|
* ```
|
|
281
282
|
*/
|
|
282
|
-
|
|
283
|
+
toParamsObject(replacer) {
|
|
283
284
|
const params = {};
|
|
284
285
|
this.#eachParam((_raw, param) => {
|
|
285
286
|
const key = replacer ? replacer(param) : param;
|
|
286
287
|
params[key] = key;
|
|
287
288
|
});
|
|
288
|
-
return Object.keys(params).length > 0 ? params :
|
|
289
|
+
return Object.keys(params).length > 0 ? params : null;
|
|
289
290
|
}
|
|
290
291
|
/** Converts the OpenAPI path to Express-style colon syntax.
|
|
291
292
|
*
|
|
@@ -299,9 +300,100 @@ var URLPath = class {
|
|
|
299
300
|
}
|
|
300
301
|
};
|
|
301
302
|
//#endregion
|
|
303
|
+
//#region ../../internals/shared/src/operation.ts
|
|
304
|
+
function getOperationParameters(node, options = {}) {
|
|
305
|
+
const params = _kubb_core.ast.caseParams(node.parameters, options.paramsCasing);
|
|
306
|
+
return {
|
|
307
|
+
path: params.filter((param) => param.in === "path"),
|
|
308
|
+
query: params.filter((param) => param.in === "query"),
|
|
309
|
+
header: params.filter((param) => param.in === "header"),
|
|
310
|
+
cookie: params.filter((param) => param.in === "cookie")
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
function getStatusCodeNumber(statusCode) {
|
|
314
|
+
const code = Number(statusCode);
|
|
315
|
+
return Number.isNaN(code) ? null : code;
|
|
316
|
+
}
|
|
317
|
+
function isErrorStatusCode(statusCode) {
|
|
318
|
+
const code = getStatusCodeNumber(statusCode);
|
|
319
|
+
return code !== null && code >= 400;
|
|
320
|
+
}
|
|
321
|
+
function resolveErrorNames(node, resolver) {
|
|
322
|
+
return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
323
|
+
}
|
|
324
|
+
function resolveStatusCodeNames(node, resolver) {
|
|
325
|
+
return node.responses.map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
326
|
+
}
|
|
327
|
+
const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
|
|
328
|
+
function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
329
|
+
const cacheKey = `${node.operationId}\0${options.paramsCasing ?? ""}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${(options.exclude ?? []).join(",")}`;
|
|
330
|
+
let byResolver = typeNamesByResolver.get(resolver);
|
|
331
|
+
if (byResolver) {
|
|
332
|
+
const cached = byResolver.get(cacheKey);
|
|
333
|
+
if (cached) return cached;
|
|
334
|
+
} else {
|
|
335
|
+
byResolver = /* @__PURE__ */ new Map();
|
|
336
|
+
typeNamesByResolver.set(resolver, byResolver);
|
|
337
|
+
}
|
|
338
|
+
const { path, query, header } = getOperationParameters(node, { paramsCasing: options.paramsCasing });
|
|
339
|
+
const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
|
|
340
|
+
const exclude = new Set(options.exclude ?? []);
|
|
341
|
+
const paramNames = [
|
|
342
|
+
...path.map((param) => resolver.resolvePathParamsName(node, param)),
|
|
343
|
+
...query.map((param) => resolver.resolveQueryParamsName(node, param)),
|
|
344
|
+
...header.map((param) => resolver.resolveHeaderParamsName(node, param))
|
|
345
|
+
];
|
|
346
|
+
const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null, resolver.resolveResponseName(node)];
|
|
347
|
+
const result = (options.order === "body-response-first" ? [
|
|
348
|
+
...bodyAndResponseNames,
|
|
349
|
+
...paramNames,
|
|
350
|
+
...responseStatusNames
|
|
351
|
+
] : [
|
|
352
|
+
...paramNames,
|
|
353
|
+
...bodyAndResponseNames,
|
|
354
|
+
...responseStatusNames
|
|
355
|
+
]).filter((name) => Boolean(name) && !exclude.has(name));
|
|
356
|
+
byResolver.set(cacheKey, result);
|
|
357
|
+
return result;
|
|
358
|
+
}
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region ../../internals/shared/src/group.ts
|
|
361
|
+
/**
|
|
362
|
+
* Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
|
|
363
|
+
* shared default naming so every plugin groups output consistently:
|
|
364
|
+
*
|
|
365
|
+
* - `path` groups use the second path segment (`/pet/findByStatus` → `pet`).
|
|
366
|
+
* - other groups use `${camelCase(group)}${suffix}` (e.g. `petController`).
|
|
367
|
+
*
|
|
368
|
+
* A user-provided `group.name` always wins over the default namer, so callers stay in
|
|
369
|
+
* control of their output folders. Returns `null` when grouping is disabled, matching the
|
|
370
|
+
* per-plugin convention.
|
|
371
|
+
*
|
|
372
|
+
* @param group - The user-supplied group option, or `undefined` to disable grouping.
|
|
373
|
+
* @param options.suffix - Appended to non-`path` group names, e.g. `'Controller'` or `'Requests'`.
|
|
374
|
+
*
|
|
375
|
+
* @example
|
|
376
|
+
* ```ts
|
|
377
|
+
* createGroupConfig(group, { suffix: 'Controller' }) // plugin-ts, plugin-client, …
|
|
378
|
+
* createGroupConfig(group, { suffix: 'Requests' }) // plugin-cypress, plugin-mcp
|
|
379
|
+
* ```
|
|
380
|
+
*/
|
|
381
|
+
function createGroupConfig(group, options) {
|
|
382
|
+
if (!group) return null;
|
|
383
|
+
const defaultName = (ctx) => {
|
|
384
|
+
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
385
|
+
return `${camelCase(ctx.group)}${options.suffix}`;
|
|
386
|
+
};
|
|
387
|
+
return {
|
|
388
|
+
...group,
|
|
389
|
+
name: group.name ? group.name : defaultName
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
//#endregion
|
|
302
393
|
//#region src/components/Request.tsx
|
|
303
394
|
const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
304
395
|
function Request({ baseURL = "", name, dataReturnType, resolver, node, paramsType, pathParamsType, paramsCasing }) {
|
|
396
|
+
if (!_kubb_core.ast.isHttpOperationNode(node)) return null;
|
|
305
397
|
const paramsNode = _kubb_core.ast.createOperationParams(node, {
|
|
306
398
|
paramsType,
|
|
307
399
|
pathParamsType,
|
|
@@ -319,24 +411,24 @@ function Request({ baseURL = "", name, dataReturnType, resolver, node, paramsTyp
|
|
|
319
411
|
const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
|
|
320
412
|
const responseType = resolver.resolveResponseName(node);
|
|
321
413
|
const returnType = dataReturnType === "data" ? `Cypress.Chainable<${responseType}>` : `Cypress.Chainable<Cypress.Response<${responseType}>>`;
|
|
322
|
-
const casedPathParams =
|
|
414
|
+
const casedPathParams = getOperationParameters(node, { paramsCasing }).path;
|
|
323
415
|
const pathParamNameMap = new Map(casedPathParams.map((p) => [camelCase(p.name), p.name]));
|
|
324
416
|
const urlTemplate = new URLPath(node.path, { casing: paramsCasing }).toTemplateString({
|
|
325
417
|
prefix: baseURL,
|
|
326
418
|
replacer: (param) => pathParamNameMap.get(camelCase(param)) ?? param
|
|
327
419
|
});
|
|
328
420
|
const requestOptions = [`method: '${node.method}'`, `url: ${urlTemplate}`];
|
|
329
|
-
const queryParams = node
|
|
421
|
+
const queryParams = getOperationParameters(node).query;
|
|
330
422
|
if (queryParams.length > 0) {
|
|
331
|
-
const casedQueryParams =
|
|
423
|
+
const casedQueryParams = getOperationParameters(node, { paramsCasing }).query;
|
|
332
424
|
if (casedQueryParams.some((p, i) => p.name !== queryParams[i].name)) {
|
|
333
425
|
const pairs = queryParams.map((orig, i) => `${orig.name}: params.${casedQueryParams[i].name}`).join(", ");
|
|
334
426
|
requestOptions.push(`qs: params ? { ${pairs} } : undefined`);
|
|
335
427
|
} else requestOptions.push("qs: params");
|
|
336
428
|
}
|
|
337
|
-
const headerParams = node
|
|
429
|
+
const headerParams = getOperationParameters(node).header;
|
|
338
430
|
if (headerParams.length > 0) {
|
|
339
|
-
const casedHeaderParams =
|
|
431
|
+
const casedHeaderParams = getOperationParameters(node, { paramsCasing }).header;
|
|
340
432
|
if (casedHeaderParams.some((p, i) => p.name !== headerParams[i].name)) {
|
|
341
433
|
const pairs = headerParams.map((orig, i) => `'${orig.name}': headers.${casedHeaderParams[i].name}`).join(", ");
|
|
342
434
|
requestOptions.push(`headers: headers ? { ${pairs} } : undefined`);
|
|
@@ -363,26 +455,22 @@ function Request({ baseURL = "", name, dataReturnType, resolver, node, paramsTyp
|
|
|
363
455
|
}
|
|
364
456
|
//#endregion
|
|
365
457
|
//#region src/generators/cypressGenerator.tsx
|
|
458
|
+
/**
|
|
459
|
+
* Built-in generator for `@kubb/plugin-cypress`. Emits one typed
|
|
460
|
+
* `cy.request()` wrapper per OpenAPI operation, ready to call inside Cypress
|
|
461
|
+
* test specs and custom commands.
|
|
462
|
+
*/
|
|
366
463
|
const cypressGenerator = (0, _kubb_core.defineGenerator)({
|
|
367
464
|
name: "cypress",
|
|
368
|
-
renderer: _kubb_renderer_jsx.
|
|
465
|
+
renderer: _kubb_renderer_jsx.jsxRendererSync,
|
|
369
466
|
operation(node, ctx) {
|
|
370
|
-
|
|
467
|
+
if (!_kubb_core.ast.isHttpOperationNode(node)) return null;
|
|
468
|
+
const { config, resolver, driver, root } = ctx;
|
|
371
469
|
const { output, baseURL, dataReturnType, paramsCasing, paramsType, pathParamsType, group } = ctx.options;
|
|
372
470
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
373
471
|
if (!pluginTs) return null;
|
|
374
472
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
375
|
-
const
|
|
376
|
-
const pathParams = casedParams.filter((p) => p.in === "path");
|
|
377
|
-
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
378
|
-
const headerParams = casedParams.filter((p) => p.in === "header");
|
|
379
|
-
const importedTypeNames = [
|
|
380
|
-
...pathParams.map((p) => tsResolver.resolvePathParamsName(node, p)),
|
|
381
|
-
...queryParams.map((p) => tsResolver.resolveQueryParamsName(node, p)),
|
|
382
|
-
...headerParams.map((p) => tsResolver.resolveHeaderParamsName(node, p)),
|
|
383
|
-
node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) : void 0,
|
|
384
|
-
tsResolver.resolveResponseName(node)
|
|
385
|
-
].filter(Boolean);
|
|
473
|
+
const importedTypeNames = resolveOperationTypeNames(node, tsResolver, { paramsCasing });
|
|
386
474
|
const meta = {
|
|
387
475
|
name: resolver.resolveName(node.operationId),
|
|
388
476
|
file: resolver.resolveFile({
|
|
@@ -393,7 +481,7 @@ const cypressGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
393
481
|
}, {
|
|
394
482
|
root,
|
|
395
483
|
output,
|
|
396
|
-
group
|
|
484
|
+
group: group ?? void 0
|
|
397
485
|
}),
|
|
398
486
|
fileTs: tsResolver.resolveFile({
|
|
399
487
|
name: node.operationId,
|
|
@@ -403,23 +491,31 @@ const cypressGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
403
491
|
}, {
|
|
404
492
|
root,
|
|
405
493
|
output: pluginTs.options?.output ?? output,
|
|
406
|
-
group: pluginTs.options?.group
|
|
494
|
+
group: pluginTs.options?.group ?? void 0
|
|
407
495
|
})
|
|
408
496
|
};
|
|
409
497
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
410
498
|
baseName: meta.file.baseName,
|
|
411
499
|
path: meta.file.path,
|
|
412
500
|
meta: meta.file.meta,
|
|
413
|
-
banner: resolver.resolveBanner(
|
|
501
|
+
banner: resolver.resolveBanner(ctx.meta, {
|
|
414
502
|
output,
|
|
415
|
-
config
|
|
503
|
+
config,
|
|
504
|
+
file: {
|
|
505
|
+
path: meta.file.path,
|
|
506
|
+
baseName: meta.file.baseName
|
|
507
|
+
}
|
|
416
508
|
}),
|
|
417
|
-
footer: resolver.resolveFooter(
|
|
509
|
+
footer: resolver.resolveFooter(ctx.meta, {
|
|
418
510
|
output,
|
|
419
|
-
config
|
|
511
|
+
config,
|
|
512
|
+
file: {
|
|
513
|
+
path: meta.file.path,
|
|
514
|
+
baseName: meta.file.baseName
|
|
515
|
+
}
|
|
420
516
|
}),
|
|
421
517
|
children: [meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
422
|
-
name:
|
|
518
|
+
name: importedTypeNames,
|
|
423
519
|
root: meta.file.path,
|
|
424
520
|
path: meta.fileTs.path,
|
|
425
521
|
isTypeOnly: true
|
|
@@ -439,43 +535,57 @@ const cypressGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
439
535
|
//#endregion
|
|
440
536
|
//#region src/resolvers/resolverCypress.ts
|
|
441
537
|
/**
|
|
442
|
-
*
|
|
538
|
+
* Default resolver used by `@kubb/plugin-cypress`. Decides the names and file
|
|
539
|
+
* paths for every generated `cy.request()` wrapper. Functions and files use
|
|
540
|
+
* camelCase, matching the convention from `@kubb/plugin-client`.
|
|
443
541
|
*
|
|
444
|
-
*
|
|
542
|
+
* @example Resolve a helper name
|
|
543
|
+
* ```ts
|
|
544
|
+
* import { resolverCypress } from '@kubb/plugin-cypress'
|
|
445
545
|
*
|
|
446
|
-
*
|
|
447
|
-
*
|
|
546
|
+
* resolverCypress.default('list pets', 'function') // 'listPets'
|
|
547
|
+
* ```
|
|
448
548
|
*/
|
|
449
|
-
const resolverCypress = (0, _kubb_core.defineResolver)((
|
|
549
|
+
const resolverCypress = (0, _kubb_core.defineResolver)(() => ({
|
|
450
550
|
name: "default",
|
|
451
551
|
pluginName: "plugin-cypress",
|
|
452
552
|
default(name, type) {
|
|
453
553
|
return camelCase(name, { isFile: type === "file" });
|
|
454
554
|
},
|
|
455
555
|
resolveName(name) {
|
|
456
|
-
return
|
|
556
|
+
return this.default(name, "function");
|
|
557
|
+
},
|
|
558
|
+
resolvePathName(name, type) {
|
|
559
|
+
return this.default(name, type);
|
|
457
560
|
}
|
|
458
561
|
}));
|
|
459
562
|
//#endregion
|
|
460
563
|
//#region src/plugin.ts
|
|
461
564
|
/**
|
|
462
|
-
* Canonical plugin name for `@kubb/plugin-cypress
|
|
463
|
-
*
|
|
565
|
+
* Canonical plugin name for `@kubb/plugin-cypress`. Used for driver lookups and
|
|
566
|
+
* cross-plugin dependency references.
|
|
464
567
|
*/
|
|
465
568
|
const pluginCypressName = "plugin-cypress";
|
|
466
569
|
/**
|
|
467
|
-
*
|
|
468
|
-
*
|
|
469
|
-
*
|
|
470
|
-
* Walks operations, delegates rendering to the active generators,
|
|
471
|
-
* and writes barrel files based on `output.barrelType`.
|
|
570
|
+
* Generates one typed `cy.request()` wrapper per OpenAPI operation. Each helper
|
|
571
|
+
* has typed path params, body, query, and a typed response, so failing API
|
|
572
|
+
* calls in Cypress show up at compile time instead of inside the test runner.
|
|
472
573
|
*
|
|
473
574
|
* @example
|
|
474
575
|
* ```ts
|
|
475
|
-
* import
|
|
576
|
+
* import { defineConfig } from 'kubb'
|
|
577
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
578
|
+
* import { pluginCypress } from '@kubb/plugin-cypress'
|
|
476
579
|
*
|
|
477
580
|
* export default defineConfig({
|
|
478
|
-
*
|
|
581
|
+
* input: { path: './petStore.yaml' },
|
|
582
|
+
* output: { path: './src/gen' },
|
|
583
|
+
* plugins: [
|
|
584
|
+
* pluginTs(),
|
|
585
|
+
* pluginCypress({
|
|
586
|
+
* output: { path: './cypress' },
|
|
587
|
+
* }),
|
|
588
|
+
* ],
|
|
479
589
|
* })
|
|
480
590
|
* ```
|
|
481
591
|
*/
|
|
@@ -484,13 +594,7 @@ const pluginCypress = (0, _kubb_core.definePlugin)((options) => {
|
|
|
484
594
|
path: "cypress",
|
|
485
595
|
barrelType: "named"
|
|
486
596
|
}, group, exclude = [], include, override = [], dataReturnType = "data", baseURL, paramsCasing, paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline", resolver: userResolver, transformer: userTransformer, generators: userGenerators = [] } = options;
|
|
487
|
-
const groupConfig = group
|
|
488
|
-
...group,
|
|
489
|
-
name: group.name ? group.name : (ctx) => {
|
|
490
|
-
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
491
|
-
return `${camelCase(ctx.group)}Requests`;
|
|
492
|
-
}
|
|
493
|
-
} : void 0;
|
|
597
|
+
const groupConfig = createGroupConfig(group, { suffix: "Requests" });
|
|
494
598
|
return {
|
|
495
599
|
name: pluginCypressName,
|
|
496
600
|
options,
|