@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.js CHANGED
@@ -430,6 +430,37 @@ function getResponseType(node) {
430
430
  if (baseType.startsWith("text/")) return "text";
431
431
  if (baseType === "application/octet-stream" || baseType === "application/pdf" || /^(image|audio|video)\//.test(baseType)) return "blob";
432
432
  }
433
+ /**
434
+ * Which of the grouped request options an operation carries.
435
+ */
436
+ function getRequestGroups(node) {
437
+ const { path, query, header } = getOperationParameters(node);
438
+ return {
439
+ path: path.length > 0,
440
+ query: query.length > 0,
441
+ body: Boolean(node.requestBody?.content?.[0]?.schema),
442
+ headers: header.length > 0
443
+ };
444
+ }
445
+ /**
446
+ * Resolves which grouped request options an operation carries together with whether each group
447
+ * holds a required member. The grouped parameter stays optional only when nothing inside it is
448
+ * required, matching the generated `RequestConfig` type.
449
+ */
450
+ function getRequestGroupOptionality(node) {
451
+ const groups = getRequestGroups(node);
452
+ const { path, query, header } = getOperationParameters(node);
453
+ const hasRequiredPath = path.some((param) => param.required);
454
+ const hasRequiredQuery = query.some((param) => param.required);
455
+ const hasRequiredHeader = header.some((param) => param.required);
456
+ return {
457
+ groups,
458
+ hasRequiredPath,
459
+ hasRequiredQuery,
460
+ hasRequiredHeader,
461
+ isOptional: !hasRequiredPath && !hasRequiredQuery && !hasRequiredHeader && !groups.body
462
+ };
463
+ }
433
464
  function buildOperationComments(node, options = {}) {
434
465
  const { link = "pathTemplate", linkPosition = "afterDeprecated", splitLines = false } = options;
435
466
  const linkComment = getOperationLink(node, link);
@@ -679,11 +710,13 @@ function buildGroupedOptionsSignature({ node, tsResolver }) {
679
710
  node,
680
711
  tsResolver
681
712
  });
713
+ const { isOptional } = getRequestGroupOptionality(node);
682
714
  return {
683
715
  dataTypeName: requestConfigName,
684
716
  paramsSignature: declarationPrinter.print(createFunctionParameters({ params: [createFunctionParameter({
685
717
  name: "options",
686
- type: `Options<${requestConfigName}, ThrowOnError>`
718
+ type: `Options<${requestConfigName}, ThrowOnError>`,
719
+ ...isOptional ? { default: "{}" } : {}
687
720
  })] })) ?? "",
688
721
  returnType: `Promise<RequestResult<${resultGenerics}>>`,
689
722
  generics: ["ThrowOnError extends boolean = true"],