@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.d.ts
CHANGED
|
@@ -74,7 +74,8 @@ type Options = OutputOptions & {
|
|
|
74
74
|
*/
|
|
75
75
|
override?: Array<Override<Omit<ResolvedOptions, 'throwOnErrorDefault'>>>;
|
|
76
76
|
/**
|
|
77
|
-
* Base URL prepended to every request. When omitted,
|
|
77
|
+
* Base URL prepended to every request. When omitted, the generated client sets no base URL, so
|
|
78
|
+
* set one at runtime with `client.setConfig({ baseURL })`. The adapter's server URL is not used.
|
|
78
79
|
* Values containing a `${...}` interpolation are emitted as template literals in the generated
|
|
79
80
|
* client config, which keeps runtime environment reads dynamic.
|
|
80
81
|
*/
|
package/dist/index.js
CHANGED
|
@@ -438,6 +438,27 @@ function createGroupConfig(group) {
|
|
|
438
438
|
};
|
|
439
439
|
}
|
|
440
440
|
//#endregion
|
|
441
|
+
//#region ../../internals/client/src/builders/contentType.ts
|
|
442
|
+
/**
|
|
443
|
+
* Builds the `contentType` entry baked into the call config, or `null` for the JSON default.
|
|
444
|
+
*
|
|
445
|
+
* `merge` is `true` when the generated function must destructure `contentType` from `options` and
|
|
446
|
+
* merge it over the baked request default, because the caller can also pick a response content type.
|
|
447
|
+
*/
|
|
448
|
+
function buildContentType({ node }) {
|
|
449
|
+
const { defaultContentType } = getContentTypeInfo(node);
|
|
450
|
+
const requestContentType = Boolean(node.requestBody?.content?.[0]?.schema) && defaultContentType !== "application/json" ? defaultContentType : null;
|
|
451
|
+
if (!requestContentType) return {
|
|
452
|
+
literal: null,
|
|
453
|
+
merge: false
|
|
454
|
+
};
|
|
455
|
+
const merge = getResponseContentTypeInfo(node).isMultipleContentTypes;
|
|
456
|
+
return {
|
|
457
|
+
merge,
|
|
458
|
+
literal: merge ? `contentType: { request: '${requestContentType}', ...(typeof contentType === 'string' ? { request: contentType } : contentType) }` : `contentType: { request: '${requestContentType}' }`
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
//#endregion
|
|
441
462
|
//#region ../../internals/client/src/builders/generics.ts
|
|
442
463
|
/**
|
|
443
464
|
* Builds the `RequestResult` generic arguments for one operation: the per-status responses record
|
|
@@ -708,11 +729,13 @@ function buildCallConfig({ node, validator, zodResolver, security, throwOnErrorD
|
|
|
708
729
|
const validatorEntries = [validators.request ? `request: ${validators.request}` : null, validators.response ? `response: ${validators.response}` : null].filter(Boolean);
|
|
709
730
|
const validatorLiteral = validatorEntries.length ? `validator: { ${validatorEntries.join(", ")} }` : null;
|
|
710
731
|
const securityLiteral = buildSecurityMetadata({ security });
|
|
732
|
+
const { literal: contentTypeLiteral } = buildContentType({ node });
|
|
711
733
|
return `{ ${[
|
|
712
734
|
`method: '${node.method.toUpperCase()}'`,
|
|
713
735
|
`url: '${node.path}'`,
|
|
714
736
|
securityLiteral ? `security: ${securityLiteral}` : null,
|
|
715
737
|
validatorLiteral,
|
|
738
|
+
contentTypeLiteral,
|
|
716
739
|
"...config",
|
|
717
740
|
`throwOnError: config.throwOnError ?? ${throwOnErrorDefault}`
|
|
718
741
|
].filter(Boolean).join(", ")} }`;
|
|
@@ -752,7 +775,7 @@ function buildSdkMethod({ node, name, types, zodResolver, validator, security, r
|
|
|
752
775
|
splitLines: true
|
|
753
776
|
}));
|
|
754
777
|
const methodBody = [
|
|
755
|
-
"const { client: request = this.client, ...config } = options",
|
|
778
|
+
buildContentType({ node }).merge ? "const { client: request = this.client, contentType, ...config } = options" : "const { client: request = this.client, ...config } = options",
|
|
756
779
|
"",
|
|
757
780
|
returnStatement
|
|
758
781
|
].map((line) => line ? ` ${line}` : "").join("\n");
|
|
@@ -834,10 +857,7 @@ function Operation({ name, node, types, zodResolver, validator, returnType, thro
|
|
|
834
857
|
});
|
|
835
858
|
const securityLiteral = buildSecurityMetadata({ security });
|
|
836
859
|
const stylesLiteral = buildStyles({ node });
|
|
837
|
-
const {
|
|
838
|
-
const bakedRequestContentType = Boolean(node.requestBody?.content?.[0]?.schema) && defaultContentType !== "application/json" ? defaultContentType : null;
|
|
839
|
-
const mergeContentType = Boolean(bakedRequestContentType) && getResponseContentTypeInfo(node).isMultipleContentTypes;
|
|
840
|
-
const contentTypeLiteral = !bakedRequestContentType ? null : mergeContentType ? `contentType: { request: '${bakedRequestContentType}', ...(typeof contentType === 'string' ? { request: contentType } : contentType) }` : `contentType: { request: '${bakedRequestContentType}' }`;
|
|
860
|
+
const { literal: contentTypeLiteral, merge: mergeContentType } = buildContentType({ node });
|
|
841
861
|
const eventStream = isEventStream(node);
|
|
842
862
|
const responseType = getResponseType(node);
|
|
843
863
|
const responseTypeLiteral = responseType ? `responseType: '${responseType}'` : null;
|