openapi-sync 5.0.6 → 5.0.7
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 +3 -0
- package/dist/index.js +150 -146
- package/dist/index.mjs +156 -152
- package/package.json +1 -1
- /package/dist/{interactive-init-OITE22SZ.mjs → interactive-init-DZKTNNQK.mjs} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,120 +1,124 @@
|
|
|
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
|
|
2
|
-
`+" ".repeat(i)+n+": ",Array.isArray(p)){
|
|
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 Ot from'lodash.isequal';import ke from'lodash.get';import Pt from'axios';import jt from'axios-retry';import vt from'@apidevtools/swagger-parser';import {CurlGenerator}from'curl-generator';var Lt=/^[A-Za-z_$][A-Za-z0-9_$]*$/,tt=/[A-Za-z0-9_$]/;var ot=l=>["object"].includes(typeof l)&&!(l instanceof Blob),Tt=l=>{try{return Ae.load(l),!0}catch(i){let c=i;if(c instanceof Ae.YAMLException)return false;throw c}},at=l=>{if(Tt(l)){let i=Ae.load(l),c=JSON.stringify(i,null,2);return JSON.parse(c)}},ye=l=>l.substring(0,1).toUpperCase()+l.substring(1),it=(l,i)=>{let c=l.split("/"),e=`${ye(i)}`,s=[];return c.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 $=t;tt.test(t)||($="/"),p+=$;}),p.split("/").forEach(t=>{e+=ye(t);});}),{name:e,variables:s,pathParts:c}},Te=(l,i=1)=>{let c="{",e=Object.keys(l);for(let s=0;s<e.length;s++){let n=e[s],p=l[n];if(c+=`
|
|
2
|
+
`+" ".repeat(i)+n+": ",Array.isArray(p)){c+="[";for(let t=0;t<p.length;t++){let $=p[t];typeof $=="object"&&$!==null?c+=Te($,i+1):c+=typeof $=="string"?`"${$}"`:$,t<p.length-1&&(c+=", ");}c+="]";}else typeof p=="object"&&p!==null?c+=""+Te(p,i+1):c+=p.split(`
|
|
3
3
|
`).filter(t=>t.trim()!=="").join(`
|
|
4
|
-
${" ".repeat(i)}`);s<e.length-1&&(
|
|
5
|
-
${" ".repeat(i-1)}}`,
|
|
4
|
+
${" ".repeat(i)}`);s<e.length-1&&(c+=", ");}return c+=`
|
|
5
|
+
${" ".repeat(i-1)}}`,c},ve=(l,i=1)=>{let c=l.replace(/\/\*\*?[\s\S]*?\*\//g,e=>e.replace(/^\/\*\*?\s*/,"").replace(/\s*\*\/$/,"").split(`
|
|
6
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(i)} ${
|
|
9
|
+
${" ".repeat(i)} ${c.split(`
|
|
10
10
|
`).filter(e=>e.trim()!=="").join(`
|
|
11
11
|
${" ".repeat(i)} `)}
|
|
12
|
-
\`\`\``};function
|
|
13
|
-
`,
|
|
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},
|
|
12
|
+
\`\`\``};function Ft(l,i){return i.split(".").reduce((e,s)=>e&&e[s]!==void 0?e[s]:void 0,l)}var At=(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,$=-1;for(let j of e){let T=l.indexOf(j.start,n);T!==-1&&($===-1||T<$)&&($=T,t=j);}if($===-1||!t)break;let d=l.indexOf(t.end,$);if(d===-1)break;let f=d+t.end.length,w=l.substring(f,f+100),M=w.match(/^\s*\n\s*((?:\/\/|#)\s*=+)/);if(M){let j=w.indexOf(`
|
|
13
|
+
`,M.index+1);j!==-1?f+=j+1:f+=M[0].length;}let R=$,O=l.substring(Math.max(0,$-200),$),U=/(^|\n)\s*(?:\/\/|#)\s*=+/g,L,k=-1;for(;(L=U.exec(O))!==null;)k=L.index+L[1].length;k!==-1&&(R=Math.max(0,$-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},rt=(l,i="CUSTOM CODE",c=true,e="//")=>{let s=c?`${e} ${l==="top"?"Add your custom code below this line":"Add your custom code above this line"}
|
|
15
15
|
${e} This section will be preserved during regeneration
|
|
16
16
|
`:"";return `${e} ${"=".repeat(60)}
|
|
17
17
|
${e} \u{1F512} ${i} START
|
|
18
18
|
${s}${e} ${"=".repeat(60)}
|
|
19
19
|
|
|
20
20
|
${e} \u{1F512} ${i} END
|
|
21
|
-
${e} ${"=".repeat(60)}`},
|
|
22
|
-
`).map(s=>e.test(s)?s.replace(/^\s*\/\//,
|
|
23
|
-
`)},qe=(l,i,
|
|
24
|
-
`)};var Re=V.join(__dirname,"../","../db.json");ue.existsSync(Re)||ue.writeFileSync(Re,"{}");var
|
|
21
|
+
${e} ${"=".repeat(60)}`},st=(l,i,c)=>{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*\/\//,c):s).join(`
|
|
23
|
+
`)},qe=(l,i,c={})=>{let{position:e="bottom",markerText:s="CUSTOM CODE",includeInstructions:n=true,commentPrefix:p="//"}=c,t={beforeGenerated:"",afterGenerated:""};i&&(t=At(i,s),t.beforeGenerated=st(t.beforeGenerated,s,p),t.afterGenerated=st(t.afterGenerated,s,p)),!t.beforeGenerated&&!t.afterGenerated&&((e==="top"||e==="both")&&(t.beforeGenerated=rt("top",s,n,p)),(e==="bottom"||e==="both")&&(t.afterGenerated=rt("bottom",s,n,p)));let $=[];return t.beforeGenerated&&($.push(t.beforeGenerated),$.push("")),$.push(l),t.afterGenerated&&($.push(""),$.push(t.afterGenerated)),$.join(`
|
|
24
|
+
`)};var Re=V.join(__dirname,"../","../db.json");ue.existsSync(Re)||ue.writeFileSync(Re,"{}");var Me={};try{Me=c(Re);}catch(l){Me={};}var we=Me||{},lt=l=>{ue.writeFileSync(Re,JSON.stringify(l));},pt=(l,i)=>{we[l]=i,lt(we);},ut=l=>we[l],Ge=()=>{we={},lt(we);};var mt={},ct=(l,i)=>{mt[l]=i;},dt=l=>mt[l]||[];var $e=process.cwd(),Fe={},ft=Pt.create({timeout:6e4});jt(ft,{retries:20,retryCondition:l=>l.code==="ECONNABORTED"||l.message.includes("Network Error"),retryDelay:l=>l*1e3});var be=(l,i,c)=>d(null,null,function*(){var t,$,d,f;if(!(((t=c==null?void 0:c.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:(($=c==null?void 0:c.customCode)==null?void 0:$.position)||"bottom",markerText:(d=c==null?void 0:c.customCode)==null?void 0:d.markerText,includeInstructions:(f=c==null?void 0:c.customCode)==null?void 0:f.includeInstructions,commentPrefix:n});yield ue.promises.writeFile(l,p);}),yt=(l,i,c,e)=>d(null,null,function*(){let s=yield Rt(l,i,c,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}`),yt(l,i,c,e);},e))),s}),Rt=(...l)=>d(null,null,function*(){var He,Ke,Ve,Ye,Ze,Xe,en,nn,tn,rn;let[i,c,e]=l,s=r=>r.startsWith("http://")||r.startsWith("https://"),n;try{if(s(i))n=(yield ft.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 ${c}:`,r),r}if(!n)return;let p=ot(n)?n:at(n),t;try{t=yield vt.parse(p);}catch(r){let o=r instanceof Error?r.message:String(r);throw new Error(`Failed to parse OpenAPI spec for ${c}: ${o}`)}let $=V.join((e==null?void 0:e.folder)||"",c),d=(e==null?void 0:e.language)==="python",f=d?"py":"ts",w={},M=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:((Ke=(He=t==null?void 0:t.servers)==null?void 0:He[(e==null?void 0:e.server)||0])==null?void 0:Ke.url)||"",O=typeof((Ye=(Ve=e==null?void 0:e.types)==null?void 0:Ve.name)==null?void 0:Ye.prefix)=="string"?e==null?void 0:e.types.name.prefix:"I",U=typeof((Xe=(Ze=e==null?void 0:e.endpoints)==null?void 0:Ze.name)==null?void 0:Xe.prefix)=="string"?e==null?void 0:e.endpoints.name.prefix:"",L=(r,o)=>{var C,u;let b=ye(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 m="",h="",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&&(m=S.name),h=x[x.length-1];let J=L(h);J.includes(".")&&(J=J.split(".").map((Ce,fe)=>fe===0?Ce:`["${Ce}"]`).join("")),g+=`${u!=null&&u.noSharedImport?"":"Shared."}${J}`;}}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 J,xe,Ce,fe,ge,he;let S="";!((xe=(J=e==null?void 0:e.types)==null?void 0:J.doc)!=null&&xe.disable)&&((fe=(Ce=o.properties)==null?void 0:Ce[N])!=null&&fe.description)&&(S=" * "+((ge=o.properties)==null?void 0:ge[N].description.split(`
|
|
25
25
|
`).filter(Ne=>Ne.trim()!=="").join(`
|
|
26
26
|
*${" ".repeat(1)}`))),v+=(S?`/**
|
|
27
27
|
${S}
|
|
28
28
|
*/
|
|
29
|
-
`:"")+`${k(r,(
|
|
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=
|
|
31
|
-
`:""}`:""},B=(r,o,b$1,C,u,y=0)=>{let
|
|
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=
|
|
29
|
+
`:"")+`${k(r,(he=o.properties)==null?void 0:he[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=m||b$1;u!=null&&u.useComponentName&&!q&&(q=h);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 m="",h="",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&&(m=S.name),h=x[x.length-1];let J=L(h);J.includes(".")&&(J=J.split(".").join("_")),g+=`${u!=null&&u.noSharedImport?"":"Shared."}${J}`;}}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=m||b$1;u!=null&&u.useComponentName&&!q&&(q=h);let Q="";q&&(Q=` ${q.replace(/[^a-zA-Z0-9_]/g,"_")}: `);let a$1=g,z=!q&&g.includes(`
|
|
33
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
34
|
`:""}`:""},j=r=>{let o=(r||"").replace(/^\n+/,"").trimEnd();if(!o)return ` pass
|
|
35
35
|
`;let b=o.split(`
|
|
36
|
-
`),C=/^[A-Za-z_][A-Za-z0-9_]*\s*:\s*.+$/,u=b.map(
|
|
36
|
+
`),C=/^[A-Za-z_][A-Za-z0-9_]*\s*:\s*.+$/,u=b.map(h=>h.trim()).filter(h=>!!h).filter(h=>!h.startsWith('"""')&&!h.endsWith('"""'));return !u.some(h=>C.test(h))&&u.length===1?` value: ${u[0]}
|
|
37
37
|
`:`${o.split(`
|
|
38
|
-
`).map(
|
|
38
|
+
`).map(h=>h.trim()?/^\s/.test(h)?h:` ${h}`:h).join(`
|
|
39
39
|
`)}
|
|
40
|
-
`},
|
|
40
|
+
`},T=r=>{let o=(r||"").replace(/^\n+/,"").trimEnd();if(!o)return null;let b=o.split(`
|
|
41
|
+
`),C=/^[A-Za-z_][A-Za-z0-9_]*\s*:\s*.+$/,u=b.map(m=>m.trim()).filter(m=>!!m).filter(m=>!m.startsWith('"""')&&!m.endsWith('"""'));return !u.some(m=>C.test(m))&&u.length===1?u[0]:null},ee=(r,o,b)=>{let C=T(o);return (b==null?void 0:b.inheritSingleTypeExpression)===true&&!!C?`@dataclass
|
|
42
|
+
class ${r}(${C}):
|
|
43
|
+
pass
|
|
44
|
+
`:`@dataclass
|
|
41
45
|
class ${r}:
|
|
42
|
-
${j(o)}
|
|
43
|
-
`:""},
|
|
46
|
+
${j(o)}`},F=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(", ")}
|
|
47
|
+
`:""},W=(r,o=72)=>{let b=(r||"").replace(/\s+/g," ").trim().split(" ");if(!b[0])return [];let C=[],u="";return b.forEach(y=>{let m=u?`${u} ${y}`:y;m.length>o&&u?(C.push(u),u=y):u=m;}),u&&C.push(u),C},ce=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(([m,h])=>({name:m,desc:((h==null?void 0:h.description)||"").trim()})).filter(m=>m.desc.length>0);if(!o&&b.length===0)return "";let C=[' """'];return o&&W(o).forEach(m=>C.push(` ${m}`)),b.length>0&&(o&&C.push(""),C.push(" Attributes:"),b.forEach(m=>{let h=W(m.desc);h.length&&(C.push(` ${m.name}: ${h[0]}`),h.slice(1).forEach(g=>C.push(` ${g}`)));})),C.push(' """'),`${C.join(`
|
|
44
48
|
`)}
|
|
45
|
-
`},
|
|
46
|
-
`)
|
|
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=
|
|
49
|
-
`).filter(
|
|
50
|
-
*${" ".repeat(1)}`)),a=
|
|
51
|
-
class ${
|
|
52
|
-
`+(a||"")+j(typeof
|
|
53
|
-
`:
|
|
49
|
+
`},se=(r,o)=>{let u="";if(o)if(o.$ref)if(o.$ref[0]==="#"){let y=(o.$ref||"").split("/");y.shift();let h=ke(r,y,null);h&&(h!=null&&h.name&&(h.name),y[y.length-1],u+=se(r,h));}else u+="";else if(o.anyOf)u+=se(r,o.anyOf[0]);else if(o.oneOf)u+=se(r,o.oneOf[0]);else if(o.allOf)u+=`{${o.allOf.map(y=>`...(${se(r,y)})`).join(",")}}`;else if(o.items)u+=`[${se(r,o.items)}]`;else if(o.properties){let h=Object.keys(o.properties).map(g=>{var q;return ` "${g}": ${se(r,(q=o.properties)==null?void 0:q[g])}`}).join(`,
|
|
50
|
+
`);h.length>0?u+=`{
|
|
51
|
+
${h}
|
|
52
|
+
}`: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=m=>{let h="";if(typeof m=="string")["string","integer","number","array","boolean","null"].includes(m)?["integer","number"].includes(m)?h+="123":m==="array"?h+="[]":m==="boolean"?h+="true":m==="null"?h+="null":h+=`"${m}"`:m==="object"&&(h+="{}");else if(Array.isArray(m)){let g=m.map(q=>y(q));g.filter(q=>q!==""),g.length>1&&(h+=g.join("|"));}else h+="any";return h};u=y(o.type);}else u+="any";else u="string";return u},ie=ut(c);if(Ot(ie,t))return;pt(c,t);let pe="",de="",le={},Pe=[],Je=(r,o)=>{let b={},C={};Object.keys(r).forEach(y=>{var g;let m=(g=r[y])!=null&&g.schema?r[y].schema:r[y],h=d?`${B(t,m,"",true,{noSharedImport:true,useComponentName:false})}`:`${k(t,m,"",true,{noSharedImport:true,useComponentName:false})}`;if(h){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]=h,a[x]=m);}}}),Object.keys(b).forEach(y=>{var z,x,P,v,N;let m=L(y),h=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(`
|
|
53
|
+
`).filter(J=>J.trim()!=="").join(`
|
|
54
|
+
*${" ".repeat(1)}`)),a=ce(q),d?le[y]=((v=le[y])!=null?v:"")+`@dataclass
|
|
55
|
+
class ${m}:
|
|
56
|
+
`+(a||"")+j(typeof h=="string"?h:"")+`
|
|
57
|
+
`:le[y]=((N=le[y])!=null?N:"")+(Q?`/**
|
|
54
58
|
${Q}
|
|
55
59
|
*/
|
|
56
|
-
`:"")+"export type "+
|
|
57
|
-
`;});};t.definitions&&
|
|
60
|
+
`:"")+"export type "+m+" = "+(typeof h=="string"?h:Te(h))+`;
|
|
61
|
+
`;});};t.definitions&&Je(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];Je(o);}});let _e=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=[],m=false;if(C.forEach(h=>{h.enum&&h.enum.forEach(g=>{g===null?m=true:y.includes(g)||y.push(g);});}),y.length>0){let h=y.map(g=>JSON.stringify(g)).join(", ");if(o==="zod"){let g=`z.enum([${h}])`;return m&&(g+=".nullable()"),g}else if(o==="yup"){let g=`yup.mixed().oneOf([${h}])`;return m&&(g+=".nullable()"),g}else return m?`Joi.valid(${h}, null)`:`Joi.valid(${h})`}else if(m)return o==="zod"?"z.null()":o==="yup"?"yup.mixed().nullable()":"Joi.valid(null)"}return o==="zod"?`z.union([${C.map(h=>me(h,o,b+1)).join(", ")}])`:o==="yup"?`yup.mixed().oneOf([${C.map(h=>me(h,o,b+1)).join(", ")}])`:`Joi.alternatives().try(${C.map(m=>me(m,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(([m,h])=>{let g=C.includes(m),q=me(h,o,b+1);return g||(q+=".optional()"),`${u}${m}: ${q}`}).join(`,
|
|
58
62
|
`);return o==="zod"?`z.object({
|
|
59
63
|
${y}
|
|
60
64
|
${" ".repeat(b)}})`:o==="yup"?`yup.object({
|
|
61
65
|
${y}
|
|
62
66
|
${" ".repeat(b)}})`:`Joi.object({
|
|
63
67
|
${y}
|
|
64
|
-
${" ".repeat(b)}})`}if(r.enum&&r.enum.length>0){let C=[],u=false;r.enum.forEach(
|
|
65
|
-
${z}}`;let A=`${y.name}Query`;if((
|
|
68
|
+
${" ".repeat(b)}})`}if(r.enum&&r.enum.length>0){let C=[],u=false;r.enum.forEach(m=>{m===null?u=true:C.includes(m)||C.push(m);});let y=C.map(m=>JSON.stringify(m)).join(", ");if(o==="zod"){let m=`z.enum([${y}])`;return u&&(m+=".nullable()"),m}else if(o==="yup"){let m=`yup.mixed().oneOf([${y}])`;return u&&(m+=".nullable()"),m}else {let m=`Joi.valid(${y})`;return u&&(m+=".allow(null)"),m}}if(r.type){let u=(y=>{switch(y){case "string":if(o==="zod"){let m="z.string()";return r.format==="email"?m+=".email()":r.format==="uuid"?m+=".uuid()":r.format==="url"||r.format==="uri"?m+=".url()":r.format==="date-time"?m+=".datetime()":r.format==="date"&&(m+=".date()"),r.minLength&&(m+=`.min(${r.minLength})`),r.maxLength&&(m+=`.max(${r.maxLength})`),r.pattern&&(m+=`.regex(/${r.pattern}/)`),m}else if(o==="yup"){let m="yup.string()";return r.format==="email"?m+=".email()":(r.format==="url"||r.format==="uri")&&(m+=".url()"),r.minLength&&(m+=`.min(${r.minLength})`),r.maxLength&&(m+=`.max(${r.maxLength})`),r.pattern&&(m+=`.matches(/${r.pattern}/)`),m}else {let m="Joi.string()";return r.format==="email"?m+=".email()":r.format==="url"||r.format==="uri"?m+=".uri()":r.format==="uuid"?m+=".guid({ version: 'uuidv4' })":r.format==="date-time"&&(m+=".isoDate()"),r.minLength&&(m+=`.min(${r.minLength})`),r.maxLength&&(m+=`.max(${r.maxLength})`),r.pattern&&(m+=`.pattern(/${r.pattern}/)`),m}case "integer":case "number":if(o==="zod"){let m="z.number()";return y==="integer"&&(m+=".int()"),r.minimum!==void 0&&(r.exclusiveMinimum?m+=`.gt(${r.minimum})`:m+=`.min(${r.minimum})`),r.maximum!==void 0&&(r.exclusiveMaximum?m+=`.lt(${r.maximum})`:m+=`.max(${r.maximum})`),m}else if(o==="yup"){let m="yup.number()";return y==="integer"&&(m+=".integer()"),r.minimum!==void 0&&(m+=`.min(${r.minimum})`),r.maximum!==void 0&&(m+=`.max(${r.maximum})`),m}else {let m="Joi.number()";return y==="integer"&&(m+=".integer()"),r.minimum!==void 0&&(r.exclusiveMinimum?m+=`.greater(${r.minimum})`:m+=`.min(${r.minimum})`),r.maximum!==void 0&&(r.exclusiveMaximum?m+=`.less(${r.maximum})`:m+=`.max(${r.maximum})`),m}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()"},Ct=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 m=r;return (y=(u=(C=e==null?void 0:e.endpoints)==null?void 0:C.value)==null?void 0:u.replaceWords)==null||y.forEach((h,g)=>{let q=new RegExp(h.replace,"g");m=m.replace(q,h.with||"");}),m}else return r},bt=(r,o,b=[])=>{var y,m;let C=(y=e==null?void 0:e.endpoints)==null?void 0:y.exclude,u=(m=e==null?void 0:e.endpoints)==null?void 0:m.include;if(u){let h=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(!h||!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 on,an,ln,pn,un,mn,cn,dn,fn,yn,gn,hn,$n,Cn,bn,In,xn,En,Tn,An,wn,On,Pn,jn,vn,qn,Rn,kn,Sn,Un,Nn,Ln,Mn,Gn,Fn,Qn,Bn,zn,Dn,Wn,Jn,_n,Hn,Kn,Vn,Yn,Zn,Xn,et,nt;let u=C,y=it(r,u),m=((on=o[u])==null?void 0:on.tags)||[];if(bt(r,u,m))return;let h=o[u],g=M({method:u,path:r,summary:h==null?void 0:h.summary,operationId:h==null?void 0:h.operationId,tags:m,parameters:h==null?void 0:h.parameters,requestBody:h==null?void 0:h.requestBody,responses:h==null?void 0:h.responses});w[g]||(w[g]={endpoints:"",types:"",validation:""});let q=((ln=(an=e==null?void 0:e.endpoints)==null?void 0:an.value)!=null&&ln.includeServer?R:"")+y.pathParts.map(E=>(E[0]==="{"&&E[E.length-1]==="}"?E=`\${${E.replace(/{/,"").replace(/}/,"")}}`:E[0]==="<"&&E[E.length-1]===">"?E=`\${${E.replace(/</,"").replace(/>/,"")}}`:E[0]===":"&&(E=`\${${E.replace(/:/,"")}}`),E)).join("/"),Q=`"${q}"`;y.variables.length>0&&(Q=`(${y.variables.map(I=>`${I}:string`).join(",")})=> \`${q}\``),Q=Ct(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:`{
|
|
69
|
+
${z}}`;let A=`${y.name}Query`;if((un=(pn=e==null?void 0:e.types)==null?void 0:pn.name)!=null&&un.useOperationId&&(a!=null&&a.operationId)&&(A=`${a.operationId}Query`),A=ye(`${O}${A}`),(cn=(mn=e==null?void 0:e.types)==null?void 0:mn.name)!=null&&cn.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 G=d?`${ee(A,z)}
|
|
66
70
|
`:`export type ${A} = ${z};
|
|
67
|
-
`;e!=null&&e.folderSplit?w[g].types+=
|
|
68
|
-
`),H=`export const ${Z} = ${
|
|
71
|
+
`;e!=null&&e.folderSplit?w[g].types+=G:de+=G;}if(((dn=e==null?void 0:e.validations)==null?void 0:dn.disable)!==true&&((yn=(fn=e==null?void 0:e.validations)==null?void 0:fn.generate)==null?void 0:yn.query)!==false&&(a!=null&&a.parameters)){let E=((gn=e.validations)==null?void 0:gn.library)||"zod",A=a.parameters.filter(G=>!G.$ref&&G.in==="query"&&G.name);if(A.length>0){let G=((hn=e==null?void 0:e.validations)==null?void 0:hn.name)||(($n=e==null?void 0:e.types)==null?void 0:$n.name),_=typeof(G==null?void 0:G.prefix)=="string"?G.prefix:"I",Y=typeof((bn=(Cn=e==null?void 0:e.validations)==null?void 0:Cn.name)==null?void 0:bn.suffix)=="string"?e.validations.name.suffix:"Schema",Z=`${y.name}Query`;if(G!=null&&G.useOperationId&&(a!=null&&a.operationId)&&(Z=`${a.operationId}Query`),Z=ye(`${_}${Z}${Y}`),(xn=(In=e==null?void 0:e.validations)==null?void 0:In.name)!=null&&xn.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((Tn=(En=e==null?void 0:e.types)==null?void 0:En.name)!=null&&Tn.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,E):E==="joi"?"Joi.string()":E==="yup"?"yup.string()":"z.string()",Et=K.required?"":".optional()";return ` ${K.name}: ${je}${Et}`}).join(`,
|
|
72
|
+
`),H=`export const ${Z} = ${E==="joi"?"Joi.object":E==="yup"?"yup.object":"z.object"}({
|
|
69
73
|
${D}
|
|
70
74
|
});
|
|
71
75
|
|
|
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=
|
|
73
|
-
`:`export type ${
|
|
74
|
-
`;e!=null&&e.folderSplit?w[g].types+=I:
|
|
76
|
+
`;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=_e(P),v)){let E=`${y.name}DTO`;if((wn=(An=e==null?void 0:e.types)==null?void 0:An.name)!=null&&wn.useOperationId&&(a!=null&&a.operationId)&&(E=`${a.operationId}DTO`),E=ye(`${O}${E}`),(Pn=(On=e==null?void 0:e.types)==null?void 0:On.name)!=null&&Pn.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},E);A&&(E=`${O}${A}`);}N=E;let I=d?`${ee(E,v,{inheritSingleTypeExpression:true})}
|
|
77
|
+
`:`export type ${E} = ${v};
|
|
78
|
+
`;e!=null&&e.folderSplit?w[g].types+=I:de+=I;}if(((jn=e==null?void 0:e.validations)==null?void 0:jn.disable)!==true&&((qn=(vn=e==null?void 0:e.validations)==null?void 0:vn.generate)==null?void 0:qn.dto)!==false&&P){let E=((Rn=e.validations)==null?void 0:Rn.library)||"zod";if(P.content){let I=Object.keys(P.content);if(I[0]&&P.content[I[0]].schema){let A=((kn=e==null?void 0:e.validations)==null?void 0:kn.name)||((Sn=e==null?void 0:e.types)==null?void 0:Sn.name),G=typeof(A==null?void 0:A.prefix)=="string"?A.prefix:"I",_=typeof((Nn=(Un=e==null?void 0:e.validations)==null?void 0:Un.name)==null?void 0:Nn.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=ye(`${G}${Y}${_}`),(Mn=(Ln=e==null?void 0:e.validations)==null?void 0:Ln.name)!=null&&Mn.format){let re=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);re&&(Y=`${G}${re}${_}`);}else if((Fn=(Gn=e==null?void 0:e.types)==null?void 0:Gn.name)!=null&&Fn.format){let re=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);re&&(Y=`${G}${re}${_}`);}let Z=me(P.content[I[0]].schema,E),D=`export const ${Y} = ${Z};
|
|
75
79
|
|
|
76
|
-
`;e!=null&&e.folderSplit||w[g]||(w[g]={endpoints:"",types:"",validation:""}),w[g].validation+=D;}}}let S={},
|
|
77
|
-
`:`export type ${D} = ${
|
|
78
|
-
`;e!=null&&e.folderSplit?w[g].types+=
|
|
80
|
+
`;e!=null&&e.folderSplit||w[g]||(w[g]={endpoints:"",types:"",validation:""}),w[g].validation+=D;}}}let S={},J="",xe="";if(a!=null&&a.responses){let E=a==null?void 0:a.responses;Object.keys(E).forEach(A=>{var G,_,Y,Z;if(J=_e(E[A]),S[A]=J,J){let D=`${y.name}${A}Response`;if((_=(G=e==null?void 0:e.types)==null?void 0:G.name)!=null&&_.useOperationId&&(a!=null&&a.operationId)&&(D=`${a.operationId}${A}Response`),D=ye(`${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 re=d?`${ee(D,J,{inheritSingleTypeExpression:true})}
|
|
81
|
+
`:`export type ${D} = ${J};
|
|
82
|
+
`;e!=null&&e.folderSplit?w[g].types+=re:de+=re,S[A]=D;let H=parseInt(A);H>=200&&H<300&&(xe=D);}});}let Ce=E=>!E||!E.length?"":E.map(I=>Object.entries(I).map(([G,_])=>{let Y=G,Z="";return Array.isArray(_)&&_.length&&(Z=`
|
|
79
83
|
- Scopes: [\`${_.join("`, `")}\`]`,Y=`**${Y}**`),`
|
|
80
84
|
- ${Y}${Z}`}).join("")).join(`
|
|
81
|
-
`),
|
|
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()}`}${
|
|
85
|
+
`),fe=a!=null&&a.security?Ce(a.security):"",ge="";if(!((Bn=(Qn=e==null?void 0:e.endpoints)==null?void 0:Qn.doc)!=null&&Bn.disable)){let E="";if((Dn=(zn=e==null?void 0:e.endpoints)==null?void 0:zn.doc)!=null&&Dn.showCurl||d){let I={},A="",G="";(Wn=a.requestBody)!=null&&Wn.content&&Object.keys(a.requestBody.content).forEach(re=>{let H=a.requestBody.content[re].schema;if(H){Array.isArray(I["Content-type"])?I["Content-type"].push(re):I["Content-type"]=[re];let K=se(t,H);K&&(A=K);}}),a!=null&&a.security&&a.security.forEach(D=>{Object.keys(D).forEach(re=>{var K,je;let H=(je=(K=t.components)==null?void 0:K.securitySchemes)==null?void 0:je[re];H&&(H.type==="mutualTLS"?G+=`
|
|
86
|
+
--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()}`}${G}`;E=d?`
|
|
83
87
|
\`\`\`bash
|
|
84
88
|
${Z}
|
|
85
89
|
\`\`\``:`
|
|
86
90
|
\`\`\`bash
|
|
87
91
|
${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**: [${((
|
|
92
|
+
\`\`\``;}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**: [${((Jn=a==null?void 0:a.tags)==null?void 0:Jn.join(", "))||""}]`),I.push(`* **OperationId**: ${(a==null?void 0:a.operationId)||""}`),z&&(I.push("* **Query**:"),I.push("```python"),z.split(`
|
|
89
93
|
`).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("```")),
|
|
91
|
-
`).filter(A=>A.trim().length>0).forEach(A=>I.push(A.replace(/\*\*/g,"")))),
|
|
94
|
+
`).filter(A=>A.trim().length>0).forEach(A=>I.push(A)),I.push("```")),J&&(I.push("* **Response**:"),I.push("```python"),Object.entries(S).forEach(([A,G])=>{I.push(`${A}: ${String(G).replace(/\n/g," ")}`);}),I.push("```")),fe&&(I.push("* **Security**:"),fe.split(`
|
|
95
|
+
`).filter(A=>A.trim().length>0).forEach(A=>I.push(A.replace(/\*\*/g,"")))),ge=`"""
|
|
92
96
|
${I.join(`
|
|
93
|
-
`)}${
|
|
97
|
+
`)}${E}
|
|
94
98
|
"""
|
|
95
|
-
`;}else
|
|
99
|
+
`;}else ge=`/**${a!=null&&a.description?`
|
|
96
100
|
* ${a==null?void 0:a.description} `:""}
|
|
97
101
|
* **Method**: \`${u.toUpperCase()}\`
|
|
98
102
|
* **Summary**: ${(a==null?void 0:a.summary)||""}
|
|
99
|
-
* **Tags**: [${((
|
|
103
|
+
* **Tags**: [${((_n=a==null?void 0:a.tags)==null?void 0:_n.join(", "))||""}]
|
|
100
104
|
* **OperationId**: ${(a==null?void 0:a.operationId)||""} ${z?`
|
|
101
105
|
* **Query**: ${ve(z)} `:""}${v?`
|
|
102
|
-
* **DTO**: ${ve(v)} `:""}${
|
|
106
|
+
* **DTO**: ${ve(v)} `:""}${J?`
|
|
103
107
|
* **Response**: ${Object.entries(S).map(([I,A])=>`
|
|
104
|
-
- **${I}**: ${ve(A,2)} `).join("")}`:""}${
|
|
105
|
-
* **Security**: ${
|
|
106
|
-
`:""}${
|
|
108
|
+
- **${I}**: ${ve(A,2)} `).join("")}`:""}${fe?`
|
|
109
|
+
* **Security**: ${fe}
|
|
110
|
+
`:""}${E}
|
|
107
111
|
*/
|
|
108
|
-
`;}let
|
|
112
|
+
`;}let he=(Kn=(Hn=e==null?void 0:e.endpoints)==null?void 0:Hn.name)!=null&&Kn.useOperationId&&((Vn=a==null?void 0:a.operationId)==null?void 0:Vn.length)>0?a.operationId:`${y.name}`;if((Zn=(Yn=e==null?void 0:e.endpoints)==null?void 0:Yn.name)!=null&&Zn.format){let E=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},he);E&&(he=E);}let Ne={method:`"${u}"`,operationId:`"${a==null?void 0:a.operationId}"`,url:Q,tags:(a==null?void 0:a.tags)||[]},It=`Endpoint(
|
|
109
113
|
method="${u}",
|
|
110
114
|
operationId="${(a==null?void 0:a.operationId)||""}",
|
|
111
115
|
url=${Q},
|
|
112
|
-
tags=[${((a==null?void 0:a.tags)||[]).map(
|
|
113
|
-
)`,
|
|
114
|
-
${
|
|
116
|
+
tags=[${((a==null?void 0:a.tags)||[]).map(E=>`"${E}"`).join(", ")}]
|
|
117
|
+
)`,sn=d?`${U}${he} = ${It}
|
|
118
|
+
${ge?`${ge}`:""}
|
|
115
119
|
|
|
116
|
-
`:`${
|
|
117
|
-
`;e!=null&&e.folderSplit?w[g].endpoints+=
|
|
120
|
+
`:`${ge}export const ${U}${he} = ${((et=(Xn=e==null?void 0:e.endpoints)==null?void 0:Xn.value)==null?void 0:et.type)==="object"?Te(Ne):Q};
|
|
121
|
+
`;e!=null&&e.folderSplit?w[g].endpoints+=sn:pe+=sn;let xt={name:`${U}${he}`,method:u,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId,tags:m,parameters:(nt=a==null?void 0:a.parameters)==null?void 0:nt.filter(E=>!E.$ref&&E.in&&E.name).map(E=>{var I;return {name:E.name,in:E.in,required:E.required,type:((I=E.schema)==null?void 0:I.type)||"string"}}),requestBody:P?{type:v,required:P.required}:void 0,responses:S?Object.entries(S).reduce((E,[I,A])=>(E[I]={type:A},E),{}):void 0,queryType:x,dtoType:N,responseType:xe||void 0};Pe.push(xt);});}),e!=null&&e.folderSplit){let r=`from dataclasses import dataclass
|
|
118
122
|
from typing import List
|
|
119
123
|
|
|
120
124
|
@dataclass
|
|
@@ -126,15 +130,15 @@ class Endpoint:
|
|
|
126
130
|
|
|
127
131
|
|
|
128
132
|
|
|
129
|
-
`;for(let[o,b]of Object.entries(w))if(b.endpoints||b.types){let C=V.join(
|
|
133
|
+
`;for(let[o,b]of Object.entries(w))if(b.endpoints||b.types){let C=V.join($,o);if(b.endpoints){let u=V.join($e,C,`endpoints.${f}`);yield ue.promises.mkdir(V.dirname(u),{recursive:true}),yield be(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(le).length>0?d?`from __future__ import annotations
|
|
130
134
|
from dataclasses import dataclass
|
|
131
135
|
from . import shared as Shared
|
|
132
|
-
${
|
|
136
|
+
${F(b.types)}
|
|
133
137
|
${b.types}`:`import * as Shared from "../shared";
|
|
134
138
|
|
|
135
|
-
${b.types}`:b.types;yield
|
|
139
|
+
${b.types}`:b.types;yield be(u,y,e);}if(((en=e==null?void 0:e.validations)==null?void 0:en.disable)!==true&&b.validation&&!d){let u=((nn=e.validations)==null?void 0:nn.library)||"zod",y=u==="joi"?'import Joi from "joi";':u==="yup"?'import * as yup from "yup";':'import { z } from "zod";',m=V.join($e,C,"validations.ts");yield ue.promises.mkdir(V.dirname(m),{recursive:true}),yield be(m,`${y}
|
|
136
140
|
|
|
137
|
-
${b.validation}`,e);}}}if(
|
|
141
|
+
${b.validation}`,e);}}}if(pe.length>0){let r=`from dataclasses import dataclass
|
|
138
142
|
from typing import List
|
|
139
143
|
|
|
140
144
|
@dataclass
|
|
@@ -146,19 +150,19 @@ class Endpoint:
|
|
|
146
150
|
|
|
147
151
|
|
|
148
152
|
|
|
149
|
-
`,o=V.join($e
|
|
150
|
-
`),o=V.join($e
|
|
153
|
+
`,o=V.join($e,$,`endpoints.${f}`);yield ue.promises.mkdir(V.dirname(o),{recursive:true}),yield be(o,d?`${r}${pe}`:pe,e);}if(Object.values(le).length>0){let r=Object.values(le).join(`
|
|
154
|
+
`),o=V.join($e,$,e!=null&&e.folderSplit?"":"types",`shared.${f}`);yield ue.promises.mkdir(V.dirname(o),{recursive:true}),yield be(o,(d?`from __future__ import annotations
|
|
151
155
|
from dataclasses import dataclass
|
|
152
|
-
${
|
|
153
|
-
`:"")+r,e);}if(
|
|
156
|
+
${F(r)}
|
|
157
|
+
`:"")+r,e);}if(de.length>0){let r=V.join($e,$,"types",`index.${f}`);yield ue.promises.mkdir(V.dirname(r),{recursive:true}),yield be(r,(Object.values(le).length>0?d?`from __future__ import annotations
|
|
154
158
|
from dataclasses import dataclass
|
|
155
159
|
from . import shared as Shared
|
|
156
|
-
${
|
|
160
|
+
${F(de)}
|
|
157
161
|
`:`import * as Shared from "./shared";
|
|
158
162
|
|
|
159
|
-
`:"")+
|
|
163
|
+
`:"")+de,e);}if(((tn=e==null?void 0:e.validations)==null?void 0:tn.disable)!==true&&!(e!=null&&e.folderSplit)&&!d){let r=((rn=e.validations)==null?void 0:rn.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,$,"validations.ts");yield ue.promises.mkdir(V.dirname(C),{recursive:true}),yield be(C,`${o}
|
|
160
164
|
|
|
161
|
-
${b}`,e);}}return
|
|
165
|
+
${b}`,e);}}return ct(c,Pe),console.info(`\u2705 Successfully synced ${c}`),{success:true}}),Qe=yt;var gt=(l,i)=>{let c=l;return i.tags&&i.tags.length>0&&(c=c.filter(e=>!e.tags||e.tags.length===0?false:e.tags.some(s=>i.tags.includes(s)))),i.endpoints&&i.endpoints.length>0&&(c=c.filter(e=>i.endpoints.includes(e.name))),c};var Be=(l,i,c=false)=>{var t,$;let e=i.baseURL||"";i.auth;let n=`// Generated Fetch API Client
|
|
162
166
|
`;n+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
163
167
|
|
|
164
168
|
`,n+=`import type {
|
|
@@ -208,7 +212,7 @@ ${b}`,e);}}return mt(m,Ie),console.info(`\u2705 Successfully synced ${m}`),{succ
|
|
|
208
212
|
`,n+=` });
|
|
209
213
|
|
|
210
214
|
`,n+=` if (!response.ok) {
|
|
211
|
-
`,(
|
|
215
|
+
`,($=i.errorHandling)!=null&&$.generateErrorClasses?(n+=` const errorData = await response.json().catch(() => ({}));
|
|
212
216
|
`,n+=` throw new ApiError(
|
|
213
217
|
`,n+=` errorData.message || response.statusText,
|
|
214
218
|
`,n+=` response.status,
|
|
@@ -219,7 +223,7 @@ ${b}`,e);}}return mt(m,Ie),console.info(`\u2705 Successfully synced ${m}`),{succ
|
|
|
219
223
|
`,n+=` return response.json();
|
|
220
224
|
`,n+=`}
|
|
221
225
|
|
|
222
|
-
`,l.forEach(d=>{var B,j;let f=d.name,w=((B=d.parameters)==null?void 0:B.filter(
|
|
226
|
+
`,l.forEach(d=>{var B,j;let f=d.name,w=((B=d.parameters)==null?void 0:B.filter(T=>T.in==="path"))||[],M=((j=d.parameters)==null?void 0:j.filter(T=>T.in==="query"))||[],R=w.length>0,O=M.length>0,U=!!d.requestBody,L=d.responseType||"any";if(n+=`/**
|
|
223
227
|
`,d.summary&&(n+=` * ${d.summary}
|
|
224
228
|
`),n+=` * @method ${d.method.toUpperCase()}
|
|
225
229
|
`,n+=` * @path ${d.path}
|
|
@@ -227,34 +231,34 @@ ${b}`,e);}}return mt(m,Ie),console.info(`\u2705 Successfully synced ${m}`),{succ
|
|
|
227
231
|
`),n+=` */
|
|
228
232
|
`,n+=`export async function ${f}(`,(R||O||U)&&(n+=`params: {
|
|
229
233
|
`,R&&(n+=` url: {
|
|
230
|
-
`,w.forEach(
|
|
234
|
+
`,w.forEach(T=>{let F={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[T.type||"string"]||"any",W=T.required?"":"?";n+=` ${T.name}${W}: ${F};
|
|
231
235
|
`;}),n+=` };
|
|
232
236
|
`),O&&(n+=` query: ${d.queryType||"Record<string, any>"};
|
|
233
237
|
`),U&&(n+=` data: ${d.dtoType||"any"};
|
|
234
238
|
`),n+=`}
|
|
235
|
-
`),n+=`): Promise<${
|
|
236
|
-
`,R||O||U){let
|
|
237
|
-
`;}let k;if(R){let
|
|
238
|
-
`,
|
|
239
|
-
`:(n+=` if (query.${
|
|
240
|
-
`,n+=` queryParams.append('${
|
|
239
|
+
`),n+=`): Promise<${L}> {
|
|
240
|
+
`,R||O||U){let T=[];R&&T.push("url"),O&&T.push("query"),U&&T.push("data"),n+=` const { ${T.join(", ")} } = params;
|
|
241
|
+
`;}let k;if(R){let T=w.map(ee=>`url.${ee.name}`).join(", ");k=`${d.name}_endpoint(${T})`;}else k=`${d.name}_endpoint`;O?(n+=` const queryParams = new URLSearchParams();
|
|
242
|
+
`,M.forEach(T=>{T.required?n+=` queryParams.append('${T.name}', String(query.${T.name}));
|
|
243
|
+
`:(n+=` if (query.${T.name} !== undefined) {
|
|
244
|
+
`,n+=` queryParams.append('${T.name}', String(query.${T.name}));
|
|
241
245
|
`,n+=` }
|
|
242
246
|
`);}),n+=` const _url = \`\${${k}}?\${queryParams.toString()}\`;
|
|
243
247
|
`):n+=` const _url = ${k};
|
|
244
|
-
`,n+=` return fetchAPI<${
|
|
248
|
+
`,n+=` return fetchAPI<${L}>(_url, {
|
|
245
249
|
`,n+=` method: '${d.method.toUpperCase()}',
|
|
246
250
|
`,U&&(n+=` body: JSON.stringify(data),
|
|
247
251
|
`),n+=` });
|
|
248
252
|
`,n+=`}
|
|
249
253
|
|
|
250
|
-
`;}),
|
|
254
|
+
`;}),c&&(n+=`// Export all functions as a default object
|
|
251
255
|
`,n+=`const apiClient = {
|
|
252
256
|
`,n+=` setApiConfig,
|
|
253
257
|
`,l.forEach(d=>{n+=` ${d.name},
|
|
254
258
|
`;}),n+=`};
|
|
255
259
|
|
|
256
260
|
`,n+=`export default apiClient;
|
|
257
|
-
`),n},
|
|
261
|
+
`),n},Ie=(l,i,c=false)=>{var t,$;let e=i.baseURL||"";i.auth;let n=`// Generated Axios API Client
|
|
258
262
|
`;n+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
259
263
|
|
|
260
264
|
`,n+=`import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
@@ -301,7 +305,7 @@ ${b}`,e);}}return mt(m,Ie),console.info(`\u2705 Successfully synced ${m}`),{succ
|
|
|
301
305
|
`,n+=` this.client.interceptors.response.use(
|
|
302
306
|
`,n+=` (response) => response,
|
|
303
307
|
`,n+=` (error) => {
|
|
304
|
-
`,(
|
|
308
|
+
`,($=i.errorHandling)!=null&&$.generateErrorClasses?(n+=` const message = error.response?.data?.message || error.message;
|
|
305
309
|
`,n+=` const statusCode = error.response?.status || 500;
|
|
306
310
|
`,n+=` throw new ApiError(message, statusCode, error.response?.data);
|
|
307
311
|
`):n+=` return Promise.reject(error);
|
|
@@ -313,7 +317,7 @@ ${b}`,e);}}return mt(m,Ie),console.info(`\u2705 Successfully synced ${m}`),{succ
|
|
|
313
317
|
`,n+=` Object.assign(this.client.defaults, config);
|
|
314
318
|
`,n+=` }
|
|
315
319
|
|
|
316
|
-
`,l.forEach(d=>{var k,B;let f=d.name,w=((k=d.parameters)==null?void 0:k.filter(j=>j.in==="path"))||[],
|
|
320
|
+
`,l.forEach(d=>{var k,B;let f=d.name,w=((k=d.parameters)==null?void 0:k.filter(j=>j.in==="path"))||[],M=((B=d.parameters)==null?void 0:B.filter(j=>j.in==="query"))||[],R=w.length>0,O=M.length>0,U=!!d.requestBody,L=d.responseType||"any";if(n+=` /**
|
|
317
321
|
`,d.summary&&(n+=` * ${d.summary}
|
|
318
322
|
`),n+=` * @method ${d.method.toUpperCase()}
|
|
319
323
|
`,n+=` * @path ${d.path}
|
|
@@ -325,13 +329,13 @@ ${b}`,e);}}return mt(m,Ie),console.info(`\u2705 Successfully synced ${m}`),{succ
|
|
|
325
329
|
`;}),n+=` };
|
|
326
330
|
`),O&&(n+=` query: ${d.queryType||"Record<string, any>"};
|
|
327
331
|
`),U&&(n+=` data: ${d.dtoType||"any"};
|
|
328
|
-
`),n+=" }"),n+=`): Promise<${
|
|
332
|
+
`),n+=" }"),n+=`): Promise<${L}> {
|
|
329
333
|
`,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(
|
|
334
|
+
`;}if(R){let j=w.map(T=>`url.${T.name}`).join(", ");n+=` const _url = ${d.name}(${j});
|
|
331
335
|
`;}else n+=` const _url = ${d.name};
|
|
332
336
|
`;n+=` const config: AxiosRequestConfig = {};
|
|
333
337
|
`,O&&(n+=` config.params = { ...query };
|
|
334
|
-
`),n+=` const response = await this.client.${d.method.toLowerCase()}<${
|
|
338
|
+
`),n+=` const response = await this.client.${d.method.toLowerCase()}<${L}>(
|
|
335
339
|
`,n+=` _url,
|
|
336
340
|
`,U?n+=` data,
|
|
337
341
|
config
|
|
@@ -342,13 +346,13 @@ ${b}`,e);}}return mt(m,Ie),console.info(`\u2705 Successfully synced ${m}`),{succ
|
|
|
342
346
|
|
|
343
347
|
`;}),n+=`}
|
|
344
348
|
|
|
345
|
-
`,
|
|
349
|
+
`,c?n+=`export default ApiClient;
|
|
346
350
|
`:(n+=`export const apiClient = new ApiClient();
|
|
347
351
|
`,n+=`export default apiClient;
|
|
348
|
-
`),n},ze=(l,i)=>{var
|
|
352
|
+
`),n},ze=(l,i)=>{var $,d;let c=(($=i.reactQuery)==null?void 0:$.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
353
|
`;n+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
350
354
|
|
|
351
|
-
`;let p=e&&l.some(f=>["POST","PUT","PATCH","DELETE"].includes(f.method.toUpperCase()));if(
|
|
355
|
+
`;let p=e&&l.some(f=>["POST","PUT","PATCH","DELETE"].includes(f.method.toUpperCase()));if(c===5){let f=p?`import { useQuery, useMutation, UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
352
356
|
`:`import { useQuery, UseQueryOptions } from '@tanstack/react-query';
|
|
353
357
|
`;s&&(f=f.replace("@tanstack/react-query';\\n",`@tanstack/react-query';
|
|
354
358
|
import { useInfiniteQuery, UseInfiniteQueryOptions } from '@tanstack/react-query';
|
|
@@ -362,16 +366,16 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
362
366
|
`;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
367
|
`;}),n+=`} from '../types';
|
|
364
368
|
|
|
365
|
-
`,l.forEach(f=>{var
|
|
369
|
+
`,l.forEach(f=>{var T,ee;let w=f.method.toUpperCase(),M=w==="GET",R=["POST","PUT","PATCH","DELETE"].includes(w),O=((T=f.parameters)==null?void 0:T.filter(F=>F.in==="path"))||[],U=((ee=f.parameters)==null?void 0:ee.filter(F=>F.in==="query"))||[],L=O.length>0,k=U.length>0,B=!!f.requestBody,j=f.responseType||"any";if(M){let F=U.map(ie=>ie.name.toLowerCase()),ce=(F.includes("page")||F.includes("cursor")||F.includes("cursorid")||F.includes("after")||F.includes("before"))&&s,se=`use${f.name.charAt(0).toUpperCase()+f.name.slice(1)}`;if(n+=`/**
|
|
366
370
|
`,f.summary&&(n+=` * ${f.summary}
|
|
367
371
|
`),n+=` * @method ${w}
|
|
368
372
|
`,n+=` * @path ${f.path}
|
|
369
373
|
`,f.tags&&f.tags.length>0&&(n+=` * @tags ${f.tags.join(", ")}
|
|
370
374
|
`),n+=` */
|
|
371
|
-
`,
|
|
375
|
+
`,L||k?(n+=`export function ${se}(
|
|
372
376
|
`,n+=` params: {
|
|
373
|
-
`,
|
|
374
|
-
`,O.forEach(
|
|
377
|
+
`,L&&(n+=` url: {
|
|
378
|
+
`,O.forEach(ie=>{let de={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[ie.type||"string"]||"any",le=ie.required?"":"?";n+=` ${ie.name}${le}: ${de};
|
|
375
379
|
`;}),n+=` };
|
|
376
380
|
`),k&&(n+=` query: ${f.queryType||"Record<string, any>"};
|
|
377
381
|
`),n+=` },
|
|
@@ -384,7 +388,7 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
384
388
|
`,n+=` });
|
|
385
389
|
`,n+=`}
|
|
386
390
|
|
|
387
|
-
`):(n+=`export function ${
|
|
391
|
+
`):(n+=`export function ${se}(
|
|
388
392
|
`,n+=` options?: Omit<UseQueryOptions<${j}>, 'queryKey' | 'queryFn'>
|
|
389
393
|
`,n+=`) {
|
|
390
394
|
`,n+=` return useQuery({
|
|
@@ -394,10 +398,10 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
394
398
|
`,n+=` });
|
|
395
399
|
`,n+=`}
|
|
396
400
|
|
|
397
|
-
`),
|
|
401
|
+
`),ce){let ie=`${se}Infinite`;L||k?(n+=`export function ${ie}(
|
|
398
402
|
`,n+=` params: {
|
|
399
|
-
`,
|
|
400
|
-
`,O.forEach(
|
|
403
|
+
`,L&&(n+=` url: {
|
|
404
|
+
`,O.forEach(pe=>{let le={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[pe.type||"string"]||"any",Pe=pe.required?"":"?";n+=` ${pe.name}${Pe}: ${le};
|
|
401
405
|
`;}),n+=` };
|
|
402
406
|
`),k&&(n+=` query: ${f.queryType||"Record<string, any>"};
|
|
403
407
|
`),n+=` },
|
|
@@ -411,7 +415,7 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
411
415
|
`,n+=` });
|
|
412
416
|
`,n+=`}
|
|
413
417
|
|
|
414
|
-
`):(n+=`export function ${
|
|
418
|
+
`):(n+=`export function ${ie}(
|
|
415
419
|
`,n+=` options?: Omit<UseInfiniteQueryOptions<${j}, Error, ${j}>, 'queryKey' | 'queryFn'>
|
|
416
420
|
`,n+=`) {
|
|
417
421
|
`,n+=` return useInfiniteQuery({
|
|
@@ -428,24 +432,24 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
428
432
|
`,n+=` * @path ${f.path}
|
|
429
433
|
`,f.tags&&f.tags.length>0&&(n+=` * @tags ${f.tags.join(", ")}
|
|
430
434
|
`),n+=` */
|
|
431
|
-
`;let
|
|
432
|
-
`,
|
|
433
|
-
`,O.forEach(
|
|
434
|
-
`;}),
|
|
435
|
-
`),k&&(
|
|
436
|
-
`),B&&(
|
|
437
|
-
`),
|
|
438
|
-
`,n+=` options?: Omit<UseMutationOptions<${j}, Error, ${
|
|
435
|
+
`;let W="void";(L||k||B)&&(W=`{
|
|
436
|
+
`,L&&(W+=` url: {
|
|
437
|
+
`,O.forEach(ce=>{let ie={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[ce.type||"string"]||"any",pe=ce.required?"":"?";W+=` ${ce.name}${pe}: ${ie};
|
|
438
|
+
`;}),W+=` };
|
|
439
|
+
`),k&&(W+=` query: ${f.queryType||"Record<string, any>"};
|
|
440
|
+
`),B&&(W+=` data: ${f.dtoType||"any"};
|
|
441
|
+
`),W+=" }"),n+=`export function ${F}(
|
|
442
|
+
`,n+=` options?: Omit<UseMutationOptions<${j}, Error, ${W}>, 'mutationFn'>
|
|
439
443
|
`,n+=`) {
|
|
440
444
|
`,n+=` return useMutation({
|
|
441
|
-
`,n+=" mutationFn: (",
|
|
442
|
-
`,n+=` return apiClient.${f.name}(${
|
|
445
|
+
`,n+=" mutationFn: (",W!=="void"&&(n+=`variables: ${W}`),n+=`) => {
|
|
446
|
+
`,n+=` return apiClient.${f.name}(${W!=="void"?"variables":""});
|
|
443
447
|
`,n+=` },
|
|
444
448
|
`,n+=` ...options,
|
|
445
449
|
`,n+=` });
|
|
446
450
|
`,n+=`}
|
|
447
451
|
|
|
448
|
-
`;}}),n},De=(l,i)=>{var p;let
|
|
452
|
+
`;}}),n},De=(l,i)=>{var p;let c=((p=i.swr)==null?void 0:p.mutations)!==false,e=`// Generated SWR Hooks
|
|
449
453
|
`;e+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
450
454
|
|
|
451
455
|
`,e+=`/**
|
|
@@ -640,27 +644,27 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
640
644
|
`,e+=` */
|
|
641
645
|
|
|
642
646
|
`,e+=`import useSWR, { SWRConfiguration } from 'swr';
|
|
643
|
-
`,
|
|
647
|
+
`,c&&l.some(t=>["POST","PUT","PATCH","DELETE"].includes(t.method.toUpperCase()))&&(e+=`import useSWRMutation, { SWRMutationConfiguration } from 'swr/mutation';
|
|
644
648
|
`),e+=`
|
|
645
649
|
`,e+=`import apiClient from './client';
|
|
646
650
|
`,e+=`import type {
|
|
647
651
|
`;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},
|
|
648
652
|
`;}),e+=`} from '../types';
|
|
649
653
|
|
|
650
|
-
`,l.forEach(t=>{var k,B;let
|
|
654
|
+
`,l.forEach(t=>{var k,B;let $=t.method.toUpperCase(),d=$==="GET",f=["POST","PUT","PATCH","DELETE"].includes($),w=((k=t.parameters)==null?void 0:k.filter(j=>j.in==="path"))||[],M=((B=t.parameters)==null?void 0:B.filter(j=>j.in==="query"))||[],R=w.length>0,O=M.length>0,U=!!t.requestBody,L=t.responseType||"any";if(d){let j=`use${t.name.charAt(0).toUpperCase()+t.name.slice(1)}`;e+=`/**
|
|
651
655
|
`,t.summary&&(e+=` * ${t.summary}
|
|
652
|
-
`),e+=` * @method ${
|
|
656
|
+
`),e+=` * @method ${$}
|
|
653
657
|
`,e+=` * @path ${t.path}
|
|
654
658
|
`,t.tags&&t.tags.length>0&&(e+=` * @tags ${t.tags.join(", ")}
|
|
655
659
|
`),e+=` */
|
|
656
660
|
`,R||O?(e+=`export function ${j}(
|
|
657
661
|
`,e+=` params: {
|
|
658
662
|
`,R&&(e+=` url: {
|
|
659
|
-
`,w.forEach(
|
|
663
|
+
`,w.forEach(T=>{let F={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[T.type||"string"]||"any",W=T.required?"":"?";e+=` ${T.name}${W}: ${F};
|
|
660
664
|
`;}),e+=` };
|
|
661
665
|
`),O&&(e+=` query: ${t.queryType||"Record<string, any>"};
|
|
662
666
|
`),e+=` },
|
|
663
|
-
`,e+=` config?: SWRConfiguration<${
|
|
667
|
+
`,e+=` config?: SWRConfiguration<${L}>
|
|
664
668
|
`,e+=`) {
|
|
665
669
|
`,e+=` return useSWR(
|
|
666
670
|
`,e+=` ['${t.name}', params],
|
|
@@ -668,7 +672,7 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
668
672
|
`,e+=` config
|
|
669
673
|
`,e+=` );
|
|
670
674
|
`):(e+=`export function ${j}(
|
|
671
|
-
`,e+=` config?: SWRConfiguration<${
|
|
675
|
+
`,e+=` config?: SWRConfiguration<${L}>
|
|
672
676
|
`,e+=`) {
|
|
673
677
|
`,e+=` return useSWR(
|
|
674
678
|
`,e+=` '${t.name}',
|
|
@@ -677,31 +681,31 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
677
681
|
`,e+=` );
|
|
678
682
|
`),e+=`}
|
|
679
683
|
|
|
680
|
-
`;}else if(f&&
|
|
684
|
+
`;}else if(f&&c){let j=`use${t.name.charAt(0).toUpperCase()+t.name.slice(1)}`;e+=`/**
|
|
681
685
|
`,t.summary&&(e+=` * ${t.summary}
|
|
682
|
-
`),e+=` * @method ${
|
|
686
|
+
`),e+=` * @method ${$}
|
|
683
687
|
`,e+=` * @path ${t.path}
|
|
684
688
|
`,t.tags&&t.tags.length>0&&(e+=` * @tags ${t.tags.join(", ")}
|
|
685
689
|
`),e+=` */
|
|
686
|
-
`;let
|
|
687
|
-
`,R&&(
|
|
688
|
-
`,w.forEach(F=>{let
|
|
689
|
-
`;}),
|
|
690
|
-
`),O&&(
|
|
691
|
-
`),U&&(
|
|
692
|
-
`),
|
|
693
|
-
`,e+=` config?: SWRMutationConfiguration<${
|
|
690
|
+
`;let T="void",ee="void";(R||O||U)&&(T=`{
|
|
691
|
+
`,R&&(T+=` url: {
|
|
692
|
+
`,w.forEach(F=>{let ce={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[F.type||"string"]||"any",se=F.required?"":"?";T+=` ${F.name}${se}: ${ce};
|
|
693
|
+
`;}),T+=` };
|
|
694
|
+
`),O&&(T+=` query: ${t.queryType||"Record<string, any>"};
|
|
695
|
+
`),U&&(T+=` data: ${t.dtoType||"any"};
|
|
696
|
+
`),T+=" }",ee=`{ arg: ${T} }`),e+=`export function ${j}(
|
|
697
|
+
`,e+=` config?: SWRMutationConfiguration<${L}, Error, string, ${T}>
|
|
694
698
|
`,e+=`) {
|
|
695
699
|
`,e+=` return useSWRMutation(
|
|
696
700
|
`,e+=` '${t.name}',
|
|
697
|
-
`,e+=" async (_, ",
|
|
698
|
-
`,e+=` return apiClient.${t.name}(${
|
|
701
|
+
`,e+=" async (_, ",T!=="void"&&(e+=`{ arg }: ${ee}`),e+=`) => {
|
|
702
|
+
`,e+=` return apiClient.${t.name}(${T!=="void"?"arg":""});
|
|
699
703
|
`,e+=` },
|
|
700
704
|
`,e+=` config
|
|
701
705
|
`,e+=` );
|
|
702
706
|
`,e+=`}
|
|
703
707
|
|
|
704
|
-
`;}}),e},We=(l,i)=>{var p;let
|
|
708
|
+
`;}}),e},We=(l,i)=>{var p;let c=((p=i.rtkQuery)==null?void 0:p.apiName)||"api",e=i.baseURL||"",s=`// Generated RTK Query API Slice
|
|
705
709
|
`;s+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
706
710
|
|
|
707
711
|
`,s+=`import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
|
|
@@ -714,8 +718,8 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
714
718
|
`,l.forEach(t=>{s+=` ${t.name},
|
|
715
719
|
`;}),s+=`} from '../endpoints';
|
|
716
720
|
|
|
717
|
-
`,s+=`const ${
|
|
718
|
-
`,s+=` reducerPath: '${
|
|
721
|
+
`,s+=`const ${c}Api = createApi({
|
|
722
|
+
`,s+=` reducerPath: '${c}Api',
|
|
719
723
|
`,s+=` baseQuery: fetchBaseQuery({
|
|
720
724
|
`,s+=` baseUrl: '${e}',
|
|
721
725
|
`,i.auth&&(s+=` prepareHeaders: (headers, { getState }) => {
|
|
@@ -729,18 +733,18 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
729
733
|
`),s+=` }),
|
|
730
734
|
`,s+=` tagTypes: [${[...new Set(l.flatMap(t=>t.tags||[]))].map(t=>`'${t}'`).join(", ")}],
|
|
731
735
|
`,s+=` endpoints: (builder) => ({
|
|
732
|
-
`,l.forEach((t
|
|
733
|
-
`,s+=` ${
|
|
736
|
+
`,l.forEach((t,$)=>{var B,j;let d=t.method.toUpperCase(),f=d==="GET",w=((B=t.parameters)==null?void 0:B.filter(T=>T.in==="path"))||[],M=((j=t.parameters)==null?void 0:j.filter(T=>T.in==="query"))||[],R=w.length>0,O=M.length>0,U=!!t.requestBody,L=t.responseType||"any";s+=` ${t.name}: builder.${f?"query":"mutation"}<
|
|
737
|
+
`,s+=` ${L},
|
|
734
738
|
`;let k="void";if((R||O||U)&&(k=`{
|
|
735
739
|
`,R&&(k+=` url: {
|
|
736
|
-
`,w.forEach(
|
|
740
|
+
`,w.forEach(T=>{let F={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[T.type||"string"]||"any",W=T.required?"":"?";k+=` ${T.name}${W}: ${F};
|
|
737
741
|
`;}),k+=` };
|
|
738
742
|
`),O&&(k+=` query: ${t.queryType||"Record<string, any>"};
|
|
739
743
|
`),U&&(k+=` data: ${t.dtoType||"any"};
|
|
740
744
|
`),k+=" }"),s+=` ${k}
|
|
741
745
|
`,s+=` >({
|
|
742
746
|
`,s+=" query: (",k!=="void"&&(s+="arg"),s+=`) => {
|
|
743
|
-
`,R){let
|
|
747
|
+
`,R){let T=w.map(ee=>`arg.url.${ee.name}`).join(", ");s+=` const url = ${t.name}(${T});
|
|
744
748
|
`;}else s+=` const url = ${t.name};
|
|
745
749
|
`;s+=` return {
|
|
746
750
|
`,s+=` url,
|
|
@@ -751,20 +755,20 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
751
755
|
`,s+=` },
|
|
752
756
|
`,t.tags&&t.tags.length>0&&(f?s+=` providesTags: ['${t.tags[0]}'],
|
|
753
757
|
`:s+=` invalidatesTags: ['${t.tags[0]}'],
|
|
754
|
-
`),s+=` })${
|
|
758
|
+
`),s+=` })${$<l.length-1?",":""}
|
|
755
759
|
`;}),s+=` }),
|
|
756
760
|
`,s+=`});
|
|
757
761
|
|
|
758
|
-
`,s+=`export default ${
|
|
762
|
+
`,s+=`export default ${c}Api;
|
|
759
763
|
|
|
760
|
-
`,s};var
|
|
764
|
+
`,s};var kt=(l,i)=>{var c,e;if((c=i==null?void 0:i.folderSplit)!=null&&c.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"},ht=(l,i,c,e,s)=>d(null,null,function*(){let n=gt(l,c);if(n.length===0)return;let p=c.type||"fetch";c.outputDir||V.join(s,e,"client");let $=!!(i!=null&&i.folderSplit&&(i.folderSplit.byTags||i.folderSplit.customFolder));if(`${p}${n.length}`,$){let f={};n.forEach(R=>{let O=kt(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 St(O,i,c,U,p,R,true);}let M=V.join(s,e);yield Ut(M,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,c);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=Ie(n,c,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 M=Ie(n,c,false);M=M.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield te(V.join(d,"clients.ts"),M,i);let R=ze(n,c);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=Ie(n,c,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,c);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 L=We(n,c);L=L.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield te(V.join(d,"api.ts"),L,i);break;default:throw new Error(`Unknown client type: ${p}`)}}),te=(l,i,c)=>d(null,null,function*(){var p,t,$,d;if(!(((p=c==null?void 0:c.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=c==null?void 0:c.customCode)==null?void 0:t.position)||"bottom",markerText:($=c==null?void 0:c.customCode)==null?void 0:$.markerText,includeInstructions:(d=c==null?void 0:c.customCode)==null?void 0:d.includeInstructions});yield ue.promises.writeFile(l,n);});var St=(l,i,c,e,s,n,p=false)=>d(null,null,function*(){let t="",$="",d=p?"./types":"../types",f=p?"./endpoints":"../endpoints";switch(s){case "fetch":t=Be(l,c,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=Ie(l,c,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=Ie(l,c,p),t=t.replace("} from '../types';",`} from '${d}';`).replace("} from '../endpoints';",`} from '${f}';`),yield te(V.join(e,"client.ts"),t,i),$=ze(l,c),$=$.replace("} from '../types';",`} from '${d}';`).replace("} from '../endpoints';",`} from '${f}';`),p){let M=n.replace(/-/g,"_");$=$.replace("import apiClient from './client';",`import { ${M}Client as apiClient } from '../clients';`);}yield te(V.join(e,"hooks.ts"),$,i);break;case "swr":if(t=Ie(l,c,p),t=t.replace("} from '../types';",`} from '${d}';`).replace("} from '../endpoints';",`} from '${f}';`),yield te(V.join(e,"client.ts"),t,i),$=De(l,c),$=$.replace("} from '../types';",`} from '${d}';`).replace("} from '../endpoints';",`} from '${f}';`),p){let M=n.replace(/-/g,"_");$=$.replace("import apiClient from './client';",`import { ${M}Client as apiClient } from '../clients';`);}yield te(V.join(e,"hooks.ts"),$,i);break;case "rtk-query":let w=p?b(a({},c),{rtkQuery:b(a({},c.rtkQuery),{apiName:n.replace(/-/g,"_")})}):c;$=We(l,w),$=$.replace("} from '../types';",`} from '${d}';`).replace("} from '../endpoints';",`} from '${f}';`),yield te(V.join(e,"api.ts"),$,i);break;default:throw new Error(`Unknown client type: ${s}`)}}),Ut=(l,i,c,e)=>d(null,null,function*(){var n;if(c==="rtk-query"){let p=`// Generated RTK Query APIs
|
|
761
765
|
`;p+=`// This file was auto-generated.
|
|
762
766
|
`,p+=`// Aggregates all API slices for easy Redux store setup
|
|
763
767
|
|
|
764
|
-
`,i.forEach(t=>{let
|
|
768
|
+
`,i.forEach(t=>{let $=t.replace(/-/g,"_");p+=`import ${$}Api from './${t}/api';
|
|
765
769
|
`;}),p+=`
|
|
766
770
|
// Export all API slices
|
|
767
|
-
`,i.forEach(t=>{let
|
|
771
|
+
`,i.forEach(t=>{let $=t.replace(/-/g,"_");p+=`export { default as ${$}Api } from './${t}/api';
|
|
768
772
|
`;}),p+=`
|
|
769
773
|
/**
|
|
770
774
|
`,p+=` * Configure Redux store with all API slices
|
|
@@ -781,32 +785,32 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
781
785
|
`,p+=` */
|
|
782
786
|
`,p+=`export const setupApiStore = {
|
|
783
787
|
`,p+=` reducer: {
|
|
784
|
-
`,i.forEach(t=>{let
|
|
788
|
+
`,i.forEach(t=>{let $=t.replace(/-/g,"_");p+=` [${$}Api.reducerPath]: ${$}Api.reducer,
|
|
785
789
|
`;}),p+=` },
|
|
786
790
|
`,p+=` middleware: [
|
|
787
|
-
`,i.forEach(t=>{let
|
|
791
|
+
`,i.forEach(t=>{let $=t.replace(/-/g,"_");p+=` ${$}Api.middleware,
|
|
788
792
|
`;}),p+=` ],
|
|
789
793
|
`,p+=`};
|
|
790
794
|
`,yield te(V.join(l,"apis.ts"),p,e);return}let s=`// Generated API Clients
|
|
791
795
|
`;if(s+=`// This file was auto-generated.
|
|
792
796
|
`,s+=`// Centralized client instances and configuration
|
|
793
797
|
|
|
794
|
-
`,
|
|
795
|
-
`;}):(i.forEach(p=>{let t=p.replace(/-/g,"_")
|
|
798
|
+
`,c==="fetch"?i.forEach(p=>{let t=p.replace(/-/g,"_");s+=`export { default as ${t}Client } from './${p}/client';
|
|
799
|
+
`;}):(i.forEach(p=>{let t=p.replace(/-/g,"_"),$=`${t.charAt(0).toUpperCase()+t.slice(1)}ApiClient`;s+=`import ${$} from './${p}/client';
|
|
796
800
|
`;}),s+=`
|
|
797
801
|
// Create client instances
|
|
798
|
-
`,i.forEach(p=>{let t=p.replace(/-/g,"_")
|
|
799
|
-
`;})),
|
|
802
|
+
`,i.forEach(p=>{let t=p.replace(/-/g,"_"),$=`${t.charAt(0).toUpperCase()+t.slice(1)}ApiClient`;s+=`export const ${t}Client = new ${$}();
|
|
803
|
+
`;})),c==="fetch"&&(s+=`
|
|
800
804
|
// Import clients for aggregation
|
|
801
805
|
`,i.forEach(p=>{let t=p.replace(/-/g,"_");s+=`import ${t}_client from './${p}/client';
|
|
802
806
|
`;})),s+=`
|
|
803
807
|
// Aggregate all client instances
|
|
804
808
|
`,s+=`export const clients = {
|
|
805
|
-
`,i.forEach(p=>{let t=p.replace(/-/g,"_");
|
|
809
|
+
`,i.forEach(p=>{let t=p.replace(/-/g,"_");c==="fetch"?s+=` ${t}: ${t}_client,
|
|
806
810
|
`:s+=` ${t}: ${t}Client,
|
|
807
811
|
`;}),s+=`};
|
|
808
812
|
|
|
809
|
-
`,
|
|
813
|
+
`,c==="axios"?(s+=`
|
|
810
814
|
/**
|
|
811
815
|
`,s+=` * Configure all API clients at once
|
|
812
816
|
`,s+=` * @param config - Configuration to apply to all clients
|
|
@@ -819,7 +823,7 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
819
823
|
`,i.forEach(p=>{let t=p.replace(/-/g,"_");s+=` ${t}Client.updateConfig(config);
|
|
820
824
|
`;}),s+=`};
|
|
821
825
|
|
|
822
|
-
`):
|
|
826
|
+
`):c==="fetch"&&(s+=`
|
|
823
827
|
/**
|
|
824
828
|
`,s+=` * Configure all API clients at once
|
|
825
829
|
`,s+=` * @param config - Configuration to apply to all clients
|
|
@@ -843,7 +847,7 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
843
847
|
`,s+=`//
|
|
844
848
|
`,s+=`// // Use specific client
|
|
845
849
|
`,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),
|
|
850
|
+
`,yield te(V.join(l,"clients.ts"),s,e),c==="react-query"||c==="swr"){let p=`// Generated Hooks Aggregator
|
|
847
851
|
`;p+=`// This file was auto-generated.
|
|
848
852
|
`,p+=`// Aggregates all folder-split hooks
|
|
849
853
|
|
|
@@ -851,4 +855,4 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
851
855
|
`;}),p+=`
|
|
852
856
|
// Example usage:
|
|
853
857
|
`,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"),
|
|
858
|
+
`,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"),c$1=V.join(Ue,"openapi.sync.ts"),e=V.join(Ue,"openapi.sync.json"),s=[i,c$1,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},Er=l=>d(null,null,function*(){let i=$t(),c=Object.keys(i.api),e=l&&"refetchInterval"in l&&!isNaN(l==null?void 0:l.refetchInterval)?l.refetchInterval:i.refetchInterval;Ge();for(let s=0;s<c.length;s+=1){let n=c[s],p=i.api[n];yield Qe(p,n,i,e);}}),Tr=l=>d(null,null,function*(){let i=$t(),c=l.apiName?[l.apiName]:Object.keys(i.api);for(let s of c)if(!i.api[s])throw new Error(`API "${s}" not found in configuration. Available APIs: ${Object.keys(i.api).join(", ")}`);Ge();for(let s of c){let n=i.api[s];yield Qe(n,s,i);}let e=(i==null?void 0:i.folder)||"api";for(let s of c){let n=dt(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 ht(n,i,p,s,V.join(Ue,e));}}),Ar=()=>d(null,null,function*(){let{interactiveInit:l}=yield import('./interactive-init-DZKTNNQK.mjs');yield l();});export{Tr as GenerateClient,Er as Init,Ar as InteractiveInit,Te as JSONStringify,ye as capitalize,rt as createCustomCodeMarker,At as extractCustomCode,it as getEndpointDetails,Ft as getNestedValue,ot as isJson,Tt as isYamlString,qe as mergeCustomCode,ve as renderTypeRefMD,Lt as variableName,tt as variableNameChar,at as yamlStringToJson};
|