From 5b7cf3545f508567c7abd6565bf259cdc39578fb Mon Sep 17 00:00:00 2001 From: LinuCC Date: Thu, 27 Feb 2025 01:51:39 +0100 Subject: [PATCH 1/3] fix: dropping Content-Type header with falsey but valid json body --- packages/client-fetch/src/client.ts | 2 +- packages/client-next/src/client.ts | 2 +- packages/client-nuxt/src/client.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/client-fetch/src/client.ts b/packages/client-fetch/src/client.ts index 12848bade..79e997eb7 100644 --- a/packages/client-fetch/src/client.ts +++ b/packages/client-fetch/src/client.ts @@ -52,7 +52,7 @@ export const createClient = (config: Config = {}): Client => { } // remove Content-Type header if body is empty to avoid sending invalid requests - if (!opts.body) { + if (opts.body === undefined || opts.body === '') { opts.headers.delete('Content-Type'); } diff --git a/packages/client-next/src/client.ts b/packages/client-next/src/client.ts index 743d84824..2cb919aaf 100644 --- a/packages/client-next/src/client.ts +++ b/packages/client-next/src/client.ts @@ -47,7 +47,7 @@ export const createClient = (config: Config = {}): Client => { } // remove Content-Type header if body is empty to avoid sending invalid requests - if (!opts.body) { + if (opts.body === undefined || opts.body === '') { opts.headers.delete('Content-Type'); } diff --git a/packages/client-nuxt/src/client.ts b/packages/client-nuxt/src/client.ts index 9e99957f3..ccf257093 100644 --- a/packages/client-nuxt/src/client.ts +++ b/packages/client-nuxt/src/client.ts @@ -85,7 +85,7 @@ export const createClient = (config: Config = {}): Client => { } // remove Content-Type header if body is empty to avoid sending invalid requests - if (!opts.body) { + if (opts.body === undefined || opts.body === '') { opts.headers.delete('Content-Type'); } From 1115bc8aac4f6ada31b9f5e353fbde692a3e405b Mon Sep 17 00:00:00 2001 From: LinuCC Date: Thu, 27 Feb 2025 09:21:23 +0100 Subject: [PATCH 2/3] fix: dropping Content-Type header with falsey but valid json body --- .../3.1.x/clients/@hey-api/client-fetch/bundle/client/index.cjs | 2 +- .../3.1.x/clients/@hey-api/client-next/bundle/client/index.cjs | 2 +- .../3.1.x/clients/@hey-api/client-nuxt/bundle/client/index.cjs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.cjs b/packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.cjs index 747c76595..979fb16f5 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.cjs +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.cjs @@ -1,2 +1,2 @@ -'use strict';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));},j=(t,r,e)=>{typeof e=="string"?t.append(r,e):t.append(r,JSON.stringify(e));},$={bodySerializer:t=>{let r=new FormData;return Object.entries(t).forEach(([e,a])=>{a!=null&&(Array.isArray(a)?a.forEach(i=>z(r,e,i)):z(r,e,a));}),r}},b={bodySerializer:t=>JSON.stringify(t,(r,e)=>typeof e=="bigint"?e.toString():e)},k={bodySerializer:t=>{let r=new URLSearchParams;return Object.entries(t).forEach(([e,a])=>{a!=null&&(Array.isArray(a)?a.forEach(i=>j(r,e,i)):j(r,e,a));}),r.toString()}},U=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 ","}},D=t=>{switch(t){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},O=({allowReserved:t,explode:r,name:e,style:a,value:i})=>{if(!r){let s=(t?i:i.map(l=>encodeURIComponent(l))).join(_(a));switch(a){case "label":return `.${s}`;case "matrix":return `;${e}=${s}`;case "simple":return s;default:return `${e}=${s}`}}let o=U(a),n=i.map(s=>a==="label"||a==="simple"?t?s:encodeURIComponent(s):y({allowReserved:t,name:e,value:s})).join(o);return a==="label"||a==="matrix"?o+n:n},y=({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)}`},q=({allowReserved:t,explode:r,name:e,style:a,value:i})=>{if(i instanceof Date)return `${e}=${i.toISOString()}`;if(a!=="deepObject"&&!r){let s=[];Object.entries(i).forEach(([f,u])=>{s=[...s,f,t?u:encodeURIComponent(u)];});let l=s.join(",");switch(a){case "form":return `${e}=${l}`;case "label":return `.${l}`;case "matrix":return `;${e}=${l}`;default:return l}}let o=D(a),n=Object.entries(i).map(([s,l])=>y({allowReserved:t,name:a==="deepObject"?`${e}[${s}]`:s,value:l})).join(o);return a==="label"||a==="matrix"?o+n:n};var H=/\{[^{}]+\}/g,B=({path:t,url:r})=>{let e=r,a=r.match(H);if(a)for(let i of a){let o=false,n=i.substring(1,i.length-1),s="simple";n.endsWith("*")&&(o=true,n=n.substring(0,n.length-1)),n.startsWith(".")?(n=n.substring(1),s="label"):n.startsWith(";")&&(n=n.substring(1),s="matrix");let l=t[n];if(l==null)continue;if(Array.isArray(l)){e=e.replace(i,O({explode:o,name:n,style:s,value:l}));continue}if(typeof l=="object"){e=e.replace(i,q({explode:o,name:n,style:s,value:l}));continue}if(s==="matrix"){e=e.replace(i,`;${y({name:n,value:l})}`);continue}let f=encodeURIComponent(s==="label"?`.${l}`:l);e=e.replace(i,f);}return e},E=({allowReserved:t,array:r,object:e}={})=>i=>{let o=[];if(i&&typeof i=="object")for(let n in i){let s=i[n];if(s!=null){if(Array.isArray(s)){o=[...o,O({allowReserved:t,explode:true,name:n,style:"form",value:s,...r})];continue}if(typeof s=="object"){o=[...o,q({allowReserved:t,explode:true,name:n,style:"deepObject",value:s,...e})];continue}o=[...o,y({allowReserved:t,name:n,value:s})];}}return o.join("&")},P=t=>{if(!t)return "stream";let r=t.split(";")[0]?.trim();if(r){if(r.startsWith("application/json")||r.endsWith("+json"))return "json";if(r==="multipart/form-data")return "formData";if(["application/","audio/","image/","video/"].some(e=>r.startsWith(e)))return "blob";if(r.startsWith("text/"))return "text"}},I=async({security:t,...r})=>{for(let e of t){let a=await A(e,r.auth);if(!a)continue;let i=e.name??"Authorization";switch(e.in){case "query":r.query||(r.query={}),r.query[i]=a;break;case "header":default:r.headers.set(i,a);break}return}},S=t=>W({baseUrl:t.baseUrl,path:t.path,query:t.query,querySerializer:typeof t.querySerializer=="function"?t.querySerializer:E(t.querySerializer),url:t.url}),W=({baseUrl:t,path:r,query:e,querySerializer:a,url:i})=>{let o=i.startsWith("/")?i:`/${i}`,n=(t??"")+o;r&&(n=B({path:r,url:n}));let s=e?a(e):"";return s.startsWith("?")&&(s=s.substring(1)),s&&(n+=`?${s}`),n},C=(t,r)=>{let e={...t,...r};return e.baseUrl?.endsWith("/")&&(e.baseUrl=e.baseUrl.substring(0,e.baseUrl.length-1)),e.headers=x(t.headers,r.headers),e},x=(...t)=>{let r=new Headers;for(let e of t){if(!e||typeof e!="object")continue;let a=e instanceof Headers?e.entries():Object.entries(e);for(let[i,o]of a)if(o===null)r.delete(i);else if(Array.isArray(o))for(let n of o)r.append(i,n);else o!==undefined&&r.set(i,typeof o=="object"?JSON.stringify(o):o);}return r},m=class{_fns;constructor(){this._fns=[];}clear(){this._fns=[];}exists(r){return this._fns.indexOf(r)!==-1}eject(r){let e=this._fns.indexOf(r);e!==-1&&(this._fns=[...this._fns.slice(0,e),...this._fns.slice(e+1)]);}use(r){this._fns=[...this._fns,r];}},T=()=>({error:new m,request:new m,response:new m}),N=E({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),Q={"Content-Type":"application/json"},w=(t={})=>({...b,headers:Q,parseAs:"auto",querySerializer:N,...t});var J=(t={})=>{let r=C(w(),t),e=()=>({...r}),a=n=>(r=C(r,n),e()),i=T(),o=async n=>{let s={...r,...n,fetch:n.fetch??r.fetch??globalThis.fetch,headers:x(r.headers,n.headers)};s.security&&await I({...s,security:s.security}),s.body&&s.bodySerializer&&(s.body=s.bodySerializer(s.body)),s.body||s.headers.delete("Content-Type");let l=S(s),f={redirect:"follow",...s},u=new Request(l,f);for(let p of i.request._fns)u=await p(u,s);let v=s.fetch,c=await v(u);for(let p of i.response._fns)c=await p(c,u,s);let h={request:u,response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return {data:{},...h};let p=(s.parseAs==="auto"?P(c.headers.get("Content-Type")):s.parseAs)??"json";if(p==="stream")return {data:c.body,...h};let R=await c[p]();return p==="json"&&(s.responseValidator&&await s.responseValidator(R),s.responseTransformer&&(R=await s.responseTransformer(R))),{data:R,...h}}let g=await c.text();try{g=JSON.parse(g);}catch{}let d=g;for(let p of i.error._fns)d=await p(g,c,u,s);if(d=d||{},s.throwOnError)throw d;return {error:d,...h}};return {buildUrl:S,connect:n=>o({...n,method:"CONNECT"}),delete:n=>o({...n,method:"DELETE"}),get:n=>o({...n,method:"GET"}),getConfig:e,head:n=>o({...n,method:"HEAD"}),interceptors:i,options:n=>o({...n,method:"OPTIONS"}),patch:n=>o({...n,method:"PATCH"}),post:n=>o({...n,method:"POST"}),put:n=>o({...n,method:"PUT"}),request:o,setConfig:a,trace:n=>o({...n,method:"TRACE"})}};exports.createClient=J;exports.createConfig=w;exports.formDataBodySerializer=$;exports.jsonBodySerializer=b;exports.urlSearchParamsBodySerializer=k;//# sourceMappingURL=index.cjs.map +'use strict';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));},j=(t,r,e)=>{typeof e=="string"?t.append(r,e):t.append(r,JSON.stringify(e));},$={bodySerializer:t=>{let r=new FormData;return Object.entries(t).forEach(([e,a])=>{a!=null&&(Array.isArray(a)?a.forEach(i=>z(r,e,i)):z(r,e,a));}),r}},R={bodySerializer:t=>JSON.stringify(t,(r,e)=>typeof e=="bigint"?e.toString():e)},k={bodySerializer:t=>{let r=new URLSearchParams;return Object.entries(t).forEach(([e,a])=>{a!=null&&(Array.isArray(a)?a.forEach(i=>j(r,e,i)):j(r,e,a));}),r.toString()}},U=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 ","}},D=t=>{switch(t){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},O=({allowReserved:t,explode:r,name:e,style:a,value:i})=>{if(!r){let s=(t?i:i.map(l=>encodeURIComponent(l))).join(_(a));switch(a){case "label":return `.${s}`;case "matrix":return `;${e}=${s}`;case "simple":return s;default:return `${e}=${s}`}}let o=U(a),n=i.map(s=>a==="label"||a==="simple"?t?s:encodeURIComponent(s):y({allowReserved:t,name:e,value:s})).join(o);return a==="label"||a==="matrix"?o+n:n},y=({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)}`},q=({allowReserved:t,explode:r,name:e,style:a,value:i})=>{if(i instanceof Date)return `${e}=${i.toISOString()}`;if(a!=="deepObject"&&!r){let s=[];Object.entries(i).forEach(([f,u])=>{s=[...s,f,t?u:encodeURIComponent(u)];});let l=s.join(",");switch(a){case "form":return `${e}=${l}`;case "label":return `.${l}`;case "matrix":return `;${e}=${l}`;default:return l}}let o=D(a),n=Object.entries(i).map(([s,l])=>y({allowReserved:t,name:a==="deepObject"?`${e}[${s}]`:s,value:l})).join(o);return a==="label"||a==="matrix"?o+n:n};var H=/\{[^{}]+\}/g,B=({path:t,url:r})=>{let e=r,a=r.match(H);if(a)for(let i of a){let o=false,n=i.substring(1,i.length-1),s="simple";n.endsWith("*")&&(o=true,n=n.substring(0,n.length-1)),n.startsWith(".")?(n=n.substring(1),s="label"):n.startsWith(";")&&(n=n.substring(1),s="matrix");let l=t[n];if(l==null)continue;if(Array.isArray(l)){e=e.replace(i,O({explode:o,name:n,style:s,value:l}));continue}if(typeof l=="object"){e=e.replace(i,q({explode:o,name:n,style:s,value:l}));continue}if(s==="matrix"){e=e.replace(i,`;${y({name:n,value:l})}`);continue}let f=encodeURIComponent(s==="label"?`.${l}`:l);e=e.replace(i,f);}return e},E=({allowReserved:t,array:r,object:e}={})=>i=>{let o=[];if(i&&typeof i=="object")for(let n in i){let s=i[n];if(s!=null){if(Array.isArray(s)){o=[...o,O({allowReserved:t,explode:true,name:n,style:"form",value:s,...r})];continue}if(typeof s=="object"){o=[...o,q({allowReserved:t,explode:true,name:n,style:"deepObject",value:s,...e})];continue}o=[...o,y({allowReserved:t,name:n,value:s})];}}return o.join("&")},P=t=>{if(!t)return "stream";let r=t.split(";")[0]?.trim();if(r){if(r.startsWith("application/json")||r.endsWith("+json"))return "json";if(r==="multipart/form-data")return "formData";if(["application/","audio/","image/","video/"].some(e=>r.startsWith(e)))return "blob";if(r.startsWith("text/"))return "text"}},I=async({security:t,...r})=>{for(let e of t){let a=await A(e,r.auth);if(!a)continue;let i=e.name??"Authorization";switch(e.in){case "query":r.query||(r.query={}),r.query[i]=a;break;case "header":default:r.headers.set(i,a);break}return}},S=t=>W({baseUrl:t.baseUrl,path:t.path,query:t.query,querySerializer:typeof t.querySerializer=="function"?t.querySerializer:E(t.querySerializer),url:t.url}),W=({baseUrl:t,path:r,query:e,querySerializer:a,url:i})=>{let o=i.startsWith("/")?i:`/${i}`,n=(t??"")+o;r&&(n=B({path:r,url:n}));let s=e?a(e):"";return s.startsWith("?")&&(s=s.substring(1)),s&&(n+=`?${s}`),n},C=(t,r)=>{let e={...t,...r};return e.baseUrl?.endsWith("/")&&(e.baseUrl=e.baseUrl.substring(0,e.baseUrl.length-1)),e.headers=x(t.headers,r.headers),e},x=(...t)=>{let r=new Headers;for(let e of t){if(!e||typeof e!="object")continue;let a=e instanceof Headers?e.entries():Object.entries(e);for(let[i,o]of a)if(o===null)r.delete(i);else if(Array.isArray(o))for(let n of o)r.append(i,n);else o!==undefined&&r.set(i,typeof o=="object"?JSON.stringify(o):o);}return r},m=class{_fns;constructor(){this._fns=[];}clear(){this._fns=[];}exists(r){return this._fns.indexOf(r)!==-1}eject(r){let e=this._fns.indexOf(r);e!==-1&&(this._fns=[...this._fns.slice(0,e),...this._fns.slice(e+1)]);}use(r){this._fns=[...this._fns,r];}},T=()=>({error:new m,request:new m,response:new m}),N=E({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),Q={"Content-Type":"application/json"},w=(t={})=>({...R,headers:Q,parseAs:"auto",querySerializer:N,...t});var J=(t={})=>{let r=C(w(),t),e=()=>({...r}),a=n=>(r=C(r,n),e()),i=T(),o=async n=>{let s={...r,...n,fetch:n.fetch??r.fetch??globalThis.fetch,headers:x(r.headers,n.headers)};s.security&&await I({...s,security:s.security}),s.body&&s.bodySerializer&&(s.body=s.bodySerializer(s.body)),(s.body===undefined||s.body==="")&&s.headers.delete("Content-Type");let l=S(s),f={redirect:"follow",...s},u=new Request(l,f);for(let p of i.request._fns)u=await p(u,s);let v=s.fetch,c=await v(u);for(let p of i.response._fns)c=await p(c,u,s);let h={request:u,response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return {data:{},...h};let p=(s.parseAs==="auto"?P(c.headers.get("Content-Type")):s.parseAs)??"json";if(p==="stream")return {data:c.body,...h};let b=await c[p]();return p==="json"&&(s.responseValidator&&await s.responseValidator(b),s.responseTransformer&&(b=await s.responseTransformer(b))),{data:b,...h}}let g=await c.text();try{g=JSON.parse(g);}catch{}let d=g;for(let p of i.error._fns)d=await p(g,c,u,s);if(d=d||{},s.throwOnError)throw d;return {error:d,...h}};return {buildUrl:S,connect:n=>o({...n,method:"CONNECT"}),delete:n=>o({...n,method:"DELETE"}),get:n=>o({...n,method:"GET"}),getConfig:e,head:n=>o({...n,method:"HEAD"}),interceptors:i,options:n=>o({...n,method:"OPTIONS"}),patch:n=>o({...n,method:"PATCH"}),post:n=>o({...n,method:"POST"}),put:n=>o({...n,method:"PUT"}),request:o,setConfig:a,trace:n=>o({...n,method:"TRACE"})}};exports.createClient=J;exports.createConfig=w;exports.formDataBodySerializer=$;exports.jsonBodySerializer=R;exports.urlSearchParamsBodySerializer=k;//# sourceMappingURL=index.cjs.map //# sourceMappingURL=index.cjs.map \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-next/bundle/client/index.cjs b/packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-next/bundle/client/index.cjs index ceb3dfc1e..7f6ee0214 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-next/bundle/client/index.cjs +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-next/bundle/client/index.cjs @@ -1,2 +1,2 @@ -'use strict';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));},j=(t,r,e)=>{typeof e=="string"?t.append(r,e):t.append(r,JSON.stringify(e));},v={bodySerializer:t=>{let r=new FormData;return Object.entries(t).forEach(([e,a])=>{a!=null&&(Array.isArray(a)?a.forEach(i=>z(r,e,i)):z(r,e,a));}),r}},b={bodySerializer:t=>JSON.stringify(t,(r,e)=>typeof e=="bigint"?e.toString():e)},T={bodySerializer:t=>{let r=new URLSearchParams;return Object.entries(t).forEach(([e,a])=>{a!=null&&(Array.isArray(a)?a.forEach(i=>j(r,e,i)):j(r,e,a));}),r.toString()}},$=t=>{switch(t){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},k=t=>{switch(t){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},U=t=>{switch(t){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},O=({allowReserved:t,explode:r,name:e,style:a,value:i})=>{if(!r){let s=(t?i:i.map(l=>encodeURIComponent(l))).join(k(a));switch(a){case "label":return `.${s}`;case "matrix":return `;${e}=${s}`;case "simple":return s;default:return `${e}=${s}`}}let o=$(a),n=i.map(s=>a==="label"||a==="simple"?t?s:encodeURIComponent(s):d({allowReserved:t,name:e,value:s})).join(o);return a==="label"||a==="matrix"?o+n:n},d=({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)}`},S=({allowReserved:t,explode:r,name:e,style:a,value:i})=>{if(i instanceof Date)return `${e}=${i.toISOString()}`;if(a!=="deepObject"&&!r){let s=[];Object.entries(i).forEach(([p,c])=>{s=[...s,p,t?c:encodeURIComponent(c)];});let l=s.join(",");switch(a){case "form":return `${e}=${l}`;case "label":return `.${l}`;case "matrix":return `;${e}=${l}`;default:return l}}let o=U(a),n=Object.entries(i).map(([s,l])=>d({allowReserved:t,name:a==="deepObject"?`${e}[${s}]`:s,value:l})).join(o);return a==="label"||a==="matrix"?o+n:n};var _=/\{[^{}]+\}/g,D=({path:t,url:r})=>{let e=r,a=r.match(_);if(a)for(let i of a){let o=false,n=i.substring(1,i.length-1),s="simple";n.endsWith("*")&&(o=true,n=n.substring(0,n.length-1)),n.startsWith(".")?(n=n.substring(1),s="label"):n.startsWith(";")&&(n=n.substring(1),s="matrix");let l=t[n];if(l==null)continue;if(Array.isArray(l)){e=e.replace(i,O({explode:o,name:n,style:s,value:l}));continue}if(typeof l=="object"){e=e.replace(i,S({explode:o,name:n,style:s,value:l}));continue}if(s==="matrix"){e=e.replace(i,`;${d({name:n,value:l})}`);continue}let p=encodeURIComponent(s==="label"?`.${l}`:l);e=e.replace(i,p);}return e},q=({allowReserved:t,array:r,object:e}={})=>i=>{let o=[];if(i&&typeof i=="object")for(let n in i){let s=i[n];if(s!=null){if(Array.isArray(s)){o=[...o,O({allowReserved:t,explode:true,name:n,style:"form",value:s,...r})];continue}if(typeof s=="object"){o=[...o,S({allowReserved:t,explode:true,name:n,style:"deepObject",value:s,...e})];continue}o=[...o,d({allowReserved:t,name:n,value:s})];}}return o.join("&")},E=t=>{if(!t)return "stream";let r=t.split(";")[0]?.trim();if(r){if(r.startsWith("application/json")||r.endsWith("+json"))return "json";if(r==="multipart/form-data")return "formData";if(["application/","audio/","image/","video/"].some(e=>r.startsWith(e)))return "blob";if(r.startsWith("text/"))return "text"}},P=async({security:t,...r})=>{for(let e of t){let a=await A(e,r.auth);if(!a)continue;let i=e.name??"Authorization";switch(e.in){case "query":r.query||(r.query={}),r.query[i]=a;break;case "header":default:r.headers.set(i,a);break}return}},C=t=>H({baseUrl:t.baseUrl,path:t.path,query:t.query,querySerializer:typeof t.querySerializer=="function"?t.querySerializer:q(t.querySerializer),url:t.url}),H=({baseUrl:t,path:r,query:e,querySerializer:a,url:i})=>{let o=i.startsWith("/")?i:`/${i}`,n=(t??"")+o;r&&(n=D({path:r,url:n}));let s=e?a(e):"";return s.startsWith("?")&&(s=s.substring(1)),s&&(n+=`?${s}`),n},R=(t,r)=>{let e={...t,...r};return e.baseUrl?.endsWith("/")&&(e.baseUrl=e.baseUrl.substring(0,e.baseUrl.length-1)),e.headers=x(t.headers,r.headers),e},x=(...t)=>{let r=new Headers;for(let e of t){if(!e||typeof e!="object")continue;let a=e instanceof Headers?e.entries():Object.entries(e);for(let[i,o]of a)if(o===null)r.delete(i);else if(Array.isArray(o))for(let n of o)r.append(i,n);else o!==undefined&&r.set(i,typeof o=="object"?JSON.stringify(o):o);}return r},y=class{_fns;constructor(){this._fns=[];}clear(){this._fns=[];}exists(r){return this._fns.indexOf(r)!==-1}eject(r){let e=this._fns.indexOf(r);e!==-1&&(this._fns=[...this._fns.slice(0,e),...this._fns.slice(e+1)]);}use(r){this._fns=[...this._fns,r];}},I=()=>({error:new y,request:new y,response:new y}),B=q({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),W={"Content-Type":"application/json"},w=(t={})=>({...b,headers:W,parseAs:"auto",querySerializer:B,...t});var N=(t={})=>{let r=R(w(),t),e=()=>({...r}),a=n=>(r=R(r,n),e()),i=I(),o=async n=>{let s={...r,...n,fetch:n.fetch??r.fetch??globalThis.fetch,headers:x(r.headers,n.headers)};s.security&&await P({...s,security:s.security}),s.body&&s.bodySerializer&&(s.body=s.bodySerializer(s.body)),s.body||s.headers.delete("Content-Type");for(let u of i.request._fns)await u(s);let l=C(s),p=s.fetch,c=await p(l,{...s,body:s.body});for(let u of i.response._fns)c=await u(c,s);let m={response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return {data:{},...m};let u=(s.parseAs==="auto"?E(c.headers.get("Content-Type")):s.parseAs)??"json";if(u==="stream")return {data:c.body,...m};let g=await c[u]();return u==="json"&&(s.responseValidator&&await s.responseValidator(g),s.responseTransformer&&(g=await s.responseTransformer(g))),{data:g,...m}}let h=await c.text();try{h=JSON.parse(h);}catch{}let f=h;for(let u of i.error._fns)f=await u(h,c,s);if(f=f||{},s.throwOnError)throw f;return {error:f,...m}};return {buildUrl:C,connect:n=>o({...n,method:"CONNECT"}),delete:n=>o({...n,method:"DELETE"}),get:n=>o({...n,method:"GET"}),getConfig:e,head:n=>o({...n,method:"HEAD"}),interceptors:i,options:n=>o({...n,method:"OPTIONS"}),patch:n=>o({...n,method:"PATCH"}),post:n=>o({...n,method:"POST"}),put:n=>o({...n,method:"PUT"}),request:o,setConfig:a,trace:n=>o({...n,method:"TRACE"})}};exports.createClient=N;exports.createConfig=w;exports.formDataBodySerializer=v;exports.jsonBodySerializer=b;exports.urlSearchParamsBodySerializer=T;//# sourceMappingURL=index.cjs.map +'use strict';var A=async(s,r)=>{let e=typeof r=="function"?await r(s):r;if(e)return s.scheme==="bearer"?`Bearer ${e}`:s.scheme==="basic"?`Basic ${btoa(e)}`:e},z=(s,r,e)=>{typeof e=="string"||e instanceof Blob?s.append(r,e):s.append(r,JSON.stringify(e));},j=(s,r,e)=>{typeof e=="string"?s.append(r,e):s.append(r,JSON.stringify(e));},v={bodySerializer:s=>{let r=new FormData;return Object.entries(s).forEach(([e,a])=>{a!=null&&(Array.isArray(a)?a.forEach(i=>z(r,e,i)):z(r,e,a));}),r}},b={bodySerializer:s=>JSON.stringify(s,(r,e)=>typeof e=="bigint"?e.toString():e)},T={bodySerializer:s=>{let r=new URLSearchParams;return Object.entries(s).forEach(([e,a])=>{a!=null&&(Array.isArray(a)?a.forEach(i=>j(r,e,i)):j(r,e,a));}),r.toString()}},$=s=>{switch(s){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},k=s=>{switch(s){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},U=s=>{switch(s){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},O=({allowReserved:s,explode:r,name:e,style:a,value:i})=>{if(!r){let t=(s?i:i.map(l=>encodeURIComponent(l))).join(k(a));switch(a){case "label":return `.${t}`;case "matrix":return `;${e}=${t}`;case "simple":return t;default:return `${e}=${t}`}}let o=$(a),n=i.map(t=>a==="label"||a==="simple"?s?t:encodeURIComponent(t):d({allowReserved:s,name:e,value:t})).join(o);return a==="label"||a==="matrix"?o+n:n},d=({allowReserved:s,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}=${s?e:encodeURIComponent(e)}`},S=({allowReserved:s,explode:r,name:e,style:a,value:i})=>{if(i instanceof Date)return `${e}=${i.toISOString()}`;if(a!=="deepObject"&&!r){let t=[];Object.entries(i).forEach(([p,c])=>{t=[...t,p,s?c:encodeURIComponent(c)];});let l=t.join(",");switch(a){case "form":return `${e}=${l}`;case "label":return `.${l}`;case "matrix":return `;${e}=${l}`;default:return l}}let o=U(a),n=Object.entries(i).map(([t,l])=>d({allowReserved:s,name:a==="deepObject"?`${e}[${t}]`:t,value:l})).join(o);return a==="label"||a==="matrix"?o+n:n};var _=/\{[^{}]+\}/g,D=({path:s,url:r})=>{let e=r,a=r.match(_);if(a)for(let i of a){let o=false,n=i.substring(1,i.length-1),t="simple";n.endsWith("*")&&(o=true,n=n.substring(0,n.length-1)),n.startsWith(".")?(n=n.substring(1),t="label"):n.startsWith(";")&&(n=n.substring(1),t="matrix");let l=s[n];if(l==null)continue;if(Array.isArray(l)){e=e.replace(i,O({explode:o,name:n,style:t,value:l}));continue}if(typeof l=="object"){e=e.replace(i,S({explode:o,name:n,style:t,value:l}));continue}if(t==="matrix"){e=e.replace(i,`;${d({name:n,value:l})}`);continue}let p=encodeURIComponent(t==="label"?`.${l}`:l);e=e.replace(i,p);}return e},q=({allowReserved:s,array:r,object:e}={})=>i=>{let o=[];if(i&&typeof i=="object")for(let n in i){let t=i[n];if(t!=null){if(Array.isArray(t)){o=[...o,O({allowReserved:s,explode:true,name:n,style:"form",value:t,...r})];continue}if(typeof t=="object"){o=[...o,S({allowReserved:s,explode:true,name:n,style:"deepObject",value:t,...e})];continue}o=[...o,d({allowReserved:s,name:n,value:t})];}}return o.join("&")},E=s=>{if(!s)return "stream";let r=s.split(";")[0]?.trim();if(r){if(r.startsWith("application/json")||r.endsWith("+json"))return "json";if(r==="multipart/form-data")return "formData";if(["application/","audio/","image/","video/"].some(e=>r.startsWith(e)))return "blob";if(r.startsWith("text/"))return "text"}},P=async({security:s,...r})=>{for(let e of s){let a=await A(e,r.auth);if(!a)continue;let i=e.name??"Authorization";switch(e.in){case "query":r.query||(r.query={}),r.query[i]=a;break;case "header":default:r.headers.set(i,a);break}return}},C=s=>H({baseUrl:s.baseUrl,path:s.path,query:s.query,querySerializer:typeof s.querySerializer=="function"?s.querySerializer:q(s.querySerializer),url:s.url}),H=({baseUrl:s,path:r,query:e,querySerializer:a,url:i})=>{let o=i.startsWith("/")?i:`/${i}`,n=(s??"")+o;r&&(n=D({path:r,url:n}));let t=e?a(e):"";return t.startsWith("?")&&(t=t.substring(1)),t&&(n+=`?${t}`),n},R=(s,r)=>{let e={...s,...r};return e.baseUrl?.endsWith("/")&&(e.baseUrl=e.baseUrl.substring(0,e.baseUrl.length-1)),e.headers=x(s.headers,r.headers),e},x=(...s)=>{let r=new Headers;for(let e of s){if(!e||typeof e!="object")continue;let a=e instanceof Headers?e.entries():Object.entries(e);for(let[i,o]of a)if(o===null)r.delete(i);else if(Array.isArray(o))for(let n of o)r.append(i,n);else o!==undefined&&r.set(i,typeof o=="object"?JSON.stringify(o):o);}return r},y=class{_fns;constructor(){this._fns=[];}clear(){this._fns=[];}exists(r){return this._fns.indexOf(r)!==-1}eject(r){let e=this._fns.indexOf(r);e!==-1&&(this._fns=[...this._fns.slice(0,e),...this._fns.slice(e+1)]);}use(r){this._fns=[...this._fns,r];}},I=()=>({error:new y,request:new y,response:new y}),B=q({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),W={"Content-Type":"application/json"},w=(s={})=>({...b,headers:W,parseAs:"auto",querySerializer:B,...s});var N=(s={})=>{let r=R(w(),s),e=()=>({...r}),a=n=>(r=R(r,n),e()),i=I(),o=async n=>{let t={...r,...n,fetch:n.fetch??r.fetch??globalThis.fetch,headers:x(r.headers,n.headers)};t.security&&await P({...t,security:t.security}),t.body&&t.bodySerializer&&(t.body=t.bodySerializer(t.body)),(t.body===undefined||t.body==="")&&t.headers.delete("Content-Type");for(let u of i.request._fns)await u(t);let l=C(t),p=t.fetch,c=await p(l,{...t,body:t.body});for(let u of i.response._fns)c=await u(c,t);let m={response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return {data:{},...m};let u=(t.parseAs==="auto"?E(c.headers.get("Content-Type")):t.parseAs)??"json";if(u==="stream")return {data:c.body,...m};let g=await c[u]();return u==="json"&&(t.responseValidator&&await t.responseValidator(g),t.responseTransformer&&(g=await t.responseTransformer(g))),{data:g,...m}}let h=await c.text();try{h=JSON.parse(h);}catch{}let f=h;for(let u of i.error._fns)f=await u(h,c,t);if(f=f||{},t.throwOnError)throw f;return {error:f,...m}};return {buildUrl:C,connect:n=>o({...n,method:"CONNECT"}),delete:n=>o({...n,method:"DELETE"}),get:n=>o({...n,method:"GET"}),getConfig:e,head:n=>o({...n,method:"HEAD"}),interceptors:i,options:n=>o({...n,method:"OPTIONS"}),patch:n=>o({...n,method:"PATCH"}),post:n=>o({...n,method:"POST"}),put:n=>o({...n,method:"PUT"}),request:o,setConfig:a,trace:n=>o({...n,method:"TRACE"})}};exports.createClient=N;exports.createConfig=w;exports.formDataBodySerializer=v;exports.jsonBodySerializer=b;exports.urlSearchParamsBodySerializer=T;//# sourceMappingURL=index.cjs.map //# sourceMappingURL=index.cjs.map \ No newline at end of file diff --git a/packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/bundle/client/index.cjs b/packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/bundle/client/index.cjs index 4790ecf79..269fb9a6a 100644 --- a/packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/bundle/client/index.cjs +++ b/packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/bundle/client/index.cjs @@ -1,2 +1,2 @@ -'use strict';var app=require('nuxt/app'),vue=require('vue');var E=async(r,t)=>{let e=typeof t=="function"?await t(r):t;if(e)return r.scheme==="bearer"?`Bearer ${e}`:r.scheme==="basic"?`Basic ${btoa(e)}`:e},U=(r,t,e)=>{typeof e=="string"||e instanceof Blob?r.append(t,e):r.append(t,JSON.stringify(e));},k=(r,t,e)=>{typeof e=="string"?r.append(t,e):r.append(t,JSON.stringify(e));},F={bodySerializer:r=>{let t=new FormData;return Object.entries(r).forEach(([e,i])=>{i!=null&&(Array.isArray(i)?i.forEach(o=>U(t,e,o)):U(t,e,i));}),t}},C={bodySerializer:r=>JSON.stringify(r,(t,e)=>typeof e=="bigint"?e.toString():e)},I={bodySerializer:r=>{let t=new URLSearchParams;return Object.entries(r).forEach(([e,i])=>{i!=null&&(Array.isArray(i)?i.forEach(o=>k(t,e,o)):k(t,e,i));}),t.toString()}},N=r=>{switch(r){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},Q=r=>{switch(r){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},V=r=>{switch(r){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},S=({allowReserved:r,explode:t,name:e,style:i,value:o})=>{if(!t){let a=(r?o:o.map(u=>encodeURIComponent(u))).join(Q(i));switch(i){case "label":return `.${a}`;case "matrix":return `;${e}=${a}`;case "simple":return a;default:return `${e}=${a}`}}let n=N(i),s=o.map(a=>i==="label"||i==="simple"?r?a:encodeURIComponent(a):p({allowReserved:r,name:e,value:a})).join(n);return i==="label"||i==="matrix"?n+s:s},p=({allowReserved:r,name:t,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 `${t}=${r?e:encodeURIComponent(e)}`},z=({allowReserved:r,explode:t,name:e,style:i,value:o})=>{if(o instanceof Date)return `${e}=${o.toISOString()}`;if(i!=="deepObject"&&!t){let a=[];Object.entries(o).forEach(([l,d])=>{a=[...a,l,r?d:encodeURIComponent(d)];});let u=a.join(",");switch(i){case "form":return `${e}=${u}`;case "label":return `.${u}`;case "matrix":return `;${e}=${u}`;default:return u}}let n=V(i),s=Object.entries(o).map(([a,u])=>p({allowReserved:r,name:i==="deepObject"?`${e}[${a}]`:a,value:u})).join(n);return i==="label"||i==="matrix"?n+s:s};var W=/\{[^{}]+\}/g,J=({path:r,url:t})=>{let e=t,i=t.match(W);if(i)for(let o of i){let n=false,s=o.substring(1,o.length-1),a="simple";s.endsWith("*")&&(n=true,s=s.substring(0,s.length-1)),s.startsWith(".")?(s=s.substring(1),a="label"):s.startsWith(";")&&(s=s.substring(1),a="matrix");let u=vue.toValue(vue.toValue(r)[s]);if(u==null)continue;if(Array.isArray(u)){e=e.replace(o,S({explode:n,name:s,style:a,value:u}));continue}if(typeof u=="object"){e=e.replace(o,z({explode:n,name:s,style:a,value:u}));continue}if(a==="matrix"){e=e.replace(o,`;${p({name:s,value:u})}`);continue}let l=encodeURIComponent(a==="label"?`.${u}`:u);e=e.replace(o,l);}return e},v=({allowReserved:r,array:t,object:e}={})=>o=>{let n=[],s=vue.toValue(o);if(s&&typeof s=="object")for(let a in s){let u=vue.toValue(s[a]);if(u!=null){if(Array.isArray(u)){n=[...n,S({allowReserved:r,explode:true,name:a,style:"form",value:u,...t})];continue}if(typeof u=="object"){n=[...n,z({allowReserved:r,explode:true,name:a,style:"deepObject",value:u,...e})];continue}n=[...n,p({allowReserved:r,name:a,value:u})];}}return n.join("&")},B=async({security:r,...t})=>{for(let e of r){let i=await E(e,t.auth);if(!i)continue;let o=e.name??"Authorization";switch(e.in){case "query":t.query||(t.query={}),vue.toValue(t.query)[o]=i;break;case "header":default:t.headers.set(o,i);break}return}},h=r=>M({baseUrl:r.baseURL,path:r.path,query:r.query,querySerializer:typeof r.querySerializer=="function"?r.querySerializer:v(r.querySerializer),url:r.url}),M=({baseUrl:r,path:t,query:e,querySerializer:i,url:o})=>{let n=o.startsWith("/")?o:`/${o}`,s=(r??"")+n;t&&(s=J({path:t,url:s}));let a=e?i(e):"";return a.startsWith("?")&&(a=a.substring(1)),a&&(s+=`?${a}`),s},A=(r,t)=>{let e={...r,...t};return e.baseURL?.endsWith("/")&&(e.baseURL=e.baseURL.substring(0,e.baseURL.length-1)),e.headers=O(r.headers,t.headers),e},O=(...r)=>{let t=new Headers;for(let e of r){if(!e||typeof e!="object")continue;let i=e;vue.isRef(i)&&(i=vue.unref(i));let o=i instanceof Headers?i.entries():Object.entries(i);for(let[n,s]of o)if(s===null)t.delete(n);else if(Array.isArray(s))for(let a of s)t.append(n,y(a));else if(s!==undefined){let a=y(s);t.set(n,typeof a=="object"?JSON.stringify(a):a);}}return t},q=(...r)=>r.reduce((t,e)=>{if(typeof e=="function")t.push(e);else if(Array.isArray(e))return t.concat(e);return t},[]),_=v({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),K={"Content-Type":"application/json"},w=(r={})=>({...C,headers:K,querySerializer:_,...r}),y=r=>{if(r===null||typeof r!="object"||r instanceof Headers)return vue.isRef(r)?vue.unref(r):r;if(Array.isArray(r))return r.map(e=>y(e));if(vue.isRef(r))return y(vue.unref(r));let t={};for(let e in r)t[e]=y(r[e]);return t},b=r=>r.body&&r.bodySerializer?r.bodySerializer(r.body):r.body,P=(r,t)=>{let e=y(r);return e.body=b(e),t(h(r),e)};var re=(r={})=>{let t=A(w(),r),e=()=>({...t}),i=n=>(t=A(t,n),e()),o=({asyncDataOptions:n,composable:s,key:a,...u})=>{let l={...t,...u,$fetch:u.$fetch??t.$fetch??$fetch,headers:O(t.headers,u.headers),onRequest:q(t.onRequest,u.onRequest),onResponse:q(t.onResponse,u.onResponse)},{responseTransformer:d,responseValidator:R,security:j}=l;j&&(l.onRequest=[async({options:c})=>{await B({auth:l.auth,headers:c.headers,query:c.query,security:j});},...l.onRequest]),(d||R)&&(l.onResponse=[...l.onResponse,async({options:c,response:f})=>{c.responseType&&c.responseType!=="json"||f.ok&&(R&&await R(f._data),d&&(f._data=await d(f._data)));}]),l.body||l.headers.delete("Content-Type");let $=l.$fetch;if(s==="$fetch")return P(l,$);if(s==="useFetch"||s==="useLazyFetch"){let c=vue.reactive({body:l.body,bodySerializer:l.bodySerializer}),f=vue.ref(b(l));return l.body=f,vue.watch(c,D=>{f.value=b(D);}),s==="useLazyFetch"?app.useLazyFetch(()=>h(l),l):app.useFetch(()=>h(l),l)}let g=()=>P(l,$);if(s==="useAsyncData")return a?app.useAsyncData(a,g,n):app.useAsyncData(g,n);if(s==="useLazyAsyncData")return a?app.useLazyAsyncData(a,g,n):app.useLazyAsyncData(g,n)};return {buildUrl:h,connect:n=>o({...n,method:"CONNECT"}),delete:n=>o({...n,method:"DELETE"}),get:n=>o({...n,method:"GET"}),getConfig:e,head:n=>o({...n,method:"HEAD"}),options:n=>o({...n,method:"OPTIONS"}),patch:n=>o({...n,method:"PATCH"}),post:n=>o({...n,method:"POST"}),put:n=>o({...n,method:"PUT"}),request:o,setConfig:i,trace:n=>o({...n,method:"TRACE"})}};exports.createClient=re;exports.createConfig=w;exports.formDataBodySerializer=F;exports.jsonBodySerializer=C;exports.urlSearchParamsBodySerializer=I;//# sourceMappingURL=index.cjs.map +'use strict';var app=require('nuxt/app'),vue=require('vue');var E=async(r,t)=>{let e=typeof t=="function"?await t(r):t;if(e)return r.scheme==="bearer"?`Bearer ${e}`:r.scheme==="basic"?`Basic ${btoa(e)}`:e},U=(r,t,e)=>{typeof e=="string"||e instanceof Blob?r.append(t,e):r.append(t,JSON.stringify(e));},k=(r,t,e)=>{typeof e=="string"?r.append(t,e):r.append(t,JSON.stringify(e));},F={bodySerializer:r=>{let t=new FormData;return Object.entries(r).forEach(([e,i])=>{i!=null&&(Array.isArray(i)?i.forEach(o=>U(t,e,o)):U(t,e,i));}),t}},C={bodySerializer:r=>JSON.stringify(r,(t,e)=>typeof e=="bigint"?e.toString():e)},I={bodySerializer:r=>{let t=new URLSearchParams;return Object.entries(r).forEach(([e,i])=>{i!=null&&(Array.isArray(i)?i.forEach(o=>k(t,e,o)):k(t,e,i));}),t.toString()}},N=r=>{switch(r){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},Q=r=>{switch(r){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},V=r=>{switch(r){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},S=({allowReserved:r,explode:t,name:e,style:i,value:o})=>{if(!t){let a=(r?o:o.map(u=>encodeURIComponent(u))).join(Q(i));switch(i){case "label":return `.${a}`;case "matrix":return `;${e}=${a}`;case "simple":return a;default:return `${e}=${a}`}}let n=N(i),s=o.map(a=>i==="label"||i==="simple"?r?a:encodeURIComponent(a):p({allowReserved:r,name:e,value:a})).join(n);return i==="label"||i==="matrix"?n+s:s},p=({allowReserved:r,name:t,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 `${t}=${r?e:encodeURIComponent(e)}`},z=({allowReserved:r,explode:t,name:e,style:i,value:o})=>{if(o instanceof Date)return `${e}=${o.toISOString()}`;if(i!=="deepObject"&&!t){let a=[];Object.entries(o).forEach(([l,d])=>{a=[...a,l,r?d:encodeURIComponent(d)];});let u=a.join(",");switch(i){case "form":return `${e}=${u}`;case "label":return `.${u}`;case "matrix":return `;${e}=${u}`;default:return u}}let n=V(i),s=Object.entries(o).map(([a,u])=>p({allowReserved:r,name:i==="deepObject"?`${e}[${a}]`:a,value:u})).join(n);return i==="label"||i==="matrix"?n+s:s};var W=/\{[^{}]+\}/g,J=({path:r,url:t})=>{let e=t,i=t.match(W);if(i)for(let o of i){let n=false,s=o.substring(1,o.length-1),a="simple";s.endsWith("*")&&(n=true,s=s.substring(0,s.length-1)),s.startsWith(".")?(s=s.substring(1),a="label"):s.startsWith(";")&&(s=s.substring(1),a="matrix");let u=vue.toValue(vue.toValue(r)[s]);if(u==null)continue;if(Array.isArray(u)){e=e.replace(o,S({explode:n,name:s,style:a,value:u}));continue}if(typeof u=="object"){e=e.replace(o,z({explode:n,name:s,style:a,value:u}));continue}if(a==="matrix"){e=e.replace(o,`;${p({name:s,value:u})}`);continue}let l=encodeURIComponent(a==="label"?`.${u}`:u);e=e.replace(o,l);}return e},v=({allowReserved:r,array:t,object:e}={})=>o=>{let n=[],s=vue.toValue(o);if(s&&typeof s=="object")for(let a in s){let u=vue.toValue(s[a]);if(u!=null){if(Array.isArray(u)){n=[...n,S({allowReserved:r,explode:true,name:a,style:"form",value:u,...t})];continue}if(typeof u=="object"){n=[...n,z({allowReserved:r,explode:true,name:a,style:"deepObject",value:u,...e})];continue}n=[...n,p({allowReserved:r,name:a,value:u})];}}return n.join("&")},B=async({security:r,...t})=>{for(let e of r){let i=await E(e,t.auth);if(!i)continue;let o=e.name??"Authorization";switch(e.in){case "query":t.query||(t.query={}),vue.toValue(t.query)[o]=i;break;case "header":default:t.headers.set(o,i);break}return}},h=r=>M({baseUrl:r.baseURL,path:r.path,query:r.query,querySerializer:typeof r.querySerializer=="function"?r.querySerializer:v(r.querySerializer),url:r.url}),M=({baseUrl:r,path:t,query:e,querySerializer:i,url:o})=>{let n=o.startsWith("/")?o:`/${o}`,s=(r??"")+n;t&&(s=J({path:t,url:s}));let a=e?i(e):"";return a.startsWith("?")&&(a=a.substring(1)),a&&(s+=`?${a}`),s},A=(r,t)=>{let e={...r,...t};return e.baseURL?.endsWith("/")&&(e.baseURL=e.baseURL.substring(0,e.baseURL.length-1)),e.headers=O(r.headers,t.headers),e},O=(...r)=>{let t=new Headers;for(let e of r){if(!e||typeof e!="object")continue;let i=e;vue.isRef(i)&&(i=vue.unref(i));let o=i instanceof Headers?i.entries():Object.entries(i);for(let[n,s]of o)if(s===null)t.delete(n);else if(Array.isArray(s))for(let a of s)t.append(n,y(a));else if(s!==undefined){let a=y(s);t.set(n,typeof a=="object"?JSON.stringify(a):a);}}return t},q=(...r)=>r.reduce((t,e)=>{if(typeof e=="function")t.push(e);else if(Array.isArray(e))return t.concat(e);return t},[]),_=v({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),K={"Content-Type":"application/json"},w=(r={})=>({...C,headers:K,querySerializer:_,...r}),y=r=>{if(r===null||typeof r!="object"||r instanceof Headers)return vue.isRef(r)?vue.unref(r):r;if(Array.isArray(r))return r.map(e=>y(e));if(vue.isRef(r))return y(vue.unref(r));let t={};for(let e in r)t[e]=y(r[e]);return t},g=r=>r.body&&r.bodySerializer?r.bodySerializer(r.body):r.body,P=(r,t)=>{let e=y(r);return e.body=g(e),t(h(r),e)};var re=(r={})=>{let t=A(w(),r),e=()=>({...t}),i=n=>(t=A(t,n),e()),o=({asyncDataOptions:n,composable:s,key:a,...u})=>{let l={...t,...u,$fetch:u.$fetch??t.$fetch??$fetch,headers:O(t.headers,u.headers),onRequest:q(t.onRequest,u.onRequest),onResponse:q(t.onResponse,u.onResponse)},{responseTransformer:d,responseValidator:R,security:j}=l;j&&(l.onRequest=[async({options:c})=>{await B({auth:l.auth,headers:c.headers,query:c.query,security:j});},...l.onRequest]),(d||R)&&(l.onResponse=[...l.onResponse,async({options:c,response:f})=>{c.responseType&&c.responseType!=="json"||f.ok&&(R&&await R(f._data),d&&(f._data=await d(f._data)));}]),(l.body===undefined||l.body==="")&&l.headers.delete("Content-Type");let $=l.$fetch;if(s==="$fetch")return P(l,$);if(s==="useFetch"||s==="useLazyFetch"){let c=vue.reactive({body:l.body,bodySerializer:l.bodySerializer}),f=vue.ref(g(l));return l.body=f,vue.watch(c,D=>{f.value=g(D);}),s==="useLazyFetch"?app.useLazyFetch(()=>h(l),l):app.useFetch(()=>h(l),l)}let b=()=>P(l,$);if(s==="useAsyncData")return a?app.useAsyncData(a,b,n):app.useAsyncData(b,n);if(s==="useLazyAsyncData")return a?app.useLazyAsyncData(a,b,n):app.useLazyAsyncData(b,n)};return {buildUrl:h,connect:n=>o({...n,method:"CONNECT"}),delete:n=>o({...n,method:"DELETE"}),get:n=>o({...n,method:"GET"}),getConfig:e,head:n=>o({...n,method:"HEAD"}),options:n=>o({...n,method:"OPTIONS"}),patch:n=>o({...n,method:"PATCH"}),post:n=>o({...n,method:"POST"}),put:n=>o({...n,method:"PUT"}),request:o,setConfig:i,trace:n=>o({...n,method:"TRACE"})}};exports.createClient=re;exports.createConfig=w;exports.formDataBodySerializer=F;exports.jsonBodySerializer=C;exports.urlSearchParamsBodySerializer=I;//# sourceMappingURL=index.cjs.map //# sourceMappingURL=index.cjs.map \ No newline at end of file From b8cc9f8a5eaf4f4ff345abc49c14c6b96744c2ea Mon Sep 17 00:00:00 2001 From: Lubos Date: Thu, 27 Feb 2025 09:37:11 +0000 Subject: [PATCH 3/3] Create brave-beds-walk.md --- .changeset/brave-beds-walk.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/brave-beds-walk.md diff --git a/.changeset/brave-beds-walk.md b/.changeset/brave-beds-walk.md new file mode 100644 index 000000000..14b7039f5 --- /dev/null +++ b/.changeset/brave-beds-walk.md @@ -0,0 +1,7 @@ +--- +"@hey-api/client-fetch": patch +"@hey-api/client-next": patch +"@hey-api/client-nuxt": patch +--- + +fix: dropping Content-Type header with falsey but valid json body