Skip to content

Commit fef1f75

Browse files
authored
Merge pull request #1649 from hey-api/fix/client-nuxt-body
fix: handle reactive refs in Nuxt client body
2 parents b767e10 + 603541e commit fef1f75

File tree

20 files changed

+1576
-2326
lines changed

20 files changed

+1576
-2326
lines changed

.changeset/light-fans-vanish.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/client-nuxt': patch
3+
---
4+
5+
fix: do not run validator and transformer when response is not ok

.changeset/metal-flowers-fix.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@hey-api/client-axios': patch
3+
'@hey-api/client-fetch': patch
4+
'@hey-api/client-nuxt': patch
5+
---
6+
7+
fix: handle BigInt in JSON body serializer

.changeset/tough-islands-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/client-nuxt': patch
3+
---
4+
5+
fix: handle reactive refs in Nuxt client body

examples/openapi-ts-axios/src/client/sdk.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import type {
4242
UploadFileResponse,
4343
} from './types.gen';
4444

45-
type Options<
45+
export type Options<
4646
TData extends TDataShape = TDataShape,
4747
ThrowOnError extends boolean = boolean,
4848
> = ClientOptions<TData, ThrowOnError> & {

examples/openapi-ts-fastify/src/client/sdk.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type {
1818
ShowPetByIdResponse,
1919
} from './types.gen';
2020

21-
type Options<
21+
export type Options<
2222
TData extends TDataShape = TDataShape,
2323
ThrowOnError extends boolean = boolean,
2424
> = ClientOptions<TData, ThrowOnError> & {

examples/openapi-ts-fetch/src/client/sdk.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import type {
4242
UploadFileResponse,
4343
} from './types.gen';
4444

45-
type Options<
45+
export type Options<
4646
TData extends TDataShape = TDataShape,
4747
ThrowOnError extends boolean = boolean,
4848
> = ClientOptions<TData, ThrowOnError> & {

examples/openapi-ts-next/src/client/sdk.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import type {
4242
UploadFileResponse,
4343
} from './types.gen';
4444

45-
type Options<
45+
export type Options<
4646
TData extends TDataShape = TDataShape,
4747
ThrowOnError extends boolean = boolean,
4848
> = ClientOptions<TData, ThrowOnError> & {

examples/openapi-ts-nuxt/client/sdk.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ import {
6969
zUploadFileResponse,
7070
} from './zod.gen';
7171

72-
type Options<
72+
export type Options<
7373
TComposable extends Composable,
7474
TData extends TDataShape = TDataShape,
7575
> = ClientOptions<TComposable, TData> & {

examples/openapi-ts-nuxt/components/home.vue

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<script setup lang="ts">
22
import {
3+
addPet,
34
findPetsByStatus,
45
getPetById,
56
type FindPetsByStatusData,
67
} from '~/client';
78
9+
const name = ref('foo');
810
const petId = ref(BigInt(8));
911
const status =
1012
ref<NonNullable<FindPetsByStatusData['query']>['status']>('available');
@@ -13,6 +15,10 @@ function incrementPetId() {
1315
petId.value++;
1416
}
1517
18+
function addNewPet() {
19+
name.value = name.value === 'foo' ? 'bar' : 'foo';
20+
}
21+
1622
function changeStatus() {
1723
status.value = status.value === 'available' ? 'pending' : 'available';
1824
}
@@ -79,6 +85,30 @@ const fetch = await getPetById({
7985
},
8086
});
8187
88+
await addPet({
89+
asyncDataOptions: {
90+
watch: [name],
91+
},
92+
body: {
93+
category: {
94+
id: BigInt(0),
95+
name: 'Cats',
96+
},
97+
id: BigInt(0),
98+
name,
99+
photoUrls: ['string'],
100+
status: 'available',
101+
tags: [
102+
{
103+
id: BigInt(0),
104+
name: 'pet',
105+
},
106+
],
107+
},
108+
composable: 'useAsyncData',
109+
key: 'addPet',
110+
});
111+
82112
/**
83113
* useLazyAsyncData
84114
*
@@ -121,23 +151,27 @@ watch(lazyFetch.data, (newPet) => {
121151
});
122152
123153
async function handleFetch() {
124-
const result = await getPetById({
125-
composable: '$fetch',
126-
onRequest: [
127-
() => {
128-
console.log('onRequest: local');
129-
},
130-
],
131-
onResponse: [
132-
() => {
133-
console.log('onResponse: local');
154+
try {
155+
const result = await getPetById({
156+
composable: '$fetch',
157+
onRequest: [
158+
() => {
159+
console.log('onRequest: local');
160+
},
161+
],
162+
onResponse: [
163+
() => {
164+
console.log('onResponse: local');
165+
},
166+
],
167+
path: {
168+
petId,
134169
},
135-
],
136-
path: {
137-
petId,
138-
},
139-
});
140-
console.log(result);
170+
});
171+
console.log(result);
172+
} catch (error) {
173+
console.log(error);
174+
}
141175
}
142176
</script>
143177

@@ -147,5 +181,11 @@ async function handleFetch() {
147181
<button @click="handleFetch" type="button">$fetch</button>
148182
<button @click="incrementPetId" type="button">increment petId</button>
149183
<button @click="changeStatus" type="button">change status</button>
184+
<button @click="addNewPet" type="button">add pet</button>
185+
<div>
186+
<p>id: {{ petId }}</p>
187+
<p>name: {{ name }}</p>
188+
<p>status: {{ status }}</p>
189+
</div>
150190
</div>
151191
</template>

examples/openapi-ts-nuxt/nuxt.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,11 @@ export default defineNuxtConfig({
44
devtools: {
55
enabled: true,
66
},
7+
imports: {
8+
transform: {
9+
// Build was throwing an error.
10+
// see https://github.com/nuxt/nuxt/issues/18823#issuecomment-1419704343
11+
exclude: [/\bclient-nuxt\b/],
12+
},
13+
},
714
});

examples/openapi-ts-nuxt/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"zod": "3.23.8"
2121
},
2222
"devDependencies": {
23-
"@hey-api/openapi-ts": "workspace:*"
23+
"@hey-api/openapi-ts": "workspace:*",
24+
"vite": "6.0.9"
2425
}
2526
}

packages/client-core/src/bodySerializer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ export const formDataBodySerializer = {
5656
};
5757

5858
export const jsonBodySerializer = {
59-
bodySerializer: <T>(body: T) => JSON.stringify(body),
59+
bodySerializer: <T>(body: T) =>
60+
JSON.stringify(body, (key, value) =>
61+
typeof value === 'bigint' ? value.toString() : value,
62+
),
6063
};
6164

6265
export const urlSearchParamsBodySerializer = {

packages/client-nuxt/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
},
7171
"devDependencies": {
7272
"@hey-api/client-core": "workspace:*",
73-
"@nuxt/test-utils": "3.15.1"
73+
"@nuxt/test-utils": "3.15.1",
74+
"vite": "6.0.9"
7475
}
7576
}

packages/client-nuxt/src/client.ts

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ import {
55
useLazyAsyncData,
66
useLazyFetch,
77
} from 'nuxt/app';
8+
import { reactive, ref, watch } from 'vue';
89

910
import type { Client, Config } from './types';
1011
import {
1112
buildUrl,
1213
createConfig,
14+
executeFetchFn,
1315
mergeConfigs,
1416
mergeHeaders,
1517
mergeInterceptors,
18+
serializeBody,
1619
setAuthParams,
17-
unwrapRefs,
1820
} from './utils';
1921

2022
export const createClient = (config: Config = {}): Client => {
@@ -68,6 +70,10 @@ export const createClient = (config: Config = {}): Client => {
6870
return;
6971
}
7072

73+
if (!response.ok) {
74+
return;
75+
}
76+
7177
if (responseValidator) {
7278
await responseValidator(response._data);
7379
}
@@ -79,10 +85,6 @@ export const createClient = (config: Config = {}): Client => {
7985
];
8086
}
8187

82-
if (opts.body && opts.bodySerializer) {
83-
opts.body = opts.bodySerializer(unwrapRefs(opts.body));
84-
}
85-
8688
// remove Content-Type header if body is empty to avoid sending invalid requests
8789
if (!opts.body) {
8890
opts.headers.delete('Content-Type');
@@ -91,32 +93,26 @@ export const createClient = (config: Config = {}): Client => {
9193
const fetchFn = opts.$fetch;
9294

9395
if (composable === '$fetch') {
94-
const url = buildUrl(opts);
95-
return fetchFn(
96-
url,
97-
// @ts-expect-error
98-
unwrapRefs(opts),
99-
);
100-
}
101-
102-
if (composable === 'useFetch') {
103-
const url = buildUrl(opts);
104-
return useFetch(url, opts);
96+
return executeFetchFn(opts, fetchFn);
10597
}
10698

107-
if (composable === 'useLazyFetch') {
108-
const url = buildUrl(opts);
109-
return useLazyFetch(url, opts);
99+
if (composable === 'useFetch' || composable === 'useLazyFetch') {
100+
const bodyParams = reactive({
101+
body: opts.body,
102+
bodySerializer: opts.bodySerializer,
103+
});
104+
const body = ref(serializeBody(opts));
105+
opts.body = body;
106+
watch(bodyParams, (changed) => {
107+
body.value = serializeBody(changed);
108+
});
109+
return composable === 'useLazyFetch'
110+
? useLazyFetch(() => buildUrl(opts), opts)
111+
: useFetch(() => buildUrl(opts), opts);
110112
}
111113

112-
const handler: (ctx?: NuxtApp) => Promise<any> = () => {
113-
const url = buildUrl(opts);
114-
return fetchFn(
115-
url,
116-
// @ts-expect-error
117-
unwrapRefs(opts),
118-
);
119-
};
114+
const handler: (ctx?: NuxtApp) => Promise<unknown> = () =>
115+
executeFetchFn(opts, fetchFn);
120116

121117
if (composable === 'useAsyncData') {
122118
return key

packages/client-nuxt/src/utils.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ type UnwrapRefs<T> =
319319
? { [K in keyof T]: UnwrapRefs<T[K]> }
320320
: T;
321321

322-
export const unwrapRefs = <T>(value: T): UnwrapRefs<T> => {
322+
const unwrapRefs = <T>(value: T): UnwrapRefs<T> => {
323323
if (value === null || typeof value !== 'object' || value instanceof Headers) {
324324
return (isRef(value) ? unref(value) : value) as UnwrapRefs<T>;
325325
}
@@ -339,3 +339,25 @@ export const unwrapRefs = <T>(value: T): UnwrapRefs<T> => {
339339
}
340340
return result as UnwrapRefs<T>;
341341
};
342+
343+
export const serializeBody = (
344+
opts: Pick<Parameters<Client['request']>[0], 'body' | 'bodySerializer'>,
345+
) => {
346+
if (opts.body && opts.bodySerializer) {
347+
return opts.bodySerializer(opts.body);
348+
}
349+
return opts.body;
350+
};
351+
352+
export const executeFetchFn = (
353+
opts: Omit<Parameters<Client['request']>[0], 'composable'>,
354+
fetchFn: Required<Config>['$fetch'],
355+
) => {
356+
const unwrappedOpts = unwrapRefs(opts);
357+
unwrappedOpts.body = serializeBody(unwrappedOpts);
358+
return fetchFn(
359+
buildUrl(opts),
360+
// @ts-expect-error
361+
unwrappedOpts,
362+
);
363+
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
'use strict';var B=require('axios');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var B__default=/*#__PURE__*/_interopDefault(B);var A=async(t,e)=>{let r=typeof e=="function"?await e(t):e;if(r)return t.scheme==="bearer"?`Bearer ${r}`:t.scheme==="basic"?`Basic ${btoa(r)}`:r},z=(t,e,r)=>{typeof r=="string"||r instanceof Blob?t.append(e,r):t.append(e,JSON.stringify(r));},w=(t,e,r)=>{typeof r=="string"?t.append(e,r):t.append(e,JSON.stringify(r));},j={bodySerializer:t=>{let e=new FormData;return Object.entries(t).forEach(([r,i])=>{i!=null&&(Array.isArray(i)?i.forEach(a=>z(e,r,a)):z(e,r,i));}),e}},q={bodySerializer:t=>JSON.stringify(t)},P={bodySerializer:t=>{let e=new URLSearchParams;return Object.entries(t).forEach(([r,i])=>{i!=null&&(Array.isArray(i)?i.forEach(a=>w(e,r,a)):w(e,r,i));}),e}},v=t=>{switch(t){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},$=t=>{switch(t){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},k=t=>{switch(t){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},h=({allowReserved:t,explode:e,name:r,style:i,value:a})=>{if(!e){let n=(t?a:a.map(o=>encodeURIComponent(o))).join($(i));switch(i){case "label":return `.${n}`;case "matrix":return `;${r}=${n}`;case "simple":return n;default:return `${r}=${n}`}}let s=v(i),l=a.map(n=>i==="label"||i==="simple"?t?n:encodeURIComponent(n):f({allowReserved:t,name:r,value:n})).join(s);return i==="label"||i==="matrix"?s+l:l},f=({allowReserved:t,name:e,value:r})=>{if(r==null)return "";if(typeof r=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return `${e}=${t?r:encodeURIComponent(r)}`},g=({allowReserved:t,explode:e,name:r,style:i,value:a})=>{if(a instanceof Date)return `${r}=${a.toISOString()}`;if(i!=="deepObject"&&!e){let n=[];Object.entries(a).forEach(([u,d])=>{n=[...n,u,t?d:encodeURIComponent(d)];});let o=n.join(",");switch(i){case "form":return `${r}=${o}`;case "label":return `.${o}`;case "matrix":return `;${r}=${o}`;default:return o}}let s=k(i),l=Object.entries(a).map(([n,o])=>f({allowReserved:t,name:i==="deepObject"?`${r}[${n}]`:n,value:o})).join(s);return i==="label"||i==="matrix"?s+l:l};var E=/\{[^{}]+\}/g,T=({path:t,url:e})=>{let r=e,i=e.match(E);if(i)for(let a of i){let s=false,l=a.substring(1,a.length-1),n="simple";l.endsWith("*")&&(s=true,l=l.substring(0,l.length-1)),l.startsWith(".")?(l=l.substring(1),n="label"):l.startsWith(";")&&(l=l.substring(1),n="matrix");let o=t[l];if(o==null)continue;if(Array.isArray(o)){r=r.replace(a,h({explode:s,name:l,style:n,value:o}));continue}if(typeof o=="object"){r=r.replace(a,g({explode:s,name:l,style:n,value:o}));continue}if(n==="matrix"){r=r.replace(a,`;${f({name:l,value:o})}`);continue}let u=encodeURIComponent(n==="label"?`.${o}`:o);r=r.replace(a,u);}return r},U=({allowReserved:t,array:e,object:r}={})=>a=>{let s=[];if(a&&typeof a=="object")for(let l in a){let n=a[l];if(n!=null){if(Array.isArray(n)){s=[...s,h({allowReserved:t,explode:true,name:l,style:"form",value:n,...e})];continue}if(typeof n=="object"){s=[...s,g({allowReserved:t,explode:true,name:l,style:"deepObject",value:n,...r})];continue}s=[...s,f({allowReserved:t,name:l,value:n})];}}return s.join("&")},R=async({security:t,...e})=>{for(let r of t){let i=await A(r,e.auth);if(!i)continue;let a=r.name??"Authorization";switch(r.in){case "query":e.query||(e.query={}),e.query[a]=i;break;case "header":default:e.headers[a]=i;break}return}},b=t=>D({path:t.path,query:t.paramsSerializer?undefined:t.query,querySerializer:typeof t.querySerializer=="function"?t.querySerializer:U(t.querySerializer),url:t.url}),D=({path:t,query:e,querySerializer:r,url:i})=>{let s=i.startsWith("/")?i:`/${i}`;t&&(s=T({path:t,url:s}));let l=e?r(e):"";return l.startsWith("?")&&(l=l.substring(1)),l&&(s+=`?${l}`),s},S=(t,e)=>{let r={...t,...e};return r.headers=y(t.headers,e.headers),r},H=["common","delete","get","head","patch","post","put"],y=(...t)=>{let e={};for(let r of t){if(!r||typeof r!="object")continue;let i=Object.entries(r);for(let[a,s]of i)if(H.includes(a)&&typeof s=="object")e[a]={...e[a],...s};else if(s===null)delete e[a];else if(Array.isArray(s))for(let l of s)e[a]=[...e[a]??[],l];else s!==undefined&&(e[a]=typeof s=="object"?JSON.stringify(s):s);}return e},x=(t={})=>({baseURL:"",...t});var I=(t={})=>{let e=S(x(),t),{auth:r,...i}=e,a=B__default.default.create(i),s=()=>({...e}),l=o=>(e=S(e,o),a.defaults={...a.defaults,...e,headers:y(a.defaults.headers,e.headers)},s()),n=async o=>{let u={...e,...o,axios:o.axios??e.axios??a,headers:y(e.headers,o.headers)};u.security&&await R({...u,security:u.security}),u.body&&u.bodySerializer&&(u.body=u.bodySerializer(u.body));let d=b(u);try{let m=u.axios,{auth:c,...O}=u,C=await m({...O,data:u.body,headers:u.headers,params:u.paramsSerializer?u.query:void 0,url:d}),{data:p}=C;return u.responseType==="json"&&(u.responseValidator&&await u.responseValidator(p),u.responseTransformer&&(p=await u.responseTransformer(p))),{...C,data:p??{}}}catch(m){let c=m;if(u.throwOnError)throw c;return c.error=c.response?.data??{},c}};return {buildUrl:b,delete:o=>n({...o,method:"DELETE"}),get:o=>n({...o,method:"GET"}),getConfig:s,head:o=>n({...o,method:"HEAD"}),instance:a,options:o=>n({...o,method:"OPTIONS"}),patch:o=>n({...o,method:"PATCH"}),post:o=>n({...o,method:"POST"}),put:o=>n({...o,method:"PUT"}),request:n,setConfig:l}};exports.createClient=I;exports.createConfig=x;exports.formDataBodySerializer=j;exports.jsonBodySerializer=q;exports.urlSearchParamsBodySerializer=P;//# sourceMappingURL=index.cjs.map
1+
'use strict';var B=require('axios');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var B__default=/*#__PURE__*/_interopDefault(B);var A=async(t,r)=>{let e=typeof r=="function"?await r(t):r;if(e)return t.scheme==="bearer"?`Bearer ${e}`:t.scheme==="basic"?`Basic ${btoa(e)}`:e},z=(t,r,e)=>{typeof e=="string"||e instanceof Blob?t.append(r,e):t.append(r,JSON.stringify(e));},w=(t,r,e)=>{typeof e=="string"?t.append(r,e):t.append(r,JSON.stringify(e));},j={bodySerializer:t=>{let r=new FormData;return Object.entries(t).forEach(([e,i])=>{i!=null&&(Array.isArray(i)?i.forEach(a=>z(r,e,a)):z(r,e,i));}),r}},q={bodySerializer:t=>JSON.stringify(t,(r,e)=>typeof e=="bigint"?e.toString():e)},P={bodySerializer:t=>{let r=new URLSearchParams;return Object.entries(t).forEach(([e,i])=>{i!=null&&(Array.isArray(i)?i.forEach(a=>w(r,e,a)):w(r,e,i));}),r}},v=t=>{switch(t){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},$=t=>{switch(t){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},k=t=>{switch(t){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},h=({allowReserved:t,explode:r,name:e,style:i,value:a})=>{if(!r){let n=(t?a:a.map(o=>encodeURIComponent(o))).join($(i));switch(i){case "label":return `.${n}`;case "matrix":return `;${e}=${n}`;case "simple":return n;default:return `${e}=${n}`}}let s=v(i),l=a.map(n=>i==="label"||i==="simple"?t?n:encodeURIComponent(n):f({allowReserved:t,name:e,value:n})).join(s);return i==="label"||i==="matrix"?s+l:l},f=({allowReserved:t,name:r,value:e})=>{if(e==null)return "";if(typeof e=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return `${r}=${t?e:encodeURIComponent(e)}`},g=({allowReserved:t,explode:r,name:e,style:i,value:a})=>{if(a instanceof Date)return `${e}=${a.toISOString()}`;if(i!=="deepObject"&&!r){let n=[];Object.entries(a).forEach(([u,d])=>{n=[...n,u,t?d:encodeURIComponent(d)];});let o=n.join(",");switch(i){case "form":return `${e}=${o}`;case "label":return `.${o}`;case "matrix":return `;${e}=${o}`;default:return o}}let s=k(i),l=Object.entries(a).map(([n,o])=>f({allowReserved:t,name:i==="deepObject"?`${e}[${n}]`:n,value:o})).join(s);return i==="label"||i==="matrix"?s+l:l};var E=/\{[^{}]+\}/g,T=({path:t,url:r})=>{let e=r,i=r.match(E);if(i)for(let a of i){let s=false,l=a.substring(1,a.length-1),n="simple";l.endsWith("*")&&(s=true,l=l.substring(0,l.length-1)),l.startsWith(".")?(l=l.substring(1),n="label"):l.startsWith(";")&&(l=l.substring(1),n="matrix");let o=t[l];if(o==null)continue;if(Array.isArray(o)){e=e.replace(a,h({explode:s,name:l,style:n,value:o}));continue}if(typeof o=="object"){e=e.replace(a,g({explode:s,name:l,style:n,value:o}));continue}if(n==="matrix"){e=e.replace(a,`;${f({name:l,value:o})}`);continue}let u=encodeURIComponent(n==="label"?`.${o}`:o);e=e.replace(a,u);}return e},U=({allowReserved:t,array:r,object:e}={})=>a=>{let s=[];if(a&&typeof a=="object")for(let l in a){let n=a[l];if(n!=null){if(Array.isArray(n)){s=[...s,h({allowReserved:t,explode:true,name:l,style:"form",value:n,...r})];continue}if(typeof n=="object"){s=[...s,g({allowReserved:t,explode:true,name:l,style:"deepObject",value:n,...e})];continue}s=[...s,f({allowReserved:t,name:l,value:n})];}}return s.join("&")},R=async({security:t,...r})=>{for(let e of t){let i=await A(e,r.auth);if(!i)continue;let a=e.name??"Authorization";switch(e.in){case "query":r.query||(r.query={}),r.query[a]=i;break;case "header":default:r.headers[a]=i;break}return}},b=t=>D({path:t.path,query:t.paramsSerializer?undefined:t.query,querySerializer:typeof t.querySerializer=="function"?t.querySerializer:U(t.querySerializer),url:t.url}),D=({path:t,query:r,querySerializer:e,url:i})=>{let s=i.startsWith("/")?i:`/${i}`;t&&(s=T({path:t,url:s}));let l=r?e(r):"";return l.startsWith("?")&&(l=l.substring(1)),l&&(s+=`?${l}`),s},S=(t,r)=>{let e={...t,...r};return e.headers=y(t.headers,r.headers),e},H=["common","delete","get","head","patch","post","put"],y=(...t)=>{let r={};for(let e of t){if(!e||typeof e!="object")continue;let i=Object.entries(e);for(let[a,s]of i)if(H.includes(a)&&typeof s=="object")r[a]={...r[a],...s};else if(s===null)delete r[a];else if(Array.isArray(s))for(let l of s)r[a]=[...r[a]??[],l];else s!==undefined&&(r[a]=typeof s=="object"?JSON.stringify(s):s);}return r},x=(t={})=>({baseURL:"",...t});var I=(t={})=>{let r=S(x(),t),{auth:e,...i}=r,a=B__default.default.create(i),s=()=>({...r}),l=o=>(r=S(r,o),a.defaults={...a.defaults,...r,headers:y(a.defaults.headers,r.headers)},s()),n=async o=>{let u={...r,...o,axios:o.axios??r.axios??a,headers:y(r.headers,o.headers)};u.security&&await R({...u,security:u.security}),u.body&&u.bodySerializer&&(u.body=u.bodySerializer(u.body));let d=b(u);try{let m=u.axios,{auth:c,...O}=u,C=await m({...O,data:u.body,headers:u.headers,params:u.paramsSerializer?u.query:void 0,url:d}),{data:p}=C;return u.responseType==="json"&&(u.responseValidator&&await u.responseValidator(p),u.responseTransformer&&(p=await u.responseTransformer(p))),{...C,data:p??{}}}catch(m){let c=m;if(u.throwOnError)throw c;return c.error=c.response?.data??{},c}};return {buildUrl:b,delete:o=>n({...o,method:"DELETE"}),get:o=>n({...o,method:"GET"}),getConfig:s,head:o=>n({...o,method:"HEAD"}),instance:a,options:o=>n({...o,method:"OPTIONS"}),patch:o=>n({...o,method:"PATCH"}),post:o=>n({...o,method:"POST"}),put:o=>n({...o,method:"PUT"}),request:n,setConfig:l}};exports.createClient=I;exports.createConfig=x;exports.formDataBodySerializer=j;exports.jsonBodySerializer=q;exports.urlSearchParamsBodySerializer=P;//# sourceMappingURL=index.cjs.map
22
//# sourceMappingURL=index.cjs.map

0 commit comments

Comments
 (0)