fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #1850 from kelnos/apikey-cookie-support

feat: add support for cookies auth

authored by

Lubos and committed by
GitHub
092215c1 2797d6c0

+209 -22
+10
.changeset/silent-camels-explain.md
··· 1 + --- 2 + "@hey-api/client-axios": patch 3 + "@hey-api/client-core": patch 4 + "@hey-api/client-fetch": patch 5 + "@hey-api/client-next": patch 6 + "@hey-api/client-nuxt": patch 7 + "@hey-api/openapi-ts": patch 8 + --- 9 + 10 + feat: add support for cookies auth
+21
packages/client-axios/src/__tests__/utils.test.ts
··· 90 90 expect(query).toEqual({}); 91 91 }); 92 92 93 + it('sets an API key in a cookie', async () => { 94 + const auth = vi.fn().mockReturnValue('foo'); 95 + const headers: Record<any, unknown> = {}; 96 + const query: Record<any, unknown> = {}; 97 + await setAuthParams({ 98 + auth, 99 + headers, 100 + query, 101 + security: [ 102 + { 103 + in: 'cookie', 104 + name: 'baz', 105 + type: 'apiKey', 106 + }, 107 + ], 108 + }); 109 + expect(auth).toHaveBeenCalled(); 110 + expect(headers.Cookie).toBe('baz=foo'); 111 + expect(query).toEqual({}); 112 + }); 113 + 93 114 it('sets first scheme only', async () => { 94 115 const auth = vi.fn().mockReturnValue('foo'); 95 116 const headers: Record<any, unknown> = {};
+9
packages/client-axios/src/utils.ts
··· 171 171 } 172 172 options.query[name] = token; 173 173 break; 174 + case 'cookie': { 175 + const value = `${name}=${token}`; 176 + if ('Cookie' in options.headers && options.headers['Cookie']) { 177 + options.headers['Cookie'] = `${options.headers['Cookie']}; ${value}`; 178 + } else { 179 + options.headers['Cookie'] = value; 180 + } 181 + break; 182 + } 174 183 case 'header': 175 184 default: 176 185 options.headers[name] = token;
+1 -1
packages/client-core/src/auth.ts
··· 6 6 * 7 7 * @default 'header' 8 8 */ 9 - in?: 'header' | 'query'; 9 + in?: 'header' | 'query' | 'cookie'; 10 10 /** 11 11 * Header or query parameter name. 12 12 *
+21
packages/client-fetch/src/__tests__/utils.test.ts
··· 186 186 expect(headers.get('baz')).toBeNull(); 187 187 expect(query.baz).toBe('Bearer foo'); 188 188 }); 189 + 190 + it('sets an API key in a cookie', async () => { 191 + const auth = vi.fn().mockReturnValue('foo'); 192 + const headers = new Headers(); 193 + const query: Record<any, unknown> = {}; 194 + await setAuthParams({ 195 + auth, 196 + headers, 197 + query, 198 + security: [ 199 + { 200 + in: 'cookie', 201 + name: 'baz', 202 + type: 'apiKey', 203 + }, 204 + ], 205 + }); 206 + expect(auth).toHaveBeenCalled(); 207 + expect(headers.get('Cookie')).toBe('baz=foo'); 208 + expect(query).toEqual({}); 209 + }); 189 210 });
+3
packages/client-fetch/src/utils.ts
··· 217 217 } 218 218 options.query[name] = token; 219 219 break; 220 + case 'cookie': 221 + options.headers.append('Cookie', `${name}=${token}`); 222 + break; 220 223 case 'header': 221 224 default: 222 225 options.headers.set(name, token);
+21
packages/client-next/src/__tests__/utils.test.ts
··· 186 186 expect(headers.get('baz')).toBeNull(); 187 187 expect(query.baz).toBe('Bearer foo'); 188 188 }); 189 + 190 + it('sets an API key in a cookie', async () => { 191 + const auth = vi.fn().mockReturnValue('foo'); 192 + const headers = new Headers(); 193 + const query: Record<any, unknown> = {}; 194 + await setAuthParams({ 195 + auth, 196 + headers, 197 + query, 198 + security: [ 199 + { 200 + in: 'cookie', 201 + name: 'baz', 202 + type: 'apiKey', 203 + }, 204 + ], 205 + }); 206 + expect(auth).toHaveBeenCalled(); 207 + expect(headers.get('Cookie')).toBe('baz=foo'); 208 + expect(query).toEqual({}); 209 + }); 189 210 });
+3
packages/client-next/src/utils.ts
··· 217 217 } 218 218 options.query[name] = token; 219 219 break; 220 + case 'cookie': 221 + options.headers.append('Cookie', `${name}=${token}`); 222 + break; 220 223 case 'header': 221 224 default: 222 225 options.headers.set(name, token);
+3
packages/client-nuxt/src/utils.ts
··· 178 178 } 179 179 toValue(options.query)[name] = token; 180 180 break; 181 + case 'cookie': 182 + options.headers.append('Cookie', `${name}=${token}`); 183 + break; 181 184 case 'header': 182 185 default: 183 186 options.headers.set(name, token);
+5 -3
packages/openapi-ts/src/plugins/@hey-api/sdk/plugin.ts
··· 37 37 * 38 38 * @default 'header' 39 39 */ 40 - in?: 'header' | 'query'; 40 + in?: 'header' | 'query' | 'cookie'; 41 41 /** 42 42 * Header or query parameter name. 43 43 * ··· 175 175 }; 176 176 } 177 177 178 - // TODO: parser - support cookies auth 179 - if (securitySchemeObject.in === 'query') { 178 + if ( 179 + securitySchemeObject.in === 'query' || 180 + securitySchemeObject.in == 'cookie' 181 + ) { 180 182 return { 181 183 in: securitySchemeObject.in, 182 184 name: securitySchemeObject.name,
+16 -2
packages/openapi-ts/test/__snapshots__/3.0.x/security-api-key/sdk.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 3 import type { Options as ClientOptions, TDataShape, Client } from '@hey-api/client-fetch'; 4 - import type { GetFooData } from './types.gen'; 4 + import type { GetFooData, GetBarData } from './types.gen'; 5 5 import { client as _heyApiClient } from './client.gen'; 6 6 7 7 export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = ClientOptions<TData, ThrowOnError> & { ··· 30 30 url: '/foo', 31 31 ...options 32 32 }); 33 - }; 33 + }; 34 + 35 + export const getBar = <ThrowOnError extends boolean = false>(options?: Options<GetBarData, ThrowOnError>) => { 36 + return (options?.client ?? _heyApiClient).get<unknown, unknown, ThrowOnError>({ 37 + security: [ 38 + { 39 + in: 'cookie', 40 + name: 'bar', 41 + type: 'apiKey' 42 + } 43 + ], 44 + url: '/bar', 45 + ...options 46 + }); 47 + };
+15 -1
packages/openapi-ts/test/__snapshots__/3.0.x/security-api-key/types.gen.ts
··· 14 14 200: unknown; 15 15 }; 16 16 17 + export type GetBarData = { 18 + body?: never; 19 + path?: never; 20 + query?: never; 21 + url: '/bar'; 22 + }; 23 + 24 + export type GetBarResponses = { 25 + /** 26 + * OK 27 + */ 28 + 200: unknown; 29 + }; 30 + 17 31 export type ClientOptions = { 18 32 baseUrl: `${string}://${string}` | (string & {}); 19 - }; 33 + };
+2 -2
packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/bundle/client/index.cjs
··· 1 - 'use strict';var B=require('axios');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var B__default=/*#__PURE__*/_interopDefault(B);var w=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));},O=(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=>O(r,e,a)):O(r,e,i));}),r.toString()}},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 T=/\{[^{}]+\}/g,E=({path:t,url:r})=>{let e=r,i=r.match(T);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("&")},A=async({security:t,...r})=>{for(let e of t){let i=await w(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=E({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={})=>({...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 A({...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,...R}=u,C=await m({...R,baseURL:u.baseURL,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 2 - //# 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 w=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));},O=(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}},k={bodySerializer:t=>JSON.stringify(t,(e,r)=>typeof r=="bigint"?r.toString():r)},$={bodySerializer:t=>{let e=new URLSearchParams;return Object.entries(t).forEach(([r,i])=>{i!=null&&(Array.isArray(i)?i.forEach(a=>O(e,r,a)):O(e,r,i));}),e.toString()}},q=t=>{switch(t){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},v=t=>{switch(t){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},P=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(s=>encodeURIComponent(s))).join(v(i));switch(i){case "label":return `.${n}`;case "matrix":return `;${r}=${n}`;case "simple":return n;default:return `${r}=${n}`}}let o=q(i),l=a.map(n=>i==="label"||i==="simple"?t?n:encodeURIComponent(n):f({allowReserved:t,name:r,value:n})).join(o);return i==="label"||i==="matrix"?o+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 s=n.join(",");switch(i){case "form":return `${r}=${s}`;case "label":return `.${s}`;case "matrix":return `;${r}=${s}`;default:return s}}let o=P(i),l=Object.entries(a).map(([n,s])=>f({allowReserved:t,name:i==="deepObject"?`${r}[${n}]`:n,value:s})).join(o);return i==="label"||i==="matrix"?o+l:l};var T=/\{[^{}]+\}/g,E=({path:t,url:e})=>{let r=e,i=e.match(T);if(i)for(let a of i){let o=false,l=a.substring(1,a.length-1),n="simple";l.endsWith("*")&&(o=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 s=t[l];if(s==null)continue;if(Array.isArray(s)){r=r.replace(a,h({explode:o,name:l,style:n,value:s}));continue}if(typeof s=="object"){r=r.replace(a,g({explode:o,name:l,style:n,value:s}));continue}if(n==="matrix"){r=r.replace(a,`;${f({name:l,value:s})}`);continue}let u=encodeURIComponent(n==="label"?`.${s}`:s);r=r.replace(a,u);}return r},U=({allowReserved:t,array:e,object:r}={})=>a=>{let o=[];if(a&&typeof a=="object")for(let l in a){let n=a[l];if(n!=null){if(Array.isArray(n)){o=[...o,h({allowReserved:t,explode:true,name:l,style:"form",value:n,...e})];continue}if(typeof n=="object"){o=[...o,g({allowReserved:t,explode:true,name:l,style:"deepObject",value:n,...r})];continue}o=[...o,f({allowReserved:t,name:l,value:n})];}}return o.join("&")},A=async({security:t,...e})=>{for(let r of t){let i=await w(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 "cookie":{let o=`${a}=${i}`;"Cookie"in e.headers&&e.headers.Cookie?e.headers.Cookie=`${e.headers.Cookie}; ${o}`:e.headers.Cookie=o;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 o=i.startsWith("/")?i:`/${i}`;t&&(o=E({path:t,url:o}));let l=e?r(e):"";return l.startsWith("?")&&(l=l.substring(1)),l&&(o+=`?${l}`),o},C=(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,o]of i)if(H.includes(a)&&typeof o=="object")e[a]={...e[a],...o};else if(o===null)delete e[a];else if(Array.isArray(o))for(let l of o)e[a]=[...e[a]??[],l];else o!==undefined&&(e[a]=typeof o=="object"?JSON.stringify(o):o);}return e},S=(t={})=>({...t});var I=(t={})=>{let e=C(S(),t),{auth:r,...i}=e,a=B__default.default.create(i),o=()=>({...e}),l=s=>(e=C(e,s),a.defaults={...a.defaults,...e,headers:y(a.defaults.headers,e.headers)},o()),n=async s=>{let u={...e,...s,axios:s.axios??e.axios??a,headers:y(e.headers,s.headers)};u.security&&await A({...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,...R}=u,x=await m({...R,baseURL:u.baseURL,data:u.body,headers:u.headers,params:u.paramsSerializer?u.query:void 0,url:d}),{data:p}=x;return u.responseType==="json"&&(u.responseValidator&&await u.responseValidator(p),u.responseTransformer&&(p=await u.responseTransformer(p))),{...x,data:p??{}}}catch(m){let c=m;if(u.throwOnError)throw c;return c.error=c.response?.data??{},c}};return {buildUrl:b,delete:s=>n({...s,method:"DELETE"}),get:s=>n({...s,method:"GET"}),getConfig:o,head:s=>n({...s,method:"HEAD"}),instance:a,options:s=>n({...s,method:"OPTIONS"}),patch:s=>n({...s,method:"PATCH"}),post:s=>n({...s,method:"POST"}),put:s=>n({...s,method:"PUT"}),request:n,setConfig:l}};exports.createClient=I;exports.createConfig=S;exports.formDataBodySerializer=j;exports.jsonBodySerializer=k;exports.urlSearchParamsBodySerializer=$;//# sourceMappingURL=index.cjs.map 2 + //# sourceMappingURL=index.cjs.map
+1 -1
packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/bundle/client/index.d.cts
··· 7 7 * 8 8 * @default 'header' 9 9 */ 10 - in?: 'header' | 'query'; 10 + in?: 'header' | 'query' | 'cookie'; 11 11 /** 12 12 * Header or query parameter name. 13 13 *
+1 -1
packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/bundle/client/index.d.ts
··· 7 7 * 8 8 * @default 'header' 9 9 */ 10 - in?: 'header' | 'query'; 10 + in?: 'header' | 'query' | 'cookie'; 11 11 /** 12 12 * Header or query parameter name. 13 13 *
+2 -2
packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.cjs
··· 1 - '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 2 - //# sourceMappingURL=index.cjs.map 1 + '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}},R={bodySerializer:t=>JSON.stringify(t,(r,e)=>typeof e=="bigint"?e.toString():e)},$={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 "cookie":r.headers.append("Cookie",`${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},h=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 h,request:new h,response:new h}),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 k=s.fetch,c=await k(u);for(let p of i.response._fns)c=await p(c,u,s);let m={request:u,response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return {data:{},...m};let p=(s.parseAs==="auto"?P(c.headers.get("Content-Type")):s.parseAs)??"json";if(p==="stream")return {data:c.body,...m};let b=await c[p]();return p==="json"&&(s.responseValidator&&await s.responseValidator(b),s.responseTransformer&&(b=await s.responseTransformer(b))),{data:b,...m}}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,...m}};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=v;exports.jsonBodySerializer=R;exports.urlSearchParamsBodySerializer=$;//# sourceMappingURL=index.cjs.map 2 + //# sourceMappingURL=index.cjs.map
+1 -1
packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.d.cts
··· 5 5 * 6 6 * @default 'header' 7 7 */ 8 - in?: 'header' | 'query'; 8 + in?: 'header' | 'query' | 'cookie'; 9 9 /** 10 10 * Header or query parameter name. 11 11 *
+1 -1
packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.d.ts
··· 5 5 * 6 6 * @default 'header' 7 7 */ 8 - in?: 'header' | 'query'; 8 + in?: 'header' | 'query' | 'cookie'; 9 9 /** 10 10 * Header or query parameter name. 11 11 *
+2 -2
packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-next/bundle/client/index.cjs
··· 1 - '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 2 - //# sourceMappingURL=index.cjs.map 1 + '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()}},k=s=>{switch(s){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},$=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($(a));switch(a){case "label":return `.${t}`;case "matrix":return `;${e}=${t}`;case "simple":return t;default:return `${e}=${t}`}}let o=k(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 "cookie":r.headers.append("Cookie",`${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 h={response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return {data:{},...h};let u=(t.parseAs==="auto"?E(c.headers.get("Content-Type")):t.parseAs)??"json";if(u==="stream")return {data:c.body,...h};let g=await c[u]();return u==="json"&&(t.responseValidator&&await t.responseValidator(g),t.responseTransformer&&(g=await t.responseTransformer(g))),{data:g,...h}}let m=await c.text();try{m=JSON.parse(m);}catch{}let f=m;for(let u of i.error._fns)f=await u(m,c,t);if(f=f||{},t.throwOnError)throw f;return {error:f,...h}};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 2 + //# sourceMappingURL=index.cjs.map
+1 -1
packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-next/bundle/client/index.d.cts
··· 5 5 * 6 6 * @default 'header' 7 7 */ 8 - in?: 'header' | 'query'; 8 + in?: 'header' | 'query' | 'cookie'; 9 9 /** 10 10 * Header or query parameter name. 11 11 *
+1 -1
packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-next/bundle/client/index.d.ts
··· 5 5 * 6 6 * @default 'header' 7 7 */ 8 - in?: 'header' | 'query'; 8 + in?: 'header' | 'query' | 'cookie'; 9 9 /** 10 10 * Header or query parameter name. 11 11 *
+16 -2
packages/openapi-ts/test/__snapshots__/3.1.x/security-api-key/sdk.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 3 import type { Options as ClientOptions, TDataShape, Client } from '@hey-api/client-fetch'; 4 - import type { GetFooData } from './types.gen'; 4 + import type { GetFooData, GetBarData } from './types.gen'; 5 5 import { client as _heyApiClient } from './client.gen'; 6 6 7 7 export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = ClientOptions<TData, ThrowOnError> & { ··· 30 30 url: '/foo', 31 31 ...options 32 32 }); 33 - }; 33 + }; 34 + 35 + export const getBar = <ThrowOnError extends boolean = false>(options?: Options<GetBarData, ThrowOnError>) => { 36 + return (options?.client ?? _heyApiClient).get<unknown, unknown, ThrowOnError>({ 37 + security: [ 38 + { 39 + in: 'cookie', 40 + name: 'bar', 41 + type: 'apiKey' 42 + } 43 + ], 44 + url: '/bar', 45 + ...options 46 + }); 47 + };
+15 -1
packages/openapi-ts/test/__snapshots__/3.1.x/security-api-key/types.gen.ts
··· 14 14 200: unknown; 15 15 }; 16 16 17 + export type GetBarData = { 18 + body?: never; 19 + path?: never; 20 + query?: never; 21 + url: '/bar'; 22 + }; 23 + 24 + export type GetBarResponses = { 25 + /** 26 + * OK 27 + */ 28 + 200: unknown; 29 + }; 30 + 17 31 export type ClientOptions = { 18 32 baseUrl: `${string}://${string}` | (string & {}); 19 - }; 33 + };
+19
packages/openapi-ts/test/spec/3.0.x/security-api-key.json
··· 18 18 } 19 19 ] 20 20 } 21 + }, 22 + "/bar": { 23 + "get": { 24 + "responses": { 25 + "200": { 26 + "description": "OK" 27 + } 28 + }, 29 + "security": [ 30 + { 31 + "bar": [] 32 + } 33 + ] 34 + } 21 35 } 22 36 }, 23 37 "components": { ··· 25 39 "foo": { 26 40 "in": "query", 27 41 "name": "foo", 42 + "type": "apiKey" 43 + }, 44 + "bar": { 45 + "in": "cookie", 46 + "name": "bar", 28 47 "type": "apiKey" 29 48 } 30 49 }
+19
packages/openapi-ts/test/spec/3.1.x/security-api-key.json
··· 18 18 } 19 19 ] 20 20 } 21 + }, 22 + "/bar": { 23 + "get": { 24 + "responses": { 25 + "200": { 26 + "description": "OK" 27 + } 28 + }, 29 + "security": [ 30 + { 31 + "bar": [] 32 + } 33 + ] 34 + } 21 35 } 22 36 }, 23 37 "components": { ··· 25 39 "foo": { 26 40 "in": "query", 27 41 "name": "foo", 42 + "type": "apiKey" 43 + }, 44 + "bar": { 45 + "in": "cookie", 46 + "name": "bar", 28 47 "type": "apiKey" 29 48 } 30 49 }