openapi-sync 5.0.4 → 5.0.5
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 +42 -25
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +608 -533
- package/dist/index.mjs +532 -457
- package/package.json +94 -94
- /package/dist/{interactive-init-GI3DBKYN.mjs → interactive-init-OITE22SZ.mjs} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,376 +1,451 @@
|
|
|
1
|
-
import {c,d,a,b}from'./chunk-PUWCZVB7.mjs';import
|
|
2
|
-
`+" ".repeat(
|
|
3
|
-
`).filter(
|
|
4
|
-
${" ".repeat(
|
|
5
|
-
${" ".repeat(
|
|
6
|
-
`).map(
|
|
1
|
+
import {c,d,a,b}from'./chunk-PUWCZVB7.mjs';import ue from'fs';import V from'path';import*as Ae from'js-yaml';import wt from'lodash.isequal';import ke from'lodash.get';import Ot from'axios';import Pt from'axios-retry';import jt from'@apidevtools/swagger-parser';import {CurlGenerator}from'curl-generator';var Nt=/^[A-Za-z_$][A-Za-z0-9_$]*$/,nt=/[A-Za-z0-9_$]/;var st=l=>["object"].includes(typeof l)&&!(l instanceof Blob),Et=l=>{try{return Ae.load(l),!0}catch(i){let m=i;if(m instanceof Ae.YAMLException)return false;throw m}},ot=l=>{if(Et(l)){let i=Ae.load(l),m=JSON.stringify(i,null,2);return JSON.parse(m)}},de=l=>l.substring(0,1).toUpperCase()+l.substring(1),at=(l,i)=>{let m=l.split("/"),e=`${de(i)}`,s=[];return m.forEach(n=>{if(n[0]==="{"&&n[n.length-1]==="}"){let t=n.replace(/{/,"").replace(/}/,"");s.push(t),n=`$${t}`;}else if(n[0]==="<"&&n[n.length-1]===">"){let t=n.replace(/</,"").replace(/>/,"");s.push(t),n=`$${t}`;}else if(n[0]===":"){let t=n.replace(/:/,"");s.push(t),n=`$${t}`;}let p="";n.split("").forEach(t=>{let h=t;nt.test(t)||(h="/"),p+=h;}),p.split("/").forEach(t=>{e+=de(t);});}),{name:e,variables:s,pathParts:m}},Te=(l,i=1)=>{let m="{",e=Object.keys(l);for(let s=0;s<e.length;s++){let n=e[s],p=l[n];if(m+=`
|
|
2
|
+
`+" ".repeat(i)+n+": ",Array.isArray(p)){m+="[";for(let t=0;t<p.length;t++){let h=p[t];typeof h=="object"&&h!==null?m+=Te(h,i+1):m+=typeof h=="string"?`"${h}"`:h,t<p.length-1&&(m+=", ");}m+="]";}else typeof p=="object"&&p!==null?m+=""+Te(p,i+1):m+=p.split(`
|
|
3
|
+
`).filter(t=>t.trim()!=="").join(`
|
|
4
|
+
${" ".repeat(i)}`);s<e.length-1&&(m+=", ");}return m+=`
|
|
5
|
+
${" ".repeat(i-1)}}`,m},ve=(l,i=1)=>{let m=l.replace(/\/\*\*?[\s\S]*?\*\//g,e=>e.replace(/^\/\*\*?\s*/,"").replace(/\s*\*\/$/,"").split(`
|
|
6
|
+
`).map(n=>n.replace(/^\s*\*\s?/,"").trim()).filter(n=>n.length>0).map(n=>`// ${n}`).join(`
|
|
7
7
|
`));return `
|
|
8
8
|
\`\`\`typescript
|
|
9
|
-
${" ".repeat(
|
|
9
|
+
${" ".repeat(i)} ${m.split(`
|
|
10
10
|
`).filter(e=>e.trim()!=="").join(`
|
|
11
|
-
${" ".repeat(
|
|
12
|
-
\`\`\``};function
|
|
13
|
-
`,
|
|
14
|
-
`).filter(
|
|
15
|
-
|
|
16
|
-
`:"";return
|
|
17
|
-
|
|
18
|
-
${e}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
`)
|
|
23
|
-
`)
|
|
24
|
-
|
|
25
|
-
|
|
11
|
+
${" ".repeat(i)} `)}
|
|
12
|
+
\`\`\``};function Lt(l,i){return i.split(".").reduce((e,s)=>e&&e[s]!==void 0?e[s]:void 0,l)}var Tt=(l,i="CUSTOM CODE")=>{let e=["//","#"].map(t=>({start:`${t} \u{1F512} ${i} START`,end:`${t} \u{1F512} ${i} END`})),s={beforeGenerated:"",afterGenerated:""},n=0,p=[];for(;n<l.length;){let t=null,h=-1;for(let j of e){let E=l.indexOf(j.start,n);E!==-1&&(h===-1||E<h)&&(h=E,t=j);}if(h===-1||!t)break;let d=l.indexOf(t.end,h);if(d===-1)break;let f=d+t.end.length,w=l.substring(f,f+100),G=w.match(/^\s*\n\s*((?:\/\/|#)\s*=+)/);if(G){let j=w.indexOf(`
|
|
13
|
+
`,G.index+1);j!==-1?f+=j+1:f+=G[0].length;}let R=h,O=l.substring(Math.max(0,h-200),h),U=/(^|\n)\s*(?:\/\/|#)\s*=+/g,M,k=-1;for(;(M=U.exec(O))!==null;)k=M.index+M[1].length;k!==-1&&(R=Math.max(0,h-200)+k);let B=l.substring(R,f);p.push({start:R,end:f,content:B}),n=f;}return p.length>0&&(l.substring(0,p[0].start).split(`
|
|
14
|
+
`).filter(d=>{let f=d.trim();return f.length>0&&!f.startsWith("//")&&!f.startsWith("#")}).join("").length===0?(s.beforeGenerated=p[0].content,p.length>1&&(s.afterGenerated=p[1].content)):(s.afterGenerated=p[0].content,p.length>1&&!s.beforeGenerated&&(s.beforeGenerated=p[1].content))),s},tt=(l,i="CUSTOM CODE",m=true,e="//")=>{let s=m?`${e} ${l==="top"?"Add your custom code below this line":"Add your custom code above this line"}
|
|
15
|
+
${e} This section will be preserved during regeneration
|
|
16
|
+
`:"";return `${e} ${"=".repeat(60)}
|
|
17
|
+
${e} \u{1F512} ${i} START
|
|
18
|
+
${s}${e} ${"=".repeat(60)}
|
|
19
|
+
|
|
20
|
+
${e} \u{1F512} ${i} END
|
|
21
|
+
${e} ${"=".repeat(60)}`},rt=(l,i,m)=>{if(!l)return l;let e=new RegExp(`^\\s*//\\s*(?:={3,}|\u{1F512}\\s+${i}\\s+(?:START|END)|Add your custom code (?:below|above) this line|This section will be preserved during regeneration)\\s*$`);return l.split(`
|
|
22
|
+
`).map(s=>e.test(s)?s.replace(/^\s*\/\//,m):s).join(`
|
|
23
|
+
`)},qe=(l,i,m={})=>{let{position:e="bottom",markerText:s="CUSTOM CODE",includeInstructions:n=true,commentPrefix:p="//"}=m,t={beforeGenerated:"",afterGenerated:""};i&&(t=Tt(i,s),t.beforeGenerated=rt(t.beforeGenerated,s,p),t.afterGenerated=rt(t.afterGenerated,s,p)),!t.beforeGenerated&&!t.afterGenerated&&((e==="top"||e==="both")&&(t.beforeGenerated=tt("top",s,n,p)),(e==="bottom"||e==="both")&&(t.afterGenerated=tt("bottom",s,n,p)));let h=[];return t.beforeGenerated&&(h.push(t.beforeGenerated),h.push("")),h.push(l),t.afterGenerated&&(h.push(""),h.push(t.afterGenerated)),h.join(`
|
|
24
|
+
`)};var Re=V.join(__dirname,"../","../db.json");ue.existsSync(Re)||ue.writeFileSync(Re,"{}");var Ge={};try{Ge=c(Re);}catch(l){Ge={};}var we=Ge||{},it=l=>{ue.writeFileSync(Re,JSON.stringify(l));},lt=(l,i)=>{we[l]=i,it(we);},pt=l=>we[l],Le=()=>{we={},it(we);};var ut={},mt=(l,i)=>{ut[l]=i;},ct=l=>ut[l]||[];var $e=process.cwd(),Fe={},dt=Ot.create({timeout:6e4});Pt(dt,{retries:20,retryCondition:l=>l.code==="ECONNABORTED"||l.message.includes("Network Error"),retryDelay:l=>l*1e3});var Ce=(l,i,m)=>d(null,null,function*(){var t,h,d,f;if(!(((t=m==null?void 0:m.customCode)==null?void 0:t.enabled)!==false)){yield ue.promises.writeFile(l,i);return}let s=null;try{s=yield ue.promises.readFile(l,"utf-8");}catch(w){}let n=l.endsWith(".py")?"#":"//",p=qe(i,s,{position:((h=m==null?void 0:m.customCode)==null?void 0:h.position)||"bottom",markerText:(d=m==null?void 0:m.customCode)==null?void 0:d.markerText,includeInstructions:(f=m==null?void 0:m.customCode)==null?void 0:f.includeInstructions,commentPrefix:n});yield ue.promises.writeFile(l,p);}),ft=(l,i,m,e)=>d(null,null,function*(){let s=yield qt(l,i,m,e);return e&&!isNaN(e)&&e>0&&(process.env.NODE_ENV&&["production","prod","test","staging"].includes(process.env.NODE_ENV)||(Fe[i]&&clearTimeout(Fe[i]),Fe[i]=setTimeout(()=>{console.info(`\u{1F504} Auto syncing ${i}`),ft(l,i,m,e);},e))),s}),qt=(...l)=>d(null,null,function*(){var _e,He,Ke,Ve,Ye,Ze,Xe,en,nn,tn;let[i,m,e]=l,s=r=>r.startsWith("http://")||r.startsWith("https://"),n;try{if(s(i))n=(yield dt.get(i)).data;else {let r=V.isAbsolute(i)?i:V.join($e,i);`${r}`,n=yield ue.promises.readFile(r,"utf-8");}}catch(r){throw process.env.NODE_ENV&&["production","prod","test","staging"].includes(process.env.NODE_ENV)||console.error(`Failed to load OpenAPI spec for ${m}:`,r),r}if(!n)return;let p=st(n)?n:ot(n),t;try{t=yield jt.parse(p);}catch(r){let o=r instanceof Error?r.message:String(r);throw new Error(`Failed to parse OpenAPI spec for ${m}: ${o}`)}let h=V.join((e==null?void 0:e.folder)||"",m),d=(e==null?void 0:e.language)==="python",f=d?"py":"ts",w={},G=r=>{var o,b;if((o=e==null?void 0:e.folderSplit)!=null&&o.customFolder){let C=e.folderSplit.customFolder(r);if(C)return C}return (b=e==null?void 0:e.folderSplit)!=null&&b.byTags&&r.tags&&r.tags.length>0?r.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},R=typeof(e==null?void 0:e.server)=="string"?e==null?void 0:e.server:((He=(_e=t==null?void 0:t.servers)==null?void 0:_e[(e==null?void 0:e.server)||0])==null?void 0:He.url)||"",O=typeof((Ve=(Ke=e==null?void 0:e.types)==null?void 0:Ke.name)==null?void 0:Ve.prefix)=="string"?e==null?void 0:e.types.name.prefix:"I",U=typeof((Ze=(Ye=e==null?void 0:e.endpoints)==null?void 0:Ye.name)==null?void 0:Ze.prefix)=="string"?e==null?void 0:e.endpoints.name.prefix:"",M=(r,o)=>{var C,u;let b=de(r);if((u=(C=e==null?void 0:e.types)==null?void 0:C.name)!=null&&u.format){let y=e==null?void 0:e.types.name.format("shared",{name:r},b);if(y)return `${O}${y}`}return `${O}${b}`},k=(r,o,b$1,C,u,y=0)=>{let c="",$="",g="";if(o)if(o.$ref)if(o.$ref[0]==="#"){let x=(o.$ref||"").split("/");x.shift();x[0]==="definitions";[...x].pop();let S=ke(r,x,null);if(S){S!=null&&S.name&&(c=S.name),$=x[x.length-1];let W=M($);W.includes(".")&&(W=W.split(".").map((he,ce)=>ce===0?he:`["${he}"]`).join("")),g+=`${u!=null&&u.noSharedImport?"":"Shared."}${W}`;}}else g+="";else if(o.anyOf)g+=`(${o.anyOf.map(x=>k(r,x,"",C,b(a({},u),{useComponentName:false}))).filter(x=>!!x).join("|")})`;else if(o.oneOf)g+=`(${o.oneOf.map(x=>k(r,x,"",C,b(a({},u),{useComponentName:false}))).filter(x=>!!x).join("|")})`;else if(o.allOf)g+=`(${o.allOf.map(x=>k(r,x,"",C,b(a({},u),{useComponentName:false}))).filter(x=>!!x).join("&")})`;else if(o.items)g+=`${k(r,o.items,"",false,b(a({},u),{useComponentName:false}))}[]`;else if(o.properties){let x=Object.keys(o.properties),P=o.required||[],v="";x.forEach(N=>{var W,xe,he,ce,ye,ge;let S="";!((xe=(W=e==null?void 0:e.types)==null?void 0:W.doc)!=null&&xe.disable)&&((ce=(he=o.properties)==null?void 0:he[N])!=null&&ce.description)&&(S=" * "+((ye=o.properties)==null?void 0:ye[N].description.split(`
|
|
25
|
+
`).filter(Ne=>Ne.trim()!=="").join(`
|
|
26
|
+
*${" ".repeat(1)}`))),v+=(S?`/**
|
|
27
|
+
${S}
|
|
26
28
|
*/
|
|
27
|
-
`:"")+`${
|
|
28
|
-
${" ".repeat(y)}${
|
|
29
|
-
`:""}`:""},
|
|
30
|
-
|
|
31
|
-
${
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
`:"")+`${k(r,(ge=o.properties)==null?void 0:ge[N],N,P.includes(N),u,y+1)}`;}),v.length>0?g+=`{
|
|
30
|
+
${" ".repeat(y)}${v}${" ".repeat(y)}}`:g+="{[k: string]: any}";}else if(o.enum&&o.enum.length>0){let x=o.enum.includes(null),P=o.enum.filter(N=>N!==null).map(N=>JSON.stringify(N)).filter(N=>N!==void 0),v=P.length>1||P.length>0&&x;v&&(g+="("),P.forEach((N,S)=>{g+=`${S===0?"":"|"}${N}`;}),x&&(g+=`${P.length>0?"|":""}null`),v&&(g+=")");}else if(o.type){let x=P=>{let v="";if(typeof P=="string")["string","integer","number","array","boolean","null"].includes(P)?["integer","number"].includes(P)?v+="number":P==="array"?v+="any[]":v+=P:P==="object"&&(o.additionalProperties?v+=`{[k: string]: ${k(r,o.additionalProperties,"",true,b(a({},u),{useComponentName:false}))||"any"}}`:v+="{[k: string]: any}");else if(Array.isArray(P)){let N=P.map(S=>x(S));N.filter(S=>S!==""),N.length>1&&(v+="("+N.join("|")+")");}else v+="any";return v};g=x(o.type);}else g+="any";else g="string";let q=c||b$1;u!=null&&u.useComponentName&&!q&&(q=$);let Q=q?` "${q}"${C?"":"?"}: `:"",a$1=(o==null?void 0:o.enum)&&o.enum.includes(null),z=o!=null&&o.nullable&&!a$1?" | null":"";return g.length>0?`${Q}${g}${z}${q?`;
|
|
31
|
+
`:""}`:""},B=(r,o,b$1,C,u,y=0)=>{let c="",$="",g="";if(o)if(o.$ref)if(o.$ref[0]==="#"){let x=(o.$ref||"").split("/");x.shift();x[0]==="definitions";[...x].pop();let S=ke(r,x,null);if(S){S!=null&&S.name&&(c=S.name),$=x[x.length-1];let W=M($);W.includes(".")&&(W=W.split(".").join("_")),g+=`${u!=null&&u.noSharedImport?"":"Shared."}${W}`;}}else g+="Any";else if(o.anyOf)g+=`Union[${o.anyOf.map(x=>B(r,x,"",C,b(a({},u),{useComponentName:false}))).filter(x=>!!x).join(", ")}]`;else if(o.oneOf)g+=`Union[${o.oneOf.map(x=>B(r,x,"",C,b(a({},u),{useComponentName:false}))).filter(x=>!!x).join(", ")}]`;else if(o.allOf)g+="Dict[str, Any]";else if(o.items)g+=`List[${B(r,o.items,"",false,b(a({},u),{useComponentName:false}))}]`;else if(o.properties){let x=Object.keys(o.properties),P=o.required||[],v="";x.forEach(N=>{var S;v+=B(r,(S=o.properties)==null?void 0:S[N],N,P.includes(N),u,y+1);}),v.length>0?b$1?g+="Dict[str, Any]":g+=`
|
|
32
|
+
${v}`:g+="Dict[str, Any]";}else if(o.enum&&o.enum.length>0){let x=o.enum.filter(P=>P!==null).map(P=>JSON.stringify(P));x.length>0?g+=`Literal[${x.join(", ")}]`:g+="Any";}else if(o.type){let x=P=>{let v="";if(typeof P=="string")["integer","number"].includes(P)?v+=P==="number"?"float":"int":P==="string"?v+="str":P==="boolean"?v+="bool":P==="array"?v+="List[Any]":P==="object"?v+="Dict[str, Any]":P==="null"?v+="None":v+="Any";else if(Array.isArray(P)){let N=P.map(S=>x(S)).filter(S=>S!=="");N.length>1?v+=`Union[${N.join(", ")}]`:v+=N[0]||"Any";}else v+="Any";return v};g=x(o.type);}else g+="Any";else g="str";let q=c||b$1;u!=null&&u.useComponentName&&!q&&(q=$);let Q="";q&&(Q=` ${q.replace(/[^a-zA-Z0-9_]/g,"_")}: `);let a$1=g,z=!q&&g.includes(`
|
|
33
|
+
`);return o!=null&&o.nullable&&!z&&(g.startsWith("Union[")?a$1=g.replace("Union[","Union[None, "):a$1=`Optional[${g}]`),g.length>0?`${Q}${a$1}${q?`
|
|
34
|
+
`:""}`:""},j=r=>{let o=(r||"").replace(/^\n+/,"").trimEnd();if(!o)return ` pass
|
|
35
|
+
`;let b=o.split(`
|
|
36
|
+
`),C=/^[A-Za-z_][A-Za-z0-9_]*\s*:\s*.+$/,u=b.map($=>$.trim()).filter($=>!!$).filter($=>!$.startsWith('"""')&&!$.endsWith('"""'));return !u.some($=>C.test($))&&u.length===1?` value: ${u[0]}
|
|
37
|
+
`:`${o.split(`
|
|
38
|
+
`).map($=>$.trim()?/^\s/.test($)?$:` ${$}`:$).join(`
|
|
39
|
+
`)}
|
|
40
|
+
`},E=(r,o)=>`@dataclass
|
|
41
|
+
class ${r}:
|
|
42
|
+
${j(o)}`,ee=r=>{let b=["Any","List","Dict","Union","Optional","Literal"].filter(C=>new RegExp(`\\b${C}\\b`).test(r));return b.length>0?`from typing import ${b.join(", ")}
|
|
43
|
+
`:""},F=(r,o=72)=>{let b=(r||"").replace(/\s+/g," ").trim().split(" ");if(!b[0])return [];let C=[],u="";return b.forEach(y=>{let c=u?`${u} ${y}`:y;c.length>o&&u?(C.push(u),u=y):u=c;}),u&&C.push(u),C},J=r=>{var u,y;if(!r||(y=(u=e==null?void 0:e.types)==null?void 0:u.doc)!=null&&y.disable)return "";let o=(r.description||"").trim(),b=Object.entries(r.properties||{}).map(([c,$])=>({name:c,desc:(($==null?void 0:$.description)||"").trim()})).filter(c=>c.desc.length>0);if(!o&&b.length===0)return "";let C=[' """'];return o&&F(o).forEach(c=>C.push(` ${c}`)),b.length>0&&(o&&C.push(""),C.push(" Attributes:"),b.forEach(c=>{let $=F(c.desc);$.length&&(C.push(` ${c.name}: ${$[0]}`),$.slice(1).forEach(g=>C.push(` ${g}`)));})),C.push(' """'),`${C.join(`
|
|
44
|
+
`)}
|
|
45
|
+
`},re=(r,o)=>{let u="";if(o)if(o.$ref)if(o.$ref[0]==="#"){let y=(o.$ref||"").split("/");y.shift();let $=ke(r,y,null);$&&($!=null&&$.name&&($.name),y[y.length-1],u+=re(r,$));}else u+="";else if(o.anyOf)u+=re(r,o.anyOf[0]);else if(o.oneOf)u+=re(r,o.oneOf[0]);else if(o.allOf)u+=`{${o.allOf.map(y=>`...(${re(r,y)})`).join(",")}}`;else if(o.items)u+=`[${re(r,o.items)}]`;else if(o.properties){let $=Object.keys(o.properties).map(g=>{var q;return ` "${g}": ${re(r,(q=o.properties)==null?void 0:q[g])}`}).join(`,
|
|
46
|
+
`);$.length>0?u+=`{
|
|
47
|
+
${$}
|
|
48
|
+
}`:u+="{}";}else if(o.enum&&o.enum.length>0)o.enum.length>1&&(u+=o.enum[0]);else if(o.type)if(o.example)u+=JSON.stringify(o.example);else {let y=c=>{let $="";if(typeof c=="string")["string","integer","number","array","boolean","null"].includes(c)?["integer","number"].includes(c)?$+="123":c==="array"?$+="[]":c==="boolean"?$+="true":c==="null"?$+="null":$+=`"${c}"`:c==="object"&&($+="{}");else if(Array.isArray(c)){let g=c.map(q=>y(q));g.filter(q=>q!==""),g.length>1&&($+=g.join("|"));}else $+="any";return $};u=y(o.type);}else u+="any";else u="string";return u},fe=pt(m);if(wt(fe,t))return;lt(m,t);let se="",ie="",pe={},Ie=[],Pe=(r,o)=>{let b={},C={};Object.keys(r).forEach(y=>{var g;let c=(g=r[y])!=null&&g.schema?r[y].schema:r[y],$=d?`${B(t,c,"",true,{noSharedImport:true,useComponentName:false})}`:`${k(t,c,"",true,{noSharedImport:true,useComponentName:false})}`;if($){let q=y.split("."),Q=b,a=C;for(let z=0;z<q.length;z++){let x=q[z];z<q.length-1?(x in Q||(Q[x]={},a[x]={}),Q=Q[x],a=a[x]):(Q[x]=$,a[x]=c);}}}),Object.keys(b).forEach(y=>{var z,x,P,v,N;let c=M(y),$=b[y],g=r[y],q=g!=null&&g.schema?g.schema:g,Q="",a="";!((x=(z=e==null?void 0:e.types)==null?void 0:z.doc)!=null&&x.disable)&&y in r&&((P=r[y])!=null&&P.description)&&(Q=" * "+r[y].description.split(`
|
|
49
|
+
`).filter(W=>W.trim()!=="").join(`
|
|
50
|
+
*${" ".repeat(1)}`)),a=J(q),d?pe[y]=((v=pe[y])!=null?v:"")+`@dataclass
|
|
51
|
+
class ${c}:
|
|
52
|
+
`+(a||"")+j(typeof $=="string"?$:"")+`
|
|
53
|
+
`:pe[y]=((N=pe[y])!=null?N:"")+(Q?`/**
|
|
54
|
+
${Q}
|
|
36
55
|
*/
|
|
37
|
-
`:"")+"export type "+c+" = "+(typeof
|
|
38
|
-
`;});};
|
|
39
|
-
`);return
|
|
56
|
+
`:"")+"export type "+c+" = "+(typeof $=="string"?$:Te($))+`;
|
|
57
|
+
`;});};t.definitions&&Pe(t.definitions),t.components&&Object.keys(t.components).forEach(r=>{if(["schemas","responses","parameters","examples","requestBodies","headers","links","callbacks"].includes(r)){let o=t.components[r];Pe(o);}});let Je=r=>{let o="";if(r.content){let b=Object.keys(r.content);b[0]&&r.content[b[0]].schema&&(o+=d?`${B(t,r.content[b[0]].schema,"")}`:`${k(t,r.content[b[0]].schema,"")}`);}return o},me=(r,o,b=0)=>{if(!r)return o==="joi"?"Joi.any()":o==="yup"?"yup.mixed()":"z.any()";if(r.$ref){if(r.$ref[0]==="#"){let C=r.$ref.split("/");C.shift();let u=C.join("."),y=ke(t,u);if(y)return me(y,o,b)}return o==="joi"?"Joi.any()":o==="yup"?"yup.mixed()":"z.any()"}if(r.anyOf||r.oneOf){let C=r.anyOf||r.oneOf;if(C.every(y=>y.enum!==void 0&&Array.isArray(y.enum))){let y=[],c=false;if(C.forEach($=>{$.enum&&$.enum.forEach(g=>{g===null?c=true:y.includes(g)||y.push(g);});}),y.length>0){let $=y.map(g=>JSON.stringify(g)).join(", ");if(o==="zod"){let g=`z.enum([${$}])`;return c&&(g+=".nullable()"),g}else if(o==="yup"){let g=`yup.mixed().oneOf([${$}])`;return c&&(g+=".nullable()"),g}else return c?`Joi.valid(${$}, null)`:`Joi.valid(${$})`}else if(c)return o==="zod"?"z.null()":o==="yup"?"yup.mixed().nullable()":"Joi.valid(null)"}return o==="zod"?`z.union([${C.map($=>me($,o,b+1)).join(", ")}])`:o==="yup"?`yup.mixed().oneOf([${C.map($=>me($,o,b+1)).join(", ")}])`:`Joi.alternatives().try(${C.map(c=>me(c,o,b+1)).join(", ")})`}if(r.allOf)if(o==="zod"){let C=r.allOf.map(y=>me(y,o,b+1)),u=C[0];for(let y=1;y<C.length;y++)u=`${u}.merge(${C[y]})`;return u}else return me(r.allOf[0],o,b+1);if(r.items){let C=me(r.items,o,b+1);if(o==="zod"){let u=`z.array(${C})`;return r.minItems!==void 0&&(u+=`.min(${r.minItems})`),r.maxItems!==void 0&&(u+=`.max(${r.maxItems})`),u}else if(o==="yup"){let u=`yup.array().of(${C})`;return r.minItems!==void 0&&(u+=`.min(${r.minItems})`),r.maxItems!==void 0&&(u+=`.max(${r.maxItems})`),u}else {let u=`Joi.array().items(${C})`;return r.minItems!==void 0&&(u+=`.min(${r.minItems})`),r.maxItems!==void 0&&(u+=`.max(${r.maxItems})`),u}}if(r.properties){let C=r.required||[],u=" ".repeat(b+1),y=Object.entries(r.properties).map(([c,$])=>{let g=C.includes(c),q=me($,o,b+1);return g||(q+=".optional()"),`${u}${c}: ${q}`}).join(`,
|
|
58
|
+
`);return o==="zod"?`z.object({
|
|
40
59
|
${y}
|
|
41
|
-
${" ".repeat(
|
|
60
|
+
${" ".repeat(b)}})`:o==="yup"?`yup.object({
|
|
42
61
|
${y}
|
|
43
|
-
${" ".repeat(
|
|
62
|
+
${" ".repeat(b)}})`:`Joi.object({
|
|
44
63
|
${y}
|
|
45
|
-
${" ".repeat(
|
|
46
|
-
${
|
|
47
|
-
|
|
48
|
-
`),
|
|
49
|
-
${
|
|
64
|
+
${" ".repeat(b)}})`}if(r.enum&&r.enum.length>0){let C=[],u=false;r.enum.forEach(c=>{c===null?u=true:C.includes(c)||C.push(c);});let y=C.map(c=>JSON.stringify(c)).join(", ");if(o==="zod"){let c=`z.enum([${y}])`;return u&&(c+=".nullable()"),c}else if(o==="yup"){let c=`yup.mixed().oneOf([${y}])`;return u&&(c+=".nullable()"),c}else {let c=`Joi.valid(${y})`;return u&&(c+=".allow(null)"),c}}if(r.type){let u=(y=>{switch(y){case "string":if(o==="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(o==="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(o==="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(o==="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 o==="joi"?"Joi.boolean()":o==="yup"?"yup.boolean()":"z.boolean()";case "null":return o==="joi"?"Joi.any().allow(null)":o==="yup"?"yup.mixed().nullable()":"z.null()";default:return o==="joi"?"Joi.any()":o==="yup"?"yup.mixed()":"z.any()"}})(typeof r.type=="string"?r.type:r.type[0]);return r.nullable&&o!=="joi"?u+=".nullable()":r.nullable&&o==="joi"&&(u+=".allow(null)"),u}return o==="joi"?"Joi.any()":o==="yup"?"yup.mixed()":"z.any()"},ht=r=>{var o,b,C,u,y;if((b=(o=e==null?void 0:e.endpoints)==null?void 0:o.value)!=null&&b.replaceWords&&Array.isArray(e==null?void 0:e.endpoints.value.replaceWords)){let c=r;return (y=(u=(C=e==null?void 0:e.endpoints)==null?void 0:C.value)==null?void 0:u.replaceWords)==null||y.forEach(($,g)=>{let q=new RegExp($.replace,"g");c=c.replace(q,$.with||"");}),c}else return r},Ct=(r,o,b=[])=>{var y,c;let C=(y=e==null?void 0:e.endpoints)==null?void 0:y.exclude,u=(c=e==null?void 0:e.endpoints)==null?void 0:c.include;if(u){let $=u.tags&&u.tags.length>0?b.some(q=>u.tags.includes(q)):true,g=u.endpoints&&u.endpoints.length>0?u.endpoints.some(q=>{let Q=!q.method||q.method.toLowerCase()===o.toLowerCase();return q.path?r===q.path&&Q:q.regex?new RegExp(q.regex).test(r)&&Q:false}):true;if(!$||!g)return true}return !!(C&&(C.tags&&C.tags.length>0&&b.some(g=>C.tags.includes(g))||C.endpoints&&C.endpoints.length>0&&C.endpoints.some(g=>{let q=!g.method||g.method.toLowerCase()===o.toLowerCase();return g.path?r===g.path&&q:g.regex?new RegExp(g.regex).test(r)&&q:false})))};if(Object.keys(t.paths||{}).forEach(r=>{let o=t.paths[r];Object.keys(o).forEach(C=>{var sn,on,an,ln,pn,un,mn,cn,dn,fn,yn,gn,$n,hn,Cn,bn,In,xn,En,Tn,An,wn,On,Pn,jn,vn,qn,Rn,kn,Sn,Un,Nn,Mn,Gn,Ln,Fn,Qn,Bn,zn,Dn,Wn,Jn,_n,Hn,Kn,Vn,Yn,Zn,Xn,et;let u=C,y=at(r,u),c=((sn=o[u])==null?void 0:sn.tags)||[];if(Ct(r,u,c))return;let $=o[u],g=G({method:u,path:r,summary:$==null?void 0:$.summary,operationId:$==null?void 0:$.operationId,tags:c,parameters:$==null?void 0:$.parameters,requestBody:$==null?void 0:$.requestBody,responses:$==null?void 0:$.responses});w[g]||(w[g]={endpoints:"",types:"",validation:""});let q=((an=(on=e==null?void 0:e.endpoints)==null?void 0:on.value)!=null&&an.includeServer?R:"")+y.pathParts.map(T=>(T[0]==="{"&&T[T.length-1]==="}"?T=`\${${T.replace(/{/,"").replace(/}/,"")}}`:T[0]==="<"&&T[T.length-1]===">"?T=`\${${T.replace(/</,"").replace(/>/,"")}}`:T[0]===":"&&(T=`\${${T.replace(/:/,"")}}`),T)).join("/"),Q=`"${q}"`;y.variables.length>0&&(Q=`(${y.variables.map(I=>`${I}:string`).join(",")})=> \`${q}\``),Q=ht(Q);let a=o[u],z="",x;if(a!=null&&a.parameters&&((a==null?void 0:a.parameters).forEach((I,A)=>{(I.$ref||I.in==="query"&&I.name)&&(z+=d?`${B(t,I.$ref?I:I.schema,I.name||"",I.required)}`:`${k(t,I.$ref?I:I.schema,I.name||"",I.required)}`);}),z)){z=d?z:`{
|
|
65
|
+
${z}}`;let A=`${y.name}Query`;if((pn=(ln=e==null?void 0:e.types)==null?void 0:ln.name)!=null&&pn.useOperationId&&(a!=null&&a.operationId)&&(A=`${a.operationId}Query`),A=de(`${O}${A}`),(mn=(un=e==null?void 0:e.types)==null?void 0:un.name)!=null&&mn.format){let _=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"query",method:u,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},A);_&&(A=`${O}${_}`);}x=A;let L=d?`${E(A,z)}
|
|
66
|
+
`:`export type ${A} = ${z};
|
|
67
|
+
`;e!=null&&e.folderSplit?w[g].types+=L:ie+=L;}if(((cn=e==null?void 0:e.validations)==null?void 0:cn.disable)!==true&&((fn=(dn=e==null?void 0:e.validations)==null?void 0:dn.generate)==null?void 0:fn.query)!==false&&(a!=null&&a.parameters)){let T=((yn=e.validations)==null?void 0:yn.library)||"zod",A=a.parameters.filter(L=>!L.$ref&&L.in==="query"&&L.name);if(A.length>0){let L=((gn=e==null?void 0:e.validations)==null?void 0:gn.name)||(($n=e==null?void 0:e.types)==null?void 0:$n.name),_=typeof(L==null?void 0:L.prefix)=="string"?L.prefix:"I",Y=typeof((Cn=(hn=e==null?void 0:e.validations)==null?void 0:hn.name)==null?void 0:Cn.suffix)=="string"?e.validations.name.suffix:"Schema",Z=`${y.name}Query`;if(L!=null&&L.useOperationId&&(a!=null&&a.operationId)&&(Z=`${a.operationId}Query`),Z=de(`${_}${Z}${Y}`),(In=(bn=e==null?void 0:e.validations)==null?void 0:bn.name)!=null&&In.format){let K=e.validations.name.format({code:"",type:"query",method:u,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},Z);K&&(Z=`${_}${K}${Y}`);}else if((En=(xn=e==null?void 0:e.types)==null?void 0:xn.name)!=null&&En.format){let K=e.types.name.format("endpoint",{code:"",type:"query",method:u,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},Z);K&&(Z=`${_}${K}${Y}`);}let D=A.map(K=>{let je=K!=null&&K.schema?me(K.schema,T):T==="joi"?"Joi.string()":T==="yup"?"yup.string()":"z.string()",xt=K.required?"":".optional()";return ` ${K.name}: ${je}${xt}`}).join(`,
|
|
68
|
+
`),H=`export const ${Z} = ${T==="joi"?"Joi.object":T==="yup"?"yup.object":"z.object"}({
|
|
69
|
+
${D}
|
|
50
70
|
});
|
|
51
71
|
|
|
52
|
-
`;e!=null&&e.folderSplit||
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
`;e!=null&&e.folderSplit
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
72
|
+
`;e!=null&&e.folderSplit||w[g]||(w[g]={endpoints:"",types:"",validation:""}),w[g].validation+=H;}}let P=a==null?void 0:a.requestBody,v="",N;if(P&&(v=Je(P),v)){let T=`${y.name}DTO`;if((An=(Tn=e==null?void 0:e.types)==null?void 0:Tn.name)!=null&&An.useOperationId&&(a!=null&&a.operationId)&&(T=`${a.operationId}DTO`),T=de(`${O}${T}`),(On=(wn=e==null?void 0:e.types)==null?void 0:wn.name)!=null&&On.format){let A=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"dto",method:u,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},T);A&&(T=`${O}${A}`);}N=T;let I=d?`${E(T,v)}
|
|
73
|
+
`:`export type ${T} = ${v};
|
|
74
|
+
`;e!=null&&e.folderSplit?w[g].types+=I:ie+=I;}if(((Pn=e==null?void 0:e.validations)==null?void 0:Pn.disable)!==true&&((vn=(jn=e==null?void 0:e.validations)==null?void 0:jn.generate)==null?void 0:vn.dto)!==false&&P){let T=((qn=e.validations)==null?void 0:qn.library)||"zod";if(P.content){let I=Object.keys(P.content);if(I[0]&&P.content[I[0]].schema){let A=((Rn=e==null?void 0:e.validations)==null?void 0:Rn.name)||((kn=e==null?void 0:e.types)==null?void 0:kn.name),L=typeof(A==null?void 0:A.prefix)=="string"?A.prefix:"I",_=typeof((Un=(Sn=e==null?void 0:e.validations)==null?void 0:Sn.name)==null?void 0:Un.suffix)=="string"?e.validations.name.suffix:"Schema",Y=`${y.name}DTO`;if(A!=null&&A.useOperationId&&(a!=null&&a.operationId)&&(Y=`${a.operationId}DTO`),Y=de(`${L}${Y}${_}`),(Mn=(Nn=e==null?void 0:e.validations)==null?void 0:Nn.name)!=null&&Mn.format){let oe=e.validations.name.format({code:"",type:"dto",method:u,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},Y);oe&&(Y=`${L}${oe}${_}`);}else if((Ln=(Gn=e==null?void 0:e.types)==null?void 0:Gn.name)!=null&&Ln.format){let oe=e.types.name.format("endpoint",{code:"",type:"dto",method:u,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},Y);oe&&(Y=`${L}${oe}${_}`);}let Z=me(P.content[I[0]].schema,T),D=`export const ${Y} = ${Z};
|
|
75
|
+
|
|
76
|
+
`;e!=null&&e.folderSplit||w[g]||(w[g]={endpoints:"",types:"",validation:""}),w[g].validation+=D;}}}let S={},W="",xe="";if(a!=null&&a.responses){let T=a==null?void 0:a.responses;Object.keys(T).forEach(A=>{var L,_,Y,Z;if(W=Je(T[A]),S[A]=W,W){let D=`${y.name}${A}Response`;if((_=(L=e==null?void 0:e.types)==null?void 0:L.name)!=null&&_.useOperationId&&(a!=null&&a.operationId)&&(D=`${a.operationId}${A}Response`),D=de(`${O}${D}`),(Z=(Y=e==null?void 0:e.types)==null?void 0:Y.name)!=null&&Z.format){let K=e==null?void 0:e.types.name.format("endpoint",{code:A,type:"response",method:u,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},D);K&&(D=`${O}${K}`);}let oe=d?`${E(D,W)}
|
|
77
|
+
`:`export type ${D} = ${W};
|
|
78
|
+
`;e!=null&&e.folderSplit?w[g].types+=oe:ie+=oe,S[A]=D;let H=parseInt(A);H>=200&&H<300&&(xe=D);}});}let he=T=>!T||!T.length?"":T.map(I=>Object.entries(I).map(([L,_])=>{let Y=L,Z="";return Array.isArray(_)&&_.length&&(Z=`
|
|
79
|
+
- Scopes: [\`${_.join("`, `")}\`]`,Y=`**${Y}**`),`
|
|
80
|
+
- ${Y}${Z}`}).join("")).join(`
|
|
81
|
+
`),ce=a!=null&&a.security?he(a.security):"",ye="";if(!((Qn=(Fn=e==null?void 0:e.endpoints)==null?void 0:Fn.doc)!=null&&Qn.disable)){let T="";if((zn=(Bn=e==null?void 0:e.endpoints)==null?void 0:Bn.doc)!=null&&zn.showCurl||d){let I={},A="",L="";(Dn=a.requestBody)!=null&&Dn.content&&Object.keys(a.requestBody.content).forEach(oe=>{let H=a.requestBody.content[oe].schema;if(H){Array.isArray(I["Content-type"])?I["Content-type"].push(oe):I["Content-type"]=[oe];let K=re(t,H);K&&(A=K);}}),a!=null&&a.security&&a.security.forEach(D=>{Object.keys(D).forEach(oe=>{var K,je;let H=(je=(K=t.components)==null?void 0:K.securitySchemes)==null?void 0:je[oe];H&&(H.type==="mutualTLS"?L+=`
|
|
82
|
+
--cert client-certificate.crt --key client-private-key.key --cacert ca-certificate.crt`:H.type==="apiKey"?I[(H==null?void 0:H.name)||"X-API-KEY"]="{API_KEY_VALUE}":I.Authorization=`${(H==null?void 0:H.scheme)==="basic"?"Basic":"Bearer"} {${(H==null?void 0:H.scheme)==="basic"?"VALUE":"TOKEN"}}`);});});let _={};Object.keys(I).forEach(D=>{Array.isArray(I[D])?_[D]=I[D].join("; "):_[D]=I[D];});let Z=`${CurlGenerator({url:R+r,method:u.toUpperCase(),headers:_,body:A})||`curl ${R+r} -X ${u.toUpperCase()}`}${L}`;T=d?`
|
|
83
|
+
\`\`\`bash
|
|
84
|
+
${Z}
|
|
85
|
+
\`\`\``:`
|
|
61
86
|
\`\`\`bash
|
|
62
|
-
${
|
|
63
|
-
\`\`\``;}
|
|
87
|
+
${Z}
|
|
88
|
+
\`\`\``;}if(d){let I=[];a!=null&&a.description&&I.push(`* ${a.description}`),I.push(`* **Method**: ${u.toUpperCase()}`),I.push(`* **Summary**: ${(a==null?void 0:a.summary)||""}`),I.push(`* **Tags**: [${((Wn=a==null?void 0:a.tags)==null?void 0:Wn.join(", "))||""}]`),I.push(`* **OperationId**: ${(a==null?void 0:a.operationId)||""}`),z&&(I.push("* **Query**:"),I.push("```python"),z.split(`
|
|
89
|
+
`).filter(A=>A.trim().length>0).forEach(A=>I.push(A)),I.push("```")),v&&(I.push("* **DTO**:"),I.push("```python"),v.split(`
|
|
90
|
+
`).filter(A=>A.trim().length>0).forEach(A=>I.push(A)),I.push("```")),W&&(I.push("* **Response**:"),I.push("```python"),Object.entries(S).forEach(([A,L])=>{I.push(`${A}: ${String(L).replace(/\n/g," ")}`);}),I.push("```")),ce&&(I.push("* **Security**:"),ce.split(`
|
|
91
|
+
`).filter(A=>A.trim().length>0).forEach(A=>I.push(A.replace(/\*\*/g,"")))),ye=`"""
|
|
92
|
+
${I.join(`
|
|
93
|
+
`)}${T}
|
|
94
|
+
"""
|
|
95
|
+
`;}else ye=`/**${a!=null&&a.description?`
|
|
64
96
|
* ${a==null?void 0:a.description} `:""}
|
|
65
|
-
* **Method**: \`${
|
|
97
|
+
* **Method**: \`${u.toUpperCase()}\`
|
|
66
98
|
* **Summary**: ${(a==null?void 0:a.summary)||""}
|
|
67
|
-
* **Tags**: [${((
|
|
68
|
-
* **OperationId**: ${(a==null?void 0:a.operationId)||""} ${
|
|
69
|
-
* **Query**: ${ve(
|
|
70
|
-
* **DTO**: ${ve(
|
|
71
|
-
* **Response**: ${Object.entries(
|
|
72
|
-
- **${
|
|
73
|
-
* **Security**: ${
|
|
74
|
-
`:""}${
|
|
99
|
+
* **Tags**: [${((Jn=a==null?void 0:a.tags)==null?void 0:Jn.join(", "))||""}]
|
|
100
|
+
* **OperationId**: ${(a==null?void 0:a.operationId)||""} ${z?`
|
|
101
|
+
* **Query**: ${ve(z)} `:""}${v?`
|
|
102
|
+
* **DTO**: ${ve(v)} `:""}${W?`
|
|
103
|
+
* **Response**: ${Object.entries(S).map(([I,A])=>`
|
|
104
|
+
- **${I}**: ${ve(A,2)} `).join("")}`:""}${ce?`
|
|
105
|
+
* **Security**: ${ce}
|
|
106
|
+
`:""}${T}
|
|
75
107
|
*/
|
|
76
|
-
`;}let
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
`,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
`),
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
`,
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
`,
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
`,
|
|
137
|
-
`,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
`,
|
|
141
|
-
`,
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
`,
|
|
146
|
-
|
|
147
|
-
`,
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
`,
|
|
151
|
-
`,
|
|
152
|
-
|
|
153
|
-
`,t+=`export
|
|
154
|
-
`,
|
|
155
|
-
`,
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
`,
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
`,
|
|
166
|
-
`,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
`,
|
|
170
|
-
`,
|
|
171
|
-
`,
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
`,
|
|
177
|
-
|
|
178
|
-
`,
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
`,
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
`,
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
`,
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
`,
|
|
197
|
-
`,
|
|
198
|
-
`,
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
`,
|
|
205
|
-
|
|
206
|
-
`,
|
|
207
|
-
|
|
208
|
-
`,
|
|
209
|
-
`,
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
`,
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
`,
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
`,
|
|
220
|
-
`,
|
|
221
|
-
`,
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
`,
|
|
229
|
-
|
|
230
|
-
`,
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
`,
|
|
235
|
-
`,
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
`,
|
|
239
|
-
`,
|
|
240
|
-
|
|
241
|
-
`,
|
|
242
|
-
`,
|
|
243
|
-
|
|
244
|
-
`,t+=`
|
|
245
|
-
`,
|
|
246
|
-
|
|
247
|
-
`,
|
|
248
|
-
`,
|
|
249
|
-
`,
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
`,
|
|
259
|
-
|
|
260
|
-
`,
|
|
261
|
-
`,
|
|
108
|
+
`;}let ge=(Hn=(_n=e==null?void 0:e.endpoints)==null?void 0:_n.name)!=null&&Hn.useOperationId&&((Kn=a==null?void 0:a.operationId)==null?void 0:Kn.length)>0?a.operationId:`${y.name}`;if((Yn=(Vn=e==null?void 0:e.endpoints)==null?void 0:Vn.name)!=null&&Yn.format){let T=e==null?void 0:e.endpoints.name.format({method:u,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},ge);T&&(ge=T);}let Ne={method:`"${u}"`,operationId:`"${a==null?void 0:a.operationId}"`,url:Q,tags:(a==null?void 0:a.tags)||[]},bt=`Endpoint(
|
|
109
|
+
method="${u}",
|
|
110
|
+
operationId="${(a==null?void 0:a.operationId)||""}",
|
|
111
|
+
url=${Q},
|
|
112
|
+
tags=[${((a==null?void 0:a.tags)||[]).map(T=>`"${T}"`).join(", ")}]
|
|
113
|
+
)`,rn=d?`${U}${ge} = ${bt}
|
|
114
|
+
${ye?`${ye}`:""}
|
|
115
|
+
|
|
116
|
+
`:`${ye}export const ${U}${ge} = ${((Xn=(Zn=e==null?void 0:e.endpoints)==null?void 0:Zn.value)==null?void 0:Xn.type)==="object"?Te(Ne):Q};
|
|
117
|
+
`;e!=null&&e.folderSplit?w[g].endpoints+=rn:se+=rn;let It={name:`${U}${ge}`,method:u,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId,tags:c,parameters:(et=a==null?void 0:a.parameters)==null?void 0:et.filter(T=>!T.$ref&&T.in&&T.name).map(T=>{var I;return {name:T.name,in:T.in,required:T.required,type:((I=T.schema)==null?void 0:I.type)||"string"}}),requestBody:P?{type:v,required:P.required}:void 0,responses:S?Object.entries(S).reduce((T,[I,A])=>(T[I]={type:A},T),{}):void 0,queryType:x,dtoType:N,responseType:xe||void 0};Ie.push(It);});}),e!=null&&e.folderSplit){let r=`from dataclasses import dataclass
|
|
118
|
+
from typing import List
|
|
119
|
+
|
|
120
|
+
@dataclass
|
|
121
|
+
class Endpoint:
|
|
122
|
+
method: str
|
|
123
|
+
operationId: str
|
|
124
|
+
url: str
|
|
125
|
+
tags: List[str]
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
`;for(let[o,b]of Object.entries(w))if(b.endpoints||b.types){let C=V.join(h,o);if(b.endpoints){let u=V.join($e,C,`endpoints.${f}`);yield ue.promises.mkdir(V.dirname(u),{recursive:true}),yield Ce(u,d?`${r}${b.endpoints}`:b.endpoints,e);}if(b.types){let u=V.join($e,C,`types.${f}`);yield ue.promises.mkdir(V.dirname(u),{recursive:true});let y=Object.values(pe).length>0?d?`from __future__ import annotations
|
|
130
|
+
from dataclasses import dataclass
|
|
131
|
+
from . import shared as Shared
|
|
132
|
+
${ee(b.types)}
|
|
133
|
+
${b.types}`:`import * as Shared from "../shared";
|
|
134
|
+
|
|
135
|
+
${b.types}`:b.types;yield Ce(u,y,e);}if(((Xe=e==null?void 0:e.validations)==null?void 0:Xe.disable)!==true&&b.validation&&!d){let u=((en=e.validations)==null?void 0:en.library)||"zod",y=u==="joi"?'import Joi from "joi";':u==="yup"?'import * as yup from "yup";':'import { z } from "zod";',c=V.join($e,C,"validations.ts");yield ue.promises.mkdir(V.dirname(c),{recursive:true}),yield Ce(c,`${y}
|
|
136
|
+
|
|
137
|
+
${b.validation}`,e);}}}if(se.length>0){let r=`from dataclasses import dataclass
|
|
138
|
+
from typing import List
|
|
139
|
+
|
|
140
|
+
@dataclass
|
|
141
|
+
class Endpoint:
|
|
142
|
+
method: str
|
|
143
|
+
operationId: str
|
|
144
|
+
url: str
|
|
145
|
+
tags: List[str]
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
`,o=V.join($e,h,`endpoints.${f}`);yield ue.promises.mkdir(V.dirname(o),{recursive:true}),yield Ce(o,d?`${r}${se}`:se,e);}if(Object.values(pe).length>0){let r=Object.values(pe).join(`
|
|
150
|
+
`),o=V.join($e,h,e!=null&&e.folderSplit?"":"types",`shared.${f}`);yield ue.promises.mkdir(V.dirname(o),{recursive:true}),yield Ce(o,(d?`from __future__ import annotations
|
|
151
|
+
from dataclasses import dataclass
|
|
152
|
+
${ee(r)}
|
|
153
|
+
`:"")+r,e);}if(ie.length>0){let r=V.join($e,h,"types",`index.${f}`);yield ue.promises.mkdir(V.dirname(r),{recursive:true}),yield Ce(r,(Object.values(pe).length>0?d?`from __future__ import annotations
|
|
154
|
+
from dataclasses import dataclass
|
|
155
|
+
from . import shared as Shared
|
|
156
|
+
${ee(ie)}
|
|
157
|
+
`:`import * as Shared from "./shared";
|
|
158
|
+
|
|
159
|
+
`:"")+ie,e);}if(((nn=e==null?void 0:e.validations)==null?void 0:nn.disable)!==true&&!(e!=null&&e.folderSplit)&&!d){let r=((tn=e.validations)==null?void 0:tn.library)||"zod",o=r==="joi"?'import Joi from "joi";':r==="yup"?'import * as yup from "yup";':'import { z } from "zod";',b=Object.values(w).map(C=>C.validation).filter(C=>C.length>0).join("");if(b){let C=V.join($e,h,"validations.ts");yield ue.promises.mkdir(V.dirname(C),{recursive:true}),yield Ce(C,`${o}
|
|
160
|
+
|
|
161
|
+
${b}`,e);}}return mt(m,Ie),console.info(`\u2705 Successfully synced ${m}`),{success:true}}),Qe=ft;var yt=(l,i)=>{let m=l;return i.tags&&i.tags.length>0&&(m=m.filter(e=>!e.tags||e.tags.length===0?false:e.tags.some(s=>i.tags.includes(s)))),i.endpoints&&i.endpoints.length>0&&(m=m.filter(e=>i.endpoints.includes(e.name))),m};var Be=(l,i,m=false)=>{var t,h;let e=i.baseURL||"";i.auth;let n=`// Generated Fetch API Client
|
|
162
|
+
`;n+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
163
|
+
|
|
164
|
+
`,n+=`import type {
|
|
165
|
+
`;let p=new Set;return l.forEach(d=>{d.queryType&&p.add(d.queryType),d.dtoType&&p.add(d.dtoType),d.responseType&&p.add(d.responseType);}),p.forEach(d=>{n+=` ${d},
|
|
166
|
+
`;}),n+=`} from '../types';
|
|
167
|
+
|
|
168
|
+
`,n+=`import {
|
|
169
|
+
`,l.forEach(d=>{n+=` ${d.name} as ${d.name}_endpoint,
|
|
170
|
+
`;}),n+=`} from '../endpoints';
|
|
171
|
+
|
|
172
|
+
`,n+=`export interface ApiConfig {
|
|
173
|
+
`,n+=` baseURL?: string;
|
|
174
|
+
`,n+=` headers?: Record<string, string>;
|
|
175
|
+
`,n+=`}
|
|
176
|
+
|
|
177
|
+
`,n+=`let globalConfig: ApiConfig = {
|
|
178
|
+
`,n+=` baseURL: "${e}",
|
|
179
|
+
`,n+=`};
|
|
180
|
+
|
|
181
|
+
`,n+=`export const setApiConfig = (config: Partial<ApiConfig>) => {
|
|
182
|
+
`,n+=` globalConfig = { ...globalConfig, ...config };
|
|
183
|
+
`,n+=`};
|
|
184
|
+
|
|
185
|
+
`,(t=i.errorHandling)!=null&&t.generateErrorClasses&&(n+=`export class ApiError extends Error {
|
|
186
|
+
`,n+=` constructor(
|
|
187
|
+
`,n+=` message: string,
|
|
188
|
+
`,n+=` public statusCode: number,
|
|
189
|
+
`,n+=` public response?: any
|
|
190
|
+
`,n+=` ) {
|
|
191
|
+
`,n+=` super(message);
|
|
192
|
+
`,n+=` this.name = 'ApiError';
|
|
193
|
+
`,n+=` }
|
|
194
|
+
`,n+=`}
|
|
195
|
+
|
|
196
|
+
`),n+=`async function fetchAPI<T>(
|
|
197
|
+
`,n+=` url: string,
|
|
198
|
+
`,n+=` options: RequestInit = {}
|
|
199
|
+
`,n+=`): Promise<T> {
|
|
200
|
+
`,n+=` const headers: Record<string, string> = {
|
|
201
|
+
`,n+=` 'Content-Type': 'application/json',
|
|
202
|
+
`,n+=` ...globalConfig.headers,
|
|
203
|
+
`,n+=` ...(options.headers as Record<string, string>),
|
|
204
|
+
`,n+=` };
|
|
205
|
+
|
|
206
|
+
`,n+=" const response = await fetch(`${globalConfig.baseURL}${url}`, {\n",n+=` ...options,
|
|
207
|
+
`,n+=` headers,
|
|
208
|
+
`,n+=` });
|
|
209
|
+
|
|
210
|
+
`,n+=` if (!response.ok) {
|
|
211
|
+
`,(h=i.errorHandling)!=null&&h.generateErrorClasses?(n+=` const errorData = await response.json().catch(() => ({}));
|
|
212
|
+
`,n+=` throw new ApiError(
|
|
213
|
+
`,n+=` errorData.message || response.statusText,
|
|
214
|
+
`,n+=` response.status,
|
|
215
|
+
`,n+=` errorData
|
|
216
|
+
`,n+=` );
|
|
217
|
+
`):n+=" throw new Error(`HTTP error! status: ${response.status}`);\n",n+=` }
|
|
218
|
+
|
|
219
|
+
`,n+=` return response.json();
|
|
220
|
+
`,n+=`}
|
|
221
|
+
|
|
222
|
+
`,l.forEach(d=>{var B,j;let f=d.name,w=((B=d.parameters)==null?void 0:B.filter(E=>E.in==="path"))||[],G=((j=d.parameters)==null?void 0:j.filter(E=>E.in==="query"))||[],R=w.length>0,O=G.length>0,U=!!d.requestBody,M=d.responseType||"any";if(n+=`/**
|
|
223
|
+
`,d.summary&&(n+=` * ${d.summary}
|
|
224
|
+
`),n+=` * @method ${d.method.toUpperCase()}
|
|
225
|
+
`,n+=` * @path ${d.path}
|
|
226
|
+
`,d.tags&&d.tags.length>0&&(n+=` * @tags ${d.tags.join(", ")}
|
|
227
|
+
`),n+=` */
|
|
228
|
+
`,n+=`export async function ${f}(`,(R||O||U)&&(n+=`params: {
|
|
229
|
+
`,R&&(n+=` url: {
|
|
230
|
+
`,w.forEach(E=>{let F={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[E.type||"string"]||"any",J=E.required?"":"?";n+=` ${E.name}${J}: ${F};
|
|
231
|
+
`;}),n+=` };
|
|
232
|
+
`),O&&(n+=` query: ${d.queryType||"Record<string, any>"};
|
|
233
|
+
`),U&&(n+=` data: ${d.dtoType||"any"};
|
|
234
|
+
`),n+=`}
|
|
235
|
+
`),n+=`): Promise<${M}> {
|
|
236
|
+
`,R||O||U){let E=[];R&&E.push("url"),O&&E.push("query"),U&&E.push("data"),n+=` const { ${E.join(", ")} } = params;
|
|
237
|
+
`;}let k;if(R){let E=w.map(ee=>`url.${ee.name}`).join(", ");k=`${d.name}_endpoint(${E})`;}else k=`${d.name}_endpoint`;O?(n+=` const queryParams = new URLSearchParams();
|
|
238
|
+
`,G.forEach(E=>{E.required?n+=` queryParams.append('${E.name}', String(query.${E.name}));
|
|
239
|
+
`:(n+=` if (query.${E.name} !== undefined) {
|
|
240
|
+
`,n+=` queryParams.append('${E.name}', String(query.${E.name}));
|
|
241
|
+
`,n+=` }
|
|
242
|
+
`);}),n+=` const _url = \`\${${k}}?\${queryParams.toString()}\`;
|
|
243
|
+
`):n+=` const _url = ${k};
|
|
244
|
+
`,n+=` return fetchAPI<${M}>(_url, {
|
|
245
|
+
`,n+=` method: '${d.method.toUpperCase()}',
|
|
246
|
+
`,U&&(n+=` body: JSON.stringify(data),
|
|
247
|
+
`),n+=` });
|
|
248
|
+
`,n+=`}
|
|
249
|
+
|
|
250
|
+
`;}),m&&(n+=`// Export all functions as a default object
|
|
251
|
+
`,n+=`const apiClient = {
|
|
252
|
+
`,n+=` setApiConfig,
|
|
253
|
+
`,l.forEach(d=>{n+=` ${d.name},
|
|
254
|
+
`;}),n+=`};
|
|
255
|
+
|
|
256
|
+
`,n+=`export default apiClient;
|
|
257
|
+
`),n},be=(l,i,m=false)=>{var t,h;let e=i.baseURL||"";i.auth;let n=`// Generated Axios API Client
|
|
258
|
+
`;n+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
259
|
+
|
|
260
|
+
`,n+=`import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
261
|
+
|
|
262
|
+
`,n+=`import type {
|
|
263
|
+
`;let p=new Set;return l.forEach(d=>{d.queryType&&p.add(d.queryType),d.dtoType&&p.add(d.dtoType),d.responseType&&p.add(d.responseType);}),p.forEach(d=>{n+=` ${d},
|
|
264
|
+
`;}),n+=`} from '../types';
|
|
265
|
+
|
|
266
|
+
`,n+=`import {
|
|
267
|
+
`,l.forEach(d=>{n+=` ${d.name},
|
|
268
|
+
`;}),n+=`} from '../endpoints';
|
|
269
|
+
|
|
270
|
+
`,n+=`export interface ApiConfig {
|
|
271
|
+
`,n+=` baseURL?: string;
|
|
272
|
+
`,n+=` headers?: Record<string, string>;
|
|
273
|
+
`,n+=` timeout?: number;
|
|
274
|
+
`,n+=`}
|
|
275
|
+
|
|
276
|
+
`,(t=i.errorHandling)!=null&&t.generateErrorClasses&&(n+=`export class ApiError extends Error {
|
|
277
|
+
`,n+=` constructor(
|
|
278
|
+
`,n+=` message: string,
|
|
279
|
+
`,n+=` public statusCode: number,
|
|
280
|
+
`,n+=` public response?: any
|
|
281
|
+
`,n+=` ) {
|
|
282
|
+
`,n+=` super(message);
|
|
283
|
+
`,n+=` this.name = 'ApiError';
|
|
284
|
+
`,n+=` }
|
|
285
|
+
`,n+=`}
|
|
286
|
+
|
|
287
|
+
`),n+=`class ApiClient {
|
|
288
|
+
`,n+=` private client: AxiosInstance;
|
|
289
|
+
|
|
290
|
+
`,n+=` constructor(config: ApiConfig = {}) {
|
|
291
|
+
`,n+=` this.client = axios.create({
|
|
292
|
+
`,n+=` baseURL: config.baseURL || "${e}",
|
|
293
|
+
`,n+=` timeout: config.timeout || 30000,
|
|
294
|
+
`,n+=` headers: {
|
|
295
|
+
`,n+=` 'Content-Type': 'application/json',
|
|
296
|
+
`,n+=` ...config.headers,
|
|
297
|
+
`,n+=` },
|
|
298
|
+
`,n+=` });
|
|
299
|
+
|
|
300
|
+
`,n+=` // Response interceptor for error handling
|
|
301
|
+
`,n+=` this.client.interceptors.response.use(
|
|
302
|
+
`,n+=` (response) => response,
|
|
303
|
+
`,n+=` (error) => {
|
|
304
|
+
`,(h=i.errorHandling)!=null&&h.generateErrorClasses?(n+=` const message = error.response?.data?.message || error.message;
|
|
305
|
+
`,n+=` const statusCode = error.response?.status || 500;
|
|
306
|
+
`,n+=` throw new ApiError(message, statusCode, error.response?.data);
|
|
307
|
+
`):n+=` return Promise.reject(error);
|
|
308
|
+
`,n+=` }
|
|
309
|
+
`,n+=` );
|
|
310
|
+
`,n+=` }
|
|
311
|
+
|
|
312
|
+
`,n+=` updateConfig(config: Partial<ApiConfig>) {
|
|
313
|
+
`,n+=` Object.assign(this.client.defaults, config);
|
|
314
|
+
`,n+=` }
|
|
315
|
+
|
|
316
|
+
`,l.forEach(d=>{var k,B;let f=d.name,w=((k=d.parameters)==null?void 0:k.filter(j=>j.in==="path"))||[],G=((B=d.parameters)==null?void 0:B.filter(j=>j.in==="query"))||[],R=w.length>0,O=G.length>0,U=!!d.requestBody,M=d.responseType||"any";if(n+=` /**
|
|
317
|
+
`,d.summary&&(n+=` * ${d.summary}
|
|
318
|
+
`),n+=` * @method ${d.method.toUpperCase()}
|
|
319
|
+
`,n+=` * @path ${d.path}
|
|
320
|
+
`,d.tags&&d.tags.length>0&&(n+=` * @tags ${d.tags.join(", ")}
|
|
321
|
+
`),n+=` */
|
|
322
|
+
`,n+=` async ${f}(`,(R||O||U)&&(n+=`params: {
|
|
323
|
+
`,R&&(n+=` url: {
|
|
324
|
+
`,w.forEach(j=>{let ee={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[j.type||"string"]||"any",F=j.required?"":"?";n+=` ${j.name}${F}: ${ee};
|
|
325
|
+
`;}),n+=` };
|
|
326
|
+
`),O&&(n+=` query: ${d.queryType||"Record<string, any>"};
|
|
327
|
+
`),U&&(n+=` data: ${d.dtoType||"any"};
|
|
328
|
+
`),n+=" }"),n+=`): Promise<${M}> {
|
|
329
|
+
`,R||O||U){let j=[];R&&j.push("url"),O&&j.push("query"),U&&j.push("data"),n+=` const { ${j.join(", ")} } = params;
|
|
330
|
+
`;}if(R){let j=w.map(E=>`url.${E.name}`).join(", ");n+=` const _url = ${d.name}(${j});
|
|
331
|
+
`;}else n+=` const _url = ${d.name};
|
|
332
|
+
`;n+=` const config: AxiosRequestConfig = {};
|
|
333
|
+
`,O&&(n+=` config.params = { ...query };
|
|
334
|
+
`),n+=` const response = await this.client.${d.method.toLowerCase()}<${M}>(
|
|
335
|
+
`,n+=` _url,
|
|
336
|
+
`,U?n+=` data,
|
|
262
337
|
config
|
|
263
|
-
`:
|
|
264
|
-
`,
|
|
265
|
-
`,
|
|
266
|
-
`,
|
|
338
|
+
`:n+=` config
|
|
339
|
+
`,n+=` );
|
|
340
|
+
`,n+=` return response.data;
|
|
341
|
+
`,n+=` }
|
|
267
342
|
|
|
268
|
-
`;}),
|
|
343
|
+
`;}),n+=`}
|
|
269
344
|
|
|
270
|
-
`,
|
|
271
|
-
`:(
|
|
272
|
-
`,
|
|
273
|
-
`),
|
|
274
|
-
`;
|
|
345
|
+
`,m?n+=`export default ApiClient;
|
|
346
|
+
`:(n+=`export const apiClient = new ApiClient();
|
|
347
|
+
`,n+=`export default apiClient;
|
|
348
|
+
`),n},ze=(l,i)=>{var h,d;let m=((h=i.reactQuery)==null?void 0:h.version)||5,e=((d=i.reactQuery)==null?void 0:d.mutations)!==false,s=!!(i.reactQuery&&i.reactQuery.infiniteQueries&&!i.reactQuery.infiniteQueries.disable),n=`// Generated React Query Hooks
|
|
349
|
+
`;n+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
275
350
|
|
|
276
|
-
`;let
|
|
351
|
+
`;let p=e&&l.some(f=>["POST","PUT","PATCH","DELETE"].includes(f.method.toUpperCase()));if(m===5){let f=p?`import { useQuery, useMutation, UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
277
352
|
`:`import { useQuery, UseQueryOptions } from '@tanstack/react-query';
|
|
278
353
|
`;s&&(f=f.replace("@tanstack/react-query';\\n",`@tanstack/react-query';
|
|
279
354
|
import { useInfiniteQuery, UseInfiniteQueryOptions } from '@tanstack/react-query';
|
|
280
|
-
`)),
|
|
355
|
+
`)),n+=f;}else {let f=p?`import { useQuery, useMutation, UseQueryOptions, UseMutationOptions } from 'react-query';
|
|
281
356
|
`:`import { useQuery, UseQueryOptions } from 'react-query';
|
|
282
357
|
`;s&&(f=f.replace("react-query';\\n",`react-query';
|
|
283
358
|
import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
284
|
-
`)),
|
|
285
|
-
`,
|
|
286
|
-
`,
|
|
287
|
-
`;let
|
|
288
|
-
`;}),
|
|
289
|
-
|
|
290
|
-
`,l.forEach(f=>{var
|
|
291
|
-
`,f.summary&&(
|
|
292
|
-
`),
|
|
293
|
-
`,
|
|
294
|
-
`,f.tags&&f.tags.length>0&&(
|
|
295
|
-
`),
|
|
296
|
-
`,k
|
|
297
|
-
`,
|
|
298
|
-
`,
|
|
299
|
-
`,
|
|
300
|
-
`;}),
|
|
301
|
-
`),
|
|
302
|
-
`),
|
|
303
|
-
`,
|
|
304
|
-
`,
|
|
305
|
-
`,
|
|
306
|
-
`,
|
|
307
|
-
`,
|
|
308
|
-
`,
|
|
309
|
-
`,
|
|
310
|
-
`,
|
|
311
|
-
|
|
312
|
-
`):(
|
|
313
|
-
`,
|
|
314
|
-
`,
|
|
315
|
-
`,
|
|
316
|
-
`,
|
|
317
|
-
`,
|
|
318
|
-
`,
|
|
319
|
-
`,
|
|
320
|
-
`,
|
|
321
|
-
|
|
322
|
-
`),
|
|
323
|
-
`,
|
|
324
|
-
`,
|
|
325
|
-
`,
|
|
326
|
-
`;}),
|
|
327
|
-
`),
|
|
328
|
-
`),
|
|
329
|
-
`,
|
|
330
|
-
`,
|
|
331
|
-
`,
|
|
332
|
-
`,
|
|
333
|
-
`,
|
|
334
|
-
`,
|
|
335
|
-
`,
|
|
336
|
-
`,
|
|
337
|
-
`,
|
|
338
|
-
|
|
339
|
-
`):(
|
|
340
|
-
`,
|
|
341
|
-
`,
|
|
342
|
-
`,
|
|
343
|
-
`,
|
|
344
|
-
`,
|
|
345
|
-
`,
|
|
346
|
-
`,
|
|
347
|
-
`,
|
|
348
|
-
`,
|
|
349
|
-
|
|
350
|
-
`);}}else if(
|
|
351
|
-
`,f.summary&&(
|
|
352
|
-
`),
|
|
353
|
-
`,
|
|
354
|
-
`,f.tags&&f.tags.length>0&&(
|
|
355
|
-
`),
|
|
356
|
-
`;let
|
|
357
|
-
`,
|
|
358
|
-
`,
|
|
359
|
-
`;}),
|
|
360
|
-
`),
|
|
361
|
-
`),
|
|
362
|
-
`),
|
|
363
|
-
`,
|
|
364
|
-
`,
|
|
365
|
-
`,
|
|
366
|
-
`,
|
|
367
|
-
`,
|
|
368
|
-
`,
|
|
369
|
-
`,
|
|
370
|
-
`,
|
|
371
|
-
`,
|
|
372
|
-
|
|
373
|
-
`;}}),
|
|
359
|
+
`)),n+=f;}n+=`
|
|
360
|
+
`,n+=`import apiClient from './client';
|
|
361
|
+
`,n+=`import type {
|
|
362
|
+
`;let t=new Set;return l.forEach(f=>{f.queryType&&t.add(f.queryType),f.dtoType&&t.add(f.dtoType),f.responseType&&t.add(f.responseType);}),t.forEach(f=>{n+=` ${f},
|
|
363
|
+
`;}),n+=`} from '../types';
|
|
364
|
+
|
|
365
|
+
`,l.forEach(f=>{var E,ee;let w=f.method.toUpperCase(),G=w==="GET",R=["POST","PUT","PATCH","DELETE"].includes(w),O=((E=f.parameters)==null?void 0:E.filter(F=>F.in==="path"))||[],U=((ee=f.parameters)==null?void 0:ee.filter(F=>F.in==="query"))||[],M=O.length>0,k=U.length>0,B=!!f.requestBody,j=f.responseType||"any";if(G){let F=U.map(se=>se.name.toLowerCase()),re=(F.includes("page")||F.includes("cursor")||F.includes("cursorid")||F.includes("after")||F.includes("before"))&&s,fe=`use${f.name.charAt(0).toUpperCase()+f.name.slice(1)}`;if(n+=`/**
|
|
366
|
+
`,f.summary&&(n+=` * ${f.summary}
|
|
367
|
+
`),n+=` * @method ${w}
|
|
368
|
+
`,n+=` * @path ${f.path}
|
|
369
|
+
`,f.tags&&f.tags.length>0&&(n+=` * @tags ${f.tags.join(", ")}
|
|
370
|
+
`),n+=` */
|
|
371
|
+
`,M||k?(n+=`export function ${fe}(
|
|
372
|
+
`,n+=` params: {
|
|
373
|
+
`,M&&(n+=` url: {
|
|
374
|
+
`,O.forEach(se=>{let pe={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[se.type||"string"]||"any",Ie=se.required?"":"?";n+=` ${se.name}${Ie}: ${pe};
|
|
375
|
+
`;}),n+=` };
|
|
376
|
+
`),k&&(n+=` query: ${f.queryType||"Record<string, any>"};
|
|
377
|
+
`),n+=` },
|
|
378
|
+
`,n+=` options?: Omit<UseQueryOptions<${j}>, 'queryKey' | 'queryFn'>
|
|
379
|
+
`,n+=`) {
|
|
380
|
+
`,n+=` return useQuery({
|
|
381
|
+
`,n+=` queryKey: ['${f.name}', params],
|
|
382
|
+
`,n+=` queryFn: () => apiClient.${f.name}(params),
|
|
383
|
+
`,n+=` ...options,
|
|
384
|
+
`,n+=` });
|
|
385
|
+
`,n+=`}
|
|
386
|
+
|
|
387
|
+
`):(n+=`export function ${fe}(
|
|
388
|
+
`,n+=` options?: Omit<UseQueryOptions<${j}>, 'queryKey' | 'queryFn'>
|
|
389
|
+
`,n+=`) {
|
|
390
|
+
`,n+=` return useQuery({
|
|
391
|
+
`,n+=` queryKey: ['${f.name}'],
|
|
392
|
+
`,n+=` queryFn: () => apiClient.${f.name}(),
|
|
393
|
+
`,n+=` ...options,
|
|
394
|
+
`,n+=` });
|
|
395
|
+
`,n+=`}
|
|
396
|
+
|
|
397
|
+
`),re){let se=`${fe}Infinite`;M||k?(n+=`export function ${se}(
|
|
398
|
+
`,n+=` params: {
|
|
399
|
+
`,M&&(n+=` url: {
|
|
400
|
+
`,O.forEach(ie=>{let Ie={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[ie.type||"string"]||"any",Pe=ie.required?"":"?";n+=` ${ie.name}${Pe}: ${Ie};
|
|
401
|
+
`;}),n+=` };
|
|
402
|
+
`),k&&(n+=` query: ${f.queryType||"Record<string, any>"};
|
|
403
|
+
`),n+=` },
|
|
404
|
+
`,n+=` options?: Omit<UseInfiniteQueryOptions<${j}, Error, ${j}>, 'queryKey' | 'queryFn'>
|
|
405
|
+
`,n+=`) {
|
|
406
|
+
`,n+=` return useInfiniteQuery({
|
|
407
|
+
`,n+=` queryKey: ['${f.name}', params],
|
|
408
|
+
`,n+=` queryFn: ({ pageParam = 1 }) => apiClient.${f.name}({ ...params, query: { ...(params.query || {}), page: pageParam } }),
|
|
409
|
+
`,n+=` getNextPageParam: (lastPage) => lastPage?.nextPage ?? lastPage?.nextCursor ?? null,
|
|
410
|
+
`,n+=` ...options,
|
|
411
|
+
`,n+=` });
|
|
412
|
+
`,n+=`}
|
|
413
|
+
|
|
414
|
+
`):(n+=`export function ${se}(
|
|
415
|
+
`,n+=` options?: Omit<UseInfiniteQueryOptions<${j}, Error, ${j}>, 'queryKey' | 'queryFn'>
|
|
416
|
+
`,n+=`) {
|
|
417
|
+
`,n+=` return useInfiniteQuery({
|
|
418
|
+
`,n+=` queryKey: ['${f.name}'],
|
|
419
|
+
`,n+=` queryFn: ({ pageParam = 1 }) => apiClient.${f.name}({ query: { page: pageParam } }),
|
|
420
|
+
`,n+=` getNextPageParam: (lastPage) => lastPage?.nextPage ?? lastPage?.nextCursor ?? null,
|
|
421
|
+
`,n+=` ...options,
|
|
422
|
+
`,n+=` });
|
|
423
|
+
`,n+=`}
|
|
424
|
+
|
|
425
|
+
`);}}else if(R&&e){let F=`use${f.name.charAt(0).toUpperCase()+f.name.slice(1)}`;n+=`/**
|
|
426
|
+
`,f.summary&&(n+=` * ${f.summary}
|
|
427
|
+
`),n+=` * @method ${w}
|
|
428
|
+
`,n+=` * @path ${f.path}
|
|
429
|
+
`,f.tags&&f.tags.length>0&&(n+=` * @tags ${f.tags.join(", ")}
|
|
430
|
+
`),n+=` */
|
|
431
|
+
`;let J="void";(M||k||B)&&(J=`{
|
|
432
|
+
`,M&&(J+=` url: {
|
|
433
|
+
`,O.forEach(re=>{let se={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[re.type||"string"]||"any",ie=re.required?"":"?";J+=` ${re.name}${ie}: ${se};
|
|
434
|
+
`;}),J+=` };
|
|
435
|
+
`),k&&(J+=` query: ${f.queryType||"Record<string, any>"};
|
|
436
|
+
`),B&&(J+=` data: ${f.dtoType||"any"};
|
|
437
|
+
`),J+=" }"),n+=`export function ${F}(
|
|
438
|
+
`,n+=` options?: Omit<UseMutationOptions<${j}, Error, ${J}>, 'mutationFn'>
|
|
439
|
+
`,n+=`) {
|
|
440
|
+
`,n+=` return useMutation({
|
|
441
|
+
`,n+=" mutationFn: (",J!=="void"&&(n+=`variables: ${J}`),n+=`) => {
|
|
442
|
+
`,n+=` return apiClient.${f.name}(${J!=="void"?"variables":""});
|
|
443
|
+
`,n+=` },
|
|
444
|
+
`,n+=` ...options,
|
|
445
|
+
`,n+=` });
|
|
446
|
+
`,n+=`}
|
|
447
|
+
|
|
448
|
+
`;}}),n},De=(l,i)=>{var p;let m=((p=i.swr)==null?void 0:p.mutations)!==false,e=`// Generated SWR Hooks
|
|
374
449
|
`;e+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
375
450
|
|
|
376
451
|
`,e+=`/**
|
|
@@ -565,173 +640,173 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
565
640
|
`,e+=` */
|
|
566
641
|
|
|
567
642
|
`,e+=`import useSWR, { SWRConfiguration } from 'swr';
|
|
568
|
-
`,
|
|
643
|
+
`,m&&l.some(t=>["POST","PUT","PATCH","DELETE"].includes(t.method.toUpperCase()))&&(e+=`import useSWRMutation, { SWRMutationConfiguration } from 'swr/mutation';
|
|
569
644
|
`),e+=`
|
|
570
645
|
`,e+=`import apiClient from './client';
|
|
571
646
|
`,e+=`import type {
|
|
572
|
-
`;let
|
|
647
|
+
`;let n=new Set;return l.forEach(t=>{t.queryType&&n.add(t.queryType),t.dtoType&&n.add(t.dtoType),t.responseType&&n.add(t.responseType);}),n.forEach(t=>{e+=` ${t},
|
|
573
648
|
`;}),e+=`} from '../types';
|
|
574
649
|
|
|
575
|
-
`,l.forEach(
|
|
576
|
-
`,
|
|
577
|
-
`),e+=` * @method ${
|
|
578
|
-
`,e+=` * @path ${
|
|
579
|
-
`,
|
|
650
|
+
`,l.forEach(t=>{var k,B;let h=t.method.toUpperCase(),d=h==="GET",f=["POST","PUT","PATCH","DELETE"].includes(h),w=((k=t.parameters)==null?void 0:k.filter(j=>j.in==="path"))||[],G=((B=t.parameters)==null?void 0:B.filter(j=>j.in==="query"))||[],R=w.length>0,O=G.length>0,U=!!t.requestBody,M=t.responseType||"any";if(d){let j=`use${t.name.charAt(0).toUpperCase()+t.name.slice(1)}`;e+=`/**
|
|
651
|
+
`,t.summary&&(e+=` * ${t.summary}
|
|
652
|
+
`),e+=` * @method ${h}
|
|
653
|
+
`,e+=` * @path ${t.path}
|
|
654
|
+
`,t.tags&&t.tags.length>0&&(e+=` * @tags ${t.tags.join(", ")}
|
|
580
655
|
`),e+=` */
|
|
581
|
-
`,
|
|
656
|
+
`,R||O?(e+=`export function ${j}(
|
|
582
657
|
`,e+=` params: {
|
|
583
|
-
`,
|
|
584
|
-
`,
|
|
658
|
+
`,R&&(e+=` url: {
|
|
659
|
+
`,w.forEach(E=>{let F={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[E.type||"string"]||"any",J=E.required?"":"?";e+=` ${E.name}${J}: ${F};
|
|
585
660
|
`;}),e+=` };
|
|
586
|
-
`),
|
|
661
|
+
`),O&&(e+=` query: ${t.queryType||"Record<string, any>"};
|
|
587
662
|
`),e+=` },
|
|
588
|
-
`,e+=` config?: SWRConfiguration<${
|
|
663
|
+
`,e+=` config?: SWRConfiguration<${M}>
|
|
589
664
|
`,e+=`) {
|
|
590
665
|
`,e+=` return useSWR(
|
|
591
|
-
`,e+=` ['${
|
|
592
|
-
`,e+=` () => apiClient.${
|
|
666
|
+
`,e+=` ['${t.name}', params],
|
|
667
|
+
`,e+=` () => apiClient.${t.name}(params),
|
|
593
668
|
`,e+=` config
|
|
594
669
|
`,e+=` );
|
|
595
|
-
`):(e+=`export function ${
|
|
596
|
-
`,e+=` config?: SWRConfiguration<${
|
|
670
|
+
`):(e+=`export function ${j}(
|
|
671
|
+
`,e+=` config?: SWRConfiguration<${M}>
|
|
597
672
|
`,e+=`) {
|
|
598
673
|
`,e+=` return useSWR(
|
|
599
|
-
`,e+=` '${
|
|
600
|
-
`,e+=` () => apiClient.${
|
|
674
|
+
`,e+=` '${t.name}',
|
|
675
|
+
`,e+=` () => apiClient.${t.name}(),
|
|
601
676
|
`,e+=` config
|
|
602
677
|
`,e+=` );
|
|
603
678
|
`),e+=`}
|
|
604
679
|
|
|
605
|
-
`;}else if(f&&
|
|
606
|
-
`,
|
|
607
|
-
`),e+=` * @method ${
|
|
608
|
-
`,e+=` * @path ${
|
|
609
|
-
`,
|
|
680
|
+
`;}else if(f&&m){let j=`use${t.name.charAt(0).toUpperCase()+t.name.slice(1)}`;e+=`/**
|
|
681
|
+
`,t.summary&&(e+=` * ${t.summary}
|
|
682
|
+
`),e+=` * @method ${h}
|
|
683
|
+
`,e+=` * @path ${t.path}
|
|
684
|
+
`,t.tags&&t.tags.length>0&&(e+=` * @tags ${t.tags.join(", ")}
|
|
610
685
|
`),e+=` */
|
|
611
|
-
`;let
|
|
612
|
-
`,
|
|
613
|
-
`,
|
|
614
|
-
`;}),
|
|
615
|
-
`),
|
|
616
|
-
`),
|
|
617
|
-
`),
|
|
618
|
-
`,e+=` config?: SWRMutationConfiguration<${
|
|
686
|
+
`;let E="void",ee="void";(R||O||U)&&(E=`{
|
|
687
|
+
`,R&&(E+=` url: {
|
|
688
|
+
`,w.forEach(F=>{let re={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[F.type||"string"]||"any",fe=F.required?"":"?";E+=` ${F.name}${fe}: ${re};
|
|
689
|
+
`;}),E+=` };
|
|
690
|
+
`),O&&(E+=` query: ${t.queryType||"Record<string, any>"};
|
|
691
|
+
`),U&&(E+=` data: ${t.dtoType||"any"};
|
|
692
|
+
`),E+=" }",ee=`{ arg: ${E} }`),e+=`export function ${j}(
|
|
693
|
+
`,e+=` config?: SWRMutationConfiguration<${M}, Error, string, ${E}>
|
|
619
694
|
`,e+=`) {
|
|
620
695
|
`,e+=` return useSWRMutation(
|
|
621
|
-
`,e+=` '${
|
|
622
|
-
`,e+=" async (_, ",
|
|
623
|
-
`,e+=` return apiClient.${
|
|
696
|
+
`,e+=` '${t.name}',
|
|
697
|
+
`,e+=" async (_, ",E!=="void"&&(e+=`{ arg }: ${ee}`),e+=`) => {
|
|
698
|
+
`,e+=` return apiClient.${t.name}(${E!=="void"?"arg":""});
|
|
624
699
|
`,e+=` },
|
|
625
700
|
`,e+=` config
|
|
626
701
|
`,e+=` );
|
|
627
702
|
`,e+=`}
|
|
628
703
|
|
|
629
|
-
`;}}),e},
|
|
704
|
+
`;}}),e},We=(l,i)=>{var p;let m=((p=i.rtkQuery)==null?void 0:p.apiName)||"api",e=i.baseURL||"",s=`// Generated RTK Query API Slice
|
|
630
705
|
`;s+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
631
706
|
|
|
632
707
|
`,s+=`import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
|
|
633
708
|
|
|
634
709
|
`,s+=`import type {
|
|
635
|
-
`;let
|
|
710
|
+
`;let n=new Set;return l.forEach(t=>{t.queryType&&n.add(t.queryType),t.dtoType&&n.add(t.dtoType),t.responseType&&n.add(t.responseType);}),n.forEach(t=>{s+=` ${t},
|
|
636
711
|
`;}),s+=`} from '../types';
|
|
637
712
|
|
|
638
713
|
`,s+=`import {
|
|
639
|
-
`,l.forEach(
|
|
714
|
+
`,l.forEach(t=>{s+=` ${t.name},
|
|
640
715
|
`;}),s+=`} from '../endpoints';
|
|
641
716
|
|
|
642
|
-
`,s+=`const ${
|
|
643
|
-
`,s+=` reducerPath: '${
|
|
717
|
+
`,s+=`const ${m}Api = createApi({
|
|
718
|
+
`,s+=` reducerPath: '${m}Api',
|
|
644
719
|
`,s+=` baseQuery: fetchBaseQuery({
|
|
645
720
|
`,s+=` baseUrl: '${e}',
|
|
646
|
-
`,
|
|
721
|
+
`,i.auth&&(s+=` prepareHeaders: (headers, { getState }) => {
|
|
647
722
|
`,s+=` // Get token from your auth state
|
|
648
723
|
`,s+=` // const token = (getState() as RootState).auth.token;
|
|
649
724
|
`,s+=` // if (token) {
|
|
650
|
-
`,
|
|
725
|
+
`,i.auth.type==="bearer"?s+=" // headers.set('Authorization', `Bearer ${token}`);\n":i.auth.type==="apiKey"&&i.auth.in==="header"&&(s+=` // headers.set('${i.auth.name||"X-API-Key"}', token);
|
|
651
726
|
`),s+=` // }
|
|
652
727
|
`,s+=` return headers;
|
|
653
728
|
`,s+=` },
|
|
654
729
|
`),s+=` }),
|
|
655
|
-
`,s+=` tagTypes: [${[...new Set(l.flatMap(
|
|
730
|
+
`,s+=` tagTypes: [${[...new Set(l.flatMap(t=>t.tags||[]))].map(t=>`'${t}'`).join(", ")}],
|
|
656
731
|
`,s+=` endpoints: (builder) => ({
|
|
657
|
-
`,l.forEach((
|
|
658
|
-
`,s+=` ${
|
|
659
|
-
`;let
|
|
660
|
-
`,
|
|
661
|
-
`,
|
|
662
|
-
`;}),
|
|
663
|
-
`),
|
|
664
|
-
`),
|
|
665
|
-
`),
|
|
732
|
+
`,l.forEach((t,h)=>{var B,j;let d=t.method.toUpperCase(),f=d==="GET",w=((B=t.parameters)==null?void 0:B.filter(E=>E.in==="path"))||[],G=((j=t.parameters)==null?void 0:j.filter(E=>E.in==="query"))||[],R=w.length>0,O=G.length>0,U=!!t.requestBody,M=t.responseType||"any";s+=` ${t.name}: builder.${f?"query":"mutation"}<
|
|
733
|
+
`,s+=` ${M},
|
|
734
|
+
`;let k="void";if((R||O||U)&&(k=`{
|
|
735
|
+
`,R&&(k+=` url: {
|
|
736
|
+
`,w.forEach(E=>{let F={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[E.type||"string"]||"any",J=E.required?"":"?";k+=` ${E.name}${J}: ${F};
|
|
737
|
+
`;}),k+=` };
|
|
738
|
+
`),O&&(k+=` query: ${t.queryType||"Record<string, any>"};
|
|
739
|
+
`),U&&(k+=` data: ${t.dtoType||"any"};
|
|
740
|
+
`),k+=" }"),s+=` ${k}
|
|
666
741
|
`,s+=` >({
|
|
667
|
-
`,s+=" query: (",
|
|
668
|
-
`,
|
|
669
|
-
`;}else s+=` const url = ${
|
|
742
|
+
`,s+=" query: (",k!=="void"&&(s+="arg"),s+=`) => {
|
|
743
|
+
`,R){let E=w.map(ee=>`arg.url.${ee.name}`).join(", ");s+=` const url = ${t.name}(${E});
|
|
744
|
+
`;}else s+=` const url = ${t.name};
|
|
670
745
|
`;s+=` return {
|
|
671
746
|
`,s+=` url,
|
|
672
|
-
`,s+=` method: '${
|
|
673
|
-
`,
|
|
674
|
-
`),
|
|
747
|
+
`,s+=` method: '${d}',
|
|
748
|
+
`,O&&(s+=` params: arg.query,
|
|
749
|
+
`),U&&(s+=` body: arg.data,
|
|
675
750
|
`),s+=` };
|
|
676
751
|
`,s+=` },
|
|
677
|
-
`,
|
|
678
|
-
`:s+=` invalidatesTags: ['${
|
|
679
|
-
`),s+=` })${
|
|
752
|
+
`,t.tags&&t.tags.length>0&&(f?s+=` providesTags: ['${t.tags[0]}'],
|
|
753
|
+
`:s+=` invalidatesTags: ['${t.tags[0]}'],
|
|
754
|
+
`),s+=` })${h<l.length-1?",":""}
|
|
680
755
|
`;}),s+=` }),
|
|
681
756
|
`,s+=`});
|
|
682
757
|
|
|
683
|
-
`,s+=`export default ${
|
|
758
|
+
`,s+=`export default ${m}Api;
|
|
684
759
|
|
|
685
|
-
`,s};var
|
|
686
|
-
`;
|
|
687
|
-
`,
|
|
760
|
+
`,s};var Rt=(l,i)=>{var m,e;if((m=i==null?void 0:i.folderSplit)!=null&&m.customFolder){let s=i.folderSplit.customFolder({method:l.method,path:l.path,tags:l.tags,operationId:l.operationId,summary:l.summary});if(s)return s}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"},gt=(l,i,m,e,s)=>d(null,null,function*(){let n=yt(l,m);if(n.length===0)return;let p=m.type||"fetch";m.outputDir||V.join(s,e,"client");let h=!!(i!=null&&i.folderSplit&&(i.folderSplit.byTags||i.folderSplit.customFolder));if(`${p}${n.length}`,h){let f={};n.forEach(R=>{let O=Rt(R,i);f[O]||(f[O]=[]),f[O].push(R);});let w=Object.keys(f);for(let[R,O]of Object.entries(f)){let U=V.join(s,e,R);yield ue.promises.mkdir(U,{recursive:true}),`${p}${R}${O.length}`,yield kt(O,i,m,U,p,R,true);}let G=V.join(s,e);yield St(G,w,p,i);return}let d=V.join(s,e);switch(yield ue.promises.mkdir(d,{recursive:true}),p){case "fetch":let f=Be(n,m);f=f.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield te(V.join(d,"clients.ts"),f,i);break;case "axios":let w=be(n,m,false);w=w.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield te(V.join(d,"clients.ts"),w,i);break;case "react-query":let G=be(n,m,false);G=G.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield te(V.join(d,"clients.ts"),G,i);let R=ze(n,m);R=R.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';").replace("import apiClient from './client';","import apiClient from './clients';"),yield te(V.join(d,"hooks.ts"),R,i);break;case "swr":let O=be(n,m,false);O=O.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield te(V.join(d,"clients.ts"),O,i);let U=De(n,m);U=U.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';").replace("import apiClient from './client';","import apiClient from './clients';"),yield te(V.join(d,"hooks.ts"),U,i);break;case "rtk-query":let M=We(n,m);M=M.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield te(V.join(d,"api.ts"),M,i);break;default:throw new Error(`Unknown client type: ${p}`)}}),te=(l,i,m)=>d(null,null,function*(){var p,t,h,d;if(!(((p=m==null?void 0:m.customCode)==null?void 0:p.enabled)!==false)){yield ue.promises.writeFile(l,i);return}let s=null;try{s=yield ue.promises.readFile(l,"utf-8");}catch(f){}let n=qe(i,s,{position:((t=m==null?void 0:m.customCode)==null?void 0:t.position)||"bottom",markerText:(h=m==null?void 0:m.customCode)==null?void 0:h.markerText,includeInstructions:(d=m==null?void 0:m.customCode)==null?void 0:d.includeInstructions});yield ue.promises.writeFile(l,n);});var kt=(l,i,m,e,s,n,p=false)=>d(null,null,function*(){let t="",h="",d=p?"./types":"../types",f=p?"./endpoints":"../endpoints";switch(s){case "fetch":t=Be(l,m,p),t=t.replace("} from '../types';",`} from '${d}';`).replace("} from '../endpoints';",`} from '${f}';`),yield te(V.join(e,"client.ts"),t,i);break;case "axios":t=be(l,m,p),t=t.replace("} from '../types';",`} from '${d}';`).replace("} from '../endpoints';",`} from '${f}';`),yield te(V.join(e,"client.ts"),t,i);break;case "react-query":if(t=be(l,m,p),t=t.replace("} from '../types';",`} from '${d}';`).replace("} from '../endpoints';",`} from '${f}';`),yield te(V.join(e,"client.ts"),t,i),h=ze(l,m),h=h.replace("} from '../types';",`} from '${d}';`).replace("} from '../endpoints';",`} from '${f}';`),p){let G=n.replace(/-/g,"_");h=h.replace("import apiClient from './client';",`import { ${G}Client as apiClient } from '../clients';`);}yield te(V.join(e,"hooks.ts"),h,i);break;case "swr":if(t=be(l,m,p),t=t.replace("} from '../types';",`} from '${d}';`).replace("} from '../endpoints';",`} from '${f}';`),yield te(V.join(e,"client.ts"),t,i),h=De(l,m),h=h.replace("} from '../types';",`} from '${d}';`).replace("} from '../endpoints';",`} from '${f}';`),p){let G=n.replace(/-/g,"_");h=h.replace("import apiClient from './client';",`import { ${G}Client as apiClient } from '../clients';`);}yield te(V.join(e,"hooks.ts"),h,i);break;case "rtk-query":let w=p?b(a({},m),{rtkQuery:b(a({},m.rtkQuery),{apiName:n.replace(/-/g,"_")})}):m;h=We(l,w),h=h.replace("} from '../types';",`} from '${d}';`).replace("} from '../endpoints';",`} from '${f}';`),yield te(V.join(e,"api.ts"),h,i);break;default:throw new Error(`Unknown client type: ${s}`)}}),St=(l,i,m,e)=>d(null,null,function*(){var n;if(m==="rtk-query"){let p=`// Generated RTK Query APIs
|
|
761
|
+
`;p+=`// This file was auto-generated.
|
|
762
|
+
`,p+=`// Aggregates all API slices for easy Redux store setup
|
|
688
763
|
|
|
689
|
-
`,
|
|
690
|
-
`;}),
|
|
764
|
+
`,i.forEach(t=>{let h=t.replace(/-/g,"_");p+=`import ${h}Api from './${t}/api';
|
|
765
|
+
`;}),p+=`
|
|
691
766
|
// Export all API slices
|
|
692
|
-
`,
|
|
693
|
-
`;}),
|
|
767
|
+
`,i.forEach(t=>{let h=t.replace(/-/g,"_");p+=`export { default as ${h}Api } from './${t}/api';
|
|
768
|
+
`;}),p+=`
|
|
694
769
|
/**
|
|
695
|
-
`,
|
|
696
|
-
`,
|
|
697
|
-
`,
|
|
698
|
-
`,
|
|
699
|
-
`,
|
|
700
|
-
`,
|
|
701
|
-
`,
|
|
702
|
-
`,
|
|
703
|
-
`,
|
|
704
|
-
`,
|
|
705
|
-
`,
|
|
706
|
-
`,
|
|
707
|
-
`,
|
|
708
|
-
`,
|
|
709
|
-
`,
|
|
710
|
-
`;}),
|
|
711
|
-
`,
|
|
712
|
-
`,
|
|
713
|
-
`;}),
|
|
714
|
-
`,
|
|
715
|
-
`,yield
|
|
770
|
+
`,p+=` * Configure Redux store with all API slices
|
|
771
|
+
`,p+=` *
|
|
772
|
+
`,p+=` * @example
|
|
773
|
+
`,p+=` * import { configureStore } from '@reduxjs/toolkit';
|
|
774
|
+
`,p+=` * import { setupApiStore } from './apis';
|
|
775
|
+
`,p+=` *
|
|
776
|
+
`,p+=` * export const store = configureStore({
|
|
777
|
+
`,p+=` * reducer: setupApiStore.reducer,
|
|
778
|
+
`,p+=` * middleware: (getDefaultMiddleware) =>
|
|
779
|
+
`,p+=` * getDefaultMiddleware().concat(setupApiStore.middleware),
|
|
780
|
+
`,p+=` * });
|
|
781
|
+
`,p+=` */
|
|
782
|
+
`,p+=`export const setupApiStore = {
|
|
783
|
+
`,p+=` reducer: {
|
|
784
|
+
`,i.forEach(t=>{let h=t.replace(/-/g,"_");p+=` [${h}Api.reducerPath]: ${h}Api.reducer,
|
|
785
|
+
`;}),p+=` },
|
|
786
|
+
`,p+=` middleware: [
|
|
787
|
+
`,i.forEach(t=>{let h=t.replace(/-/g,"_");p+=` ${h}Api.middleware,
|
|
788
|
+
`;}),p+=` ],
|
|
789
|
+
`,p+=`};
|
|
790
|
+
`,yield te(V.join(l,"apis.ts"),p,e);return}let s=`// Generated API Clients
|
|
716
791
|
`;if(s+=`// This file was auto-generated.
|
|
717
792
|
`,s+=`// Centralized client instances and configuration
|
|
718
793
|
|
|
719
|
-
`,
|
|
720
|
-
`;}):(
|
|
794
|
+
`,m==="fetch"?i.forEach(p=>{let t=p.replace(/-/g,"_");s+=`export { default as ${t}Client } from './${p}/client';
|
|
795
|
+
`;}):(i.forEach(p=>{let t=p.replace(/-/g,"_"),h=`${t.charAt(0).toUpperCase()+t.slice(1)}ApiClient`;s+=`import ${h} from './${p}/client';
|
|
721
796
|
`;}),s+=`
|
|
722
797
|
// Create client instances
|
|
723
|
-
`,
|
|
724
|
-
`;})),
|
|
798
|
+
`,i.forEach(p=>{let t=p.replace(/-/g,"_"),h=`${t.charAt(0).toUpperCase()+t.slice(1)}ApiClient`;s+=`export const ${t}Client = new ${h}();
|
|
799
|
+
`;})),m==="fetch"&&(s+=`
|
|
725
800
|
// Import clients for aggregation
|
|
726
|
-
`,
|
|
801
|
+
`,i.forEach(p=>{let t=p.replace(/-/g,"_");s+=`import ${t}_client from './${p}/client';
|
|
727
802
|
`;})),s+=`
|
|
728
803
|
// Aggregate all client instances
|
|
729
804
|
`,s+=`export const clients = {
|
|
730
|
-
`,
|
|
731
|
-
`:s+=` ${
|
|
805
|
+
`,i.forEach(p=>{let t=p.replace(/-/g,"_");m==="fetch"?s+=` ${t}: ${t}_client,
|
|
806
|
+
`:s+=` ${t}: ${t}Client,
|
|
732
807
|
`;}),s+=`};
|
|
733
808
|
|
|
734
|
-
`,
|
|
809
|
+
`,m==="axios"?(s+=`
|
|
735
810
|
/**
|
|
736
811
|
`,s+=` * Configure all API clients at once
|
|
737
812
|
`,s+=` * @param config - Configuration to apply to all clients
|
|
@@ -741,10 +816,10 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
741
816
|
`,s+=` headers?: Record<string, string>;
|
|
742
817
|
`,s+=` timeout?: number;
|
|
743
818
|
`,s+=`}) => {
|
|
744
|
-
`,
|
|
819
|
+
`,i.forEach(p=>{let t=p.replace(/-/g,"_");s+=` ${t}Client.updateConfig(config);
|
|
745
820
|
`;}),s+=`};
|
|
746
821
|
|
|
747
|
-
`):
|
|
822
|
+
`):m==="fetch"&&(s+=`
|
|
748
823
|
/**
|
|
749
824
|
`,s+=` * Configure all API clients at once
|
|
750
825
|
`,s+=` * @param config - Configuration to apply to all clients
|
|
@@ -754,7 +829,7 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
754
829
|
`,s+=` headers?: Record<string, string>;
|
|
755
830
|
`,s+=` auth?: { token?: string };
|
|
756
831
|
`,s+=`}) => {
|
|
757
|
-
`,
|
|
832
|
+
`,i.forEach(p=>{let t=p.replace(/-/g,"_");s+=` ${t}_client.setApiConfig(config);
|
|
758
833
|
`;}),s+=`};
|
|
759
834
|
|
|
760
835
|
`),s+=`// Example usage:
|
|
@@ -767,13 +842,13 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
767
842
|
`,s+=`// });
|
|
768
843
|
`,s+=`//
|
|
769
844
|
`,s+=`// // Use specific client
|
|
770
|
-
`,s+=`// const data = await clients.${(
|
|
771
|
-
`,yield
|
|
772
|
-
`;
|
|
773
|
-
`,
|
|
845
|
+
`,s+=`// const data = await clients.${(n=i[0])==null?void 0:n.replace(/-/g,"_")}.someMethod(...);
|
|
846
|
+
`,yield te(V.join(l,"clients.ts"),s,e),m==="react-query"||m==="swr"){let p=`// Generated Hooks Aggregator
|
|
847
|
+
`;p+=`// This file was auto-generated.
|
|
848
|
+
`,p+=`// Aggregates all folder-split hooks
|
|
774
849
|
|
|
775
|
-
`,
|
|
776
|
-
`;}),
|
|
850
|
+
`,i.forEach(t=>{p+=`export * from './${t}/hooks';
|
|
851
|
+
`;}),p+=`
|
|
777
852
|
// Example usage:
|
|
778
|
-
`,
|
|
779
|
-
`,yield
|
|
853
|
+
`,p+=`// import { useGetSomething } from './hooks';
|
|
854
|
+
`,yield te(V.join(l,"hooks.ts"),p,e);}});var Ue=process.cwd(),$t=()=>{let l;try{c("esbuild-register");}catch(p){throw p}let i=V.join(Ue,"openapi.sync.js"),m=V.join(Ue,"openapi.sync.ts"),e=V.join(Ue,"openapi.sync.json"),s=[i,m,e];try{for(let p of s)ue.existsSync(p)&&(l=c(p),Object.keys(l).length===1&&l.default&&(l=l.default));}catch(p){}typeof l=="function"&&(l=l());let n=l;if(!n)throw new Error("No config found");return n},xr=l=>d(null,null,function*(){let i=$t(),m=Object.keys(i.api),e=l&&"refetchInterval"in l&&!isNaN(l==null?void 0:l.refetchInterval)?l.refetchInterval:i.refetchInterval;Le();for(let s=0;s<m.length;s+=1){let n=m[s],p=i.api[n];yield Qe(p,n,i,e);}}),Er=l=>d(null,null,function*(){let i=$t(),m=l.apiName?[l.apiName]:Object.keys(i.api);for(let s of m)if(!i.api[s])throw new Error(`API "${s}" not found in configuration. Available APIs: ${Object.keys(i.api).join(", ")}`);Le();for(let s of m){let n=i.api[s];yield Qe(n,s,i);}let e=(i==null?void 0:i.folder)||"api";for(let s of m){let n=ct(s);if(n.length===0){continue}`${n.length}${s}`;let p=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 gt(n,i,p,s,V.join(Ue,e));}}),Tr=()=>d(null,null,function*(){let{interactiveInit:l}=yield import('./interactive-init-OITE22SZ.mjs');yield l();});export{Er as GenerateClient,xr as Init,Tr as InteractiveInit,Te as JSONStringify,de as capitalize,tt as createCustomCodeMarker,Tt as extractCustomCode,at as getEndpointDetails,Lt as getNestedValue,st as isJson,Et as isYamlString,qe as mergeCustomCode,ve as renderTypeRefMD,Nt as variableName,nt as variableNameChar,ot as yamlStringToJson};
|