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