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