@kubb/plugin-fetch 5.5.5 → 5.5.7
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 +25 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +25 -5
- package/dist/index.js.map +1 -1
- package/package.json +6 -9
package/dist/index.cjs
CHANGED
|
@@ -464,6 +464,27 @@ function createGroupConfig(group) {
|
|
|
464
464
|
};
|
|
465
465
|
}
|
|
466
466
|
//#endregion
|
|
467
|
+
//#region ../../internals/client/src/builders/contentType.ts
|
|
468
|
+
/**
|
|
469
|
+
* Builds the `contentType` entry baked into the call config, or `null` for the JSON default.
|
|
470
|
+
*
|
|
471
|
+
* `merge` is `true` when the generated function must destructure `contentType` from `options` and
|
|
472
|
+
* merge it over the baked request default, because the caller can also pick a response content type.
|
|
473
|
+
*/
|
|
474
|
+
function buildContentType({ node }) {
|
|
475
|
+
const { defaultContentType } = getContentTypeInfo(node);
|
|
476
|
+
const requestContentType = Boolean(node.requestBody?.content?.[0]?.schema) && defaultContentType !== "application/json" ? defaultContentType : null;
|
|
477
|
+
if (!requestContentType) return {
|
|
478
|
+
literal: null,
|
|
479
|
+
merge: false
|
|
480
|
+
};
|
|
481
|
+
const merge = getResponseContentTypeInfo(node).isMultipleContentTypes;
|
|
482
|
+
return {
|
|
483
|
+
merge,
|
|
484
|
+
literal: merge ? `contentType: { request: '${requestContentType}', ...(typeof contentType === 'string' ? { request: contentType } : contentType) }` : `contentType: { request: '${requestContentType}' }`
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
//#endregion
|
|
467
488
|
//#region ../../internals/client/src/builders/generics.ts
|
|
468
489
|
/**
|
|
469
490
|
* Builds the `RequestResult` generic arguments for one operation: the per-status responses record
|
|
@@ -734,11 +755,13 @@ function buildCallConfig({ node, validator, zodResolver, security, throwOnErrorD
|
|
|
734
755
|
const validatorEntries = [validators.request ? `request: ${validators.request}` : null, validators.response ? `response: ${validators.response}` : null].filter(Boolean);
|
|
735
756
|
const validatorLiteral = validatorEntries.length ? `validator: { ${validatorEntries.join(", ")} }` : null;
|
|
736
757
|
const securityLiteral = buildSecurityMetadata({ security });
|
|
758
|
+
const { literal: contentTypeLiteral } = buildContentType({ node });
|
|
737
759
|
return `{ ${[
|
|
738
760
|
`method: '${node.method.toUpperCase()}'`,
|
|
739
761
|
`url: '${node.path}'`,
|
|
740
762
|
securityLiteral ? `security: ${securityLiteral}` : null,
|
|
741
763
|
validatorLiteral,
|
|
764
|
+
contentTypeLiteral,
|
|
742
765
|
"...config",
|
|
743
766
|
`throwOnError: config.throwOnError ?? ${throwOnErrorDefault}`
|
|
744
767
|
].filter(Boolean).join(", ")} }`;
|
|
@@ -778,7 +801,7 @@ function buildSdkMethod({ node, name, types, zodResolver, validator, security, r
|
|
|
778
801
|
splitLines: true
|
|
779
802
|
}));
|
|
780
803
|
const methodBody = [
|
|
781
|
-
"const { client: request = this.client, ...config } = options",
|
|
804
|
+
buildContentType({ node }).merge ? "const { client: request = this.client, contentType, ...config } = options" : "const { client: request = this.client, ...config } = options",
|
|
782
805
|
"",
|
|
783
806
|
returnStatement
|
|
784
807
|
].map((line) => line ? ` ${line}` : "").join("\n");
|
|
@@ -860,10 +883,7 @@ function Operation({ name, node, types, zodResolver, validator, returnType, thro
|
|
|
860
883
|
});
|
|
861
884
|
const securityLiteral = buildSecurityMetadata({ security });
|
|
862
885
|
const stylesLiteral = buildStyles({ node });
|
|
863
|
-
const {
|
|
864
|
-
const bakedRequestContentType = Boolean(node.requestBody?.content?.[0]?.schema) && defaultContentType !== "application/json" ? defaultContentType : null;
|
|
865
|
-
const mergeContentType = Boolean(bakedRequestContentType) && getResponseContentTypeInfo(node).isMultipleContentTypes;
|
|
866
|
-
const contentTypeLiteral = !bakedRequestContentType ? null : mergeContentType ? `contentType: { request: '${bakedRequestContentType}', ...(typeof contentType === 'string' ? { request: contentType } : contentType) }` : `contentType: { request: '${bakedRequestContentType}' }`;
|
|
886
|
+
const { literal: contentTypeLiteral, merge: mergeContentType } = buildContentType({ node });
|
|
867
887
|
const eventStream = isEventStream(node);
|
|
868
888
|
const responseType = getResponseType(node);
|
|
869
889
|
const responseTypeLiteral = responseType ? `responseType: '${responseType}'` : null;
|