@kubb/plugin-fetch 5.0.0-beta.79 → 5.0.0-beta.80
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 +34 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -456,6 +456,37 @@ function getResponseType(node) {
|
|
|
456
456
|
if (baseType.startsWith("text/")) return "text";
|
|
457
457
|
if (baseType === "application/octet-stream" || baseType === "application/pdf" || /^(image|audio|video)\//.test(baseType)) return "blob";
|
|
458
458
|
}
|
|
459
|
+
/**
|
|
460
|
+
* Which of the grouped request options an operation carries.
|
|
461
|
+
*/
|
|
462
|
+
function getRequestGroups(node) {
|
|
463
|
+
const { path, query, header } = getOperationParameters(node);
|
|
464
|
+
return {
|
|
465
|
+
path: path.length > 0,
|
|
466
|
+
query: query.length > 0,
|
|
467
|
+
body: Boolean(node.requestBody?.content?.[0]?.schema),
|
|
468
|
+
headers: header.length > 0
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Resolves which grouped request options an operation carries together with whether each group
|
|
473
|
+
* holds a required member. The grouped parameter stays optional only when nothing inside it is
|
|
474
|
+
* required, matching the generated `RequestConfig` type.
|
|
475
|
+
*/
|
|
476
|
+
function getRequestGroupOptionality(node) {
|
|
477
|
+
const groups = getRequestGroups(node);
|
|
478
|
+
const { path, query, header } = getOperationParameters(node);
|
|
479
|
+
const hasRequiredPath = path.some((param) => param.required);
|
|
480
|
+
const hasRequiredQuery = query.some((param) => param.required);
|
|
481
|
+
const hasRequiredHeader = header.some((param) => param.required);
|
|
482
|
+
return {
|
|
483
|
+
groups,
|
|
484
|
+
hasRequiredPath,
|
|
485
|
+
hasRequiredQuery,
|
|
486
|
+
hasRequiredHeader,
|
|
487
|
+
isOptional: !hasRequiredPath && !hasRequiredQuery && !hasRequiredHeader && !groups.body
|
|
488
|
+
};
|
|
489
|
+
}
|
|
459
490
|
function buildOperationComments(node, options = {}) {
|
|
460
491
|
const { link = "pathTemplate", linkPosition = "afterDeprecated", splitLines = false } = options;
|
|
461
492
|
const linkComment = getOperationLink(node, link);
|
|
@@ -705,11 +736,13 @@ function buildGroupedOptionsSignature({ node, tsResolver }) {
|
|
|
705
736
|
node,
|
|
706
737
|
tsResolver
|
|
707
738
|
});
|
|
739
|
+
const { isOptional } = getRequestGroupOptionality(node);
|
|
708
740
|
return {
|
|
709
741
|
dataTypeName: requestConfigName,
|
|
710
742
|
paramsSignature: declarationPrinter.print((0, _kubb_plugin_ts.createFunctionParameters)({ params: [(0, _kubb_plugin_ts.createFunctionParameter)({
|
|
711
743
|
name: "options",
|
|
712
|
-
type: `Options<${requestConfigName}, ThrowOnError
|
|
744
|
+
type: `Options<${requestConfigName}, ThrowOnError>`,
|
|
745
|
+
...isOptional ? { default: "{}" } : {}
|
|
713
746
|
})] })) ?? "",
|
|
714
747
|
returnType: `Promise<RequestResult<${resultGenerics}>>`,
|
|
715
748
|
generics: ["ThrowOnError extends boolean = true"],
|