@kubb/plugin-fetch 5.0.0-beta.86 → 5.0.0-beta.87
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 +26 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +26 -12
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -145,7 +145,7 @@ const reservedWords = /* @__PURE__ */ new Set([
|
|
|
145
145
|
*/
|
|
146
146
|
function isValidVarName(name) {
|
|
147
147
|
if (!name || reservedWords.has(name)) return false;
|
|
148
|
-
return
|
|
148
|
+
return isIdentifier(name);
|
|
149
149
|
}
|
|
150
150
|
/**
|
|
151
151
|
* Returns `name` when it's a syntactically valid JavaScript variable name,
|
|
@@ -167,6 +167,22 @@ function ensureValidVarName(name) {
|
|
|
167
167
|
if (!name || isValidVarName(name)) return name;
|
|
168
168
|
return `_${name}`;
|
|
169
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.
|
|
172
|
+
*
|
|
173
|
+
* Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys
|
|
174
|
+
* even though they are not valid variable names, so use this (not {@link isValidVarName}) when
|
|
175
|
+
* deciding whether an object key needs quoting.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* isIdentifier('name') // true
|
|
180
|
+
* isIdentifier('x-total')// false
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
function isIdentifier(name) {
|
|
184
|
+
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
185
|
+
}
|
|
170
186
|
//#endregion
|
|
171
187
|
//#region ../../internals/utils/src/codegen.ts
|
|
172
188
|
/**
|
|
@@ -388,8 +404,11 @@ function getOperationLink(node, link) {
|
|
|
388
404
|
if (link === "urlPath") return node.path ? `{@link ${Url.toPath(node.path)}}` : null;
|
|
389
405
|
return node.path ? `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}` : null;
|
|
390
406
|
}
|
|
391
|
-
|
|
392
|
-
|
|
407
|
+
/**
|
|
408
|
+
* Derives the shared `ContentTypeInfo` shape from a list of content types, tracking whether several
|
|
409
|
+
* are present and the union, default, and form-data flags the client uses to pick one.
|
|
410
|
+
*/
|
|
411
|
+
function buildContentTypeInfo(contentTypes) {
|
|
393
412
|
const isMultipleContentTypes = contentTypes.length > 1;
|
|
394
413
|
return {
|
|
395
414
|
contentTypes,
|
|
@@ -399,20 +418,15 @@ function getContentTypeInfo(node) {
|
|
|
399
418
|
hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
|
|
400
419
|
};
|
|
401
420
|
}
|
|
421
|
+
function getContentTypeInfo(node) {
|
|
422
|
+
return buildContentTypeInfo(node.requestBody?.content?.map((e) => e.contentType) ?? []);
|
|
423
|
+
}
|
|
402
424
|
/**
|
|
403
425
|
* The request-body counterpart for the primary success response: the content types it documents and
|
|
404
426
|
* whether several are present, so the client can let a caller pick which one to accept.
|
|
405
427
|
*/
|
|
406
428
|
function getResponseContentTypeInfo(node) {
|
|
407
|
-
|
|
408
|
-
const isMultipleContentTypes = contentTypes.length > 1;
|
|
409
|
-
return {
|
|
410
|
-
contentTypes,
|
|
411
|
-
isMultipleContentTypes,
|
|
412
|
-
contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(" | ") : "",
|
|
413
|
-
defaultContentType: contentTypes[0] ?? "application/json",
|
|
414
|
-
hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
|
|
415
|
-
};
|
|
429
|
+
return buildContentTypeInfo(getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? []);
|
|
416
430
|
}
|
|
417
431
|
/**
|
|
418
432
|
* Reads the single base content type of an operation's primary success response, lowercased and
|