@kubb/plugin-cypress 5.3.0-canary.20261111T115959 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +190 -251
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +191 -252
- package/dist/index.js.map +1 -1
- package/kubb-extension.json +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,7 +1,146 @@
|
|
|
1
|
-
import { Resolver, Url, addGenerator, ast,
|
|
1
|
+
import { Resolver, Url, addGenerator, ast, casing, createResolver, defineExtension, defineGenerator, setMacros, setResolver, text } from "@kubb/kit";
|
|
2
2
|
import { File, Function, jsxRenderer } from "@kubb/renderer-jsx";
|
|
3
3
|
import { jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
|
|
4
4
|
import { pluginTsName } from "@kubb/plugin-ts";
|
|
5
|
+
// ../../internals/utils/src/reserved.ts
|
|
6
|
+
/**
|
|
7
|
+
* JavaScript and Java reserved words.
|
|
8
|
+
* @link https://github.com/jonschlinkert/reserved/blob/master/index.js
|
|
9
|
+
*/
|
|
10
|
+
const reservedWords = /* @__PURE__ */ new Set([
|
|
11
|
+
"abstract",
|
|
12
|
+
"arguments",
|
|
13
|
+
"await",
|
|
14
|
+
"boolean",
|
|
15
|
+
"break",
|
|
16
|
+
"byte",
|
|
17
|
+
"case",
|
|
18
|
+
"catch",
|
|
19
|
+
"char",
|
|
20
|
+
"class",
|
|
21
|
+
"const",
|
|
22
|
+
"continue",
|
|
23
|
+
"debugger",
|
|
24
|
+
"default",
|
|
25
|
+
"delete",
|
|
26
|
+
"do",
|
|
27
|
+
"double",
|
|
28
|
+
"else",
|
|
29
|
+
"enum",
|
|
30
|
+
"eval",
|
|
31
|
+
"export",
|
|
32
|
+
"extends",
|
|
33
|
+
"false",
|
|
34
|
+
"final",
|
|
35
|
+
"finally",
|
|
36
|
+
"float",
|
|
37
|
+
"for",
|
|
38
|
+
"function",
|
|
39
|
+
"goto",
|
|
40
|
+
"if",
|
|
41
|
+
"implements",
|
|
42
|
+
"import",
|
|
43
|
+
"in",
|
|
44
|
+
"instanceof",
|
|
45
|
+
"int",
|
|
46
|
+
"interface",
|
|
47
|
+
"let",
|
|
48
|
+
"long",
|
|
49
|
+
"native",
|
|
50
|
+
"new",
|
|
51
|
+
"null",
|
|
52
|
+
"package",
|
|
53
|
+
"private",
|
|
54
|
+
"protected",
|
|
55
|
+
"public",
|
|
56
|
+
"return",
|
|
57
|
+
"short",
|
|
58
|
+
"static",
|
|
59
|
+
"super",
|
|
60
|
+
"switch",
|
|
61
|
+
"synchronized",
|
|
62
|
+
"this",
|
|
63
|
+
"throw",
|
|
64
|
+
"throws",
|
|
65
|
+
"transient",
|
|
66
|
+
"true",
|
|
67
|
+
"try",
|
|
68
|
+
"typeof",
|
|
69
|
+
"var",
|
|
70
|
+
"void",
|
|
71
|
+
"volatile",
|
|
72
|
+
"while",
|
|
73
|
+
"with",
|
|
74
|
+
"yield",
|
|
75
|
+
"Array",
|
|
76
|
+
"Date",
|
|
77
|
+
"hasOwnProperty",
|
|
78
|
+
"Infinity",
|
|
79
|
+
"isFinite",
|
|
80
|
+
"isNaN",
|
|
81
|
+
"isPrototypeOf",
|
|
82
|
+
"length",
|
|
83
|
+
"Math",
|
|
84
|
+
"name",
|
|
85
|
+
"NaN",
|
|
86
|
+
"Number",
|
|
87
|
+
"Object",
|
|
88
|
+
"prototype",
|
|
89
|
+
"String",
|
|
90
|
+
"toString",
|
|
91
|
+
"undefined",
|
|
92
|
+
"valueOf"
|
|
93
|
+
]);
|
|
94
|
+
/**
|
|
95
|
+
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* isValidVarName('status') // true
|
|
100
|
+
* isValidVarName('class') // false (reserved word)
|
|
101
|
+
* isValidVarName('42foo') // false (starts with digit)
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
function isValidVarName(name) {
|
|
105
|
+
if (!name || reservedWords.has(name)) return false;
|
|
106
|
+
return isIdentifier(name);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Returns `name` when it's a syntactically valid JavaScript variable name,
|
|
110
|
+
* otherwise prefixes it with `_` so the result is a valid identifier.
|
|
111
|
+
*
|
|
112
|
+
* Useful for sanitizing OpenAPI schema names or operation IDs that start with
|
|
113
|
+
* a digit (e.g. `409`, `504AccountCancel`) before using them as exported
|
|
114
|
+
* variable, type, or function names.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* ensureValidVarName('409') // '_409'
|
|
119
|
+
* ensureValidVarName('504AccountCancel') // '_504AccountCancel'
|
|
120
|
+
* ensureValidVarName('Pet') // 'Pet'
|
|
121
|
+
* ensureValidVarName('class') // '_class'
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
function ensureValidVarName(name) {
|
|
125
|
+
if (!name || isValidVarName(name)) return name;
|
|
126
|
+
return `_${name}`;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.
|
|
130
|
+
*
|
|
131
|
+
* Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys
|
|
132
|
+
* even though they are not valid variable names, so use this (not {@link isValidVarName}) when
|
|
133
|
+
* deciding whether an object key needs quoting.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* isIdentifier('name') // true
|
|
138
|
+
* isIdentifier('x-total')// false
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
function isIdentifier(name) {
|
|
142
|
+
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
143
|
+
}
|
|
5
144
|
// ../../internals/shared/src/operation.ts
|
|
6
145
|
/**
|
|
7
146
|
* Builds the `ResolverFileParams` every operation generator passes to
|
|
@@ -89,7 +228,7 @@ function getContentTypeInfo(node) {
|
|
|
89
228
|
* whether several are present, so the client can let a caller pick which one to accept.
|
|
90
229
|
*/
|
|
91
230
|
function getResponseContentTypeInfo(node) {
|
|
92
|
-
return buildContentTypeInfo(
|
|
231
|
+
return buildContentTypeInfo(ast.http.responses.findPrimary(node)?.content?.map((e) => e.contentType) ?? []);
|
|
93
232
|
}
|
|
94
233
|
/**
|
|
95
234
|
* Builds the `client?:` option type shared by the generated query hooks (`useQuery`,
|
|
@@ -132,11 +271,11 @@ const requestGroupOrder = [
|
|
|
132
271
|
* Which of the grouped request options an operation carries.
|
|
133
272
|
*/
|
|
134
273
|
function getRequestGroups(node) {
|
|
135
|
-
const { path, query, header, cookie } =
|
|
274
|
+
const { path, query, header, cookie } = ast.http.groupParameters(node);
|
|
136
275
|
return {
|
|
137
276
|
path: path.length > 0,
|
|
138
277
|
query: query.length > 0,
|
|
139
|
-
body: Boolean(
|
|
278
|
+
body: Boolean(ast.http.requestBody.getSchema(node)),
|
|
140
279
|
headers: header.length > 0,
|
|
141
280
|
cookies: cookie.length > 0
|
|
142
281
|
};
|
|
@@ -148,7 +287,7 @@ function getRequestGroups(node) {
|
|
|
148
287
|
*/
|
|
149
288
|
function getRequestGroupOptionality(node) {
|
|
150
289
|
const groups = getRequestGroups(node);
|
|
151
|
-
const { path, query, header } =
|
|
290
|
+
const { path, query, header } = ast.http.groupParameters(node);
|
|
152
291
|
const hasRequiredPath = path.some((param) => param.required);
|
|
153
292
|
const hasRequiredQuery = query.some((param) => param.required);
|
|
154
293
|
const hasRequiredHeader = header.some((param) => param.required);
|
|
@@ -177,79 +316,14 @@ function buildRequestParamsSignature(node, resolver, options = {}) {
|
|
|
177
316
|
names
|
|
178
317
|
};
|
|
179
318
|
}
|
|
180
|
-
const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
|
|
181
|
-
/**
|
|
182
|
-
* An OpenAPI 3.2 `querystring` parameter is the whole query string, so a form-encoded object becomes one query parameter
|
|
183
|
-
* per property, typed and serialized like any other.
|
|
184
|
-
* Another content type, such as JSON, stays one parameter named after it, and the runtime sends its value as the whole query string.
|
|
185
|
-
*/
|
|
186
|
-
function spreadQuerystring(param) {
|
|
187
|
-
const schema = param.schema.type === "ref" ? param.schema.schema : param.schema;
|
|
188
|
-
const formEncoded = !param.contentType || param.contentType.split(";")[0].trim().toLowerCase() === "application/x-www-form-urlencoded";
|
|
189
|
-
if (schema?.type !== "object" || !formEncoded) return [param];
|
|
190
|
-
return schema.properties.map((property) => ast.factory.createParameter({
|
|
191
|
-
name: property.name,
|
|
192
|
-
in: "query",
|
|
193
|
-
schema: property.schema,
|
|
194
|
-
required: param.required && property.required
|
|
195
|
-
}));
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
|
|
199
|
-
* group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
|
|
200
|
-
* (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
|
|
201
|
-
* same parameters once per plugin.
|
|
202
|
-
*/
|
|
203
|
-
function getOperationParameters(node) {
|
|
204
|
-
const cached = operationParameterGroupsByNode.get(node);
|
|
205
|
-
if (cached) return cached;
|
|
206
|
-
const dedupe = (params) => {
|
|
207
|
-
const seen = /* @__PURE__ */ new Set();
|
|
208
|
-
return params.filter((param) => {
|
|
209
|
-
if (seen.has(param.name)) return false;
|
|
210
|
-
seen.add(param.name);
|
|
211
|
-
return true;
|
|
212
|
-
});
|
|
213
|
-
};
|
|
214
|
-
const group = (location) => dedupe(node.parameters.filter((param) => param.in === location));
|
|
215
|
-
const groups = {
|
|
216
|
-
path: group("path"),
|
|
217
|
-
query: dedupe([...group("query"), ...group("querystring").flatMap(spreadQuerystring)]),
|
|
218
|
-
header: group("header"),
|
|
219
|
-
cookie: group("cookie")
|
|
220
|
-
};
|
|
221
|
-
operationParameterGroupsByNode.set(node, groups);
|
|
222
|
-
return groups;
|
|
223
|
-
}
|
|
224
319
|
/**
|
|
225
320
|
* Whether the operation declares more than one request media type with a schema, so a caller must pick one on `contentType`.
|
|
226
321
|
*/
|
|
227
322
|
function hasRequestContentTypeChoice(node) {
|
|
228
323
|
return (node.requestBody?.content ?? []).filter((entry) => entry.schema).length > 1;
|
|
229
324
|
}
|
|
230
|
-
function getStatusCodeNumber(statusCode) {
|
|
231
|
-
const code = Number(statusCode);
|
|
232
|
-
return Number.isNaN(code) ? null : code;
|
|
233
|
-
}
|
|
234
|
-
function isSuccessStatusCode(statusCode) {
|
|
235
|
-
const code = getStatusCodeNumber(statusCode);
|
|
236
|
-
return code !== null && code >= 200 && code < 300;
|
|
237
|
-
}
|
|
238
|
-
function isErrorStatusCode(statusCode) {
|
|
239
|
-
const code = getStatusCodeNumber(statusCode);
|
|
240
|
-
return code !== null && code >= 400;
|
|
241
|
-
}
|
|
242
|
-
function getSuccessResponses(responses) {
|
|
243
|
-
return responses.filter((response) => isSuccessStatusCode(response.statusCode));
|
|
244
|
-
}
|
|
245
|
-
function getOperationSuccessResponses(node) {
|
|
246
|
-
return getSuccessResponses(node.responses);
|
|
247
|
-
}
|
|
248
|
-
function getPrimarySuccessResponse(node) {
|
|
249
|
-
return getOperationSuccessResponses(node)[0] ?? null;
|
|
250
|
-
}
|
|
251
325
|
function resolveErrorNames(node, resolver) {
|
|
252
|
-
return
|
|
326
|
+
return ast.http.responses.filterError(node).map((response) => resolver.response.status(node, response.statusCode));
|
|
253
327
|
}
|
|
254
328
|
function resolveStatusCodeNames(node, resolver) {
|
|
255
329
|
return node.responses.map((response) => resolver.response.status(node, response.statusCode));
|
|
@@ -261,7 +335,7 @@ function resolveStatusCodeNames(node, resolver) {
|
|
|
261
335
|
function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
262
336
|
const key = `${node.operationId}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${options.includeParams === false ? "noparams" : ""}\0${(options.exclude ?? []).join(",")}`;
|
|
263
337
|
return resolver.memo(`operationTypeNames:${key}`, () => {
|
|
264
|
-
const { path, query, header, cookie } =
|
|
338
|
+
const { path, query, header, cookie } = ast.http.groupParameters(node);
|
|
265
339
|
const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
|
|
266
340
|
const exclude = new Set(options.exclude ?? []);
|
|
267
341
|
const paramNames = options.includeParams === false ? [] : [
|
|
@@ -270,7 +344,7 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
|
270
344
|
...header.map((param) => resolver.param.headers(node, param)),
|
|
271
345
|
...cookie.map((param) => resolver.param.cookies(node, param))
|
|
272
346
|
];
|
|
273
|
-
const bodyAndResponseNames = [
|
|
347
|
+
const bodyAndResponseNames = [ast.http.requestBody.getSchema(node) ? resolver.response.body(node) : null, resolver.response.response(node)];
|
|
274
348
|
return (options.order === "body-response-first" ? [
|
|
275
349
|
...bodyAndResponseNames,
|
|
276
350
|
...paramNames,
|
|
@@ -282,157 +356,21 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
|
282
356
|
]).filter((name) => Boolean(name) && !exclude.has(name));
|
|
283
357
|
});
|
|
284
358
|
}
|
|
285
|
-
// ../../internals/utils/src/reserved.ts
|
|
286
|
-
/**
|
|
287
|
-
* JavaScript and Java reserved words.
|
|
288
|
-
* @link https://github.com/jonschlinkert/reserved/blob/master/index.js
|
|
289
|
-
*/
|
|
290
|
-
const reservedWords = /* @__PURE__ */ new Set([
|
|
291
|
-
"abstract",
|
|
292
|
-
"arguments",
|
|
293
|
-
"await",
|
|
294
|
-
"boolean",
|
|
295
|
-
"break",
|
|
296
|
-
"byte",
|
|
297
|
-
"case",
|
|
298
|
-
"catch",
|
|
299
|
-
"char",
|
|
300
|
-
"class",
|
|
301
|
-
"const",
|
|
302
|
-
"continue",
|
|
303
|
-
"debugger",
|
|
304
|
-
"default",
|
|
305
|
-
"delete",
|
|
306
|
-
"do",
|
|
307
|
-
"double",
|
|
308
|
-
"else",
|
|
309
|
-
"enum",
|
|
310
|
-
"eval",
|
|
311
|
-
"export",
|
|
312
|
-
"extends",
|
|
313
|
-
"false",
|
|
314
|
-
"final",
|
|
315
|
-
"finally",
|
|
316
|
-
"float",
|
|
317
|
-
"for",
|
|
318
|
-
"function",
|
|
319
|
-
"goto",
|
|
320
|
-
"if",
|
|
321
|
-
"implements",
|
|
322
|
-
"import",
|
|
323
|
-
"in",
|
|
324
|
-
"instanceof",
|
|
325
|
-
"int",
|
|
326
|
-
"interface",
|
|
327
|
-
"let",
|
|
328
|
-
"long",
|
|
329
|
-
"native",
|
|
330
|
-
"new",
|
|
331
|
-
"null",
|
|
332
|
-
"package",
|
|
333
|
-
"private",
|
|
334
|
-
"protected",
|
|
335
|
-
"public",
|
|
336
|
-
"return",
|
|
337
|
-
"short",
|
|
338
|
-
"static",
|
|
339
|
-
"super",
|
|
340
|
-
"switch",
|
|
341
|
-
"synchronized",
|
|
342
|
-
"this",
|
|
343
|
-
"throw",
|
|
344
|
-
"throws",
|
|
345
|
-
"transient",
|
|
346
|
-
"true",
|
|
347
|
-
"try",
|
|
348
|
-
"typeof",
|
|
349
|
-
"var",
|
|
350
|
-
"void",
|
|
351
|
-
"volatile",
|
|
352
|
-
"while",
|
|
353
|
-
"with",
|
|
354
|
-
"yield",
|
|
355
|
-
"Array",
|
|
356
|
-
"Date",
|
|
357
|
-
"hasOwnProperty",
|
|
358
|
-
"Infinity",
|
|
359
|
-
"isFinite",
|
|
360
|
-
"isNaN",
|
|
361
|
-
"isPrototypeOf",
|
|
362
|
-
"length",
|
|
363
|
-
"Math",
|
|
364
|
-
"name",
|
|
365
|
-
"NaN",
|
|
366
|
-
"Number",
|
|
367
|
-
"Object",
|
|
368
|
-
"prototype",
|
|
369
|
-
"String",
|
|
370
|
-
"toString",
|
|
371
|
-
"undefined",
|
|
372
|
-
"valueOf"
|
|
373
|
-
]);
|
|
374
|
-
/**
|
|
375
|
-
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
376
|
-
*
|
|
377
|
-
* @example
|
|
378
|
-
* ```ts
|
|
379
|
-
* isValidVarName('status') // true
|
|
380
|
-
* isValidVarName('class') // false (reserved word)
|
|
381
|
-
* isValidVarName('42foo') // false (starts with digit)
|
|
382
|
-
* ```
|
|
383
|
-
*/
|
|
384
|
-
function isValidVarName(name) {
|
|
385
|
-
if (!name || reservedWords.has(name)) return false;
|
|
386
|
-
return isIdentifier(name);
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
* Returns `name` when it's a syntactically valid JavaScript variable name,
|
|
390
|
-
* otherwise prefixes it with `_` so the result is a valid identifier.
|
|
391
|
-
*
|
|
392
|
-
* Useful for sanitizing OpenAPI schema names or operation IDs that start with
|
|
393
|
-
* a digit (e.g. `409`, `504AccountCancel`) before using them as exported
|
|
394
|
-
* variable, type, or function names.
|
|
395
|
-
*
|
|
396
|
-
* @example
|
|
397
|
-
* ```ts
|
|
398
|
-
* ensureValidVarName('409') // '_409'
|
|
399
|
-
* ensureValidVarName('504AccountCancel') // '_504AccountCancel'
|
|
400
|
-
* ensureValidVarName('Pet') // 'Pet'
|
|
401
|
-
* ensureValidVarName('class') // '_class'
|
|
402
|
-
* ```
|
|
403
|
-
*/
|
|
404
|
-
function ensureValidVarName(name) {
|
|
405
|
-
if (!name || isValidVarName(name)) return name;
|
|
406
|
-
return `_${name}`;
|
|
407
|
-
}
|
|
408
|
-
/**
|
|
409
|
-
* Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.
|
|
410
|
-
*
|
|
411
|
-
* Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys
|
|
412
|
-
* even though they are not valid variable names, so use this (not {@link isValidVarName}) when
|
|
413
|
-
* deciding whether an object key needs quoting.
|
|
414
|
-
*
|
|
415
|
-
* @example
|
|
416
|
-
* ```ts
|
|
417
|
-
* isIdentifier('name') // true
|
|
418
|
-
* isIdentifier('x-total')// false
|
|
419
|
-
* ```
|
|
420
|
-
*/
|
|
421
|
-
function isIdentifier(name) {
|
|
422
|
-
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
423
|
-
}
|
|
424
359
|
// ../../internals/shared/src/resolver.ts
|
|
425
360
|
/**
|
|
426
361
|
* The shared top-level `name` of the operation plugins, computed once per operation name and build.
|
|
427
362
|
*/
|
|
428
363
|
function resolveOperationName(name) {
|
|
429
|
-
return this.memo(`operation:${name}`, () => ensureValidVarName(
|
|
364
|
+
return this.memo(`operation:${name}`, () => ensureValidVarName(casing.camel(name)));
|
|
430
365
|
}
|
|
431
366
|
/**
|
|
432
367
|
* Builds the allocation key for a declaration an operation owns. `scope` names which declaration
|
|
433
368
|
* it is, so two of them never share an allocation even when a custom resolver gives both the same
|
|
434
369
|
* name. Leave `scope` empty for the operation's own declaration.
|
|
435
370
|
*
|
|
371
|
+
* The key starts from the operation's input `pointer`, which macros keep, so a plugin whose macro
|
|
372
|
+
* rewrites the method or path still resolves another plugin's names for the same operation.
|
|
373
|
+
*
|
|
436
374
|
* @example
|
|
437
375
|
* ```ts
|
|
438
376
|
* resolver.resolveName({ key: operationKey(node, 'response', 'status', 404), name })
|
|
@@ -441,41 +379,10 @@ function resolveOperationName(name) {
|
|
|
441
379
|
function operationKey(node, ...scope) {
|
|
442
380
|
return [
|
|
443
381
|
"operation",
|
|
444
|
-
node.method,
|
|
445
|
-
node.path,
|
|
382
|
+
...node.pointer ? [node.pointer] : [node.method, node.path],
|
|
446
383
|
...scope.map(String)
|
|
447
384
|
];
|
|
448
385
|
}
|
|
449
|
-
// ../../internals/shared/src/group.ts
|
|
450
|
-
/**
|
|
451
|
-
* Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
|
|
452
|
-
* shared default naming so every plugin groups output consistently:
|
|
453
|
-
*
|
|
454
|
-
* - `path` groups use the second path segment (`/pet/findByStatus` → `pet`).
|
|
455
|
-
* - other groups use the camelCased group (`pet store` → `petStore`).
|
|
456
|
-
*
|
|
457
|
-
* A user-provided `group.name` always wins over the default namer, so callers stay in
|
|
458
|
-
* control of their output folders. Returns `null` when grouping is disabled, matching the
|
|
459
|
-
* per-plugin convention.
|
|
460
|
-
*
|
|
461
|
-
* @param group - The user-supplied group option, or `undefined` to disable grouping.
|
|
462
|
-
*
|
|
463
|
-
* @example
|
|
464
|
-
* ```ts
|
|
465
|
-
* createGroupConfig(group) // shared across every plugin
|
|
466
|
-
* ```
|
|
467
|
-
*/
|
|
468
|
-
function createGroupConfig(group) {
|
|
469
|
-
if (!group) return null;
|
|
470
|
-
const defaultName = (ctx) => {
|
|
471
|
-
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
472
|
-
return camelCase(ctx.group);
|
|
473
|
-
};
|
|
474
|
-
return {
|
|
475
|
-
...group,
|
|
476
|
-
name: group.name ? group.name : defaultName
|
|
477
|
-
};
|
|
478
|
-
}
|
|
479
386
|
// src/components/Request.tsx
|
|
480
387
|
function Request({ baseURL = "", name, resolver, node }) {
|
|
481
388
|
const { signature, groups } = buildRequestParamsSignature(node, resolver, { isConfigurable: false });
|
|
@@ -483,13 +390,45 @@ function Request({ baseURL = "", name, resolver, node }) {
|
|
|
483
390
|
const responseType = resolver.response.response(node);
|
|
484
391
|
const returnType = `Cypress.Chainable<${responseType}>`;
|
|
485
392
|
const urlTemplate = Url.toGroupedTemplateString(node.path, { prefix: baseURL });
|
|
486
|
-
const
|
|
393
|
+
const cookieText = "value instanceof Date ? value.toISOString() : Array.isArray(value) ? value.join(',') : typeof value === 'object' ? JSON.stringify(value) : String(value)";
|
|
394
|
+
const rawParameters = node.parameters.filter((parameter) => parameter.in === "cookie" && parameter.style === "cookie");
|
|
395
|
+
const isComposite = (parameter) => ![
|
|
396
|
+
"string",
|
|
397
|
+
"number",
|
|
398
|
+
"integer",
|
|
399
|
+
"bigint",
|
|
400
|
+
"boolean"
|
|
401
|
+
].includes(ast.ref.getSchema(parameter.schema).primitive ?? "");
|
|
402
|
+
const isExploded = (parameter) => parameter.explode !== false && isComposite(parameter);
|
|
403
|
+
const explodedCookies = rawParameters.filter(isExploded).map((parameter) => text.quote(parameter.name));
|
|
404
|
+
const joinedCookies = rawParameters.filter((parameter) => !isExploded(parameter)).map((parameter) => text.quote(parameter.name));
|
|
405
|
+
const explodedFormCookies = node.parameters.filter((parameter) => parameter.in === "cookie" && parameter.style !== "cookie" && parameter.explode === true && isComposite(parameter)).map((parameter) => text.quote(parameter.name));
|
|
406
|
+
const compositeLines = rawParameters.some(isComposite) ? ` if (Array.isArray(value)) return value.filter((item) => item != null).map(rawCookie).join(',')
|
|
407
|
+
if (typeof value === 'object' && value !== null && !(value instanceof Date)) return Object.entries(value).filter(([, item]) => item != null).flat().map(rawCookie).join(',')\n` : "";
|
|
408
|
+
const explodeCookieLine = explodedCookies.length || explodedFormCookies.length ? `const explodeCookie = (name: string, value: unknown, encode: (item: unknown) => string): Array<string> => {
|
|
409
|
+
if (Array.isArray(value)) return value.filter((item) => item != null).map((item) => \`\${name}=\${encode(item)}\`)
|
|
410
|
+
if (typeof value === 'object' && value !== null && !(value instanceof Date)) return Object.entries(value).filter(([, item]) => item != null).map(([key, item]) => \`\${encode(key)}=\${encode(item)}\`)
|
|
411
|
+
return [\`\${name}=\${encode(value)}\`]
|
|
412
|
+
}\n` : "";
|
|
413
|
+
const formCookieLine = explodedFormCookies.length ? "const formCookie = (item: unknown): string => encodeURIComponent(item instanceof Date ? item.toISOString() : String(item))\n" : "";
|
|
414
|
+
const rawCookieLine = rawParameters.length ? `const rawCookie = (value: unknown): string => {
|
|
415
|
+
${compositeLines} const text = value instanceof Date ? value.toISOString() : String(value)
|
|
416
|
+
if (!/^[\\x21\\x23-\\x2B\\x2D-\\x3A\\x3C-\\x5B\\x5D-\\x7E]*$/.test(text)) throw new TypeError('A cookie has characters the cookie style cannot send, escape it first.')
|
|
417
|
+
return text
|
|
418
|
+
}\n` : "";
|
|
419
|
+
const encodeCookie = joinedCookies.length ? `([${joinedCookies.join(", ")}].includes(name) ? rawCookie(value) : encodeURIComponent(${cookieText}))` : `encodeURIComponent(${cookieText})`;
|
|
420
|
+
const explodeRaw = explodedCookies.length ? `[${explodedCookies.join(", ")}].includes(name) ? explodeCookie(name, value, rawCookie) : ` : "";
|
|
421
|
+
const explodeForm = explodedFormCookies.length ? `[${explodedFormCookies.join(", ")}].includes(name) ? explodeCookie(name, value, formCookie) : ` : "";
|
|
422
|
+
const cookieLine = `${rawCookieLine}${explodeCookieLine}${formCookieLine}const cookie = (Object.entries(cookies ?? {}) as Array<[string, unknown]>).filter(([, value]) => value != null)${explodeRaw || explodeForm ? `.flatMap(([name, value]) => (${explodeRaw}${explodeForm}[\`\${name}=\${${encodeCookie}}\`]))` : `.map(([name, value]) => \`\${name}=\${${encodeCookie}}\`)`}.join('; ')\n`;
|
|
423
|
+
const requestSchema = ast.http.requestBody.getSchema(node);
|
|
424
|
+
const bodySchema = requestSchema && ast.ref.getSchema(requestSchema);
|
|
425
|
+
const castBody = bodySchema && (["number", "integer"].includes(bodySchema.primitive ?? "") || ["unknown", "any"].includes(bodySchema.type));
|
|
487
426
|
const requestOptions = [
|
|
488
|
-
`method:
|
|
427
|
+
`method: ${text.quote(node.method)}`,
|
|
489
428
|
`url: ${urlTemplate}`,
|
|
490
429
|
groups.query && "qs: query",
|
|
491
430
|
groups.cookies ? `headers: { ${groups.headers ? "...headers, " : ""}...(cookie ? { Cookie: cookie } : {}) }` : groups.headers && "headers",
|
|
492
|
-
groups.body && "body",
|
|
431
|
+
groups.body && (castBody ? "body: body as unknown as Cypress.RequestBody" : "body"),
|
|
493
432
|
"...options"
|
|
494
433
|
].filter(Boolean);
|
|
495
434
|
const requestCall = `${groups.cookies ? cookieLine : ""}return cy.request<${responseType}>({
|
|
@@ -518,7 +457,7 @@ const cypressGenerator = defineGenerator({
|
|
|
518
457
|
name: "cypress",
|
|
519
458
|
renderer: jsxRenderer,
|
|
520
459
|
operation(node, ctx) {
|
|
521
|
-
if (!ast.
|
|
460
|
+
if (!ast.http.isOperation(node)) return null;
|
|
522
461
|
const { config, resolver, driver, root } = ctx;
|
|
523
462
|
const { output, baseURL, group } = ctx.options;
|
|
524
463
|
const pluginTs = ctx.requirePlugin(pluginTsName);
|
|
@@ -584,11 +523,11 @@ const cypressGenerator = defineGenerator({
|
|
|
584
523
|
});
|
|
585
524
|
// kubb-extension.json
|
|
586
525
|
var compatibility = {
|
|
587
|
-
"kubb": ">=5.
|
|
526
|
+
"kubb": ">=5.18.4",
|
|
588
527
|
"node": ">=22.22"
|
|
589
528
|
};
|
|
590
529
|
// package.json
|
|
591
|
-
var version = "5.3.0
|
|
530
|
+
var version = "5.3.0";
|
|
592
531
|
// src/resolvers/resolverCypress.ts
|
|
593
532
|
/**
|
|
594
533
|
* Default resolver used by `@kubb/plugin-cypress`. Decides the names and file
|
|
@@ -657,7 +596,7 @@ const pluginCypress = defineExtension({
|
|
|
657
596
|
exclude,
|
|
658
597
|
include,
|
|
659
598
|
override,
|
|
660
|
-
group:
|
|
599
|
+
group: group ?? null,
|
|
661
600
|
baseURL
|
|
662
601
|
};
|
|
663
602
|
}
|