openapi-sync 5.0.2 → 5.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +331 -329
- package/dist/index.mjs +281 -279
- package/package.json +1 -1
- /package/dist/{interactive-init-GU7WCWDC.mjs → interactive-init-GI3DBKYN.mjs} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,91 +1,93 @@
|
|
|
1
|
-
import {c,d,a,b}from'./chunk-PUWCZVB7.mjs';import
|
|
2
|
-
`+" ".repeat(
|
|
1
|
+
import {c,d,a,b}from'./chunk-PUWCZVB7.mjs';import ie from'fs';import J from'path';import*as Te from'js-yaml';import yn from'lodash.isequal';import Ge from'lodash.get';import gn from'axios';import hn from'axios-retry';import $n from'@apidevtools/swagger-parser';import {CurlGenerator}from'curl-generator';var wn=/^[A-Za-z_$][A-Za-z0-9_$]*$/,Wt=/[A-Za-z0-9_$]/;var Kt=l=>["object"].includes(typeof l)&&!(l instanceof Blob),cn=l=>{try{return Te.load(l),!0}catch(o){let p=o;if(p instanceof Te.YAMLException)return false;throw p}},_t=l=>{if(cn(l)){let o=Te.load(l),p=JSON.stringify(o,null,2);return JSON.parse(p)}},ue=l=>l.substring(0,1).toUpperCase()+l.substring(1),Vt=(l,o)=>{let p=l.split("/"),e=`${ue(o)}`,s=[];return p.forEach(t=>{if(t[0]==="{"&&t[t.length-1]==="}"){let n=t.replace(/{/,"").replace(/}/,"");s.push(n),t=`$${n}`;}else if(t[0]==="<"&&t[t.length-1]===">"){let n=t.replace(/</,"").replace(/>/,"");s.push(n),t=`$${n}`;}else if(t[0]===":"){let n=t.replace(/:/,"");s.push(n),t=`$${n}`;}let i="";t.split("").forEach(n=>{let g=n;Wt.test(n)||(g="/"),i+=g;}),i.split("/").forEach(n=>{e+=ue(n);});}),{name:e,variables:s,pathParts:p}},Ee=(l,o=1)=>{let p="{",e=Object.keys(l);for(let s=0;s<e.length;s++){let t=e[s],i=l[t];if(p+=`
|
|
2
|
+
`+" ".repeat(o)+t+": ",Array.isArray(i)){p+="[";for(let n=0;n<i.length;n++){let g=i[n];typeof g=="object"&&g!==null?p+=Ee(g,o+1):p+=typeof g=="string"?`"${g}"`:g,n<i.length-1&&(p+=", ");}p+="]";}else typeof i=="object"&&i!==null?p+=""+Ee(i,o+1):p+=i.split(`
|
|
3
3
|
`).filter(n=>n.trim()!=="").join(`
|
|
4
|
-
${" ".repeat(
|
|
5
|
-
${" ".repeat(
|
|
4
|
+
${" ".repeat(o)}`);s<e.length-1&&(p+=", ");}return p+=`
|
|
5
|
+
${" ".repeat(o-1)}}`,p},ve=(l,o=1)=>{let p=l.replace(/\/\*\*?[\s\S]*?\*\//g,e=>e.replace(/^\/\*\*?\s*/,"").replace(/\s*\*\/$/,"").split(`
|
|
6
|
+
`).map(t=>t.replace(/^\s*\*\s?/,"").trim()).filter(t=>t.length>0).map(t=>`// ${t}`).join(`
|
|
7
|
+
`));return `
|
|
6
8
|
\`\`\`typescript
|
|
7
|
-
${" ".repeat(
|
|
8
|
-
`).filter(
|
|
9
|
-
${" ".repeat(
|
|
10
|
-
|
|
11
|
-
`,
|
|
12
|
-
`).filter(m=>{let f=m.trim();return f.length>0&&!f.startsWith("//")}).join("").length===0?(
|
|
9
|
+
${" ".repeat(o)} ${p.split(`
|
|
10
|
+
`).filter(e=>e.trim()!=="").join(`
|
|
11
|
+
${" ".repeat(o)} `)}
|
|
12
|
+
\`\`\``};function vn(l,o){return o.split(".").reduce((e,s)=>e&&e[s]!==void 0?e[s]:void 0,l)}var dn=(l,o="CUSTOM CODE")=>{let p=`// \u{1F512} ${o} START`,e=`// \u{1F512} ${o} END`,s={beforeGenerated:"",afterGenerated:""},t=0,i=[];for(;t<l.length;){let n=l.indexOf(p,t);if(n===-1)break;let g=l.indexOf(e,n);if(g===-1)break;let m=g+e.length,f=l.substring(m,m+100),O=f.match(/^\s*\n\s*(\/\/ =+)/);if(O){let k=f.indexOf(`
|
|
13
|
+
`,O.index+1);k!==-1?m+=k+1:m+=O[0].length;}let q=n,w=l.substring(Math.max(0,n-200),n).lastIndexOf("// ==========");w!==-1&&(q=Math.max(0,n-200)+w);let A=l.substring(q,m);i.push({start:q,end:m,content:A}),t=m;}return i.length>0&&(l.substring(0,i[0].start).split(`
|
|
14
|
+
`).filter(m=>{let f=m.trim();return f.length>0&&!f.startsWith("//")}).join("").length===0?(s.beforeGenerated=i[0].content,i.length>1&&(s.afterGenerated=i[1].content)):(s.afterGenerated=i[0].content,i.length>1&&!s.beforeGenerated&&(s.beforeGenerated=i[1].content))),s},Ht=(l,o="CUSTOM CODE",p=true)=>{let e=p?`// ${l==="top"?"Add your custom code below this line":"Add your custom code above this line"}
|
|
13
15
|
// This section will be preserved during regeneration
|
|
14
16
|
`:"";return `// ${"=".repeat(60)}
|
|
15
|
-
// \u{1F512} ${
|
|
17
|
+
// \u{1F512} ${o} START
|
|
16
18
|
${e}// ${"=".repeat(60)}
|
|
17
19
|
|
|
18
|
-
// \u{1F512} ${
|
|
19
|
-
// ${"=".repeat(60)}`},
|
|
20
|
-
`)};var
|
|
20
|
+
// \u{1F512} ${o} END
|
|
21
|
+
// ${"=".repeat(60)}`},je=(l,o,p={})=>{let{position:e="bottom",markerText:s="CUSTOM CODE",includeInstructions:t=true}=p,i={beforeGenerated:"",afterGenerated:""};o&&(i=dn(o,s)),!i.beforeGenerated&&!i.afterGenerated&&((e==="top"||e==="both")&&(i.beforeGenerated=Ht("top",s,t)),(e==="bottom"||e==="both")&&(i.afterGenerated=Ht("bottom",s,t)));let n=[];return i.beforeGenerated&&(n.push(i.beforeGenerated),n.push("")),n.push(l),i.afterGenerated&&(n.push(""),n.push(i.afterGenerated)),n.join(`
|
|
22
|
+
`)};var qe=J.join(__dirname,"../","../db.json");ie.existsSync(qe)||ie.writeFileSync(qe,"{}");var Ue={};try{Ue=c(qe);}catch(l){Ue={};}var we=Ue||{},Yt=l=>{ie.writeFileSync(qe,JSON.stringify(l));},Zt=(l,o)=>{we[l]=o,Yt(we);},Xt=l=>we[l],Me=()=>{we={},Yt(we);};var en={},tn=(l,o)=>{en[l]=o;},nn=l=>en[l]||[];var ce=process.cwd(),Ne={},rn=gn.create({timeout:6e4});hn(rn,{retries:20,retryCondition:l=>l.code==="ECONNABORTED"||l.message.includes("Network Error"),retryDelay:l=>l*1e3});var ge=(l,o,p)=>d(null,null,function*(){var i,n,g,m;if(!(((i=p==null?void 0:p.customCode)==null?void 0:i.enabled)!==false)){yield ie.promises.writeFile(l,o);return}let s=null;try{s=yield ie.promises.readFile(l,"utf-8");}catch(f){}let t=je(o,s,{position:((n=p==null?void 0:p.customCode)==null?void 0:n.position)||"bottom",markerText:(g=p==null?void 0:p.customCode)==null?void 0:g.markerText,includeInstructions:(m=p==null?void 0:p.customCode)==null?void 0:m.includeInstructions});yield ie.promises.writeFile(l,t);}),sn=(l,o,p,e)=>d(null,null,function*(){let s=yield bn(l,o,p,e);return e&&!isNaN(e)&&e>0&&(process.env.NODE_ENV&&["production","prod","test","staging"].includes(process.env.NODE_ENV)||(Ne[o]&&clearTimeout(Ne[o]),Ne[o]=setTimeout(()=>{console.info(`\u{1F504} Auto syncing ${o}`),sn(l,o,p,e);},e))),s}),bn=(...l)=>d(null,null,function*(){var le,be,$e,Pe,De,Je,We,He,Ke,_e;let[o,p,e]=l,s=r=>r.startsWith("http://")||r.startsWith("https://"),t;try{if(s(o))t=(yield rn.get(o)).data;else {let r=J.isAbsolute(o)?o:J.join(ce,o);`${r}`,t=yield ie.promises.readFile(r,"utf-8");}}catch(r){console.error(`Failed to load OpenAPI spec for ${p}:`,r);return}if(!t)return;let i=Kt(t)?t:_t(t),n;try{n=yield $n.parse(i);}catch(r){let u=r instanceof Error?r.message:String(r);throw new Error(`Failed to parse OpenAPI spec for ${p}: ${u}`)}let g=J.join((e==null?void 0:e.folder)||"",p),m={},f=r=>{var u,E;if((u=e==null?void 0:e.folderSplit)!=null&&u.customFolder){let $=e.folderSplit.customFolder(r);if($)return $}return (E=e==null?void 0:e.folderSplit)!=null&&E.byTags&&r.tags&&r.tags.length>0?r.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},O=typeof(e==null?void 0:e.server)=="string"?e==null?void 0:e.server:((be=(le=n==null?void 0:n.servers)==null?void 0:le[(e==null?void 0:e.server)||0])==null?void 0:be.url)||"",q=typeof((Pe=($e=e==null?void 0:e.types)==null?void 0:$e.name)==null?void 0:Pe.prefix)=="string"?e==null?void 0:e.types.name.prefix:"I",j=typeof((Je=(De=e==null?void 0:e.endpoints)==null?void 0:De.name)==null?void 0:Je.prefix)=="string"?e==null?void 0:e.endpoints.name.prefix:"",w=(r,u)=>{var $,d;let E=ue(r);if((d=($=e==null?void 0:e.types)==null?void 0:$.name)!=null&&d.format){let y=e==null?void 0:e.types.name.format("shared",{name:r},E);if(y)return `${q}${y}`}return `${q}${E}`},A=(r,u,E,$,d,y=0)=>{let c="",C="",h="";if(u)if(u.$ref)if(u.$ref[0]==="#"){let v=(u.$ref||"").split("/");v.shift();v[0]==="definitions";[...v].pop();let D=Ge(r,v,null);if(D){D!=null&&D.name&&(c=D.name),C=v[v.length-1];let re=w(C);re.includes(".")&&(re=re.split(".").map((de,fe)=>fe===0?de:`["${de}"]`).join("")),h+=`${d!=null&&d.noSharedImport?"":"Shared."}${re}`;}}else h+="";else if(u.anyOf)h+=`(${u.anyOf.map(v=>A(r,v,"",$,b(a({},d),{useComponentName:false}))).filter(v=>!!v).join("|")})`;else if(u.oneOf)h+=`(${u.oneOf.map(v=>A(r,v,"",$,b(a({},d),{useComponentName:false}))).filter(v=>!!v).join("|")})`;else if(u.allOf)h+=`(${u.allOf.map(v=>A(r,v,"",$,b(a({},d),{useComponentName:false}))).filter(v=>!!v).join("&")})`;else if(u.items)h+=`${A(r,u.items,"",false,b(a({},d),{useComponentName:false}))}[]`;else if(u.properties){let v=Object.keys(u.properties),N=u.required||[],F="";v.forEach(z=>{var re,Ce,de,fe,Ie,ye;let D="";!((Ce=(re=e==null?void 0:e.types)==null?void 0:re.doc)!=null&&Ce.disable)&&((fe=(de=u.properties)==null?void 0:de[z])!=null&&fe.description)&&(D=" * "+((Ie=u.properties)==null?void 0:Ie[z].description.split(`
|
|
21
23
|
`).filter(Re=>Re.trim()!=="").join(`
|
|
22
|
-
*${" ".repeat(1)}`))),
|
|
23
|
-
${
|
|
24
|
+
*${" ".repeat(1)}`))),F+=(D?`/**
|
|
25
|
+
${D}
|
|
24
26
|
*/
|
|
25
|
-
`:"")+`${
|
|
26
|
-
${" ".repeat(
|
|
27
|
-
`:""}`:""},
|
|
27
|
+
`:"")+`${A(r,(ye=u.properties)==null?void 0:ye[z],z,N.includes(z),d,y+1)}`;}),F.length>0?h+=`{
|
|
28
|
+
${" ".repeat(y)}${F}${" ".repeat(y)}}`:h+="{[k: string]: any}";}else if(u.enum&&u.enum.length>0){let v=u.enum.includes(null),N=u.enum.filter(z=>z!==null).map(z=>JSON.stringify(z)).filter(z=>z!==void 0),F=N.length>1||N.length>0&&v;F&&(h+="("),N.forEach((z,D)=>{h+=`${D===0?"":"|"}${z}`;}),v&&(h+=`${N.length>0?"|":""}null`),F&&(h+=")");}else if(u.type){let v=N=>{let F="";if(typeof N=="string")["string","integer","number","array","boolean","null"].includes(N)?["integer","number"].includes(N)?F+="number":N==="array"?F+="any[]":F+=N:N==="object"&&(u.additionalProperties?F+=`{[k: string]: ${A(r,u.additionalProperties,"",true,b(a({},d),{useComponentName:false}))||"any"}}`:F+="{[k: string]: any}");else if(Array.isArray(N)){let z=N.map(D=>v(D));z.filter(D=>D!==""),z.length>1&&(F+="("+z.join("|")+")");}else F+="any";return F};h=v(u.type);}else h+="any";else h="string";let P=c||E;d!=null&&d.useComponentName&&!P&&(P=C);let W=P?` "${P}"${$?"":"?"}: `:"",a$1=(u==null?void 0:u.enum)&&u.enum.includes(null),Z=u!=null&&u.nullable&&!a$1?" | null":"";return h.length>0?`${W}${h}${Z}${P?`;
|
|
29
|
+
`:""}`:""},k=(r,u)=>{let d="";if(u)if(u.$ref)if(u.$ref[0]==="#"){let y=(u.$ref||"").split("/");y.shift();let C=Ge(r,y,null);C&&(C!=null&&C.name&&(C.name),y[y.length-1],d+=k(r,C));}else d+="";else if(u.anyOf)d+=k(r,u.anyOf[0]);else if(u.oneOf)d+=k(r,u.oneOf[0]);else if(u.allOf)d+=`{${u.allOf.map(y=>`...(${k(r,y)})`).join(",")}}`;else if(u.items)d+=`[${k(r,u.items)}]`;else if(u.properties){let C=Object.keys(u.properties).map(h=>{var P;return ` "${h}": ${k(r,(P=u.properties)==null?void 0:P[h])}`}).join(`,
|
|
28
30
|
`);C.length>0?d+=`{
|
|
29
31
|
${C}
|
|
30
|
-
}`:d+="{}";}else if(u.enum&&u.enum.length>0)u.enum.length>1&&(d+=u.enum[0]);else if(u.type)if(u.example)d+=JSON.stringify(u.example);else {let
|
|
31
|
-
`).filter(
|
|
32
|
-
*${" ".repeat(1)}`)),
|
|
32
|
+
}`:d+="{}";}else if(u.enum&&u.enum.length>0)u.enum.length>1&&(d+=u.enum[0]);else if(u.type)if(u.example)d+=JSON.stringify(u.example);else {let y=c=>{let C="";if(typeof c=="string")["string","integer","number","array","boolean","null"].includes(c)?["integer","number"].includes(c)?C+="123":c==="array"?C+="[]":c==="boolean"?C+="true":c==="null"?C+="null":C+=`"${c}"`:c==="object"&&(C+="{}");else if(Array.isArray(c)){let h=c.map(P=>y(P));h.filter(P=>P!==""),h.length>1&&(C+=h.join("|"));}else C+="any";return C};d=y(u.type);}else d+="any";else d="string";return d},S=Xt(p);if(yn(S,n))return;Zt(p,n);let H="",T="",b$1={},Y=[],G=(r,u)=>{let E={},$={};Object.keys(r).forEach(y=>{var h;let c=(h=r[y])!=null&&h.schema?r[y].schema:r[y],C=`${A(n,c,"",true,{noSharedImport:true,useComponentName:false})}`;if(C){let P=y.split("."),W=E,a=$;for(let Z=0;Z<P.length;Z++){let v=P[Z];Z<P.length-1?(v in W||(W[v]={},a[v]={}),W=W[v],a=a[v]):(W[v]=C,a[v]=c);}}}),Object.keys(E).forEach(y=>{var P,W,a,Z;let c=w(y),C=E[y],h="";!((W=(P=e==null?void 0:e.types)==null?void 0:P.doc)!=null&&W.disable)&&y in r&&((a=r[y])!=null&&a.description)&&(h=" * "+r[y].description.split(`
|
|
33
|
+
`).filter(v=>v.trim()!=="").join(`
|
|
34
|
+
*${" ".repeat(1)}`)),b$1[y]=((Z=b$1[y])!=null?Z:"")+(h?`/**
|
|
33
35
|
${h}
|
|
34
36
|
*/
|
|
35
37
|
`:"")+"export type "+c+" = "+(typeof C=="string"?C:Ee(C))+`;
|
|
36
|
-
`;});}});let
|
|
38
|
+
`;});};n.definitions&&G(n.definitions),n.components&&Object.keys(n.components).forEach(r=>{if(["schemas","responses","parameters","examples","requestBodies","headers","links","callbacks"].includes(r)){let u=n.components[r];G(u);}});let Q=r=>{let u="";if(r.content){let E=Object.keys(r.content);E[0]&&r.content[E[0]].schema&&(u+=`${A(n,r.content[E[0]].schema,"")}`);}return u},K=(r,u,E=0)=>{if(!r)return u==="joi"?"Joi.any()":u==="yup"?"yup.mixed()":"z.any()";if(r.$ref){if(r.$ref[0]==="#"){let $=r.$ref.split("/");$.shift();let d=$.join("."),y=Ge(n,d);if(y)return K(y,u,E)}return u==="joi"?"Joi.any()":u==="yup"?"yup.mixed()":"z.any()"}if(r.anyOf||r.oneOf){let $=r.anyOf||r.oneOf;if($.every(y=>y.enum!==void 0&&Array.isArray(y.enum))){let y=[],c=false;if($.forEach(C=>{C.enum&&C.enum.forEach(h=>{h===null?c=true:y.includes(h)||y.push(h);});}),y.length>0){let C=y.map(h=>JSON.stringify(h)).join(", ");if(u==="zod"){let h=`z.enum([${C}])`;return c&&(h+=".nullable()"),h}else if(u==="yup"){let h=`yup.mixed().oneOf([${C}])`;return c&&(h+=".nullable()"),h}else return c?`Joi.valid(${C}, null)`:`Joi.valid(${C})`}else if(c)return u==="zod"?"z.null()":u==="yup"?"yup.mixed().nullable()":"Joi.valid(null)"}return u==="zod"?`z.union([${$.map(C=>K(C,u,E+1)).join(", ")}])`:u==="yup"?`yup.mixed().oneOf([${$.map(C=>K(C,u,E+1)).join(", ")}])`:`Joi.alternatives().try(${$.map(c=>K(c,u,E+1)).join(", ")})`}if(r.allOf)if(u==="zod"){let $=r.allOf.map(y=>K(y,u,E+1)),d=$[0];for(let y=1;y<$.length;y++)d=`${d}.merge(${$[y]})`;return d}else return K(r.allOf[0],u,E+1);if(r.items){let $=K(r.items,u,E+1);if(u==="zod"){let d=`z.array(${$})`;return r.minItems!==void 0&&(d+=`.min(${r.minItems})`),r.maxItems!==void 0&&(d+=`.max(${r.maxItems})`),d}else if(u==="yup"){let d=`yup.array().of(${$})`;return r.minItems!==void 0&&(d+=`.min(${r.minItems})`),r.maxItems!==void 0&&(d+=`.max(${r.maxItems})`),d}else {let d=`Joi.array().items(${$})`;return r.minItems!==void 0&&(d+=`.min(${r.minItems})`),r.maxItems!==void 0&&(d+=`.max(${r.maxItems})`),d}}if(r.properties){let $=r.required||[],d=" ".repeat(E+1),y=Object.entries(r.properties).map(([c,C])=>{let h=$.includes(c),P=K(C,u,E+1);return h||(P+=".optional()"),`${d}${c}: ${P}`}).join(`,
|
|
37
39
|
`);return u==="zod"?`z.object({
|
|
38
|
-
${
|
|
39
|
-
${" ".repeat(
|
|
40
|
-
${
|
|
41
|
-
${" ".repeat(
|
|
42
|
-
${
|
|
43
|
-
${" ".repeat(
|
|
44
|
-
${
|
|
45
|
-
`;e!=null&&e.folderSplit?
|
|
46
|
-
`),me=`export const ${B} = ${
|
|
40
|
+
${y}
|
|
41
|
+
${" ".repeat(E)}})`:u==="yup"?`yup.object({
|
|
42
|
+
${y}
|
|
43
|
+
${" ".repeat(E)}})`:`Joi.object({
|
|
44
|
+
${y}
|
|
45
|
+
${" ".repeat(E)}})`}if(r.enum&&r.enum.length>0){let $=[],d=false;r.enum.forEach(c=>{c===null?d=true:$.includes(c)||$.push(c);});let y=$.map(c=>JSON.stringify(c)).join(", ");if(u==="zod"){let c=`z.enum([${y}])`;return d&&(c+=".nullable()"),c}else if(u==="yup"){let c=`yup.mixed().oneOf([${y}])`;return d&&(c+=".nullable()"),c}else {let c=`Joi.valid(${y})`;return d&&(c+=".allow(null)"),c}}if(r.type){let d=(y=>{switch(y){case "string":if(u==="zod"){let c="z.string()";return r.format==="email"?c+=".email()":r.format==="uuid"?c+=".uuid()":r.format==="url"||r.format==="uri"?c+=".url()":r.format==="date-time"?c+=".datetime()":r.format==="date"&&(c+=".date()"),r.minLength&&(c+=`.min(${r.minLength})`),r.maxLength&&(c+=`.max(${r.maxLength})`),r.pattern&&(c+=`.regex(/${r.pattern}/)`),c}else if(u==="yup"){let c="yup.string()";return r.format==="email"?c+=".email()":(r.format==="url"||r.format==="uri")&&(c+=".url()"),r.minLength&&(c+=`.min(${r.minLength})`),r.maxLength&&(c+=`.max(${r.maxLength})`),r.pattern&&(c+=`.matches(/${r.pattern}/)`),c}else {let c="Joi.string()";return r.format==="email"?c+=".email()":r.format==="url"||r.format==="uri"?c+=".uri()":r.format==="uuid"?c+=".guid({ version: 'uuidv4' })":r.format==="date-time"&&(c+=".isoDate()"),r.minLength&&(c+=`.min(${r.minLength})`),r.maxLength&&(c+=`.max(${r.maxLength})`),r.pattern&&(c+=`.pattern(/${r.pattern}/)`),c}case "integer":case "number":if(u==="zod"){let c="z.number()";return y==="integer"&&(c+=".int()"),r.minimum!==void 0&&(r.exclusiveMinimum?c+=`.gt(${r.minimum})`:c+=`.min(${r.minimum})`),r.maximum!==void 0&&(r.exclusiveMaximum?c+=`.lt(${r.maximum})`:c+=`.max(${r.maximum})`),c}else if(u==="yup"){let c="yup.number()";return y==="integer"&&(c+=".integer()"),r.minimum!==void 0&&(c+=`.min(${r.minimum})`),r.maximum!==void 0&&(c+=`.max(${r.maximum})`),c}else {let c="Joi.number()";return y==="integer"&&(c+=".integer()"),r.minimum!==void 0&&(r.exclusiveMinimum?c+=`.greater(${r.minimum})`:c+=`.min(${r.minimum})`),r.maximum!==void 0&&(r.exclusiveMaximum?c+=`.less(${r.maximum})`:c+=`.max(${r.maximum})`),c}case "boolean":return u==="joi"?"Joi.boolean()":u==="yup"?"yup.boolean()":"z.boolean()";case "null":return u==="joi"?"Joi.any().allow(null)":u==="yup"?"yup.mixed().nullable()":"z.null()";default:return u==="joi"?"Joi.any()":u==="yup"?"yup.mixed()":"z.any()"}})(typeof r.type=="string"?r.type:r.type[0]);return r.nullable&&u!=="joi"?d+=".nullable()":r.nullable&&u==="joi"&&(d+=".allow(null)"),d}return u==="joi"?"Joi.any()":u==="yup"?"yup.mixed()":"z.any()"},pe=r=>{var u,E,$,d,y;if((E=(u=e==null?void 0:e.endpoints)==null?void 0:u.value)!=null&&E.replaceWords&&Array.isArray(e==null?void 0:e.endpoints.value.replaceWords)){let c=r;return (y=(d=($=e==null?void 0:e.endpoints)==null?void 0:$.value)==null?void 0:d.replaceWords)==null||y.forEach((C,h)=>{let P=new RegExp(C.replace,"g");c=c.replace(P,C.with||"");}),c}else return r},oe=(r,u,E=[])=>{var y,c;let $=(y=e==null?void 0:e.endpoints)==null?void 0:y.exclude,d=(c=e==null?void 0:e.endpoints)==null?void 0:c.include;if(d){let C=d.tags&&d.tags.length>0?E.some(P=>d.tags.includes(P)):true,h=d.endpoints&&d.endpoints.length>0?d.endpoints.some(P=>{let W=!P.method||P.method.toLowerCase()===u.toLowerCase();return P.path?r===P.path&&W:P.regex?new RegExp(P.regex).test(r)&&W:false}):true;if(!C||!h)return true}return !!($&&($.tags&&$.tags.length>0&&E.some(h=>$.tags.includes(h))||$.endpoints&&$.endpoints.length>0&&$.endpoints.some(h=>{let P=!h.method||h.method.toLowerCase()===u.toLowerCase();return h.path?r===h.path&&P:h.regex?new RegExp(h.regex).test(r)&&P:false})))};if(Object.keys(n.paths||{}).forEach(r=>{let u=n.paths[r];Object.keys(u).forEach($=>{var Ye,Ze,Xe,et,tt,nt,rt,st,ot,at,it,lt,ut,pt,mt,ct,dt,ft,yt,gt,ht,$t,Ct,bt,It,xt,Et,Tt,wt,At,Pt,vt,jt,qt,Ot,kt,Rt,St,Ut,Mt,Gt,Nt,Lt,Ft,Qt,Bt,zt,Dt,Jt;let d=$,y=Vt(r,d),c=((Ye=u[d])==null?void 0:Ye.tags)||[];if(oe(r,d,c))return;let C=u[d],h=f({method:d,path:r,summary:C==null?void 0:C.summary,operationId:C==null?void 0:C.operationId,tags:c,parameters:C==null?void 0:C.parameters,requestBody:C==null?void 0:C.requestBody,responses:C==null?void 0:C.responses});m[h]||(m[h]={endpoints:"",types:"",validation:""});let P=((Xe=(Ze=e==null?void 0:e.endpoints)==null?void 0:Ze.value)!=null&&Xe.includeServer?O:"")+y.pathParts.map(I=>(I[0]==="{"&&I[I.length-1]==="}"?I=`\${${I.replace(/{/,"").replace(/}/,"")}}`:I[0]==="<"&&I[I.length-1]===">"?I=`\${${I.replace(/</,"").replace(/>/,"")}}`:I[0]===":"&&(I=`\${${I.replace(/:/,"")}}`),I)).join("/"),W=`"${P}"`;y.variables.length>0&&(W=`(${y.variables.map(x=>`${x}:string`).join(",")})=> \`${P}\``),W=pe(W);let a=u[d],Z="",v;if(a!=null&&a.parameters&&((a==null?void 0:a.parameters).forEach((x,R)=>{(x.$ref||x.in==="query"&&x.name)&&(Z+=`${A(n,x.$ref?x:x.schema,x.name||"",x.required)}`);}),Z)){Z=`{
|
|
46
|
+
${Z}}`;let x=`${y.name}Query`;if((tt=(et=e==null?void 0:e.types)==null?void 0:et.name)!=null&&tt.useOperationId&&(a!=null&&a.operationId)&&(x=`${a.operationId}Query`),x=ue(`${q}${x}`),(rt=(nt=e==null?void 0:e.types)==null?void 0:nt.name)!=null&&rt.format){let L=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"query",method:d,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},x);L&&(x=`${q}${L}`);}v=x;let R=`export type ${x} = ${Z};
|
|
47
|
+
`;e!=null&&e.folderSplit?m[h].types+=R:T+=R;}if(((st=e==null?void 0:e.validations)==null?void 0:st.disable)!==true&&((at=(ot=e==null?void 0:e.validations)==null?void 0:ot.generate)==null?void 0:at.query)!==false&&(a!=null&&a.parameters)){let I=((it=e.validations)==null?void 0:it.library)||"zod",R=a.parameters.filter(L=>!L.$ref&&L.in==="query"&&L.name);if(R.length>0){let L=((lt=e==null?void 0:e.validations)==null?void 0:lt.name)||((ut=e==null?void 0:e.types)==null?void 0:ut.name),_=typeof(L==null?void 0:L.prefix)=="string"?L.prefix:"I",M=typeof((mt=(pt=e==null?void 0:e.validations)==null?void 0:pt.name)==null?void 0:mt.suffix)=="string"?e.validations.name.suffix:"Schema",B=`${y.name}Query`;if(L!=null&&L.useOperationId&&(a!=null&&a.operationId)&&(B=`${a.operationId}Query`),B=ue(`${_}${B}${M}`),(dt=(ct=e==null?void 0:e.validations)==null?void 0:ct.name)!=null&&dt.format){let ne=e.validations.name.format({code:"",type:"query",method:d,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},B);ne&&(B=`${_}${ne}${M}`);}else if((yt=(ft=e==null?void 0:e.types)==null?void 0:ft.name)!=null&&yt.format){let ne=e.types.name.format("endpoint",{code:"",type:"query",method:d,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},B);ne&&(B=`${_}${ne}${M}`);}let U=R.map(ne=>{let pn=ne!=null&&ne.schema?K(ne.schema,I):I==="joi"?"Joi.string()":I==="yup"?"yup.string()":"z.string()",mn=ne.required?"":".optional()";return ` ${ne.name}: ${pn}${mn}`}).join(`,
|
|
48
|
+
`),me=`export const ${B} = ${I==="joi"?"Joi.object":I==="yup"?"yup.object":"z.object"}({
|
|
47
49
|
${U}
|
|
48
50
|
});
|
|
49
51
|
|
|
50
|
-
`;e!=null&&e.folderSplit||
|
|
51
|
-
`;e!=null&&e.folderSplit?
|
|
52
|
+
`;e!=null&&e.folderSplit||m[h]||(m[h]={endpoints:"",types:"",validation:""}),m[h].validation+=me;}}let N=a==null?void 0:a.requestBody,F="",z;if(N&&(F=Q(N),F)){let I=`${y.name}DTO`;if((ht=(gt=e==null?void 0:e.types)==null?void 0:gt.name)!=null&&ht.useOperationId&&(a!=null&&a.operationId)&&(I=`${a.operationId}DTO`),I=ue(`${q}${I}`),(Ct=($t=e==null?void 0:e.types)==null?void 0:$t.name)!=null&&Ct.format){let R=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"dto",method:d,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},I);R&&(I=`${q}${R}`);}z=I;let x=`export type ${I} = ${F};
|
|
53
|
+
`;e!=null&&e.folderSplit?m[h].types+=x:T+=x;}if(((bt=e==null?void 0:e.validations)==null?void 0:bt.disable)!==true&&((xt=(It=e==null?void 0:e.validations)==null?void 0:It.generate)==null?void 0:xt.dto)!==false&&N){let I=((Et=e.validations)==null?void 0:Et.library)||"zod";if(N.content){let x=Object.keys(N.content);if(x[0]&&N.content[x[0]].schema){let R=((Tt=e==null?void 0:e.validations)==null?void 0:Tt.name)||((wt=e==null?void 0:e.types)==null?void 0:wt.name),L=typeof(R==null?void 0:R.prefix)=="string"?R.prefix:"I",_=typeof((Pt=(At=e==null?void 0:e.validations)==null?void 0:At.name)==null?void 0:Pt.suffix)=="string"?e.validations.name.suffix:"Schema",M=`${y.name}DTO`;if(R!=null&&R.useOperationId&&(a!=null&&a.operationId)&&(M=`${a.operationId}DTO`),M=ue(`${L}${M}${_}`),(jt=(vt=e==null?void 0:e.validations)==null?void 0:vt.name)!=null&&jt.format){let te=e.validations.name.format({code:"",type:"dto",method:d,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},M);te&&(M=`${L}${te}${_}`);}else if((Ot=(qt=e==null?void 0:e.types)==null?void 0:qt.name)!=null&&Ot.format){let te=e.types.name.format("endpoint",{code:"",type:"dto",method:d,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},M);te&&(M=`${L}${te}${_}`);}let B=K(N.content[x[0]].schema,I),U=`export const ${M} = ${B};
|
|
52
54
|
|
|
53
|
-
`;e!=null&&e.folderSplit||
|
|
54
|
-
`;e!=null&&e.folderSplit?
|
|
55
|
-
- Scopes: [\`${
|
|
55
|
+
`;e!=null&&e.folderSplit||m[h]||(m[h]={endpoints:"",types:"",validation:""}),m[h].validation+=U;}}}let D={},re="",Ce="";if(a!=null&&a.responses){let I=a==null?void 0:a.responses;Object.keys(I).forEach(R=>{var L,_,M,B;if(re=Q(I[R]),D[R]=re,re){let U=`${y.name}${R}Response`;if((_=(L=e==null?void 0:e.types)==null?void 0:L.name)!=null&&_.useOperationId&&(a!=null&&a.operationId)&&(U=`${a.operationId}${R}Response`),U=ue(`${q}${U}`),(B=(M=e==null?void 0:e.types)==null?void 0:M.name)!=null&&B.format){let ne=e==null?void 0:e.types.name.format("endpoint",{code:R,type:"response",method:d,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},U);ne&&(U=`${q}${ne}`);}let te=`export type ${U} = ${re};
|
|
56
|
+
`;e!=null&&e.folderSplit?m[h].types+=te:T+=te,D[R]=U;let me=parseInt(R);me>=200&&me<300&&(Ce=U);}});}let de=I=>!I||!I.length?"":I.map(x=>Object.entries(x).map(([L,_])=>{let M=L,B="";return Array.isArray(_)&&_.length&&(B=`
|
|
57
|
+
- Scopes: [\`${_.join("`, `")}\`]`,M=`**${M}**`),`
|
|
56
58
|
- ${M}${B}`}).join("")).join(`
|
|
57
|
-
`),
|
|
58
|
-
--cert client-certificate.crt --key client-private-key.key --cacert ca-certificate.crt`:U.type==="apiKey"?
|
|
59
|
+
`),fe=a!=null&&a.security?de(a.security):"",Ie="";if(!((Rt=(kt=e==null?void 0:e.endpoints)==null?void 0:kt.doc)!=null&&Rt.disable)){let I="";if((Ut=(St=e==null?void 0:e.endpoints)==null?void 0:St.doc)!=null&&Ut.showCurl){let x={},R="",L="";(Mt=a.requestBody)!=null&&Mt.content&&Object.keys(a.requestBody.content).forEach(B=>{let U=a.requestBody.content[B].schema;if(U){Array.isArray(x["Content-type"])?x["Content-type"].push(B):x["Content-type"]=[B];let te=k(n,U);te&&(R=te);}}),a!=null&&a.security&&a.security.forEach(M=>{Object.keys(M).forEach(B=>{var te,me;let U=(me=(te=n.components)==null?void 0:te.securitySchemes)==null?void 0:me[B];U&&(U.type==="mutualTLS"?L+=`
|
|
60
|
+
--cert client-certificate.crt --key client-private-key.key --cacert ca-certificate.crt`:U.type==="apiKey"?x[(U==null?void 0:U.name)||"X-API-KEY"]="{API_KEY_VALUE}":x.Authorization=`${(U==null?void 0:U.scheme)==="basic"?"Basic":"Bearer"} {${(U==null?void 0:U.scheme)==="basic"?"VALUE":"TOKEN"}}`);});});let _={};Object.keys(x).forEach(M=>{Array.isArray(x[M])?_[M]=x[M].join("; "):_[M]=x[M];}),I=`
|
|
59
61
|
\`\`\`bash
|
|
60
|
-
${CurlGenerator({url:
|
|
61
|
-
\`\`\``;}
|
|
62
|
+
${CurlGenerator({url:O+r,method:d.toUpperCase(),headers:_,body:R})}${L}
|
|
63
|
+
\`\`\``;}Ie=`/**${a!=null&&a.description?`
|
|
62
64
|
* ${a==null?void 0:a.description} `:""}
|
|
63
65
|
* **Method**: \`${d.toUpperCase()}\`
|
|
64
66
|
* **Summary**: ${(a==null?void 0:a.summary)||""}
|
|
65
|
-
* **Tags**: [${((
|
|
66
|
-
* **OperationId**: ${(a==null?void 0:a.operationId)||""} ${
|
|
67
|
-
* **Query**: ${ve(
|
|
68
|
-
* **DTO**: ${ve(
|
|
69
|
-
* **Response**: ${Object.entries(
|
|
70
|
-
- **${
|
|
71
|
-
* **Security**: ${
|
|
72
|
-
`:""}${
|
|
67
|
+
* **Tags**: [${((Gt=a==null?void 0:a.tags)==null?void 0:Gt.join(", "))||""}]
|
|
68
|
+
* **OperationId**: ${(a==null?void 0:a.operationId)||""} ${Z?`
|
|
69
|
+
* **Query**: ${ve(Z)} `:""}${F?`
|
|
70
|
+
* **DTO**: ${ve(F)} `:""}${re?`
|
|
71
|
+
* **Response**: ${Object.entries(D).map(([x,R])=>`
|
|
72
|
+
- **${x}**: ${ve(R,2)} `).join("")}`:""}${fe?`
|
|
73
|
+
* **Security**: ${fe}
|
|
74
|
+
`:""}${I}
|
|
73
75
|
*/
|
|
74
|
-
`;}let
|
|
75
|
-
`;e!=null&&e.folderSplit?
|
|
76
|
+
`;}let ye=(Lt=(Nt=e==null?void 0:e.endpoints)==null?void 0:Nt.name)!=null&&Lt.useOperationId&&((Ft=a==null?void 0:a.operationId)==null?void 0:Ft.length)>0?a.operationId:`${y.name}`;if((Bt=(Qt=e==null?void 0:e.endpoints)==null?void 0:Qt.name)!=null&&Bt.format){let I=e==null?void 0:e.endpoints.name.format({method:d,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},ye);I&&(ye=I);}let Re={method:`"${d}"`,operationId:`"${a==null?void 0:a.operationId}"`,url:W,tags:(a==null?void 0:a.tags)||[]},Ve=`${Ie}export const ${j}${ye} = ${((Dt=(zt=e==null?void 0:e.endpoints)==null?void 0:zt.value)==null?void 0:Dt.type)==="object"?Ee(Re):W};
|
|
77
|
+
`;e!=null&&e.folderSplit?m[h].endpoints+=Ve:H+=Ve;let un={name:`${j}${ye}`,method:d,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId,tags:c,parameters:(Jt=a==null?void 0:a.parameters)==null?void 0:Jt.filter(I=>!I.$ref&&I.in&&I.name).map(I=>{var x;return {name:I.name,in:I.in,required:I.required,type:((x=I.schema)==null?void 0:x.type)||"string"}}),requestBody:N?{type:F,required:N.required}:void 0,responses:D?Object.entries(D).reduce((I,[x,R])=>(I[x]={type:R},I),{}):void 0,queryType:v,dtoType:z,responseType:Ce||void 0};Y.push(un);});}),e!=null&&e.folderSplit){for(let[r,u]of Object.entries(m))if(u.endpoints||u.types){let E=J.join(g,r);if(u.endpoints){let $=J.join(ce,E,"endpoints.ts");yield ie.promises.mkdir(J.dirname($),{recursive:true}),yield ge($,u.endpoints,e);}if(u.types){let $=J.join(ce,E,"types.ts");yield ie.promises.mkdir(J.dirname($),{recursive:true});let d=Object.values(b$1).length>0?`import * as Shared from "../shared";
|
|
76
78
|
|
|
77
|
-
${u.types}`:u.types;yield
|
|
79
|
+
${u.types}`:u.types;yield ge($,d,e);}if(((We=e==null?void 0:e.validations)==null?void 0:We.disable)!==true&&u.validation){let $=((He=e.validations)==null?void 0:He.library)||"zod",d=$==="joi"?'import Joi from "joi";':$==="yup"?'import * as yup from "yup";':'import { z } from "zod";',y=J.join(ce,E,"validations.ts");yield ie.promises.mkdir(J.dirname(y),{recursive:true}),yield ge(y,`${d}
|
|
78
80
|
|
|
79
|
-
${u.validation}`,e);}}}if(
|
|
80
|
-
`),e);}if(
|
|
81
|
+
${u.validation}`,e);}}}if(H.length>0){let r=J.join(ce,g,"endpoints.ts");yield ie.promises.mkdir(J.dirname(r),{recursive:true}),yield ge(r,H,e);}if(Object.values(b$1).length>0){let r=J.join(ce,g,e!=null&&e.folderSplit?"":"types","shared.ts");yield ie.promises.mkdir(J.dirname(r),{recursive:true}),yield ge(r,Object.values(b$1).join(`
|
|
82
|
+
`),e);}if(T.length>0){let r=J.join(ce,g,"types","index.ts");yield ie.promises.mkdir(J.dirname(r),{recursive:true}),yield ge(r,`${Object.values(b$1).length>0?`import * as Shared from "./shared";
|
|
81
83
|
|
|
82
|
-
`:""}${
|
|
84
|
+
`:""}${T}`,e);}if(((Ke=e==null?void 0:e.validations)==null?void 0:Ke.disable)!==true&&!(e!=null&&e.folderSplit)){let r=((_e=e.validations)==null?void 0:_e.library)||"zod",u=r==="joi"?'import Joi from "joi";':r==="yup"?'import * as yup from "yup";':'import { z } from "zod";',E=Object.values(m).map($=>$.validation).filter($=>$.length>0).join("");if(E){let $=J.join(ce,g,"validations.ts");yield ie.promises.mkdir(J.dirname($),{recursive:true}),yield ge($,`${u}
|
|
83
85
|
|
|
84
|
-
${
|
|
86
|
+
${E}`,e);}}return tn(p,Y),console.info(`\u2705 Successfully synced ${p}`),{success:true}}),Le=sn;var on=(l,o)=>{let p=l;return o.tags&&o.tags.length>0&&(p=p.filter(e=>!e.tags||e.tags.length===0?false:e.tags.some(s=>o.tags.includes(s)))),o.endpoints&&o.endpoints.length>0&&(p=p.filter(e=>o.endpoints.includes(e.name))),p};var Fe=(l,o,p=false)=>{var n,g;let e=o.baseURL||"";o.auth;let t=`// Generated Fetch API Client
|
|
85
87
|
`;t+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
86
88
|
|
|
87
89
|
`,t+=`import type {
|
|
88
|
-
`;let
|
|
90
|
+
`;let i=new Set;return l.forEach(m=>{m.queryType&&i.add(m.queryType),m.dtoType&&i.add(m.dtoType),m.responseType&&i.add(m.responseType);}),i.forEach(m=>{t+=` ${m},
|
|
89
91
|
`;}),t+=`} from '../types';
|
|
90
92
|
|
|
91
93
|
`,t+=`import {
|
|
@@ -105,7 +107,7 @@ ${w}`,e);}}return Xt(p,I),console.info(`\u2705 Successfully synced ${p}`),{succe
|
|
|
105
107
|
`,t+=` globalConfig = { ...globalConfig, ...config };
|
|
106
108
|
`,t+=`};
|
|
107
109
|
|
|
108
|
-
`,(n=
|
|
110
|
+
`,(n=o.errorHandling)!=null&&n.generateErrorClasses&&(t+=`export class ApiError extends Error {
|
|
109
111
|
`,t+=` constructor(
|
|
110
112
|
`,t+=` message: string,
|
|
111
113
|
`,t+=` public statusCode: number,
|
|
@@ -131,7 +133,7 @@ ${w}`,e);}}return Xt(p,I),console.info(`\u2705 Successfully synced ${p}`),{succe
|
|
|
131
133
|
`,t+=` });
|
|
132
134
|
|
|
133
135
|
`,t+=` if (!response.ok) {
|
|
134
|
-
`,(
|
|
136
|
+
`,(g=o.errorHandling)!=null&&g.generateErrorClasses?(t+=` const errorData = await response.json().catch(() => ({}));
|
|
135
137
|
`,t+=` throw new ApiError(
|
|
136
138
|
`,t+=` errorData.message || response.statusText,
|
|
137
139
|
`,t+=` response.status,
|
|
@@ -142,31 +144,31 @@ ${w}`,e);}}return Xt(p,I),console.info(`\u2705 Successfully synced ${p}`),{succe
|
|
|
142
144
|
`,t+=` return response.json();
|
|
143
145
|
`,t+=`}
|
|
144
146
|
|
|
145
|
-
`,l.forEach(m=>{var
|
|
147
|
+
`,l.forEach(m=>{var H,T;let f=m.name,O=((H=m.parameters)==null?void 0:H.filter(b=>b.in==="path"))||[],q=((T=m.parameters)==null?void 0:T.filter(b=>b.in==="query"))||[],j=O.length>0,w=q.length>0,A=!!m.requestBody,k=m.responseType||"any";if(t+=`/**
|
|
146
148
|
`,m.summary&&(t+=` * ${m.summary}
|
|
147
149
|
`),t+=` * @method ${m.method.toUpperCase()}
|
|
148
150
|
`,t+=` * @path ${m.path}
|
|
149
151
|
`,m.tags&&m.tags.length>0&&(t+=` * @tags ${m.tags.join(", ")}
|
|
150
152
|
`),t+=` */
|
|
151
|
-
`,t+=`export async function ${f}(`,(j||
|
|
153
|
+
`,t+=`export async function ${f}(`,(j||w||A)&&(t+=`params: {
|
|
152
154
|
`,j&&(t+=` url: {
|
|
153
|
-
`,
|
|
155
|
+
`,O.forEach(b=>{let G={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[b.type||"string"]||"any",Q=b.required?"":"?";t+=` ${b.name}${Q}: ${G};
|
|
154
156
|
`;}),t+=` };
|
|
155
|
-
`),
|
|
156
|
-
`),
|
|
157
|
+
`),w&&(t+=` query: ${m.queryType||"Record<string, any>"};
|
|
158
|
+
`),A&&(t+=` data: ${m.dtoType||"any"};
|
|
157
159
|
`),t+=`}
|
|
158
|
-
`),t+=`): Promise<${
|
|
159
|
-
`,j||
|
|
160
|
-
`;}let
|
|
161
|
-
`,
|
|
162
|
-
`:(t+=` if (query.${
|
|
163
|
-
`,t+=` queryParams.append('${
|
|
160
|
+
`),t+=`): Promise<${k}> {
|
|
161
|
+
`,j||w||A){let b=[];j&&b.push("url"),w&&b.push("query"),A&&b.push("data"),t+=` const { ${b.join(", ")} } = params;
|
|
162
|
+
`;}let S;if(j){let b=O.map(Y=>`url.${Y.name}`).join(", ");S=`${m.name}_endpoint(${b})`;}else S=`${m.name}_endpoint`;w?(t+=` const queryParams = new URLSearchParams();
|
|
163
|
+
`,q.forEach(b=>{b.required?t+=` queryParams.append('${b.name}', String(query.${b.name}));
|
|
164
|
+
`:(t+=` if (query.${b.name} !== undefined) {
|
|
165
|
+
`,t+=` queryParams.append('${b.name}', String(query.${b.name}));
|
|
164
166
|
`,t+=` }
|
|
165
|
-
`);}),t+=` const _url = \`\${${
|
|
166
|
-
`):t+=` const _url = ${
|
|
167
|
-
`,t+=` return fetchAPI<${
|
|
167
|
+
`);}),t+=` const _url = \`\${${S}}?\${queryParams.toString()}\`;
|
|
168
|
+
`):t+=` const _url = ${S};
|
|
169
|
+
`,t+=` return fetchAPI<${k}>(_url, {
|
|
168
170
|
`,t+=` method: '${m.method.toUpperCase()}',
|
|
169
|
-
`,
|
|
171
|
+
`,A&&(t+=` body: JSON.stringify(data),
|
|
170
172
|
`),t+=` });
|
|
171
173
|
`,t+=`}
|
|
172
174
|
|
|
@@ -177,13 +179,13 @@ ${w}`,e);}}return Xt(p,I),console.info(`\u2705 Successfully synced ${p}`),{succe
|
|
|
177
179
|
`;}),t+=`};
|
|
178
180
|
|
|
179
181
|
`,t+=`export default apiClient;
|
|
180
|
-
`),t},
|
|
182
|
+
`),t},he=(l,o,p=false)=>{var n,g;let e=o.baseURL||"";o.auth;let t=`// Generated Axios API Client
|
|
181
183
|
`;t+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
182
184
|
|
|
183
185
|
`,t+=`import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
184
186
|
|
|
185
187
|
`,t+=`import type {
|
|
186
|
-
`;let
|
|
188
|
+
`;let i=new Set;return l.forEach(m=>{m.queryType&&i.add(m.queryType),m.dtoType&&i.add(m.dtoType),m.responseType&&i.add(m.responseType);}),i.forEach(m=>{t+=` ${m},
|
|
187
189
|
`;}),t+=`} from '../types';
|
|
188
190
|
|
|
189
191
|
`,t+=`import {
|
|
@@ -196,7 +198,7 @@ ${w}`,e);}}return Xt(p,I),console.info(`\u2705 Successfully synced ${p}`),{succe
|
|
|
196
198
|
`,t+=` timeout?: number;
|
|
197
199
|
`,t+=`}
|
|
198
200
|
|
|
199
|
-
`,(n=
|
|
201
|
+
`,(n=o.errorHandling)!=null&&n.generateErrorClasses&&(t+=`export class ApiError extends Error {
|
|
200
202
|
`,t+=` constructor(
|
|
201
203
|
`,t+=` message: string,
|
|
202
204
|
`,t+=` public statusCode: number,
|
|
@@ -224,7 +226,7 @@ ${w}`,e);}}return Xt(p,I),console.info(`\u2705 Successfully synced ${p}`),{succe
|
|
|
224
226
|
`,t+=` this.client.interceptors.response.use(
|
|
225
227
|
`,t+=` (response) => response,
|
|
226
228
|
`,t+=` (error) => {
|
|
227
|
-
`,(
|
|
229
|
+
`,(g=o.errorHandling)!=null&&g.generateErrorClasses?(t+=` const message = error.response?.data?.message || error.message;
|
|
228
230
|
`,t+=` const statusCode = error.response?.status || 500;
|
|
229
231
|
`,t+=` throw new ApiError(message, statusCode, error.response?.data);
|
|
230
232
|
`):t+=` return Promise.reject(error);
|
|
@@ -236,27 +238,27 @@ ${w}`,e);}}return Xt(p,I),console.info(`\u2705 Successfully synced ${p}`),{succe
|
|
|
236
238
|
`,t+=` Object.assign(this.client.defaults, config);
|
|
237
239
|
`,t+=` }
|
|
238
240
|
|
|
239
|
-
`,l.forEach(m=>{var
|
|
241
|
+
`,l.forEach(m=>{var S,H;let f=m.name,O=((S=m.parameters)==null?void 0:S.filter(T=>T.in==="path"))||[],q=((H=m.parameters)==null?void 0:H.filter(T=>T.in==="query"))||[],j=O.length>0,w=q.length>0,A=!!m.requestBody,k=m.responseType||"any";if(t+=` /**
|
|
240
242
|
`,m.summary&&(t+=` * ${m.summary}
|
|
241
243
|
`),t+=` * @method ${m.method.toUpperCase()}
|
|
242
244
|
`,t+=` * @path ${m.path}
|
|
243
245
|
`,m.tags&&m.tags.length>0&&(t+=` * @tags ${m.tags.join(", ")}
|
|
244
246
|
`),t+=` */
|
|
245
|
-
`,t+=` async ${f}(`,(j||
|
|
247
|
+
`,t+=` async ${f}(`,(j||w||A)&&(t+=`params: {
|
|
246
248
|
`,j&&(t+=` url: {
|
|
247
|
-
`,
|
|
249
|
+
`,O.forEach(T=>{let Y={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[T.type||"string"]||"any",G=T.required?"":"?";t+=` ${T.name}${G}: ${Y};
|
|
248
250
|
`;}),t+=` };
|
|
249
|
-
`),
|
|
250
|
-
`),
|
|
251
|
-
`),t+=" }"),t+=`): Promise<${
|
|
252
|
-
`,j||
|
|
253
|
-
`;}if(j){let T=
|
|
251
|
+
`),w&&(t+=` query: ${m.queryType||"Record<string, any>"};
|
|
252
|
+
`),A&&(t+=` data: ${m.dtoType||"any"};
|
|
253
|
+
`),t+=" }"),t+=`): Promise<${k}> {
|
|
254
|
+
`,j||w||A){let T=[];j&&T.push("url"),w&&T.push("query"),A&&T.push("data"),t+=` const { ${T.join(", ")} } = params;
|
|
255
|
+
`;}if(j){let T=O.map(b=>`url.${b.name}`).join(", ");t+=` const _url = ${m.name}(${T});
|
|
254
256
|
`;}else t+=` const _url = ${m.name};
|
|
255
257
|
`;t+=` const config: AxiosRequestConfig = {};
|
|
256
|
-
`,
|
|
257
|
-
`),t+=` const response = await this.client.${m.method.toLowerCase()}<${
|
|
258
|
+
`,w&&(t+=` config.params = { ...query };
|
|
259
|
+
`),t+=` const response = await this.client.${m.method.toLowerCase()}<${k}>(
|
|
258
260
|
`,t+=` _url,
|
|
259
|
-
`,
|
|
261
|
+
`,A?t+=` data,
|
|
260
262
|
config
|
|
261
263
|
`:t+=` config
|
|
262
264
|
`,t+=` );
|
|
@@ -268,16 +270,16 @@ ${w}`,e);}}return Xt(p,I),console.info(`\u2705 Successfully synced ${p}`),{succe
|
|
|
268
270
|
`,p?t+=`export default ApiClient;
|
|
269
271
|
`:(t+=`export const apiClient = new ApiClient();
|
|
270
272
|
`,t+=`export default apiClient;
|
|
271
|
-
`),t},Qe=(l,
|
|
273
|
+
`),t},Qe=(l,o)=>{var g,m;let p=((g=o.reactQuery)==null?void 0:g.version)||5,e=((m=o.reactQuery)==null?void 0:m.mutations)!==false,s=!!(o.reactQuery&&o.reactQuery.infiniteQueries&&!o.reactQuery.infiniteQueries.disable),t=`// Generated React Query Hooks
|
|
272
274
|
`;t+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
273
275
|
|
|
274
|
-
`;let
|
|
276
|
+
`;let i=e&&l.some(f=>["POST","PUT","PATCH","DELETE"].includes(f.method.toUpperCase()));if(p===5){let f=i?`import { useQuery, useMutation, UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
275
277
|
`:`import { useQuery, UseQueryOptions } from '@tanstack/react-query';
|
|
276
|
-
`;
|
|
278
|
+
`;s&&(f=f.replace("@tanstack/react-query';\\n",`@tanstack/react-query';
|
|
277
279
|
import { useInfiniteQuery, UseInfiniteQueryOptions } from '@tanstack/react-query';
|
|
278
|
-
`)),t+=f;}else {let f=
|
|
280
|
+
`)),t+=f;}else {let f=i?`import { useQuery, useMutation, UseQueryOptions, UseMutationOptions } from 'react-query';
|
|
279
281
|
`:`import { useQuery, UseQueryOptions } from 'react-query';
|
|
280
|
-
`;
|
|
282
|
+
`;s&&(f=f.replace("react-query';\\n",`react-query';
|
|
281
283
|
import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
282
284
|
`)),t+=f;}t+=`
|
|
283
285
|
`,t+=`import apiClient from './client';
|
|
@@ -285,18 +287,18 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
285
287
|
`;let n=new Set;return l.forEach(f=>{f.queryType&&n.add(f.queryType),f.dtoType&&n.add(f.dtoType),f.responseType&&n.add(f.responseType);}),n.forEach(f=>{t+=` ${f},
|
|
286
288
|
`;}),t+=`} from '../types';
|
|
287
289
|
|
|
288
|
-
`,l.forEach(f=>{var
|
|
290
|
+
`,l.forEach(f=>{var b,Y;let O=f.method.toUpperCase(),q=O==="GET",j=["POST","PUT","PATCH","DELETE"].includes(O),w=((b=f.parameters)==null?void 0:b.filter(G=>G.in==="path"))||[],A=((Y=f.parameters)==null?void 0:Y.filter(G=>G.in==="query"))||[],k=w.length>0,S=A.length>0,H=!!f.requestBody,T=f.responseType||"any";if(q){let G=A.map(oe=>oe.name.toLowerCase()),K=(G.includes("page")||G.includes("cursor")||G.includes("cursorid")||G.includes("after")||G.includes("before"))&&s,pe=`use${f.name.charAt(0).toUpperCase()+f.name.slice(1)}`;if(t+=`/**
|
|
289
291
|
`,f.summary&&(t+=` * ${f.summary}
|
|
290
|
-
`),t+=` * @method ${
|
|
292
|
+
`),t+=` * @method ${O}
|
|
291
293
|
`,t+=` * @path ${f.path}
|
|
292
294
|
`,f.tags&&f.tags.length>0&&(t+=` * @tags ${f.tags.join(", ")}
|
|
293
295
|
`),t+=` */
|
|
294
|
-
`,
|
|
296
|
+
`,k||S?(t+=`export function ${pe}(
|
|
295
297
|
`,t+=` params: {
|
|
296
|
-
`,
|
|
297
|
-
`,
|
|
298
|
+
`,k&&(t+=` url: {
|
|
299
|
+
`,w.forEach(oe=>{let be={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[oe.type||"string"]||"any",$e=oe.required?"":"?";t+=` ${oe.name}${$e}: ${be};
|
|
298
300
|
`;}),t+=` };
|
|
299
|
-
`),
|
|
301
|
+
`),S&&(t+=` query: ${f.queryType||"Record<string, any>"};
|
|
300
302
|
`),t+=` },
|
|
301
303
|
`,t+=` options?: Omit<UseQueryOptions<${T}>, 'queryKey' | 'queryFn'>
|
|
302
304
|
`,t+=`) {
|
|
@@ -307,7 +309,7 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
307
309
|
`,t+=` });
|
|
308
310
|
`,t+=`}
|
|
309
311
|
|
|
310
|
-
`):(t+=`export function ${
|
|
312
|
+
`):(t+=`export function ${pe}(
|
|
311
313
|
`,t+=` options?: Omit<UseQueryOptions<${T}>, 'queryKey' | 'queryFn'>
|
|
312
314
|
`,t+=`) {
|
|
313
315
|
`,t+=` return useQuery({
|
|
@@ -317,12 +319,12 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
317
319
|
`,t+=` });
|
|
318
320
|
`,t+=`}
|
|
319
321
|
|
|
320
|
-
`),
|
|
322
|
+
`),K){let oe=`${pe}Infinite`;k||S?(t+=`export function ${oe}(
|
|
321
323
|
`,t+=` params: {
|
|
322
|
-
`,
|
|
323
|
-
`,
|
|
324
|
+
`,k&&(t+=` url: {
|
|
325
|
+
`,w.forEach(le=>{let $e={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[le.type||"string"]||"any",Pe=le.required?"":"?";t+=` ${le.name}${Pe}: ${$e};
|
|
324
326
|
`;}),t+=` };
|
|
325
|
-
`),
|
|
327
|
+
`),S&&(t+=` query: ${f.queryType||"Record<string, any>"};
|
|
326
328
|
`),t+=` },
|
|
327
329
|
`,t+=` options?: Omit<UseInfiniteQueryOptions<${T}, Error, ${T}>, 'queryKey' | 'queryFn'>
|
|
328
330
|
`,t+=`) {
|
|
@@ -334,7 +336,7 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
334
336
|
`,t+=` });
|
|
335
337
|
`,t+=`}
|
|
336
338
|
|
|
337
|
-
`):(t+=`export function ${
|
|
339
|
+
`):(t+=`export function ${oe}(
|
|
338
340
|
`,t+=` options?: Omit<UseInfiniteQueryOptions<${T}, Error, ${T}>, 'queryKey' | 'queryFn'>
|
|
339
341
|
`,t+=`) {
|
|
340
342
|
`,t+=` return useInfiniteQuery({
|
|
@@ -345,30 +347,30 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
345
347
|
`,t+=` });
|
|
346
348
|
`,t+=`}
|
|
347
349
|
|
|
348
|
-
`);}}else if(j&&e){let
|
|
350
|
+
`);}}else if(j&&e){let G=`use${f.name.charAt(0).toUpperCase()+f.name.slice(1)}`;t+=`/**
|
|
349
351
|
`,f.summary&&(t+=` * ${f.summary}
|
|
350
|
-
`),t+=` * @method ${
|
|
352
|
+
`),t+=` * @method ${O}
|
|
351
353
|
`,t+=` * @path ${f.path}
|
|
352
354
|
`,f.tags&&f.tags.length>0&&(t+=` * @tags ${f.tags.join(", ")}
|
|
353
355
|
`),t+=` */
|
|
354
|
-
`;let
|
|
355
|
-
`,
|
|
356
|
-
`,
|
|
357
|
-
`;}),
|
|
358
|
-
`),
|
|
359
|
-
`),
|
|
360
|
-
`),
|
|
361
|
-
`,t+=` options?: Omit<UseMutationOptions<${T}, Error, ${
|
|
356
|
+
`;let Q="void";(k||S||H)&&(Q=`{
|
|
357
|
+
`,k&&(Q+=` url: {
|
|
358
|
+
`,w.forEach(K=>{let oe={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[K.type||"string"]||"any",le=K.required?"":"?";Q+=` ${K.name}${le}: ${oe};
|
|
359
|
+
`;}),Q+=` };
|
|
360
|
+
`),S&&(Q+=` query: ${f.queryType||"Record<string, any>"};
|
|
361
|
+
`),H&&(Q+=` data: ${f.dtoType||"any"};
|
|
362
|
+
`),Q+=" }"),t+=`export function ${G}(
|
|
363
|
+
`,t+=` options?: Omit<UseMutationOptions<${T}, Error, ${Q}>, 'mutationFn'>
|
|
362
364
|
`,t+=`) {
|
|
363
365
|
`,t+=` return useMutation({
|
|
364
|
-
`,t+=" mutationFn: (",
|
|
365
|
-
`,t+=` return apiClient.${f.name}(${
|
|
366
|
+
`,t+=" mutationFn: (",Q!=="void"&&(t+=`variables: ${Q}`),t+=`) => {
|
|
367
|
+
`,t+=` return apiClient.${f.name}(${Q!=="void"?"variables":""});
|
|
366
368
|
`,t+=` },
|
|
367
369
|
`,t+=` ...options,
|
|
368
370
|
`,t+=` });
|
|
369
371
|
`,t+=`}
|
|
370
372
|
|
|
371
|
-
`;}}),t},Be=(l,
|
|
373
|
+
`;}}),t},Be=(l,o)=>{var i;let p=((i=o.swr)==null?void 0:i.mutations)!==false,e=`// Generated SWR Hooks
|
|
372
374
|
`;e+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
373
375
|
|
|
374
376
|
`,e+=`/**
|
|
@@ -570,20 +572,20 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
570
572
|
`;let t=new Set;return l.forEach(n=>{n.queryType&&t.add(n.queryType),n.dtoType&&t.add(n.dtoType),n.responseType&&t.add(n.responseType);}),t.forEach(n=>{e+=` ${n},
|
|
571
573
|
`;}),e+=`} from '../types';
|
|
572
574
|
|
|
573
|
-
`,l.forEach(n=>{var
|
|
575
|
+
`,l.forEach(n=>{var S,H;let g=n.method.toUpperCase(),m=g==="GET",f=["POST","PUT","PATCH","DELETE"].includes(g),O=((S=n.parameters)==null?void 0:S.filter(T=>T.in==="path"))||[],q=((H=n.parameters)==null?void 0:H.filter(T=>T.in==="query"))||[],j=O.length>0,w=q.length>0,A=!!n.requestBody,k=n.responseType||"any";if(m){let T=`use${n.name.charAt(0).toUpperCase()+n.name.slice(1)}`;e+=`/**
|
|
574
576
|
`,n.summary&&(e+=` * ${n.summary}
|
|
575
|
-
`),e+=` * @method ${
|
|
577
|
+
`),e+=` * @method ${g}
|
|
576
578
|
`,e+=` * @path ${n.path}
|
|
577
579
|
`,n.tags&&n.tags.length>0&&(e+=` * @tags ${n.tags.join(", ")}
|
|
578
580
|
`),e+=` */
|
|
579
|
-
`,j||
|
|
581
|
+
`,j||w?(e+=`export function ${T}(
|
|
580
582
|
`,e+=` params: {
|
|
581
583
|
`,j&&(e+=` url: {
|
|
582
|
-
`,
|
|
584
|
+
`,O.forEach(b=>{let G={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[b.type||"string"]||"any",Q=b.required?"":"?";e+=` ${b.name}${Q}: ${G};
|
|
583
585
|
`;}),e+=` };
|
|
584
|
-
`),
|
|
586
|
+
`),w&&(e+=` query: ${n.queryType||"Record<string, any>"};
|
|
585
587
|
`),e+=` },
|
|
586
|
-
`,e+=` config?: SWRConfiguration<${
|
|
588
|
+
`,e+=` config?: SWRConfiguration<${k}>
|
|
587
589
|
`,e+=`) {
|
|
588
590
|
`,e+=` return useSWR(
|
|
589
591
|
`,e+=` ['${n.name}', params],
|
|
@@ -591,7 +593,7 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
591
593
|
`,e+=` config
|
|
592
594
|
`,e+=` );
|
|
593
595
|
`):(e+=`export function ${T}(
|
|
594
|
-
`,e+=` config?: SWRConfiguration<${
|
|
596
|
+
`,e+=` config?: SWRConfiguration<${k}>
|
|
595
597
|
`,e+=`) {
|
|
596
598
|
`,e+=` return useSWR(
|
|
597
599
|
`,e+=` '${n.name}',
|
|
@@ -602,176 +604,176 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
602
604
|
|
|
603
605
|
`;}else if(f&&p){let T=`use${n.name.charAt(0).toUpperCase()+n.name.slice(1)}`;e+=`/**
|
|
604
606
|
`,n.summary&&(e+=` * ${n.summary}
|
|
605
|
-
`),e+=` * @method ${
|
|
607
|
+
`),e+=` * @method ${g}
|
|
606
608
|
`,e+=` * @path ${n.path}
|
|
607
609
|
`,n.tags&&n.tags.length>0&&(e+=` * @tags ${n.tags.join(", ")}
|
|
608
610
|
`),e+=` */
|
|
609
|
-
`;let
|
|
610
|
-
`,j&&(
|
|
611
|
-
`,
|
|
612
|
-
`;}),
|
|
613
|
-
`),
|
|
614
|
-
`),
|
|
615
|
-
`),
|
|
616
|
-
`,e+=` config?: SWRMutationConfiguration<${
|
|
611
|
+
`;let b="void",Y="void";(j||w||A)&&(b=`{
|
|
612
|
+
`,j&&(b+=` url: {
|
|
613
|
+
`,O.forEach(G=>{let K={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[G.type||"string"]||"any",pe=G.required?"":"?";b+=` ${G.name}${pe}: ${K};
|
|
614
|
+
`;}),b+=` };
|
|
615
|
+
`),w&&(b+=` query: ${n.queryType||"Record<string, any>"};
|
|
616
|
+
`),A&&(b+=` data: ${n.dtoType||"any"};
|
|
617
|
+
`),b+=" }",Y=`{ arg: ${b} }`),e+=`export function ${T}(
|
|
618
|
+
`,e+=` config?: SWRMutationConfiguration<${k}, Error, string, ${b}>
|
|
617
619
|
`,e+=`) {
|
|
618
620
|
`,e+=` return useSWRMutation(
|
|
619
621
|
`,e+=` '${n.name}',
|
|
620
|
-
`,e+=" async (_, ",
|
|
621
|
-
`,e+=` return apiClient.${n.name}(${
|
|
622
|
+
`,e+=" async (_, ",b!=="void"&&(e+=`{ arg }: ${Y}`),e+=`) => {
|
|
623
|
+
`,e+=` return apiClient.${n.name}(${b!=="void"?"arg":""});
|
|
622
624
|
`,e+=` },
|
|
623
625
|
`,e+=` config
|
|
624
626
|
`,e+=` );
|
|
625
627
|
`,e+=`}
|
|
626
628
|
|
|
627
|
-
`;}}),e},ze=(l,
|
|
628
|
-
`;
|
|
629
|
-
|
|
630
|
-
`,
|
|
631
|
-
|
|
632
|
-
`,
|
|
633
|
-
`;let t=new Set;return l.forEach(n=>{n.queryType&&t.add(n.queryType),n.dtoType&&t.add(n.dtoType),n.responseType&&t.add(n.responseType);}),t.forEach(n=>{
|
|
634
|
-
`;}),
|
|
635
|
-
|
|
636
|
-
`,
|
|
637
|
-
`,l.forEach(n=>{
|
|
638
|
-
`;}),
|
|
639
|
-
|
|
640
|
-
`,
|
|
641
|
-
`,
|
|
642
|
-
`,
|
|
643
|
-
`,
|
|
644
|
-
`,
|
|
645
|
-
`,
|
|
646
|
-
`,
|
|
647
|
-
`,
|
|
648
|
-
`,
|
|
649
|
-
`),
|
|
650
|
-
`,
|
|
651
|
-
`,
|
|
652
|
-
`),
|
|
653
|
-
`,
|
|
654
|
-
`,
|
|
655
|
-
`,l.forEach((n,
|
|
656
|
-
`,
|
|
657
|
-
`;let
|
|
658
|
-
`,j&&(
|
|
659
|
-
`,
|
|
660
|
-
`;}),
|
|
661
|
-
`),
|
|
662
|
-
`),
|
|
663
|
-
`),
|
|
664
|
-
`,
|
|
665
|
-
`,
|
|
666
|
-
`,j){let
|
|
667
|
-
`;}else
|
|
668
|
-
`;
|
|
669
|
-
`,
|
|
670
|
-
`,
|
|
671
|
-
`,
|
|
672
|
-
`),
|
|
673
|
-
`),
|
|
674
|
-
`,
|
|
675
|
-
`,n.tags&&n.tags.length>0&&(f?
|
|
676
|
-
`:
|
|
677
|
-
`),
|
|
678
|
-
`;}),
|
|
679
|
-
`,
|
|
680
|
-
|
|
681
|
-
`,
|
|
682
|
-
|
|
683
|
-
`,
|
|
684
|
-
`;
|
|
685
|
-
`,
|
|
686
|
-
|
|
687
|
-
`,
|
|
688
|
-
`;}),
|
|
629
|
+
`;}}),e},ze=(l,o)=>{var i;let p=((i=o.rtkQuery)==null?void 0:i.apiName)||"api",e=o.baseURL||"",s=`// Generated RTK Query API Slice
|
|
630
|
+
`;s+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
631
|
+
|
|
632
|
+
`,s+=`import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
|
|
633
|
+
|
|
634
|
+
`,s+=`import type {
|
|
635
|
+
`;let t=new Set;return l.forEach(n=>{n.queryType&&t.add(n.queryType),n.dtoType&&t.add(n.dtoType),n.responseType&&t.add(n.responseType);}),t.forEach(n=>{s+=` ${n},
|
|
636
|
+
`;}),s+=`} from '../types';
|
|
637
|
+
|
|
638
|
+
`,s+=`import {
|
|
639
|
+
`,l.forEach(n=>{s+=` ${n.name},
|
|
640
|
+
`;}),s+=`} from '../endpoints';
|
|
641
|
+
|
|
642
|
+
`,s+=`const ${p}Api = createApi({
|
|
643
|
+
`,s+=` reducerPath: '${p}Api',
|
|
644
|
+
`,s+=` baseQuery: fetchBaseQuery({
|
|
645
|
+
`,s+=` baseUrl: '${e}',
|
|
646
|
+
`,o.auth&&(s+=` prepareHeaders: (headers, { getState }) => {
|
|
647
|
+
`,s+=` // Get token from your auth state
|
|
648
|
+
`,s+=` // const token = (getState() as RootState).auth.token;
|
|
649
|
+
`,s+=` // if (token) {
|
|
650
|
+
`,o.auth.type==="bearer"?s+=" // headers.set('Authorization', `Bearer ${token}`);\n":o.auth.type==="apiKey"&&o.auth.in==="header"&&(s+=` // headers.set('${o.auth.name||"X-API-Key"}', token);
|
|
651
|
+
`),s+=` // }
|
|
652
|
+
`,s+=` return headers;
|
|
653
|
+
`,s+=` },
|
|
654
|
+
`),s+=` }),
|
|
655
|
+
`,s+=` tagTypes: [${[...new Set(l.flatMap(n=>n.tags||[]))].map(n=>`'${n}'`).join(", ")}],
|
|
656
|
+
`,s+=` endpoints: (builder) => ({
|
|
657
|
+
`,l.forEach((n,g)=>{var H,T;let m=n.method.toUpperCase(),f=m==="GET",O=((H=n.parameters)==null?void 0:H.filter(b=>b.in==="path"))||[],q=((T=n.parameters)==null?void 0:T.filter(b=>b.in==="query"))||[],j=O.length>0,w=q.length>0,A=!!n.requestBody,k=n.responseType||"any";s+=` ${n.name}: builder.${f?"query":"mutation"}<
|
|
658
|
+
`,s+=` ${k},
|
|
659
|
+
`;let S="void";if((j||w||A)&&(S=`{
|
|
660
|
+
`,j&&(S+=` url: {
|
|
661
|
+
`,O.forEach(b=>{let G={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[b.type||"string"]||"any",Q=b.required?"":"?";S+=` ${b.name}${Q}: ${G};
|
|
662
|
+
`;}),S+=` };
|
|
663
|
+
`),w&&(S+=` query: ${n.queryType||"Record<string, any>"};
|
|
664
|
+
`),A&&(S+=` data: ${n.dtoType||"any"};
|
|
665
|
+
`),S+=" }"),s+=` ${S}
|
|
666
|
+
`,s+=` >({
|
|
667
|
+
`,s+=" query: (",S!=="void"&&(s+="arg"),s+=`) => {
|
|
668
|
+
`,j){let b=O.map(Y=>`arg.url.${Y.name}`).join(", ");s+=` const url = ${n.name}(${b});
|
|
669
|
+
`;}else s+=` const url = ${n.name};
|
|
670
|
+
`;s+=` return {
|
|
671
|
+
`,s+=` url,
|
|
672
|
+
`,s+=` method: '${m}',
|
|
673
|
+
`,w&&(s+=` params: arg.query,
|
|
674
|
+
`),A&&(s+=` body: arg.data,
|
|
675
|
+
`),s+=` };
|
|
676
|
+
`,s+=` },
|
|
677
|
+
`,n.tags&&n.tags.length>0&&(f?s+=` providesTags: ['${n.tags[0]}'],
|
|
678
|
+
`:s+=` invalidatesTags: ['${n.tags[0]}'],
|
|
679
|
+
`),s+=` })${g<l.length-1?",":""}
|
|
680
|
+
`;}),s+=` }),
|
|
681
|
+
`,s+=`});
|
|
682
|
+
|
|
683
|
+
`,s+=`export default ${p}Api;
|
|
684
|
+
|
|
685
|
+
`,s};var In=(l,o)=>{var p,e;if((p=o==null?void 0:o.folderSplit)!=null&&p.customFolder){let s=o.folderSplit.customFolder({method:l.method,path:l.path,tags:l.tags,operationId:l.operationId,summary:l.summary});if(s)return s}return (e=o==null?void 0:o.folderSplit)!=null&&e.byTags&&l.tags&&l.tags.length>0?l.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},an=(l,o,p,e,s)=>d(null,null,function*(){let t=on(l,p);if(t.length===0)return;let i=p.type||"fetch";p.outputDir||J.join(s,e,"client");let g=!!(o!=null&&o.folderSplit&&(o.folderSplit.byTags||o.folderSplit.customFolder));if(`${i}${t.length}`,g){let f={};t.forEach(j=>{let w=In(j,o);f[w]||(f[w]=[]),f[w].push(j);});let O=Object.keys(f);for(let[j,w]of Object.entries(f)){let A=J.join(s,e,j);yield ie.promises.mkdir(A,{recursive:true}),`${i}${j}${w.length}`,yield xn(w,o,p,A,i,j,true);}let q=J.join(s,e);yield En(q,O,i,o);return}let m=J.join(s,e);switch(yield ie.promises.mkdir(m,{recursive:true}),i){case "fetch":let f=Fe(t,p);f=f.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield X(J.join(m,"clients.ts"),f,o);break;case "axios":let O=he(t,p,false);O=O.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield X(J.join(m,"clients.ts"),O,o);break;case "react-query":let q=he(t,p,false);q=q.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield X(J.join(m,"clients.ts"),q,o);let j=Qe(t,p);j=j.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';").replace("import apiClient from './client';","import apiClient from './clients';"),yield X(J.join(m,"hooks.ts"),j,o);break;case "swr":let w=he(t,p,false);w=w.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield X(J.join(m,"clients.ts"),w,o);let A=Be(t,p);A=A.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';").replace("import apiClient from './client';","import apiClient from './clients';"),yield X(J.join(m,"hooks.ts"),A,o);break;case "rtk-query":let k=ze(t,p);k=k.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield X(J.join(m,"api.ts"),k,o);break;default:throw new Error(`Unknown client type: ${i}`)}}),X=(l,o,p)=>d(null,null,function*(){var i,n,g,m;if(!(((i=p==null?void 0:p.customCode)==null?void 0:i.enabled)!==false)){yield ie.promises.writeFile(l,o);return}let s=null;try{s=yield ie.promises.readFile(l,"utf-8");}catch(f){}let t=je(o,s,{position:((n=p==null?void 0:p.customCode)==null?void 0:n.position)||"bottom",markerText:(g=p==null?void 0:p.customCode)==null?void 0:g.markerText,includeInstructions:(m=p==null?void 0:p.customCode)==null?void 0:m.includeInstructions});yield ie.promises.writeFile(l,t);});var xn=(l,o,p,e,s,t,i=false)=>d(null,null,function*(){let n="",g="",m=i?"./types":"../types",f=i?"./endpoints":"../endpoints";switch(s){case "fetch":n=Fe(l,p,i),n=n.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${f}';`),yield X(J.join(e,"client.ts"),n,o);break;case "axios":n=he(l,p,i),n=n.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${f}';`),yield X(J.join(e,"client.ts"),n,o);break;case "react-query":if(n=he(l,p,i),n=n.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${f}';`),yield X(J.join(e,"client.ts"),n,o),g=Qe(l,p),g=g.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${f}';`),i){let q=t.replace(/-/g,"_");g=g.replace("import apiClient from './client';",`import { ${q}Client as apiClient } from '../clients';`);}yield X(J.join(e,"hooks.ts"),g,o);break;case "swr":if(n=he(l,p,i),n=n.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${f}';`),yield X(J.join(e,"client.ts"),n,o),g=Be(l,p),g=g.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${f}';`),i){let q=t.replace(/-/g,"_");g=g.replace("import apiClient from './client';",`import { ${q}Client as apiClient } from '../clients';`);}yield X(J.join(e,"hooks.ts"),g,o);break;case "rtk-query":let O=i?b(a({},p),{rtkQuery:b(a({},p.rtkQuery),{apiName:t.replace(/-/g,"_")})}):p;g=ze(l,O),g=g.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${f}';`),yield X(J.join(e,"api.ts"),g,o);break;default:throw new Error(`Unknown client type: ${s}`)}}),En=(l,o,p,e)=>d(null,null,function*(){var t;if(p==="rtk-query"){let i=`// Generated RTK Query APIs
|
|
686
|
+
`;i+=`// This file was auto-generated.
|
|
687
|
+
`,i+=`// Aggregates all API slices for easy Redux store setup
|
|
688
|
+
|
|
689
|
+
`,o.forEach(n=>{let g=n.replace(/-/g,"_");i+=`import ${g}Api from './${n}/api';
|
|
690
|
+
`;}),i+=`
|
|
689
691
|
// Export all API slices
|
|
690
|
-
`,
|
|
691
|
-
`;}),
|
|
692
|
+
`,o.forEach(n=>{let g=n.replace(/-/g,"_");i+=`export { default as ${g}Api } from './${n}/api';
|
|
693
|
+
`;}),i+=`
|
|
692
694
|
/**
|
|
693
|
-
`,
|
|
694
|
-
`,
|
|
695
|
-
`,
|
|
696
|
-
`,
|
|
697
|
-
`,
|
|
698
|
-
`,
|
|
699
|
-
`,
|
|
700
|
-
`,
|
|
701
|
-
`,
|
|
702
|
-
`,
|
|
703
|
-
`,
|
|
704
|
-
`,
|
|
705
|
-
`,
|
|
706
|
-
`,
|
|
707
|
-
`,
|
|
708
|
-
`;}),
|
|
709
|
-
`,
|
|
710
|
-
`,
|
|
711
|
-
`;}),
|
|
712
|
-
`,
|
|
713
|
-
`,yield
|
|
714
|
-
`;if(
|
|
715
|
-
`,
|
|
716
|
-
|
|
717
|
-
`,p==="fetch"?
|
|
718
|
-
`;}):(
|
|
719
|
-
`;}),
|
|
695
|
+
`,i+=` * Configure Redux store with all API slices
|
|
696
|
+
`,i+=` *
|
|
697
|
+
`,i+=` * @example
|
|
698
|
+
`,i+=` * import { configureStore } from '@reduxjs/toolkit';
|
|
699
|
+
`,i+=` * import { setupApiStore } from './apis';
|
|
700
|
+
`,i+=` *
|
|
701
|
+
`,i+=` * export const store = configureStore({
|
|
702
|
+
`,i+=` * reducer: setupApiStore.reducer,
|
|
703
|
+
`,i+=` * middleware: (getDefaultMiddleware) =>
|
|
704
|
+
`,i+=` * getDefaultMiddleware().concat(setupApiStore.middleware),
|
|
705
|
+
`,i+=` * });
|
|
706
|
+
`,i+=` */
|
|
707
|
+
`,i+=`export const setupApiStore = {
|
|
708
|
+
`,i+=` reducer: {
|
|
709
|
+
`,o.forEach(n=>{let g=n.replace(/-/g,"_");i+=` [${g}Api.reducerPath]: ${g}Api.reducer,
|
|
710
|
+
`;}),i+=` },
|
|
711
|
+
`,i+=` middleware: [
|
|
712
|
+
`,o.forEach(n=>{let g=n.replace(/-/g,"_");i+=` ${g}Api.middleware,
|
|
713
|
+
`;}),i+=` ],
|
|
714
|
+
`,i+=`};
|
|
715
|
+
`,yield X(J.join(l,"apis.ts"),i,e);return}let s=`// Generated API Clients
|
|
716
|
+
`;if(s+=`// This file was auto-generated.
|
|
717
|
+
`,s+=`// Centralized client instances and configuration
|
|
718
|
+
|
|
719
|
+
`,p==="fetch"?o.forEach(i=>{let n=i.replace(/-/g,"_");s+=`export { default as ${n}Client } from './${i}/client';
|
|
720
|
+
`;}):(o.forEach(i=>{let n=i.replace(/-/g,"_"),g=`${n.charAt(0).toUpperCase()+n.slice(1)}ApiClient`;s+=`import ${g} from './${i}/client';
|
|
721
|
+
`;}),s+=`
|
|
720
722
|
// Create client instances
|
|
721
|
-
`,
|
|
722
|
-
`;})),p==="fetch"&&(
|
|
723
|
+
`,o.forEach(i=>{let n=i.replace(/-/g,"_"),g=`${n.charAt(0).toUpperCase()+n.slice(1)}ApiClient`;s+=`export const ${n}Client = new ${g}();
|
|
724
|
+
`;})),p==="fetch"&&(s+=`
|
|
723
725
|
// Import clients for aggregation
|
|
724
|
-
`,
|
|
725
|
-
`;})),
|
|
726
|
+
`,o.forEach(i=>{let n=i.replace(/-/g,"_");s+=`import ${n}_client from './${i}/client';
|
|
727
|
+
`;})),s+=`
|
|
726
728
|
// Aggregate all client instances
|
|
727
|
-
`,
|
|
728
|
-
`,
|
|
729
|
-
`:
|
|
730
|
-
`;}),
|
|
729
|
+
`,s+=`export const clients = {
|
|
730
|
+
`,o.forEach(i=>{let n=i.replace(/-/g,"_");p==="fetch"?s+=` ${n}: ${n}_client,
|
|
731
|
+
`:s+=` ${n}: ${n}Client,
|
|
732
|
+
`;}),s+=`};
|
|
731
733
|
|
|
732
|
-
`,p==="axios"?(
|
|
734
|
+
`,p==="axios"?(s+=`
|
|
733
735
|
/**
|
|
734
|
-
`,
|
|
735
|
-
`,
|
|
736
|
-
`,
|
|
737
|
-
`,
|
|
738
|
-
`,
|
|
739
|
-
`,
|
|
740
|
-
`,
|
|
741
|
-
`,
|
|
742
|
-
`,
|
|
743
|
-
`;}),
|
|
744
|
-
|
|
745
|
-
`):p==="fetch"&&(
|
|
736
|
+
`,s+=` * Configure all API clients at once
|
|
737
|
+
`,s+=` * @param config - Configuration to apply to all clients
|
|
738
|
+
`,s+=` */
|
|
739
|
+
`,s+=`export const configureAllClients = (config: {
|
|
740
|
+
`,s+=` baseURL?: string;
|
|
741
|
+
`,s+=` headers?: Record<string, string>;
|
|
742
|
+
`,s+=` timeout?: number;
|
|
743
|
+
`,s+=`}) => {
|
|
744
|
+
`,o.forEach(i=>{let n=i.replace(/-/g,"_");s+=` ${n}Client.updateConfig(config);
|
|
745
|
+
`;}),s+=`};
|
|
746
|
+
|
|
747
|
+
`):p==="fetch"&&(s+=`
|
|
746
748
|
/**
|
|
747
|
-
`,
|
|
748
|
-
`,
|
|
749
|
-
`,
|
|
750
|
-
`,
|
|
751
|
-
`,
|
|
752
|
-
`,
|
|
753
|
-
`,
|
|
754
|
-
`,
|
|
755
|
-
`,
|
|
756
|
-
`;}),
|
|
757
|
-
|
|
758
|
-
`),
|
|
759
|
-
`,
|
|
760
|
-
`,
|
|
761
|
-
`,
|
|
762
|
-
`,
|
|
763
|
-
`,
|
|
764
|
-
`,
|
|
765
|
-
`,
|
|
766
|
-
`,
|
|
767
|
-
`,
|
|
768
|
-
`,
|
|
769
|
-
`,yield
|
|
770
|
-
`;
|
|
771
|
-
`,
|
|
772
|
-
|
|
773
|
-
`,
|
|
774
|
-
`;}),
|
|
749
|
+
`,s+=` * Configure all API clients at once
|
|
750
|
+
`,s+=` * @param config - Configuration to apply to all clients
|
|
751
|
+
`,s+=` */
|
|
752
|
+
`,s+=`export const configureAllClients = (config: {
|
|
753
|
+
`,s+=` baseURL?: string;
|
|
754
|
+
`,s+=` headers?: Record<string, string>;
|
|
755
|
+
`,s+=` auth?: { token?: string };
|
|
756
|
+
`,s+=`}) => {
|
|
757
|
+
`,o.forEach(i=>{let n=i.replace(/-/g,"_");s+=` ${n}_client.setApiConfig(config);
|
|
758
|
+
`;}),s+=`};
|
|
759
|
+
|
|
760
|
+
`),s+=`// Example usage:
|
|
761
|
+
`,s+=`// import { configureAllClients, clients } from './clients';
|
|
762
|
+
`,s+=`//
|
|
763
|
+
`,s+=`// // Configure all clients at once
|
|
764
|
+
`,s+=`// configureAllClients({
|
|
765
|
+
`,s+=`// baseURL: 'https://api.example.com',
|
|
766
|
+
`,s+=`// timeout: 10000,
|
|
767
|
+
`,s+=`// });
|
|
768
|
+
`,s+=`//
|
|
769
|
+
`,s+=`// // Use specific client
|
|
770
|
+
`,s+=`// const data = await clients.${(t=o[0])==null?void 0:t.replace(/-/g,"_")}.someMethod(...);
|
|
771
|
+
`,yield X(J.join(l,"clients.ts"),s,e),p==="react-query"||p==="swr"){let i=`// Generated Hooks Aggregator
|
|
772
|
+
`;i+=`// This file was auto-generated.
|
|
773
|
+
`,i+=`// Aggregates all folder-split hooks
|
|
774
|
+
|
|
775
|
+
`,o.forEach(n=>{i+=`export * from './${n}/hooks';
|
|
776
|
+
`;}),i+=`
|
|
775
777
|
// Example usage:
|
|
776
|
-
`,
|
|
777
|
-
`,yield
|
|
778
|
+
`,i+=`// import { useGetSomething } from './hooks';
|
|
779
|
+
`,yield X(J.join(l,"hooks.ts"),i,e);}});var ke=process.cwd(),ln=()=>{let l;try{c("esbuild-register");}catch(i){throw i}let o=J.join(ke,"openapi.sync.js"),p=J.join(ke,"openapi.sync.ts"),e=J.join(ke,"openapi.sync.json"),s=[o,p,e];try{for(let i of s)ie.existsSync(i)&&(l=c(i),Object.keys(l).length===1&&l.default&&(l=l.default));}catch(i){}typeof l=="function"&&(l=l());let t=l;if(!t)throw new Error("No config found");return t},mr=l=>d(null,null,function*(){let o=ln(),p=Object.keys(o.api),e=l&&"refetchInterval"in l&&!isNaN(l==null?void 0:l.refetchInterval)?l.refetchInterval:o.refetchInterval;Me();for(let s=0;s<p.length;s+=1){let t=p[s],i=o.api[t];yield Le(i,t,o,e);}}),cr=l=>d(null,null,function*(){let o=ln(),p=l.apiName?[l.apiName]:Object.keys(o.api);for(let s of p)if(!o.api[s])throw new Error(`API "${s}" not found in configuration. Available APIs: ${Object.keys(o.api).join(", ")}`);Me();for(let s of p){let t=o.api[s];yield Le(t,s,o);}let e=(o==null?void 0:o.folder)||"api";for(let s of p){let t=nn(s);if(t.length===0){continue}`${t.length}${s}`;let i=a(a(a(a(b(a({enabled:true},o.clientGeneration||{}),{type:l.type}),l.outputDir&&{outputDir:l.outputDir}),l.baseURL&&{baseURL:l.baseURL}),l.tags&&{tags:l.tags}),l.endpoints&&{endpoints:l.endpoints});yield an(t,o,i,s,J.join(ke,e));}}),dr=()=>d(null,null,function*(){let{interactiveInit:l}=yield import('./interactive-init-GI3DBKYN.mjs');yield l();});export{cr as GenerateClient,mr as Init,dr as InteractiveInit,Ee as JSONStringify,ue as capitalize,Ht as createCustomCodeMarker,dn as extractCustomCode,Vt as getEndpointDetails,vn as getNestedValue,Kt as isJson,cn as isYamlString,je as mergeCustomCode,ve as renderTypeRefMD,wn as variableName,Wt as variableNameChar,_t as yamlStringToJson};
|