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.js
CHANGED
|
@@ -1,376 +1,451 @@
|
|
|
1
|
-
'use strict';var
|
|
2
|
-
`+" ".repeat(o)+
|
|
3
|
-
`).filter(
|
|
4
|
-
${" ".repeat(o)}`);
|
|
5
|
-
${" ".repeat(o-1)}}`,
|
|
6
|
-
`).map(
|
|
1
|
+
'use strict';var Pe=require('js-yaml'),V=require('path'),ce=require('fs'),Xt=require('lodash.isequal'),Le=require('lodash.get'),er=require('axios'),nr=require('axios-retry'),tr=require('@apidevtools/swagger-parser'),curlGenerator=require('curl-generator'),Ut=require('prompts');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var Pe__namespace=/*#__PURE__*/_interopNamespace(Pe);var V__default=/*#__PURE__*/_interopDefault(V);var ce__default=/*#__PURE__*/_interopDefault(ce);var Xt__default=/*#__PURE__*/_interopDefault(Xt);var Le__default=/*#__PURE__*/_interopDefault(Le);var er__default=/*#__PURE__*/_interopDefault(er);var nr__default=/*#__PURE__*/_interopDefault(nr);var tr__default=/*#__PURE__*/_interopDefault(tr);var Ut__default=/*#__PURE__*/_interopDefault(Ut);var gt=Object.defineProperty,Jt=Object.defineProperties;var _t=Object.getOwnPropertyDescriptors;var ft=Object.getOwnPropertySymbols;var Ht=Object.prototype.hasOwnProperty,Kt=Object.prototype.propertyIsEnumerable;var yt=(r,o,p)=>o in r?gt(r,o,{enumerable:true,configurable:true,writable:true,value:p}):r[o]=p,X=(r,o)=>{for(var p in o||(o={}))Ht.call(o,p)&&yt(r,p,o[p]);if(ft)for(var p of ft(o))Kt.call(o,p)&&yt(r,p,o[p]);return r},ae=(r,o)=>Jt(r,_t(o));var ve=(r=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(r,{get:(o,p)=>(typeof require!="undefined"?require:o)[p]}):r)(function(r){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var de=(r,o)=>()=>(r&&(o=r(r=0)),o);var ht=(r,o)=>{for(var p in o)gt(r,p,{get:o[p],enumerable:true});};var ie=(r,o,p)=>new Promise((e,i)=>{var n=f=>{try{t(p.next(f));}catch(c){i(c);}},u=f=>{try{t(p.throw(f));}catch(c){i(c);}},t=f=>f.done?e(f.value):Promise.resolve(f.value).then(n,u);t((p=p.apply(r,o)).next());});exports.variableName=void 0;exports.variableNameChar=void 0;var ze=de(()=>{exports.variableName=/^[A-Za-z_$][A-Za-z0-9_$]*$/,exports.variableNameChar=/[A-Za-z0-9_$]/;});function Yt(r,o){return o.split(".").reduce((e,i)=>e&&e[i]!==void 0?e[i]:void 0,r)}exports.isJson=void 0;exports.isYamlString=void 0;exports.yamlStringToJson=void 0;exports.capitalize=void 0;exports.getEndpointDetails=void 0;exports.JSONStringify=void 0;exports.renderTypeRefMD=void 0;exports.extractCustomCode=void 0;exports.createCustomCodeMarker=void 0;var $t;exports.mergeCustomCode=void 0;var Ne=de(()=>{ze();exports.isJson=r=>["object"].includes(typeof r)&&!(r instanceof Blob),exports.isYamlString=r=>{try{return Pe__namespace.load(r),!0}catch(o){let p=o;if(p instanceof Pe__namespace.YAMLException)return false;throw p}},exports.yamlStringToJson=r=>{if(exports.isYamlString(r)){let o=Pe__namespace.load(r),p=JSON.stringify(o,null,2);return JSON.parse(p)}},exports.capitalize=r=>r.substring(0,1).toUpperCase()+r.substring(1),exports.getEndpointDetails=(r,o)=>{let p=r.split("/"),e=`${exports.capitalize(o)}`,i=[];return p.forEach(n=>{if(n[0]==="{"&&n[n.length-1]==="}"){let t=n.replace(/{/,"").replace(/}/,"");i.push(t),n=`$${t}`;}else if(n[0]==="<"&&n[n.length-1]===">"){let t=n.replace(/</,"").replace(/>/,"");i.push(t),n=`$${t}`;}else if(n[0]===":"){let t=n.replace(/:/,"");i.push(t),n=`$${t}`;}let u="";n.split("").forEach(t=>{let f=t;exports.variableNameChar.test(t)||(f="/"),u+=f;}),u.split("/").forEach(t=>{e+=exports.capitalize(t);});}),{name:e,variables:i,pathParts:p}},exports.JSONStringify=(r,o=1)=>{let p="{",e=Object.keys(r);for(let i=0;i<e.length;i++){let n=e[i],u=r[n];if(p+=`
|
|
2
|
+
`+" ".repeat(o)+n+": ",Array.isArray(u)){p+="[";for(let t=0;t<u.length;t++){let f=u[t];typeof f=="object"&&f!==null?p+=exports.JSONStringify(f,o+1):p+=typeof f=="string"?`"${f}"`:f,t<u.length-1&&(p+=", ");}p+="]";}else typeof u=="object"&&u!==null?p+=""+exports.JSONStringify(u,o+1):p+=u.split(`
|
|
3
|
+
`).filter(t=>t.trim()!=="").join(`
|
|
4
|
+
${" ".repeat(o)}`);i<e.length-1&&(p+=", ");}return p+=`
|
|
5
|
+
${" ".repeat(o-1)}}`,p},exports.renderTypeRefMD=(r,o=1)=>{let p=r.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(o)} ${
|
|
9
|
+
${" ".repeat(o)} ${p.split(`
|
|
10
10
|
`).filter(e=>e.trim()!=="").join(`
|
|
11
11
|
${" ".repeat(o)} `)}
|
|
12
|
-
\`\`\``};exports.extractCustomCode=(r,o="CUSTOM CODE")=>{let
|
|
13
|
-
`,
|
|
14
|
-
`).filter(c=>{let
|
|
15
|
-
|
|
16
|
-
`:"";return
|
|
17
|
-
|
|
18
|
-
${e}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
`)
|
|
23
|
-
`).
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
\`\`\``};exports.extractCustomCode=(r,o="CUSTOM CODE")=>{let e=["//","#"].map(t=>({start:`${t} \u{1F512} ${o} START`,end:`${t} \u{1F512} ${o} END`})),i={beforeGenerated:"",afterGenerated:""},n=0,u=[];for(;n<r.length;){let t=null,f=-1;for(let P of e){let T=r.indexOf(P.start,n);T!==-1&&(f===-1||T<f)&&(f=T,t=P);}if(f===-1||!t)break;let c=r.indexOf(t.end,f);if(c===-1)break;let y=c+t.end.length,A=r.substring(y,y+100),L=A.match(/^\s*\n\s*((?:\/\/|#)\s*=+)/);if(L){let P=A.indexOf(`
|
|
13
|
+
`,L.index+1);P!==-1?y+=P+1:y+=L[0].length;}let q=f,O=r.substring(Math.max(0,f-200),f),U=/(^|\n)\s*(?:\/\/|#)\s*=+/g,F,R=-1;for(;(F=U.exec(O))!==null;)R=F.index+F[1].length;R!==-1&&(q=Math.max(0,f-200)+R);let B=r.substring(q,y);u.push({start:q,end:y,content:B}),n=y;}return u.length>0&&(r.substring(0,u[0].start).split(`
|
|
14
|
+
`).filter(c=>{let y=c.trim();return y.length>0&&!y.startsWith("//")&&!y.startsWith("#")}).join("").length===0?(i.beforeGenerated=u[0].content,u.length>1&&(i.afterGenerated=u[1].content)):(i.afterGenerated=u[0].content,u.length>1&&!i.beforeGenerated&&(i.beforeGenerated=u[1].content))),i},exports.createCustomCodeMarker=(r,o="CUSTOM CODE",p=true,e="//")=>{let i=p?`${e} ${r==="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} ${o} START
|
|
18
|
+
${i}${e} ${"=".repeat(60)}
|
|
19
|
+
|
|
20
|
+
${e} \u{1F512} ${o} END
|
|
21
|
+
${e} ${"=".repeat(60)}`},$t=(r,o,p)=>{if(!r)return r;let e=new RegExp(`^\\s*//\\s*(?:={3,}|\u{1F512}\\s+${o}\\s+(?:START|END)|Add your custom code (?:below|above) this line|This section will be preserved during regeneration)\\s*$`);return r.split(`
|
|
22
|
+
`).map(i=>e.test(i)?i.replace(/^\s*\/\//,p):i).join(`
|
|
23
|
+
`)},exports.mergeCustomCode=(r,o,p={})=>{let{position:e="bottom",markerText:i="CUSTOM CODE",includeInstructions:n=true,commentPrefix:u="//"}=p,t={beforeGenerated:"",afterGenerated:""};o&&(t=exports.extractCustomCode(o,i),t.beforeGenerated=$t(t.beforeGenerated,i,u),t.afterGenerated=$t(t.afterGenerated,i,u)),!t.beforeGenerated&&!t.afterGenerated&&((e==="top"||e==="both")&&(t.beforeGenerated=exports.createCustomCodeMarker("top",i,n,u)),(e==="bottom"||e==="both")&&(t.afterGenerated=exports.createCustomCodeMarker("bottom",i,n,u)));let f=[];return t.beforeGenerated&&(f.push(t.beforeGenerated),f.push("")),f.push(r),t.afterGenerated&&(f.push(""),f.push(t.afterGenerated)),f.join(`
|
|
24
|
+
`)};});var Fe,Ke,qe,It,xt,Tt,Ve,Ye=de(()=>{Fe=V__default.default.join(__dirname,"../","../db.json");ce__default.default.existsSync(Fe)||ce__default.default.writeFileSync(Fe,"{}");Ke={};try{Ke=ve(Fe);}catch(r){Ke={};}qe=Ke||{},It=r=>{ce__default.default.writeFileSync(Fe,JSON.stringify(r));},xt=(r,o)=>{qe[r]=o,It(qe);},Tt=r=>qe[r],Ve=()=>{qe={},It(qe);};});var Et,wt,At,Ze=de(()=>{Et={},wt=(r,o)=>{Et[r]=o;},At=r=>Et[r]||[];});var be,Xe,Ot,Ie,vt,sr,en,Pt=de(()=>{Ne();Ye();Ze();be=process.cwd(),Xe={},Ot=er__default.default.create({timeout:6e4});nr__default.default(Ot,{retries:20,retryCondition:r=>r.code==="ECONNABORTED"||r.message.includes("Network Error"),retryDelay:r=>r*1e3});Ie=(r,o,p)=>ie(null,null,function*(){var t,f,c,y;if(!(((t=p==null?void 0:p.customCode)==null?void 0:t.enabled)!==false)){yield ce__default.default.promises.writeFile(r,o);return}let i=null;try{i=yield ce__default.default.promises.readFile(r,"utf-8");}catch(A){}let n=r.endsWith(".py")?"#":"//",u=exports.mergeCustomCode(o,i,{position:((f=p==null?void 0:p.customCode)==null?void 0:f.position)||"bottom",markerText:(c=p==null?void 0:p.customCode)==null?void 0:c.markerText,includeInstructions:(y=p==null?void 0:p.customCode)==null?void 0:y.includeInstructions,commentPrefix:n});yield ce__default.default.promises.writeFile(r,u);}),vt=(r,o,p,e)=>ie(null,null,function*(){let i=yield sr(r,o,p,e);return e&&!isNaN(e)&&e>0&&(process.env.NODE_ENV&&["production","prod","test","staging"].includes(process.env.NODE_ENV)||(Xe[o]&&clearTimeout(Xe[o]),Xe[o]=setTimeout(()=>{console.info(`\u{1F504} Auto syncing ${o}`),vt(r,o,p,e);},e))),i}),sr=(...r)=>ie(null,null,function*(){var an,ln,pn,un,cn,mn,dn,fn,yn,gn;let[o,p,e]=r,i=s=>s.startsWith("http://")||s.startsWith("https://"),n;try{if(i(o))n=(yield Ot.get(o)).data;else {let s=V__default.default.isAbsolute(o)?o:V__default.default.join(be,o);`${s}`,n=yield ce__default.default.promises.readFile(s,"utf-8");}}catch(s){throw process.env.NODE_ENV&&["production","prod","test","staging"].includes(process.env.NODE_ENV)||console.error(`Failed to load OpenAPI spec for ${p}:`,s),s}if(!n)return;let u=exports.isJson(n)?n:exports.yamlStringToJson(n),t;try{t=yield tr__default.default.parse(u);}catch(s){let a=s instanceof Error?s.message:String(s);throw new Error(`Failed to parse OpenAPI spec for ${p}: ${a}`)}let f=V__default.default.join((e==null?void 0:e.folder)||"",p),c=(e==null?void 0:e.language)==="python",y=c?"py":"ts",A={},L=s=>{var a,C;if((a=e==null?void 0:e.folderSplit)!=null&&a.customFolder){let b=e.folderSplit.customFolder(s);if(b)return b}return (C=e==null?void 0:e.folderSplit)!=null&&C.byTags&&s.tags&&s.tags.length>0?s.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},q=typeof(e==null?void 0:e.server)=="string"?e==null?void 0:e.server:((ln=(an=t==null?void 0:t.servers)==null?void 0:an[(e==null?void 0:e.server)||0])==null?void 0:ln.url)||"",O=typeof((un=(pn=e==null?void 0:e.types)==null?void 0:pn.name)==null?void 0:un.prefix)=="string"?e==null?void 0:e.types.name.prefix:"I",U=typeof((mn=(cn=e==null?void 0:e.endpoints)==null?void 0:cn.name)==null?void 0:mn.prefix)=="string"?e==null?void 0:e.endpoints.name.prefix:"",F=(s,a)=>{var b,m;let C=exports.capitalize(s);if((m=(b=e==null?void 0:e.types)==null?void 0:b.name)!=null&&m.format){let g=e==null?void 0:e.types.name.format("shared",{name:s},C);if(g)return `${O}${g}`}return `${O}${C}`},R=(s,a,C,b,m,g=0)=>{let d="",$="",h="";if(a)if(a.$ref)if(a.$ref[0]==="#"){let x=(a.$ref||"").split("/");x.shift();x[0]==="definitions";[...x].pop();let k=Le__default.default(s,x,null);if(k){k!=null&&k.name&&(d=k.name),$=x[x.length-1];let W=F($);W.includes(".")&&(W=W.split(".").map((Ce,ye)=>ye===0?Ce:`["${Ce}"]`).join("")),h+=`${m!=null&&m.noSharedImport?"":"Shared."}${W}`;}}else h+="";else if(a.anyOf)h+=`(${a.anyOf.map(x=>R(s,x,"",b,ae(X({},m),{useComponentName:false}))).filter(x=>!!x).join("|")})`;else if(a.oneOf)h+=`(${a.oneOf.map(x=>R(s,x,"",b,ae(X({},m),{useComponentName:false}))).filter(x=>!!x).join("|")})`;else if(a.allOf)h+=`(${a.allOf.map(x=>R(s,x,"",b,ae(X({},m),{useComponentName:false}))).filter(x=>!!x).join("&")})`;else if(a.items)h+=`${R(s,a.items,"",false,ae(X({},m),{useComponentName:false}))}[]`;else if(a.properties){let x=Object.keys(a.properties),v=a.required||[],j="";x.forEach(N=>{var W,Ae,Ce,ye,he,$e;let k="";!((Ae=(W=e==null?void 0:e.types)==null?void 0:W.doc)!=null&&Ae.disable)&&((ye=(Ce=a.properties)==null?void 0:Ce[N])!=null&&ye.description)&&(k=" * "+((he=a.properties)==null?void 0:he[N].description.split(`
|
|
25
|
+
`).filter(Qe=>Qe.trim()!=="").join(`
|
|
26
|
+
*${" ".repeat(1)}`))),j+=(k?`/**
|
|
27
|
+
${k}
|
|
26
28
|
*/
|
|
27
|
-
`:"")+`${
|
|
28
|
-
${" ".repeat(g)}${
|
|
29
|
-
`:""}`:""},
|
|
30
|
-
|
|
31
|
-
${
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
`:"")+`${R(s,($e=a.properties)==null?void 0:$e[N],N,v.includes(N),m,g+1)}`;}),j.length>0?h+=`{
|
|
30
|
+
${" ".repeat(g)}${j}${" ".repeat(g)}}`:h+="{[k: string]: any}";}else if(a.enum&&a.enum.length>0){let x=a.enum.includes(null),v=a.enum.filter(N=>N!==null).map(N=>JSON.stringify(N)).filter(N=>N!==void 0),j=v.length>1||v.length>0&&x;j&&(h+="("),v.forEach((N,k)=>{h+=`${k===0?"":"|"}${N}`;}),x&&(h+=`${v.length>0?"|":""}null`),j&&(h+=")");}else if(a.type){let x=v=>{let j="";if(typeof v=="string")["string","integer","number","array","boolean","null"].includes(v)?["integer","number"].includes(v)?j+="number":v==="array"?j+="any[]":j+=v:v==="object"&&(a.additionalProperties?j+=`{[k: string]: ${R(s,a.additionalProperties,"",true,ae(X({},m),{useComponentName:false}))||"any"}}`:j+="{[k: string]: any}");else if(Array.isArray(v)){let N=v.map(k=>x(k));N.filter(k=>k!==""),N.length>1&&(j+="("+N.join("|")+")");}else j+="any";return j};h=x(a.type);}else h+="any";else h="string";let S=d||C;m!=null&&m.useComponentName&&!S&&(S=$);let Q=S?` "${S}"${b?"":"?"}: `:"",l=(a==null?void 0:a.enum)&&a.enum.includes(null),z=a!=null&&a.nullable&&!l?" | null":"";return h.length>0?`${Q}${h}${z}${S?`;
|
|
31
|
+
`:""}`:""},B=(s,a,C,b,m,g=0)=>{let d="",$="",h="";if(a)if(a.$ref)if(a.$ref[0]==="#"){let x=(a.$ref||"").split("/");x.shift();x[0]==="definitions";[...x].pop();let k=Le__default.default(s,x,null);if(k){k!=null&&k.name&&(d=k.name),$=x[x.length-1];let W=F($);W.includes(".")&&(W=W.split(".").join("_")),h+=`${m!=null&&m.noSharedImport?"":"Shared."}${W}`;}}else h+="Any";else if(a.anyOf)h+=`Union[${a.anyOf.map(x=>B(s,x,"",b,ae(X({},m),{useComponentName:false}))).filter(x=>!!x).join(", ")}]`;else if(a.oneOf)h+=`Union[${a.oneOf.map(x=>B(s,x,"",b,ae(X({},m),{useComponentName:false}))).filter(x=>!!x).join(", ")}]`;else if(a.allOf)h+="Dict[str, Any]";else if(a.items)h+=`List[${B(s,a.items,"",false,ae(X({},m),{useComponentName:false}))}]`;else if(a.properties){let x=Object.keys(a.properties),v=a.required||[],j="";x.forEach(N=>{var k;j+=B(s,(k=a.properties)==null?void 0:k[N],N,v.includes(N),m,g+1);}),j.length>0?C?h+="Dict[str, Any]":h+=`
|
|
32
|
+
${j}`:h+="Dict[str, Any]";}else if(a.enum&&a.enum.length>0){let x=a.enum.filter(v=>v!==null).map(v=>JSON.stringify(v));x.length>0?h+=`Literal[${x.join(", ")}]`:h+="Any";}else if(a.type){let x=v=>{let j="";if(typeof v=="string")["integer","number"].includes(v)?j+=v==="number"?"float":"int":v==="string"?j+="str":v==="boolean"?j+="bool":v==="array"?j+="List[Any]":v==="object"?j+="Dict[str, Any]":v==="null"?j+="None":j+="Any";else if(Array.isArray(v)){let N=v.map(k=>x(k)).filter(k=>k!=="");N.length>1?j+=`Union[${N.join(", ")}]`:j+=N[0]||"Any";}else j+="Any";return j};h=x(a.type);}else h+="Any";else h="str";let S=d||C;m!=null&&m.useComponentName&&!S&&(S=$);let Q="";S&&(Q=` ${S.replace(/[^a-zA-Z0-9_]/g,"_")}: `);let l=h,z=!S&&h.includes(`
|
|
33
|
+
`);return a!=null&&a.nullable&&!z&&(h.startsWith("Union[")?l=h.replace("Union[","Union[None, "):l=`Optional[${h}]`),h.length>0?`${Q}${l}${S?`
|
|
34
|
+
`:""}`:""},P=s=>{let a=(s||"").replace(/^\n+/,"").trimEnd();if(!a)return ` pass
|
|
35
|
+
`;let C=a.split(`
|
|
36
|
+
`),b=/^[A-Za-z_][A-Za-z0-9_]*\s*:\s*.+$/,m=C.map($=>$.trim()).filter($=>!!$).filter($=>!$.startsWith('"""')&&!$.endsWith('"""'));return !m.some($=>b.test($))&&m.length===1?` value: ${m[0]}
|
|
37
|
+
`:`${a.split(`
|
|
38
|
+
`).map($=>$.trim()?/^\s/.test($)?$:` ${$}`:$).join(`
|
|
39
|
+
`)}
|
|
40
|
+
`},T=(s,a)=>`@dataclass
|
|
41
|
+
class ${s}:
|
|
42
|
+
${P(a)}`,ee=s=>{let C=["Any","List","Dict","Union","Optional","Literal"].filter(b=>new RegExp(`\\b${b}\\b`).test(s));return C.length>0?`from typing import ${C.join(", ")}
|
|
43
|
+
`:""},M=(s,a=72)=>{let C=(s||"").replace(/\s+/g," ").trim().split(" ");if(!C[0])return [];let b=[],m="";return C.forEach(g=>{let d=m?`${m} ${g}`:g;d.length>a&&m?(b.push(m),m=g):m=d;}),m&&b.push(m),b},J=s=>{var m,g;if(!s||(g=(m=e==null?void 0:e.types)==null?void 0:m.doc)!=null&&g.disable)return "";let a=(s.description||"").trim(),C=Object.entries(s.properties||{}).map(([d,$])=>({name:d,desc:(($==null?void 0:$.description)||"").trim()})).filter(d=>d.desc.length>0);if(!a&&C.length===0)return "";let b=[' """'];return a&&M(a).forEach(d=>b.push(` ${d}`)),C.length>0&&(a&&b.push(""),b.push(" Attributes:"),C.forEach(d=>{let $=M(d.desc);$.length&&(b.push(` ${d.name}: ${$[0]}`),$.slice(1).forEach(h=>b.push(` ${h}`)));})),b.push(' """'),`${b.join(`
|
|
44
|
+
`)}
|
|
45
|
+
`},re=(s,a)=>{let m="";if(a)if(a.$ref)if(a.$ref[0]==="#"){let g=(a.$ref||"").split("/");g.shift();let $=Le__default.default(s,g,null);$&&($!=null&&$.name&&($.name),g[g.length-1],m+=re(s,$));}else m+="";else if(a.anyOf)m+=re(s,a.anyOf[0]);else if(a.oneOf)m+=re(s,a.oneOf[0]);else if(a.allOf)m+=`{${a.allOf.map(g=>`...(${re(s,g)})`).join(",")}}`;else if(a.items)m+=`[${re(s,a.items)}]`;else if(a.properties){let $=Object.keys(a.properties).map(h=>{var S;return ` "${h}": ${re(s,(S=a.properties)==null?void 0:S[h])}`}).join(`,
|
|
46
|
+
`);$.length>0?m+=`{
|
|
47
|
+
${$}
|
|
48
|
+
}`:m+="{}";}else if(a.enum&&a.enum.length>0)a.enum.length>1&&(m+=a.enum[0]);else if(a.type)if(a.example)m+=JSON.stringify(a.example);else {let g=d=>{let $="";if(typeof d=="string")["string","integer","number","array","boolean","null"].includes(d)?["integer","number"].includes(d)?$+="123":d==="array"?$+="[]":d==="boolean"?$+="true":d==="null"?$+="null":$+=`"${d}"`:d==="object"&&($+="{}");else if(Array.isArray(d)){let h=d.map(S=>g(S));h.filter(S=>S!==""),h.length>1&&($+=h.join("|"));}else $+="any";return $};m=g(a.type);}else m+="any";else m="string";return m},ge=Tt(p);if(Xt__default.default(ge,t))return;xt(p,t);let se="",le="",ue={},we=[],ke=(s,a)=>{let C={},b={};Object.keys(s).forEach(g=>{var h;let d=(h=s[g])!=null&&h.schema?s[g].schema:s[g],$=c?`${B(t,d,"",true,{noSharedImport:true,useComponentName:false})}`:`${R(t,d,"",true,{noSharedImport:true,useComponentName:false})}`;if($){let S=g.split("."),Q=C,l=b;for(let z=0;z<S.length;z++){let x=S[z];z<S.length-1?(x in Q||(Q[x]={},l[x]={}),Q=Q[x],l=l[x]):(Q[x]=$,l[x]=d);}}}),Object.keys(C).forEach(g=>{var z,x,v,j,N;let d=F(g),$=C[g],h=s[g],S=h!=null&&h.schema?h.schema:h,Q="",l="";!((x=(z=e==null?void 0:e.types)==null?void 0:z.doc)!=null&&x.disable)&&g in s&&((v=s[g])!=null&&v.description)&&(Q=" * "+s[g].description.split(`
|
|
49
|
+
`).filter(W=>W.trim()!=="").join(`
|
|
50
|
+
*${" ".repeat(1)}`)),l=J(S),c?ue[g]=((j=ue[g])!=null?j:"")+`@dataclass
|
|
51
|
+
class ${d}:
|
|
52
|
+
`+(l||"")+P(typeof $=="string"?$:"")+`
|
|
53
|
+
`:ue[g]=((N=ue[g])!=null?N:"")+(Q?`/**
|
|
54
|
+
${Q}
|
|
36
55
|
*/
|
|
37
|
-
`:"")+"export type "+
|
|
38
|
-
`;});};
|
|
39
|
-
`);return
|
|
56
|
+
`:"")+"export type "+d+" = "+(typeof $=="string"?$:exports.JSONStringify($))+`;
|
|
57
|
+
`;});};t.definitions&&ke(t.definitions),t.components&&Object.keys(t.components).forEach(s=>{if(["schemas","responses","parameters","examples","requestBodies","headers","links","callbacks"].includes(s)){let a=t.components[s];ke(a);}});let on=s=>{let a="";if(s.content){let C=Object.keys(s.content);C[0]&&s.content[C[0]].schema&&(a+=c?`${B(t,s.content[C[0]].schema,"")}`:`${R(t,s.content[C[0]].schema,"")}`);}return a},me=(s,a,C=0)=>{if(!s)return a==="joi"?"Joi.any()":a==="yup"?"yup.mixed()":"z.any()";if(s.$ref){if(s.$ref[0]==="#"){let b=s.$ref.split("/");b.shift();let m=b.join("."),g=Le__default.default(t,m);if(g)return me(g,a,C)}return a==="joi"?"Joi.any()":a==="yup"?"yup.mixed()":"z.any()"}if(s.anyOf||s.oneOf){let b=s.anyOf||s.oneOf;if(b.every(g=>g.enum!==void 0&&Array.isArray(g.enum))){let g=[],d=false;if(b.forEach($=>{$.enum&&$.enum.forEach(h=>{h===null?d=true:g.includes(h)||g.push(h);});}),g.length>0){let $=g.map(h=>JSON.stringify(h)).join(", ");if(a==="zod"){let h=`z.enum([${$}])`;return d&&(h+=".nullable()"),h}else if(a==="yup"){let h=`yup.mixed().oneOf([${$}])`;return d&&(h+=".nullable()"),h}else return d?`Joi.valid(${$}, null)`:`Joi.valid(${$})`}else if(d)return a==="zod"?"z.null()":a==="yup"?"yup.mixed().nullable()":"Joi.valid(null)"}return a==="zod"?`z.union([${b.map($=>me($,a,C+1)).join(", ")}])`:a==="yup"?`yup.mixed().oneOf([${b.map($=>me($,a,C+1)).join(", ")}])`:`Joi.alternatives().try(${b.map(d=>me(d,a,C+1)).join(", ")})`}if(s.allOf)if(a==="zod"){let b=s.allOf.map(g=>me(g,a,C+1)),m=b[0];for(let g=1;g<b.length;g++)m=`${m}.merge(${b[g]})`;return m}else return me(s.allOf[0],a,C+1);if(s.items){let b=me(s.items,a,C+1);if(a==="zod"){let m=`z.array(${b})`;return s.minItems!==void 0&&(m+=`.min(${s.minItems})`),s.maxItems!==void 0&&(m+=`.max(${s.maxItems})`),m}else if(a==="yup"){let m=`yup.array().of(${b})`;return s.minItems!==void 0&&(m+=`.min(${s.minItems})`),s.maxItems!==void 0&&(m+=`.max(${s.maxItems})`),m}else {let m=`Joi.array().items(${b})`;return s.minItems!==void 0&&(m+=`.min(${s.minItems})`),s.maxItems!==void 0&&(m+=`.max(${s.maxItems})`),m}}if(s.properties){let b=s.required||[],m=" ".repeat(C+1),g=Object.entries(s.properties).map(([d,$])=>{let h=b.includes(d),S=me($,a,C+1);return h||(S+=".optional()"),`${m}${d}: ${S}`}).join(`,
|
|
58
|
+
`);return a==="zod"?`z.object({
|
|
40
59
|
${g}
|
|
41
|
-
${" ".repeat(
|
|
60
|
+
${" ".repeat(C)}})`:a==="yup"?`yup.object({
|
|
42
61
|
${g}
|
|
43
|
-
${" ".repeat(
|
|
62
|
+
${" ".repeat(C)}})`:`Joi.object({
|
|
44
63
|
${g}
|
|
45
|
-
${" ".repeat(
|
|
46
|
-
${
|
|
47
|
-
|
|
48
|
-
`),
|
|
49
|
-
${
|
|
64
|
+
${" ".repeat(C)}})`}if(s.enum&&s.enum.length>0){let b=[],m=false;s.enum.forEach(d=>{d===null?m=true:b.includes(d)||b.push(d);});let g=b.map(d=>JSON.stringify(d)).join(", ");if(a==="zod"){let d=`z.enum([${g}])`;return m&&(d+=".nullable()"),d}else if(a==="yup"){let d=`yup.mixed().oneOf([${g}])`;return m&&(d+=".nullable()"),d}else {let d=`Joi.valid(${g})`;return m&&(d+=".allow(null)"),d}}if(s.type){let m=(g=>{switch(g){case "string":if(a==="zod"){let d="z.string()";return s.format==="email"?d+=".email()":s.format==="uuid"?d+=".uuid()":s.format==="url"||s.format==="uri"?d+=".url()":s.format==="date-time"?d+=".datetime()":s.format==="date"&&(d+=".date()"),s.minLength&&(d+=`.min(${s.minLength})`),s.maxLength&&(d+=`.max(${s.maxLength})`),s.pattern&&(d+=`.regex(/${s.pattern}/)`),d}else if(a==="yup"){let d="yup.string()";return s.format==="email"?d+=".email()":(s.format==="url"||s.format==="uri")&&(d+=".url()"),s.minLength&&(d+=`.min(${s.minLength})`),s.maxLength&&(d+=`.max(${s.maxLength})`),s.pattern&&(d+=`.matches(/${s.pattern}/)`),d}else {let d="Joi.string()";return s.format==="email"?d+=".email()":s.format==="url"||s.format==="uri"?d+=".uri()":s.format==="uuid"?d+=".guid({ version: 'uuidv4' })":s.format==="date-time"&&(d+=".isoDate()"),s.minLength&&(d+=`.min(${s.minLength})`),s.maxLength&&(d+=`.max(${s.maxLength})`),s.pattern&&(d+=`.pattern(/${s.pattern}/)`),d}case "integer":case "number":if(a==="zod"){let d="z.number()";return g==="integer"&&(d+=".int()"),s.minimum!==void 0&&(s.exclusiveMinimum?d+=`.gt(${s.minimum})`:d+=`.min(${s.minimum})`),s.maximum!==void 0&&(s.exclusiveMaximum?d+=`.lt(${s.maximum})`:d+=`.max(${s.maximum})`),d}else if(a==="yup"){let d="yup.number()";return g==="integer"&&(d+=".integer()"),s.minimum!==void 0&&(d+=`.min(${s.minimum})`),s.maximum!==void 0&&(d+=`.max(${s.maximum})`),d}else {let d="Joi.number()";return g==="integer"&&(d+=".integer()"),s.minimum!==void 0&&(s.exclusiveMinimum?d+=`.greater(${s.minimum})`:d+=`.min(${s.minimum})`),s.maximum!==void 0&&(s.exclusiveMaximum?d+=`.less(${s.maximum})`:d+=`.max(${s.maximum})`),d}case "boolean":return a==="joi"?"Joi.boolean()":a==="yup"?"yup.boolean()":"z.boolean()";case "null":return a==="joi"?"Joi.any().allow(null)":a==="yup"?"yup.mixed().nullable()":"z.null()";default:return a==="joi"?"Joi.any()":a==="yup"?"yup.mixed()":"z.any()"}})(typeof s.type=="string"?s.type:s.type[0]);return s.nullable&&a!=="joi"?m+=".nullable()":s.nullable&&a==="joi"&&(m+=".allow(null)"),m}return a==="joi"?"Joi.any()":a==="yup"?"yup.mixed()":"z.any()"},Qt=s=>{var a,C,b,m,g;if((C=(a=e==null?void 0:e.endpoints)==null?void 0:a.value)!=null&&C.replaceWords&&Array.isArray(e==null?void 0:e.endpoints.value.replaceWords)){let d=s;return (g=(m=(b=e==null?void 0:e.endpoints)==null?void 0:b.value)==null?void 0:m.replaceWords)==null||g.forEach(($,h)=>{let S=new RegExp($.replace,"g");d=d.replace(S,$.with||"");}),d}else return s},Bt=(s,a,C=[])=>{var g,d;let b=(g=e==null?void 0:e.endpoints)==null?void 0:g.exclude,m=(d=e==null?void 0:e.endpoints)==null?void 0:d.include;if(m){let $=m.tags&&m.tags.length>0?C.some(S=>m.tags.includes(S)):true,h=m.endpoints&&m.endpoints.length>0?m.endpoints.some(S=>{let Q=!S.method||S.method.toLowerCase()===a.toLowerCase();return S.path?s===S.path&&Q:S.regex?new RegExp(S.regex).test(s)&&Q:false}):true;if(!$||!h)return true}return !!(b&&(b.tags&&b.tags.length>0&&C.some(h=>b.tags.includes(h))||b.endpoints&&b.endpoints.length>0&&b.endpoints.some(h=>{let S=!h.method||h.method.toLowerCase()===a.toLowerCase();return h.path?s===h.path&&S:h.regex?new RegExp(h.regex).test(s)&&S:false})))};if(Object.keys(t.paths||{}).forEach(s=>{let a=t.paths[s];Object.keys(a).forEach(b=>{var $n,bn,Cn,In,xn,Tn,En,wn,An,On,vn,Pn,jn,Sn,qn,Rn,kn,Un,Nn,Fn,Ln,Gn,Mn,Qn,Bn,zn,Dn,Wn,Jn,_n,Hn,Kn,Vn,Yn,Zn,Xn,et,nt,tt,rt,st,ot,it,at,lt,pt,ut,ct,mt,dt;let m=b,g=exports.getEndpointDetails(s,m),d=(($n=a[m])==null?void 0:$n.tags)||[];if(Bt(s,m,d))return;let $=a[m],h=L({method:m,path:s,summary:$==null?void 0:$.summary,operationId:$==null?void 0:$.operationId,tags:d,parameters:$==null?void 0:$.parameters,requestBody:$==null?void 0:$.requestBody,responses:$==null?void 0:$.responses});A[h]||(A[h]={endpoints:"",types:"",validation:""});let S=((Cn=(bn=e==null?void 0:e.endpoints)==null?void 0:bn.value)!=null&&Cn.includeServer?q:"")+g.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=`"${S}"`;g.variables.length>0&&(Q=`(${g.variables.map(I=>`${I}:string`).join(",")})=> \`${S}\``),Q=Qt(Q);let l=a[m],z="",x;if(l!=null&&l.parameters&&((l==null?void 0:l.parameters).forEach((I,w)=>{(I.$ref||I.in==="query"&&I.name)&&(z+=c?`${B(t,I.$ref?I:I.schema,I.name||"",I.required)}`:`${R(t,I.$ref?I:I.schema,I.name||"",I.required)}`);}),z)){z=c?z:`{
|
|
65
|
+
${z}}`;let w=`${g.name}Query`;if((xn=(In=e==null?void 0:e.types)==null?void 0:In.name)!=null&&xn.useOperationId&&(l!=null&&l.operationId)&&(w=`${l.operationId}Query`),w=exports.capitalize(`${O}${w}`),(En=(Tn=e==null?void 0:e.types)==null?void 0:Tn.name)!=null&&En.format){let _=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"query",method:m,path:s,summary:l==null?void 0:l.summary,operationId:l==null?void 0:l.operationId},w);_&&(w=`${O}${_}`);}x=w;let G=c?`${T(w,z)}
|
|
66
|
+
`:`export type ${w} = ${z};
|
|
67
|
+
`;e!=null&&e.folderSplit?A[h].types+=G:le+=G;}if(((wn=e==null?void 0:e.validations)==null?void 0:wn.disable)!==true&&((On=(An=e==null?void 0:e.validations)==null?void 0:An.generate)==null?void 0:On.query)!==false&&(l!=null&&l.parameters)){let E=((vn=e.validations)==null?void 0:vn.library)||"zod",w=l.parameters.filter(G=>!G.$ref&&G.in==="query"&&G.name);if(w.length>0){let G=((Pn=e==null?void 0:e.validations)==null?void 0:Pn.name)||((jn=e==null?void 0:e.types)==null?void 0:jn.name),_=typeof(G==null?void 0:G.prefix)=="string"?G.prefix:"I",Y=typeof((qn=(Sn=e==null?void 0:e.validations)==null?void 0:Sn.name)==null?void 0:qn.suffix)=="string"?e.validations.name.suffix:"Schema",Z=`${g.name}Query`;if(G!=null&&G.useOperationId&&(l!=null&&l.operationId)&&(Z=`${l.operationId}Query`),Z=exports.capitalize(`${_}${Z}${Y}`),(kn=(Rn=e==null?void 0:e.validations)==null?void 0:Rn.name)!=null&&kn.format){let K=e.validations.name.format({code:"",type:"query",method:m,path:s,summary:l==null?void 0:l.summary,operationId:l==null?void 0:l.operationId},Z);K&&(Z=`${_}${K}${Y}`);}else if((Nn=(Un=e==null?void 0:e.types)==null?void 0:Un.name)!=null&&Nn.format){let K=e.types.name.format("endpoint",{code:"",type:"query",method:m,path:s,summary:l==null?void 0:l.summary,operationId:l==null?void 0:l.operationId},Z);K&&(Z=`${_}${K}${Y}`);}let D=w.map(K=>{let Ue=K!=null&&K.schema?me(K.schema,E):E==="joi"?"Joi.string()":E==="yup"?"yup.string()":"z.string()",Wt=K.required?"":".optional()";return ` ${K.name}: ${Ue}${Wt}`}).join(`,
|
|
68
|
+
`),H=`export const ${Z} = ${E==="joi"?"Joi.object":E==="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||A[h]||(A[h]={endpoints:"",types:"",validation:""}),A[h].validation+=H;}}let v=l==null?void 0:l.requestBody,j="",N;if(v&&(j=on(v),j)){let E=`${g.name}DTO`;if((Ln=(Fn=e==null?void 0:e.types)==null?void 0:Fn.name)!=null&&Ln.useOperationId&&(l!=null&&l.operationId)&&(E=`${l.operationId}DTO`),E=exports.capitalize(`${O}${E}`),(Mn=(Gn=e==null?void 0:e.types)==null?void 0:Gn.name)!=null&&Mn.format){let w=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"dto",method:m,path:s,summary:l==null?void 0:l.summary,operationId:l==null?void 0:l.operationId},E);w&&(E=`${O}${w}`);}N=E;let I=c?`${T(E,j)}
|
|
73
|
+
`:`export type ${E} = ${j};
|
|
74
|
+
`;e!=null&&e.folderSplit?A[h].types+=I:le+=I;}if(((Qn=e==null?void 0:e.validations)==null?void 0:Qn.disable)!==true&&((zn=(Bn=e==null?void 0:e.validations)==null?void 0:Bn.generate)==null?void 0:zn.dto)!==false&&v){let E=((Dn=e.validations)==null?void 0:Dn.library)||"zod";if(v.content){let I=Object.keys(v.content);if(I[0]&&v.content[I[0]].schema){let w=((Wn=e==null?void 0:e.validations)==null?void 0:Wn.name)||((Jn=e==null?void 0:e.types)==null?void 0:Jn.name),G=typeof(w==null?void 0:w.prefix)=="string"?w.prefix:"I",_=typeof((Hn=(_n=e==null?void 0:e.validations)==null?void 0:_n.name)==null?void 0:Hn.suffix)=="string"?e.validations.name.suffix:"Schema",Y=`${g.name}DTO`;if(w!=null&&w.useOperationId&&(l!=null&&l.operationId)&&(Y=`${l.operationId}DTO`),Y=exports.capitalize(`${G}${Y}${_}`),(Vn=(Kn=e==null?void 0:e.validations)==null?void 0:Kn.name)!=null&&Vn.format){let oe=e.validations.name.format({code:"",type:"dto",method:m,path:s,summary:l==null?void 0:l.summary,operationId:l==null?void 0:l.operationId},Y);oe&&(Y=`${G}${oe}${_}`);}else if((Zn=(Yn=e==null?void 0:e.types)==null?void 0:Yn.name)!=null&&Zn.format){let oe=e.types.name.format("endpoint",{code:"",type:"dto",method:m,path:s,summary:l==null?void 0:l.summary,operationId:l==null?void 0:l.operationId},Y);oe&&(Y=`${G}${oe}${_}`);}let Z=me(v.content[I[0]].schema,E),D=`export const ${Y} = ${Z};
|
|
75
|
+
|
|
76
|
+
`;e!=null&&e.folderSplit||A[h]||(A[h]={endpoints:"",types:"",validation:""}),A[h].validation+=D;}}}let k={},W="",Ae="";if(l!=null&&l.responses){let E=l==null?void 0:l.responses;Object.keys(E).forEach(w=>{var G,_,Y,Z;if(W=on(E[w]),k[w]=W,W){let D=`${g.name}${w}Response`;if((_=(G=e==null?void 0:e.types)==null?void 0:G.name)!=null&&_.useOperationId&&(l!=null&&l.operationId)&&(D=`${l.operationId}${w}Response`),D=exports.capitalize(`${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:w,type:"response",method:m,path:s,summary:l==null?void 0:l.summary,operationId:l==null?void 0:l.operationId},D);K&&(D=`${O}${K}`);}let oe=c?`${T(D,W)}
|
|
77
|
+
`:`export type ${D} = ${W};
|
|
78
|
+
`;e!=null&&e.folderSplit?A[h].types+=oe:le+=oe,k[w]=D;let H=parseInt(w);H>=200&&H<300&&(Ae=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
|
+
- Scopes: [\`${_.join("`, `")}\`]`,Y=`**${Y}**`),`
|
|
80
|
+
- ${Y}${Z}`}).join("")).join(`
|
|
81
|
+
`),ye=l!=null&&l.security?Ce(l.security):"",he="";if(!((et=(Xn=e==null?void 0:e.endpoints)==null?void 0:Xn.doc)!=null&&et.disable)){let E="";if((tt=(nt=e==null?void 0:e.endpoints)==null?void 0:nt.doc)!=null&&tt.showCurl||c){let I={},w="",G="";(rt=l.requestBody)!=null&&rt.content&&Object.keys(l.requestBody.content).forEach(oe=>{let H=l.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&&(w=K);}}),l!=null&&l.security&&l.security.forEach(D=>{Object.keys(D).forEach(oe=>{var K,Ue;let H=(Ue=(K=t.components)==null?void 0:K.securitySchemes)==null?void 0:Ue[oe];H&&(H.type==="mutualTLS"?G+=`
|
|
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.CurlGenerator({url:q+s,method:m.toUpperCase(),headers:_,body:w})||`curl ${q+s} -X ${m.toUpperCase()}`}${G}`;E=c?`
|
|
83
|
+
\`\`\`bash
|
|
84
|
+
${Z}
|
|
85
|
+
\`\`\``:`
|
|
61
86
|
\`\`\`bash
|
|
62
|
-
${
|
|
63
|
-
\`\`\``;}
|
|
64
|
-
*
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
* **
|
|
74
|
-
|
|
87
|
+
${Z}
|
|
88
|
+
\`\`\``;}if(c){let I=[];l!=null&&l.description&&I.push(`* ${l.description}`),I.push(`* **Method**: ${m.toUpperCase()}`),I.push(`* **Summary**: ${(l==null?void 0:l.summary)||""}`),I.push(`* **Tags**: [${((st=l==null?void 0:l.tags)==null?void 0:st.join(", "))||""}]`),I.push(`* **OperationId**: ${(l==null?void 0:l.operationId)||""}`),z&&(I.push("* **Query**:"),I.push("```python"),z.split(`
|
|
89
|
+
`).filter(w=>w.trim().length>0).forEach(w=>I.push(w)),I.push("```")),j&&(I.push("* **DTO**:"),I.push("```python"),j.split(`
|
|
90
|
+
`).filter(w=>w.trim().length>0).forEach(w=>I.push(w)),I.push("```")),W&&(I.push("* **Response**:"),I.push("```python"),Object.entries(k).forEach(([w,G])=>{I.push(`${w}: ${String(G).replace(/\n/g," ")}`);}),I.push("```")),ye&&(I.push("* **Security**:"),ye.split(`
|
|
91
|
+
`).filter(w=>w.trim().length>0).forEach(w=>I.push(w.replace(/\*\*/g,"")))),he=`"""
|
|
92
|
+
${I.join(`
|
|
93
|
+
`)}${E}
|
|
94
|
+
"""
|
|
95
|
+
`;}else he=`/**${l!=null&&l.description?`
|
|
96
|
+
* ${l==null?void 0:l.description} `:""}
|
|
97
|
+
* **Method**: \`${m.toUpperCase()}\`
|
|
98
|
+
* **Summary**: ${(l==null?void 0:l.summary)||""}
|
|
99
|
+
* **Tags**: [${((ot=l==null?void 0:l.tags)==null?void 0:ot.join(", "))||""}]
|
|
100
|
+
* **OperationId**: ${(l==null?void 0:l.operationId)||""} ${z?`
|
|
101
|
+
* **Query**: ${exports.renderTypeRefMD(z)} `:""}${j?`
|
|
102
|
+
* **DTO**: ${exports.renderTypeRefMD(j)} `:""}${W?`
|
|
103
|
+
* **Response**: ${Object.entries(k).map(([I,w])=>`
|
|
104
|
+
- **${I}**: ${exports.renderTypeRefMD(w,2)} `).join("")}`:""}${ye?`
|
|
105
|
+
* **Security**: ${ye}
|
|
106
|
+
`:""}${E}
|
|
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 $e=(at=(it=e==null?void 0:e.endpoints)==null?void 0:it.name)!=null&&at.useOperationId&&((lt=l==null?void 0:l.operationId)==null?void 0:lt.length)>0?l.operationId:`${g.name}`;if((ut=(pt=e==null?void 0:e.endpoints)==null?void 0:pt.name)!=null&&ut.format){let E=e==null?void 0:e.endpoints.name.format({method:m,path:s,summary:l==null?void 0:l.summary,operationId:l==null?void 0:l.operationId},$e);E&&($e=E);}let Qe={method:`"${m}"`,operationId:`"${l==null?void 0:l.operationId}"`,url:Q,tags:(l==null?void 0:l.tags)||[]},zt=`Endpoint(
|
|
109
|
+
method="${m}",
|
|
110
|
+
operationId="${(l==null?void 0:l.operationId)||""}",
|
|
111
|
+
url=${Q},
|
|
112
|
+
tags=[${((l==null?void 0:l.tags)||[]).map(E=>`"${E}"`).join(", ")}]
|
|
113
|
+
)`,hn=c?`${U}${$e} = ${zt}
|
|
114
|
+
${he?`${he}`:""}
|
|
115
|
+
|
|
116
|
+
`:`${he}export const ${U}${$e} = ${((mt=(ct=e==null?void 0:e.endpoints)==null?void 0:ct.value)==null?void 0:mt.type)==="object"?exports.JSONStringify(Qe):Q};
|
|
117
|
+
`;e!=null&&e.folderSplit?A[h].endpoints+=hn:se+=hn;let Dt={name:`${U}${$e}`,method:m,path:s,summary:l==null?void 0:l.summary,operationId:l==null?void 0:l.operationId,tags:d,parameters:(dt=l==null?void 0:l.parameters)==null?void 0:dt.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:v?{type:j,required:v.required}:void 0,responses:k?Object.entries(k).reduce((E,[I,w])=>(E[I]={type:w},E),{}):void 0,queryType:x,dtoType:N,responseType:Ae||void 0};we.push(Dt);});}),e!=null&&e.folderSplit){let s=`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[a,C]of Object.entries(A))if(C.endpoints||C.types){let b=V__default.default.join(f,a);if(C.endpoints){let m=V__default.default.join(be,b,`endpoints.${y}`);yield ce__default.default.promises.mkdir(V__default.default.dirname(m),{recursive:true}),yield Ie(m,c?`${s}${C.endpoints}`:C.endpoints,e);}if(C.types){let m=V__default.default.join(be,b,`types.${y}`);yield ce__default.default.promises.mkdir(V__default.default.dirname(m),{recursive:true});let g=Object.values(ue).length>0?c?`from __future__ import annotations
|
|
130
|
+
from dataclasses import dataclass
|
|
131
|
+
from . import shared as Shared
|
|
132
|
+
${ee(C.types)}
|
|
133
|
+
${C.types}`:`import * as Shared from "../shared";
|
|
134
|
+
|
|
135
|
+
${C.types}`:C.types;yield Ie(m,g,e);}if(((dn=e==null?void 0:e.validations)==null?void 0:dn.disable)!==true&&C.validation&&!c){let m=((fn=e.validations)==null?void 0:fn.library)||"zod",g=m==="joi"?'import Joi from "joi";':m==="yup"?'import * as yup from "yup";':'import { z } from "zod";',d=V__default.default.join(be,b,"validations.ts");yield ce__default.default.promises.mkdir(V__default.default.dirname(d),{recursive:true}),yield Ie(d,`${g}
|
|
136
|
+
|
|
137
|
+
${C.validation}`,e);}}}if(se.length>0){let s=`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
|
+
`,a=V__default.default.join(be,f,`endpoints.${y}`);yield ce__default.default.promises.mkdir(V__default.default.dirname(a),{recursive:true}),yield Ie(a,c?`${s}${se}`:se,e);}if(Object.values(ue).length>0){let s=Object.values(ue).join(`
|
|
150
|
+
`),a=V__default.default.join(be,f,e!=null&&e.folderSplit?"":"types",`shared.${y}`);yield ce__default.default.promises.mkdir(V__default.default.dirname(a),{recursive:true}),yield Ie(a,(c?`from __future__ import annotations
|
|
151
|
+
from dataclasses import dataclass
|
|
152
|
+
${ee(s)}
|
|
153
|
+
`:"")+s,e);}if(le.length>0){let s=V__default.default.join(be,f,"types",`index.${y}`);yield ce__default.default.promises.mkdir(V__default.default.dirname(s),{recursive:true}),yield Ie(s,(Object.values(ue).length>0?c?`from __future__ import annotations
|
|
154
|
+
from dataclasses import dataclass
|
|
155
|
+
from . import shared as Shared
|
|
156
|
+
${ee(le)}
|
|
157
|
+
`:`import * as Shared from "./shared";
|
|
158
|
+
|
|
159
|
+
`:"")+le,e);}if(((yn=e==null?void 0:e.validations)==null?void 0:yn.disable)!==true&&!(e!=null&&e.folderSplit)&&!c){let s=((gn=e.validations)==null?void 0:gn.library)||"zod",a=s==="joi"?'import Joi from "joi";':s==="yup"?'import * as yup from "yup";':'import { z } from "zod";',C=Object.values(A).map(b=>b.validation).filter(b=>b.length>0).join("");if(C){let b=V__default.default.join(be,f,"validations.ts");yield ce__default.default.promises.mkdir(V__default.default.dirname(b),{recursive:true}),yield Ie(b,`${a}
|
|
160
|
+
|
|
161
|
+
${C}`,e);}}return wt(p,we),console.info(`\u2705 Successfully synced ${p}`),{success:true}}),en=vt;});var jt,nn,xe,tn,rn,sn,St=de(()=>{jt=(r,o)=>{let p=r;return o.tags&&o.tags.length>0&&(p=p.filter(e=>!e.tags||e.tags.length===0?false:e.tags.some(i=>o.tags.includes(i)))),o.endpoints&&o.endpoints.length>0&&(p=p.filter(e=>o.endpoints.includes(e.name))),p},nn=(r,o,p=false)=>{var t,f;let e=o.baseURL||"";o.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 u=new Set;return r.forEach(c=>{c.queryType&&u.add(c.queryType),c.dtoType&&u.add(c.dtoType),c.responseType&&u.add(c.responseType);}),u.forEach(c=>{n+=` ${c},
|
|
166
|
+
`;}),n+=`} from '../types';
|
|
167
|
+
|
|
168
|
+
`,n+=`import {
|
|
169
|
+
`,r.forEach(c=>{n+=` ${c.name} as ${c.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=o.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
|
+
`,(f=o.errorHandling)!=null&&f.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
|
+
`,r.forEach(c=>{var B,P;let y=c.name,A=((B=c.parameters)==null?void 0:B.filter(T=>T.in==="path"))||[],L=((P=c.parameters)==null?void 0:P.filter(T=>T.in==="query"))||[],q=A.length>0,O=L.length>0,U=!!c.requestBody,F=c.responseType||"any";if(n+=`/**
|
|
223
|
+
`,c.summary&&(n+=` * ${c.summary}
|
|
224
|
+
`),n+=` * @method ${c.method.toUpperCase()}
|
|
225
|
+
`,n+=` * @path ${c.path}
|
|
226
|
+
`,c.tags&&c.tags.length>0&&(n+=` * @tags ${c.tags.join(", ")}
|
|
227
|
+
`),n+=` */
|
|
228
|
+
`,n+=`export async function ${y}(`,(q||O||U)&&(n+=`params: {
|
|
229
|
+
`,q&&(n+=` url: {
|
|
230
|
+
`,A.forEach(T=>{let M={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[T.type||"string"]||"any",J=T.required?"":"?";n+=` ${T.name}${J}: ${M};
|
|
231
|
+
`;}),n+=` };
|
|
232
|
+
`),O&&(n+=` query: ${c.queryType||"Record<string, any>"};
|
|
233
|
+
`),U&&(n+=` data: ${c.dtoType||"any"};
|
|
234
|
+
`),n+=`}
|
|
235
|
+
`),n+=`): Promise<${F}> {
|
|
236
|
+
`,q||O||U){let T=[];q&&T.push("url"),O&&T.push("query"),U&&T.push("data"),n+=` const { ${T.join(", ")} } = params;
|
|
237
|
+
`;}let R;if(q){let T=A.map(ee=>`url.${ee.name}`).join(", ");R=`${c.name}_endpoint(${T})`;}else R=`${c.name}_endpoint`;O?(n+=` const queryParams = new URLSearchParams();
|
|
238
|
+
`,L.forEach(T=>{T.required?n+=` queryParams.append('${T.name}', String(query.${T.name}));
|
|
239
|
+
`:(n+=` if (query.${T.name} !== undefined) {
|
|
240
|
+
`,n+=` queryParams.append('${T.name}', String(query.${T.name}));
|
|
241
|
+
`,n+=` }
|
|
242
|
+
`);}),n+=` const _url = \`\${${R}}?\${queryParams.toString()}\`;
|
|
243
|
+
`):n+=` const _url = ${R};
|
|
244
|
+
`,n+=` return fetchAPI<${F}>(_url, {
|
|
245
|
+
`,n+=` method: '${c.method.toUpperCase()}',
|
|
246
|
+
`,U&&(n+=` body: JSON.stringify(data),
|
|
247
|
+
`),n+=` });
|
|
248
|
+
`,n+=`}
|
|
249
|
+
|
|
250
|
+
`;}),p&&(n+=`// Export all functions as a default object
|
|
251
|
+
`,n+=`const apiClient = {
|
|
252
|
+
`,n+=` setApiConfig,
|
|
253
|
+
`,r.forEach(c=>{n+=` ${c.name},
|
|
254
|
+
`;}),n+=`};
|
|
255
|
+
|
|
256
|
+
`,n+=`export default apiClient;
|
|
257
|
+
`),n},xe=(r,o,p=false)=>{var t,f;let e=o.baseURL||"";o.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 u=new Set;return r.forEach(c=>{c.queryType&&u.add(c.queryType),c.dtoType&&u.add(c.dtoType),c.responseType&&u.add(c.responseType);}),u.forEach(c=>{n+=` ${c},
|
|
264
|
+
`;}),n+=`} from '../types';
|
|
265
|
+
|
|
266
|
+
`,n+=`import {
|
|
267
|
+
`,r.forEach(c=>{n+=` ${c.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=o.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
|
+
`,(f=o.errorHandling)!=null&&f.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
|
+
`,r.forEach(c=>{var R,B;let y=c.name,A=((R=c.parameters)==null?void 0:R.filter(P=>P.in==="path"))||[],L=((B=c.parameters)==null?void 0:B.filter(P=>P.in==="query"))||[],q=A.length>0,O=L.length>0,U=!!c.requestBody,F=c.responseType||"any";if(n+=` /**
|
|
317
|
+
`,c.summary&&(n+=` * ${c.summary}
|
|
318
|
+
`),n+=` * @method ${c.method.toUpperCase()}
|
|
319
|
+
`,n+=` * @path ${c.path}
|
|
320
|
+
`,c.tags&&c.tags.length>0&&(n+=` * @tags ${c.tags.join(", ")}
|
|
321
|
+
`),n+=` */
|
|
322
|
+
`,n+=` async ${y}(`,(q||O||U)&&(n+=`params: {
|
|
323
|
+
`,q&&(n+=` url: {
|
|
324
|
+
`,A.forEach(P=>{let ee={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[P.type||"string"]||"any",M=P.required?"":"?";n+=` ${P.name}${M}: ${ee};
|
|
325
|
+
`;}),n+=` };
|
|
326
|
+
`),O&&(n+=` query: ${c.queryType||"Record<string, any>"};
|
|
327
|
+
`),U&&(n+=` data: ${c.dtoType||"any"};
|
|
328
|
+
`),n+=" }"),n+=`): Promise<${F}> {
|
|
329
|
+
`,q||O||U){let P=[];q&&P.push("url"),O&&P.push("query"),U&&P.push("data"),n+=` const { ${P.join(", ")} } = params;
|
|
330
|
+
`;}if(q){let P=A.map(T=>`url.${T.name}`).join(", ");n+=` const _url = ${c.name}(${P});
|
|
331
|
+
`;}else n+=` const _url = ${c.name};
|
|
332
|
+
`;n+=` const config: AxiosRequestConfig = {};
|
|
333
|
+
`,O&&(n+=` config.params = { ...query };
|
|
334
|
+
`),n+=` const response = await this.client.${c.method.toLowerCase()}<${F}>(
|
|
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
|
+
`,p?n+=`export default ApiClient;
|
|
346
|
+
`:(n+=`export const apiClient = new ApiClient();
|
|
347
|
+
`,n+=`export default apiClient;
|
|
348
|
+
`),n},tn=(r,o)=>{var f,c;let p=((f=o.reactQuery)==null?void 0:f.version)||5,e=((c=o.reactQuery)==null?void 0:c.mutations)!==false,i=!!(o.reactQuery&&o.reactQuery.infiniteQueries&&!o.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 u=e&&r.some(y=>["POST","PUT","PATCH","DELETE"].includes(y.method.toUpperCase()));if(p===5){let y=u?`import { useQuery, useMutation, UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
277
352
|
`:`import { useQuery, UseQueryOptions } from '@tanstack/react-query';
|
|
278
|
-
`;
|
|
353
|
+
`;i&&(y=y.replace("@tanstack/react-query';\\n",`@tanstack/react-query';
|
|
279
354
|
import { useInfiniteQuery, UseInfiniteQueryOptions } from '@tanstack/react-query';
|
|
280
|
-
`)),
|
|
355
|
+
`)),n+=y;}else {let y=u?`import { useQuery, useMutation, UseQueryOptions, UseMutationOptions } from 'react-query';
|
|
281
356
|
`:`import { useQuery, UseQueryOptions } from 'react-query';
|
|
282
|
-
`;
|
|
357
|
+
`;i&&(y=y.replace("react-query';\\n",`react-query';
|
|
283
358
|
import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
284
|
-
`)),
|
|
285
|
-
`,
|
|
286
|
-
`,
|
|
287
|
-
`;let
|
|
288
|
-
`;}),
|
|
289
|
-
|
|
290
|
-
`,r.forEach(
|
|
291
|
-
`,
|
|
292
|
-
`),
|
|
293
|
-
`,
|
|
294
|
-
`,
|
|
295
|
-
`),
|
|
296
|
-
`,
|
|
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
|
-
`,
|
|
352
|
-
`),
|
|
353
|
-
`,
|
|
354
|
-
`,
|
|
355
|
-
`),
|
|
356
|
-
`;let
|
|
357
|
-
`,
|
|
358
|
-
`,
|
|
359
|
-
`;}),
|
|
360
|
-
`),
|
|
361
|
-
`),
|
|
362
|
-
`),
|
|
363
|
-
`,
|
|
364
|
-
`,
|
|
365
|
-
`,
|
|
366
|
-
`,
|
|
367
|
-
`,
|
|
368
|
-
`,
|
|
369
|
-
`,
|
|
370
|
-
`,
|
|
371
|
-
`,
|
|
372
|
-
|
|
373
|
-
`;}}),
|
|
359
|
+
`)),n+=y;}n+=`
|
|
360
|
+
`,n+=`import apiClient from './client';
|
|
361
|
+
`,n+=`import type {
|
|
362
|
+
`;let t=new Set;return r.forEach(y=>{y.queryType&&t.add(y.queryType),y.dtoType&&t.add(y.dtoType),y.responseType&&t.add(y.responseType);}),t.forEach(y=>{n+=` ${y},
|
|
363
|
+
`;}),n+=`} from '../types';
|
|
364
|
+
|
|
365
|
+
`,r.forEach(y=>{var T,ee;let A=y.method.toUpperCase(),L=A==="GET",q=["POST","PUT","PATCH","DELETE"].includes(A),O=((T=y.parameters)==null?void 0:T.filter(M=>M.in==="path"))||[],U=((ee=y.parameters)==null?void 0:ee.filter(M=>M.in==="query"))||[],F=O.length>0,R=U.length>0,B=!!y.requestBody,P=y.responseType||"any";if(L){let M=U.map(se=>se.name.toLowerCase()),re=(M.includes("page")||M.includes("cursor")||M.includes("cursorid")||M.includes("after")||M.includes("before"))&&i,ge=`use${y.name.charAt(0).toUpperCase()+y.name.slice(1)}`;if(n+=`/**
|
|
366
|
+
`,y.summary&&(n+=` * ${y.summary}
|
|
367
|
+
`),n+=` * @method ${A}
|
|
368
|
+
`,n+=` * @path ${y.path}
|
|
369
|
+
`,y.tags&&y.tags.length>0&&(n+=` * @tags ${y.tags.join(", ")}
|
|
370
|
+
`),n+=` */
|
|
371
|
+
`,F||R?(n+=`export function ${ge}(
|
|
372
|
+
`,n+=` params: {
|
|
373
|
+
`,F&&(n+=` url: {
|
|
374
|
+
`,O.forEach(se=>{let ue={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[se.type||"string"]||"any",we=se.required?"":"?";n+=` ${se.name}${we}: ${ue};
|
|
375
|
+
`;}),n+=` };
|
|
376
|
+
`),R&&(n+=` query: ${y.queryType||"Record<string, any>"};
|
|
377
|
+
`),n+=` },
|
|
378
|
+
`,n+=` options?: Omit<UseQueryOptions<${P}>, 'queryKey' | 'queryFn'>
|
|
379
|
+
`,n+=`) {
|
|
380
|
+
`,n+=` return useQuery({
|
|
381
|
+
`,n+=` queryKey: ['${y.name}', params],
|
|
382
|
+
`,n+=` queryFn: () => apiClient.${y.name}(params),
|
|
383
|
+
`,n+=` ...options,
|
|
384
|
+
`,n+=` });
|
|
385
|
+
`,n+=`}
|
|
386
|
+
|
|
387
|
+
`):(n+=`export function ${ge}(
|
|
388
|
+
`,n+=` options?: Omit<UseQueryOptions<${P}>, 'queryKey' | 'queryFn'>
|
|
389
|
+
`,n+=`) {
|
|
390
|
+
`,n+=` return useQuery({
|
|
391
|
+
`,n+=` queryKey: ['${y.name}'],
|
|
392
|
+
`,n+=` queryFn: () => apiClient.${y.name}(),
|
|
393
|
+
`,n+=` ...options,
|
|
394
|
+
`,n+=` });
|
|
395
|
+
`,n+=`}
|
|
396
|
+
|
|
397
|
+
`),re){let se=`${ge}Infinite`;F||R?(n+=`export function ${se}(
|
|
398
|
+
`,n+=` params: {
|
|
399
|
+
`,F&&(n+=` url: {
|
|
400
|
+
`,O.forEach(le=>{let we={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[le.type||"string"]||"any",ke=le.required?"":"?";n+=` ${le.name}${ke}: ${we};
|
|
401
|
+
`;}),n+=` };
|
|
402
|
+
`),R&&(n+=` query: ${y.queryType||"Record<string, any>"};
|
|
403
|
+
`),n+=` },
|
|
404
|
+
`,n+=` options?: Omit<UseInfiniteQueryOptions<${P}, Error, ${P}>, 'queryKey' | 'queryFn'>
|
|
405
|
+
`,n+=`) {
|
|
406
|
+
`,n+=` return useInfiniteQuery({
|
|
407
|
+
`,n+=` queryKey: ['${y.name}', params],
|
|
408
|
+
`,n+=` queryFn: ({ pageParam = 1 }) => apiClient.${y.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<${P}, Error, ${P}>, 'queryKey' | 'queryFn'>
|
|
416
|
+
`,n+=`) {
|
|
417
|
+
`,n+=` return useInfiniteQuery({
|
|
418
|
+
`,n+=` queryKey: ['${y.name}'],
|
|
419
|
+
`,n+=` queryFn: ({ pageParam = 1 }) => apiClient.${y.name}({ query: { page: pageParam } }),
|
|
420
|
+
`,n+=` getNextPageParam: (lastPage) => lastPage?.nextPage ?? lastPage?.nextCursor ?? null,
|
|
421
|
+
`,n+=` ...options,
|
|
422
|
+
`,n+=` });
|
|
423
|
+
`,n+=`}
|
|
424
|
+
|
|
425
|
+
`);}}else if(q&&e){let M=`use${y.name.charAt(0).toUpperCase()+y.name.slice(1)}`;n+=`/**
|
|
426
|
+
`,y.summary&&(n+=` * ${y.summary}
|
|
427
|
+
`),n+=` * @method ${A}
|
|
428
|
+
`,n+=` * @path ${y.path}
|
|
429
|
+
`,y.tags&&y.tags.length>0&&(n+=` * @tags ${y.tags.join(", ")}
|
|
430
|
+
`),n+=` */
|
|
431
|
+
`;let J="void";(F||R||B)&&(J=`{
|
|
432
|
+
`,F&&(J+=` url: {
|
|
433
|
+
`,O.forEach(re=>{let se={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[re.type||"string"]||"any",le=re.required?"":"?";J+=` ${re.name}${le}: ${se};
|
|
434
|
+
`;}),J+=` };
|
|
435
|
+
`),R&&(J+=` query: ${y.queryType||"Record<string, any>"};
|
|
436
|
+
`),B&&(J+=` data: ${y.dtoType||"any"};
|
|
437
|
+
`),J+=" }"),n+=`export function ${M}(
|
|
438
|
+
`,n+=` options?: Omit<UseMutationOptions<${P}, Error, ${J}>, 'mutationFn'>
|
|
439
|
+
`,n+=`) {
|
|
440
|
+
`,n+=` return useMutation({
|
|
441
|
+
`,n+=" mutationFn: (",J!=="void"&&(n+=`variables: ${J}`),n+=`) => {
|
|
442
|
+
`,n+=` return apiClient.${y.name}(${J!=="void"?"variables":""});
|
|
443
|
+
`,n+=` },
|
|
444
|
+
`,n+=` ...options,
|
|
445
|
+
`,n+=` });
|
|
446
|
+
`,n+=`}
|
|
447
|
+
|
|
448
|
+
`;}}),n},rn=(r,o)=>{var u;let p=((u=o.swr)==null?void 0:u.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,226 +640,226 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
565
640
|
`,e+=` */
|
|
566
641
|
|
|
567
642
|
`,e+=`import useSWR, { SWRConfiguration } from 'swr';
|
|
568
|
-
`,
|
|
643
|
+
`,p&&r.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 r.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
|
-
`,r.forEach(
|
|
576
|
-
`,
|
|
577
|
-
`),e+=` * @method ${
|
|
578
|
-
`,e+=` * @path ${
|
|
579
|
-
`,
|
|
650
|
+
`,r.forEach(t=>{var R,B;let f=t.method.toUpperCase(),c=f==="GET",y=["POST","PUT","PATCH","DELETE"].includes(f),A=((R=t.parameters)==null?void 0:R.filter(P=>P.in==="path"))||[],L=((B=t.parameters)==null?void 0:B.filter(P=>P.in==="query"))||[],q=A.length>0,O=L.length>0,U=!!t.requestBody,F=t.responseType||"any";if(c){let P=`use${t.name.charAt(0).toUpperCase()+t.name.slice(1)}`;e+=`/**
|
|
651
|
+
`,t.summary&&(e+=` * ${t.summary}
|
|
652
|
+
`),e+=` * @method ${f}
|
|
653
|
+
`,e+=` * @path ${t.path}
|
|
654
|
+
`,t.tags&&t.tags.length>0&&(e+=` * @tags ${t.tags.join(", ")}
|
|
580
655
|
`),e+=` */
|
|
581
|
-
`,
|
|
656
|
+
`,q||O?(e+=`export function ${P}(
|
|
582
657
|
`,e+=` params: {
|
|
583
|
-
`,
|
|
584
|
-
`,
|
|
658
|
+
`,q&&(e+=` url: {
|
|
659
|
+
`,A.forEach(T=>{let M={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[T.type||"string"]||"any",J=T.required?"":"?";e+=` ${T.name}${J}: ${M};
|
|
585
660
|
`;}),e+=` };
|
|
586
|
-
`),
|
|
661
|
+
`),O&&(e+=` query: ${t.queryType||"Record<string, any>"};
|
|
587
662
|
`),e+=` },
|
|
588
|
-
`,e+=` config?: SWRConfiguration<${
|
|
663
|
+
`,e+=` config?: SWRConfiguration<${F}>
|
|
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 ${P}(
|
|
671
|
+
`,e+=` config?: SWRConfiguration<${F}>
|
|
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(
|
|
606
|
-
`,
|
|
607
|
-
`),e+=` * @method ${
|
|
608
|
-
`,e+=` * @path ${
|
|
609
|
-
`,
|
|
680
|
+
`;}else if(y&&p){let P=`use${t.name.charAt(0).toUpperCase()+t.name.slice(1)}`;e+=`/**
|
|
681
|
+
`,t.summary&&(e+=` * ${t.summary}
|
|
682
|
+
`),e+=` * @method ${f}
|
|
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 T="void",ee="void";(q||O||U)&&(T=`{
|
|
687
|
+
`,q&&(T+=` url: {
|
|
688
|
+
`,A.forEach(M=>{let re={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[M.type||"string"]||"any",ge=M.required?"":"?";T+=` ${M.name}${ge}: ${re};
|
|
689
|
+
`;}),T+=` };
|
|
690
|
+
`),O&&(T+=` query: ${t.queryType||"Record<string, any>"};
|
|
691
|
+
`),U&&(T+=` data: ${t.dtoType||"any"};
|
|
692
|
+
`),T+=" }",ee=`{ arg: ${T} }`),e+=`export function ${P}(
|
|
693
|
+
`,e+=` config?: SWRMutationConfiguration<${F}, Error, string, ${T}>
|
|
619
694
|
`,e+=`) {
|
|
620
695
|
`,e+=` return useSWRMutation(
|
|
621
|
-
`,e+=` '${
|
|
622
|
-
`,e+=" async (_, ",
|
|
623
|
-
`,e+=` return apiClient.${
|
|
696
|
+
`,e+=` '${t.name}',
|
|
697
|
+
`,e+=" async (_, ",T!=="void"&&(e+=`{ arg }: ${ee}`),e+=`) => {
|
|
698
|
+
`,e+=` return apiClient.${t.name}(${T!=="void"?"arg":""});
|
|
624
699
|
`,e+=` },
|
|
625
700
|
`,e+=` config
|
|
626
701
|
`,e+=` );
|
|
627
702
|
`,e+=`}
|
|
628
703
|
|
|
629
|
-
`;}}),e},
|
|
630
|
-
`;
|
|
631
|
-
|
|
632
|
-
`,
|
|
633
|
-
|
|
634
|
-
`,
|
|
635
|
-
`;let
|
|
636
|
-
`;}),
|
|
637
|
-
|
|
638
|
-
`,
|
|
639
|
-
`,r.forEach(
|
|
640
|
-
`;}),
|
|
641
|
-
|
|
642
|
-
`,
|
|
643
|
-
`,
|
|
644
|
-
`,
|
|
645
|
-
`,
|
|
646
|
-
`,o.auth&&(
|
|
647
|
-
`,
|
|
648
|
-
`,
|
|
649
|
-
`,
|
|
650
|
-
`,o.auth.type==="bearer"?
|
|
651
|
-
`),
|
|
652
|
-
`,
|
|
653
|
-
`,
|
|
654
|
-
`),
|
|
655
|
-
`,
|
|
656
|
-
`,
|
|
657
|
-
`,r.forEach((
|
|
658
|
-
`,
|
|
659
|
-
`;let
|
|
660
|
-
`,
|
|
661
|
-
`,
|
|
662
|
-
`;}),
|
|
663
|
-
`),
|
|
664
|
-
`),
|
|
665
|
-
`),
|
|
666
|
-
`,
|
|
667
|
-
`,
|
|
668
|
-
`,
|
|
669
|
-
`;}else
|
|
670
|
-
`;
|
|
671
|
-
`,
|
|
672
|
-
`,
|
|
673
|
-
`,
|
|
674
|
-
`),
|
|
675
|
-
`),
|
|
676
|
-
`,
|
|
677
|
-
`,
|
|
678
|
-
`:
|
|
679
|
-
`),
|
|
680
|
-
`;}),
|
|
681
|
-
`,
|
|
682
|
-
|
|
683
|
-
`,
|
|
684
|
-
|
|
685
|
-
`,
|
|
686
|
-
`;
|
|
687
|
-
`,
|
|
688
|
-
|
|
689
|
-
`,o.forEach(
|
|
690
|
-
`;}),
|
|
704
|
+
`;}}),e},sn=(r,o)=>{var u;let p=((u=o.rtkQuery)==null?void 0:u.apiName)||"api",e=o.baseURL||"",i=`// Generated RTK Query API Slice
|
|
705
|
+
`;i+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
706
|
+
|
|
707
|
+
`,i+=`import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
|
|
708
|
+
|
|
709
|
+
`,i+=`import type {
|
|
710
|
+
`;let n=new Set;return r.forEach(t=>{t.queryType&&n.add(t.queryType),t.dtoType&&n.add(t.dtoType),t.responseType&&n.add(t.responseType);}),n.forEach(t=>{i+=` ${t},
|
|
711
|
+
`;}),i+=`} from '../types';
|
|
712
|
+
|
|
713
|
+
`,i+=`import {
|
|
714
|
+
`,r.forEach(t=>{i+=` ${t.name},
|
|
715
|
+
`;}),i+=`} from '../endpoints';
|
|
716
|
+
|
|
717
|
+
`,i+=`const ${p}Api = createApi({
|
|
718
|
+
`,i+=` reducerPath: '${p}Api',
|
|
719
|
+
`,i+=` baseQuery: fetchBaseQuery({
|
|
720
|
+
`,i+=` baseUrl: '${e}',
|
|
721
|
+
`,o.auth&&(i+=` prepareHeaders: (headers, { getState }) => {
|
|
722
|
+
`,i+=` // Get token from your auth state
|
|
723
|
+
`,i+=` // const token = (getState() as RootState).auth.token;
|
|
724
|
+
`,i+=` // if (token) {
|
|
725
|
+
`,o.auth.type==="bearer"?i+=" // headers.set('Authorization', `Bearer ${token}`);\n":o.auth.type==="apiKey"&&o.auth.in==="header"&&(i+=` // headers.set('${o.auth.name||"X-API-Key"}', token);
|
|
726
|
+
`),i+=` // }
|
|
727
|
+
`,i+=` return headers;
|
|
728
|
+
`,i+=` },
|
|
729
|
+
`),i+=` }),
|
|
730
|
+
`,i+=` tagTypes: [${[...new Set(r.flatMap(t=>t.tags||[]))].map(t=>`'${t}'`).join(", ")}],
|
|
731
|
+
`,i+=` endpoints: (builder) => ({
|
|
732
|
+
`,r.forEach((t,f)=>{var B,P;let c=t.method.toUpperCase(),y=c==="GET",A=((B=t.parameters)==null?void 0:B.filter(T=>T.in==="path"))||[],L=((P=t.parameters)==null?void 0:P.filter(T=>T.in==="query"))||[],q=A.length>0,O=L.length>0,U=!!t.requestBody,F=t.responseType||"any";i+=` ${t.name}: builder.${y?"query":"mutation"}<
|
|
733
|
+
`,i+=` ${F},
|
|
734
|
+
`;let R="void";if((q||O||U)&&(R=`{
|
|
735
|
+
`,q&&(R+=` url: {
|
|
736
|
+
`,A.forEach(T=>{let M={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[T.type||"string"]||"any",J=T.required?"":"?";R+=` ${T.name}${J}: ${M};
|
|
737
|
+
`;}),R+=` };
|
|
738
|
+
`),O&&(R+=` query: ${t.queryType||"Record<string, any>"};
|
|
739
|
+
`),U&&(R+=` data: ${t.dtoType||"any"};
|
|
740
|
+
`),R+=" }"),i+=` ${R}
|
|
741
|
+
`,i+=` >({
|
|
742
|
+
`,i+=" query: (",R!=="void"&&(i+="arg"),i+=`) => {
|
|
743
|
+
`,q){let T=A.map(ee=>`arg.url.${ee.name}`).join(", ");i+=` const url = ${t.name}(${T});
|
|
744
|
+
`;}else i+=` const url = ${t.name};
|
|
745
|
+
`;i+=` return {
|
|
746
|
+
`,i+=` url,
|
|
747
|
+
`,i+=` method: '${c}',
|
|
748
|
+
`,O&&(i+=` params: arg.query,
|
|
749
|
+
`),U&&(i+=` body: arg.data,
|
|
750
|
+
`),i+=` };
|
|
751
|
+
`,i+=` },
|
|
752
|
+
`,t.tags&&t.tags.length>0&&(y?i+=` providesTags: ['${t.tags[0]}'],
|
|
753
|
+
`:i+=` invalidatesTags: ['${t.tags[0]}'],
|
|
754
|
+
`),i+=` })${f<r.length-1?",":""}
|
|
755
|
+
`;}),i+=` }),
|
|
756
|
+
`,i+=`});
|
|
757
|
+
|
|
758
|
+
`,i+=`export default ${p}Api;
|
|
759
|
+
|
|
760
|
+
`,i};});var or,qt,te,ir,ar,Rt=de(()=>{St();Ne();or=(r,o)=>{var p,e;if((p=o==null?void 0:o.folderSplit)!=null&&p.customFolder){let i=o.folderSplit.customFolder({method:r.method,path:r.path,tags:r.tags,operationId:r.operationId,summary:r.summary});if(i)return i}return (e=o==null?void 0:o.folderSplit)!=null&&e.byTags&&r.tags&&r.tags.length>0?r.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},qt=(r,o,p,e,i)=>ie(null,null,function*(){let n=jt(r,p);if(n.length===0)return;let u=p.type||"fetch";p.outputDir||V__default.default.join(i,e,"client");let f=!!(o!=null&&o.folderSplit&&(o.folderSplit.byTags||o.folderSplit.customFolder));if(`${u}${n.length}`,f){let y={};n.forEach(q=>{let O=or(q,o);y[O]||(y[O]=[]),y[O].push(q);});let A=Object.keys(y);for(let[q,O]of Object.entries(y)){let U=V__default.default.join(i,e,q);yield ce__default.default.promises.mkdir(U,{recursive:true}),`${u}${q}${O.length}`,yield ir(O,o,p,U,u,q,true);}let L=V__default.default.join(i,e);yield ar(L,A,u,o);return}let c=V__default.default.join(i,e);switch(yield ce__default.default.promises.mkdir(c,{recursive:true}),u){case "fetch":let y=nn(n,p);y=y.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield te(V__default.default.join(c,"clients.ts"),y,o);break;case "axios":let A=xe(n,p,false);A=A.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield te(V__default.default.join(c,"clients.ts"),A,o);break;case "react-query":let L=xe(n,p,false);L=L.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield te(V__default.default.join(c,"clients.ts"),L,o);let q=tn(n,p);q=q.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';").replace("import apiClient from './client';","import apiClient from './clients';"),yield te(V__default.default.join(c,"hooks.ts"),q,o);break;case "swr":let O=xe(n,p,false);O=O.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield te(V__default.default.join(c,"clients.ts"),O,o);let U=rn(n,p);U=U.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';").replace("import apiClient from './client';","import apiClient from './clients';"),yield te(V__default.default.join(c,"hooks.ts"),U,o);break;case "rtk-query":let F=sn(n,p);F=F.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield te(V__default.default.join(c,"api.ts"),F,o);break;default:throw new Error(`Unknown client type: ${u}`)}}),te=(r,o,p)=>ie(null,null,function*(){var u,t,f,c;if(!(((u=p==null?void 0:p.customCode)==null?void 0:u.enabled)!==false)){yield ce__default.default.promises.writeFile(r,o);return}let i=null;try{i=yield ce__default.default.promises.readFile(r,"utf-8");}catch(y){}let n=exports.mergeCustomCode(o,i,{position:((t=p==null?void 0:p.customCode)==null?void 0:t.position)||"bottom",markerText:(f=p==null?void 0:p.customCode)==null?void 0:f.markerText,includeInstructions:(c=p==null?void 0:p.customCode)==null?void 0:c.includeInstructions});yield ce__default.default.promises.writeFile(r,n);}),ir=(r,o,p,e,i,n,u=false)=>ie(null,null,function*(){let t="",f="",c=u?"./types":"../types",y=u?"./endpoints":"../endpoints";switch(i){case "fetch":t=nn(r,p,u),t=t.replace("} from '../types';",`} from '${c}';`).replace("} from '../endpoints';",`} from '${y}';`),yield te(V__default.default.join(e,"client.ts"),t,o);break;case "axios":t=xe(r,p,u),t=t.replace("} from '../types';",`} from '${c}';`).replace("} from '../endpoints';",`} from '${y}';`),yield te(V__default.default.join(e,"client.ts"),t,o);break;case "react-query":if(t=xe(r,p,u),t=t.replace("} from '../types';",`} from '${c}';`).replace("} from '../endpoints';",`} from '${y}';`),yield te(V__default.default.join(e,"client.ts"),t,o),f=tn(r,p),f=f.replace("} from '../types';",`} from '${c}';`).replace("} from '../endpoints';",`} from '${y}';`),u){let L=n.replace(/-/g,"_");f=f.replace("import apiClient from './client';",`import { ${L}Client as apiClient } from '../clients';`);}yield te(V__default.default.join(e,"hooks.ts"),f,o);break;case "swr":if(t=xe(r,p,u),t=t.replace("} from '../types';",`} from '${c}';`).replace("} from '../endpoints';",`} from '${y}';`),yield te(V__default.default.join(e,"client.ts"),t,o),f=rn(r,p),f=f.replace("} from '../types';",`} from '${c}';`).replace("} from '../endpoints';",`} from '${y}';`),u){let L=n.replace(/-/g,"_");f=f.replace("import apiClient from './client';",`import { ${L}Client as apiClient } from '../clients';`);}yield te(V__default.default.join(e,"hooks.ts"),f,o);break;case "rtk-query":let A=u?ae(X({},p),{rtkQuery:ae(X({},p.rtkQuery),{apiName:n.replace(/-/g,"_")})}):p;f=sn(r,A),f=f.replace("} from '../types';",`} from '${c}';`).replace("} from '../endpoints';",`} from '${y}';`),yield te(V__default.default.join(e,"api.ts"),f,o);break;default:throw new Error(`Unknown client type: ${i}`)}}),ar=(r,o,p,e)=>ie(null,null,function*(){var n;if(p==="rtk-query"){let u=`// Generated RTK Query APIs
|
|
761
|
+
`;u+=`// This file was auto-generated.
|
|
762
|
+
`,u+=`// Aggregates all API slices for easy Redux store setup
|
|
763
|
+
|
|
764
|
+
`,o.forEach(t=>{let f=t.replace(/-/g,"_");u+=`import ${f}Api from './${t}/api';
|
|
765
|
+
`;}),u+=`
|
|
691
766
|
// Export all API slices
|
|
692
|
-
`,o.forEach(
|
|
693
|
-
`;}),
|
|
767
|
+
`,o.forEach(t=>{let f=t.replace(/-/g,"_");u+=`export { default as ${f}Api } from './${t}/api';
|
|
768
|
+
`;}),u+=`
|
|
694
769
|
/**
|
|
695
|
-
`,
|
|
696
|
-
`,
|
|
697
|
-
`,
|
|
698
|
-
`,
|
|
699
|
-
`,
|
|
700
|
-
`,
|
|
701
|
-
`,
|
|
702
|
-
`,
|
|
703
|
-
`,
|
|
704
|
-
`,
|
|
705
|
-
`,
|
|
706
|
-
`,
|
|
707
|
-
`,
|
|
708
|
-
`,
|
|
709
|
-
`,o.forEach(
|
|
710
|
-
`;}),
|
|
711
|
-
`,
|
|
712
|
-
`,o.forEach(
|
|
713
|
-
`;}),
|
|
714
|
-
`,
|
|
715
|
-
`,yield
|
|
716
|
-
`;if(
|
|
717
|
-
`,
|
|
718
|
-
|
|
719
|
-
`,
|
|
720
|
-
`;}):(o.forEach(
|
|
721
|
-
`;}),
|
|
770
|
+
`,u+=` * Configure Redux store with all API slices
|
|
771
|
+
`,u+=` *
|
|
772
|
+
`,u+=` * @example
|
|
773
|
+
`,u+=` * import { configureStore } from '@reduxjs/toolkit';
|
|
774
|
+
`,u+=` * import { setupApiStore } from './apis';
|
|
775
|
+
`,u+=` *
|
|
776
|
+
`,u+=` * export const store = configureStore({
|
|
777
|
+
`,u+=` * reducer: setupApiStore.reducer,
|
|
778
|
+
`,u+=` * middleware: (getDefaultMiddleware) =>
|
|
779
|
+
`,u+=` * getDefaultMiddleware().concat(setupApiStore.middleware),
|
|
780
|
+
`,u+=` * });
|
|
781
|
+
`,u+=` */
|
|
782
|
+
`,u+=`export const setupApiStore = {
|
|
783
|
+
`,u+=` reducer: {
|
|
784
|
+
`,o.forEach(t=>{let f=t.replace(/-/g,"_");u+=` [${f}Api.reducerPath]: ${f}Api.reducer,
|
|
785
|
+
`;}),u+=` },
|
|
786
|
+
`,u+=` middleware: [
|
|
787
|
+
`,o.forEach(t=>{let f=t.replace(/-/g,"_");u+=` ${f}Api.middleware,
|
|
788
|
+
`;}),u+=` ],
|
|
789
|
+
`,u+=`};
|
|
790
|
+
`,yield te(V__default.default.join(r,"apis.ts"),u,e);return}let i=`// Generated API Clients
|
|
791
|
+
`;if(i+=`// This file was auto-generated.
|
|
792
|
+
`,i+=`// Centralized client instances and configuration
|
|
793
|
+
|
|
794
|
+
`,p==="fetch"?o.forEach(u=>{let t=u.replace(/-/g,"_");i+=`export { default as ${t}Client } from './${u}/client';
|
|
795
|
+
`;}):(o.forEach(u=>{let t=u.replace(/-/g,"_"),f=`${t.charAt(0).toUpperCase()+t.slice(1)}ApiClient`;i+=`import ${f} from './${u}/client';
|
|
796
|
+
`;}),i+=`
|
|
722
797
|
// Create client instances
|
|
723
|
-
`,o.forEach(
|
|
724
|
-
`;})),
|
|
798
|
+
`,o.forEach(u=>{let t=u.replace(/-/g,"_"),f=`${t.charAt(0).toUpperCase()+t.slice(1)}ApiClient`;i+=`export const ${t}Client = new ${f}();
|
|
799
|
+
`;})),p==="fetch"&&(i+=`
|
|
725
800
|
// Import clients for aggregation
|
|
726
|
-
`,o.forEach(
|
|
727
|
-
`;})),
|
|
801
|
+
`,o.forEach(u=>{let t=u.replace(/-/g,"_");i+=`import ${t}_client from './${u}/client';
|
|
802
|
+
`;})),i+=`
|
|
728
803
|
// Aggregate all client instances
|
|
729
|
-
`,
|
|
730
|
-
`,o.forEach(
|
|
731
|
-
`:
|
|
732
|
-
`;}),
|
|
804
|
+
`,i+=`export const clients = {
|
|
805
|
+
`,o.forEach(u=>{let t=u.replace(/-/g,"_");p==="fetch"?i+=` ${t}: ${t}_client,
|
|
806
|
+
`:i+=` ${t}: ${t}Client,
|
|
807
|
+
`;}),i+=`};
|
|
733
808
|
|
|
734
|
-
`,
|
|
809
|
+
`,p==="axios"?(i+=`
|
|
735
810
|
/**
|
|
736
|
-
`,
|
|
737
|
-
`,
|
|
738
|
-
`,
|
|
739
|
-
`,
|
|
740
|
-
`,
|
|
741
|
-
`,
|
|
742
|
-
`,
|
|
743
|
-
`,
|
|
744
|
-
`,o.forEach(
|
|
745
|
-
`;}),
|
|
746
|
-
|
|
747
|
-
`):
|
|
811
|
+
`,i+=` * Configure all API clients at once
|
|
812
|
+
`,i+=` * @param config - Configuration to apply to all clients
|
|
813
|
+
`,i+=` */
|
|
814
|
+
`,i+=`export const configureAllClients = (config: {
|
|
815
|
+
`,i+=` baseURL?: string;
|
|
816
|
+
`,i+=` headers?: Record<string, string>;
|
|
817
|
+
`,i+=` timeout?: number;
|
|
818
|
+
`,i+=`}) => {
|
|
819
|
+
`,o.forEach(u=>{let t=u.replace(/-/g,"_");i+=` ${t}Client.updateConfig(config);
|
|
820
|
+
`;}),i+=`};
|
|
821
|
+
|
|
822
|
+
`):p==="fetch"&&(i+=`
|
|
748
823
|
/**
|
|
749
|
-
`,
|
|
750
|
-
`,
|
|
751
|
-
`,
|
|
752
|
-
`,
|
|
753
|
-
`,
|
|
754
|
-
`,
|
|
755
|
-
`,
|
|
756
|
-
`,
|
|
757
|
-
`,o.forEach(
|
|
758
|
-
`;}),
|
|
759
|
-
|
|
760
|
-
`),
|
|
761
|
-
`,
|
|
762
|
-
`,
|
|
763
|
-
`,
|
|
764
|
-
`,
|
|
765
|
-
`,
|
|
766
|
-
`,
|
|
767
|
-
`,
|
|
768
|
-
`,
|
|
769
|
-
`,
|
|
770
|
-
`,
|
|
771
|
-
`,yield
|
|
772
|
-
`;
|
|
773
|
-
`,
|
|
774
|
-
|
|
775
|
-
`,o.forEach(
|
|
776
|
-
`;}),
|
|
824
|
+
`,i+=` * Configure all API clients at once
|
|
825
|
+
`,i+=` * @param config - Configuration to apply to all clients
|
|
826
|
+
`,i+=` */
|
|
827
|
+
`,i+=`export const configureAllClients = (config: {
|
|
828
|
+
`,i+=` baseURL?: string;
|
|
829
|
+
`,i+=` headers?: Record<string, string>;
|
|
830
|
+
`,i+=` auth?: { token?: string };
|
|
831
|
+
`,i+=`}) => {
|
|
832
|
+
`,o.forEach(u=>{let t=u.replace(/-/g,"_");i+=` ${t}_client.setApiConfig(config);
|
|
833
|
+
`;}),i+=`};
|
|
834
|
+
|
|
835
|
+
`),i+=`// Example usage:
|
|
836
|
+
`,i+=`// import { configureAllClients, clients } from './clients';
|
|
837
|
+
`,i+=`//
|
|
838
|
+
`,i+=`// // Configure all clients at once
|
|
839
|
+
`,i+=`// configureAllClients({
|
|
840
|
+
`,i+=`// baseURL: 'https://api.example.com',
|
|
841
|
+
`,i+=`// timeout: 10000,
|
|
842
|
+
`,i+=`// });
|
|
843
|
+
`,i+=`//
|
|
844
|
+
`,i+=`// // Use specific client
|
|
845
|
+
`,i+=`// const data = await clients.${(n=o[0])==null?void 0:n.replace(/-/g,"_")}.someMethod(...);
|
|
846
|
+
`,yield te(V__default.default.join(r,"clients.ts"),i,e),p==="react-query"||p==="swr"){let u=`// Generated Hooks Aggregator
|
|
847
|
+
`;u+=`// This file was auto-generated.
|
|
848
|
+
`,u+=`// Aggregates all folder-split hooks
|
|
849
|
+
|
|
850
|
+
`,o.forEach(t=>{u+=`export * from './${t}/hooks';
|
|
851
|
+
`;}),u+=`
|
|
777
852
|
// Example usage:
|
|
778
|
-
`,
|
|
779
|
-
`,yield
|
|
853
|
+
`,u+=`// import { useGetSomething } from './hooks';
|
|
854
|
+
`,yield te(V__default.default.join(r,"hooks.ts"),u,e);}});});var kt=de(()=>{});var Nt={};ht(Nt,{interactiveInit:()=>lr});function lr(){return ie(this,null,function*(){try{let r=yield Ut__default.default([{type:"select",name:"configFormat",message:"What configuration format would you like to use?",choices:[{title:"TypeScript (openapi.sync.ts)",value:"typescript"},{title:"JSON (openapi.sync.json)",value:"json"},{title:"JavaScript (openapi.sync.js)",value:"javascript"}],initial:0},{type:"select",name:"apiSource",message:"Where is your OpenAPI specification?",choices:[{title:"URL (e.g., https://api.example.com/openapi.json)",value:"url"},{title:"Local file",value:"file"}],initial:0},{type:t=>t==="url"?"text":null,name:"apiUrl",message:"Enter the OpenAPI specification URL:",validate:t=>t.startsWith("http://")||t.startsWith("https://")?!0:"Please enter a valid URL starting with http:// or https://"},{type:(t,f)=>f.apiSource==="file"?"text":null,name:"apiFile",message:"Enter the path to your OpenAPI file:",validate:t=>t.trim()!==""?!0:"Please enter a valid file path"},{type:"text",name:"apiName",message:"What would you like to name this API?",initial:"myapi",validate:t=>/^[a-zA-Z0-9_-]+$/.test(t)?!0:"API name must contain only letters, numbers, hyphens, and underscores"},{type:"text",name:"outputFolder",message:"Where should generated files be saved?",initial:"./src/api",validate:t=>{if(!t||t.trim()==="")return "Output folder cannot be empty";let f=V__default.default.normalize(t);if(f==="/"||f==="C:\\"||f==="\\")return "Cannot use filesystem root directory. Please use a project subfolder like './src/api'";if(V__default.default.isAbsolute(t)){let c=process.cwd();if(!t.startsWith(c))return "\u26A0\uFE0F Warning: Using absolute path outside project directory. Recommended: use relative path like './src/api'"}return !0}},{type:"confirm",name:"enableFolderSplit",message:"Organize generated code into folders by OpenAPI tags?",initial:!1},{type:"confirm",name:"generateClient",message:"Generate API client code?",initial:!0},{type:t=>t?"select":null,name:"clientType",message:"Which client type would you like?",choices:[{title:"React Query (Recommended for React)",value:"react-query"},{title:"RTK Query (Redux Toolkit)",value:"rtk-query"},{title:"SWR",value:"swr"},{title:"Fetch API",value:"fetch"},{title:"Axios",value:"axios"}],initial:0},{type:"confirm",name:"enableValidation",message:"Enable runtime validation schemas?",initial:!0},{type:t=>t?"select":null,name:"validationLibrary",message:"Which validation library?",choices:[{title:"Zod (Recommended)",value:"zod"},{title:"Yup",value:"yup"},{title:"Joi",value:"joi"}],initial:0},{type:"confirm",name:"enableCustomCode",message:"Enable custom code preservation?",initial:!0},{type:"confirm",name:"typesUseOperationId",message:"Use operationId from OpenAPI spec for type names?",initial:!0},{type:"text",name:"typesPrefix",message:"Prefix for TypeScript interface names (leave empty for none):",initial:"I"},{type:"confirm",name:"excludeEndpointsByTags",message:"Exclude endpoints by tags (e.g., deprecated, internal)?",initial:!1},{type:t=>t?"text":null,name:"excludeTags",message:"Enter tags to exclude (comma-separated):",initial:"deprecated,internal"},{type:"confirm",name:"showCurlInDocs",message:"Include cURL examples in generated documentation?",initial:!0},{type:"number",name:"refetchInterval",message:"Refetch interval in milliseconds (0 to disable auto-refresh):",initial:5e3,min:0},{type:"confirm",name:"runSync",message:"Run initial sync after setup?",initial:!0}],{onCancel:()=>{throw pe||process.exit(0),new Error("Setup cancelled")}}),o={refetchInterval:r.refetchInterval||void 0,folder:r.outputFolder,api:{[r.apiName]:r.apiUrl||r.apiFile}};r.enableFolderSplit&&(o.folderSplit={byTags:!0}),o.types={name:{prefix:r.typesPrefix||"",useOperationId:r.typesUseOperationId}},o.endpoints={name:{useOperationId:r.typesUseOperationId},doc:{showCurl:r.showCurlInDocs}},r.excludeEndpointsByTags&&r.excludeTags&&(o.endpoints.exclude={tags:r.excludeTags.split(",").map(t=>t.trim())}),r.generateClient&&r.clientType&&(o.clientGeneration={enabled:!0,type:r.clientType,outputDir:V__default.default.join(r.outputFolder,r.apiName,"client")},r.clientType==="react-query"?o.clientGeneration.reactQuery={version:5,mutations:!0}:r.clientType==="swr"&&(o.clientGeneration.swr={mutations:!0})),r.enableValidation&&r.validationLibrary&&(o.validations={library:r.validationLibrary}),r.enableCustomCode&&(o.customCode={enabled:!0,position:"bottom"});let p,e;r.configFormat==="json"?(e="openapi.sync.json",p=JSON.stringify(o,null,2)):r.configFormat==="typescript"?(e="openapi.sync.ts",p=`import { IConfig } from "openapi-sync";
|
|
780
855
|
|
|
781
856
|
const config: IConfig = ${JSON.stringify(o,null,2)};
|
|
782
857
|
|
|
783
858
|
export default config;
|
|
784
|
-
`):(e="openapi.sync.js",
|
|
785
|
-
`);let
|
|
859
|
+
`):(e="openapi.sync.js",p=`module.exports = ${JSON.stringify(o,null,2)};
|
|
860
|
+
`);let i=V__default.default.join(process.cwd(),e);if(ce__default.default.existsSync(i)&&!(yield Ut__default.default({type:"confirm",name:"value",message:`${e} already exists. Overwrite?`,initial:!1})).value)throw pe||process.exit(0),new Error("Configuration file not created");ce__default.default.writeFileSync(i,p,"utf-8"),pe||`${e}`;let n=V__default.default.isAbsolute(r.outputFolder)?r.outputFolder:V__default.default.join(process.cwd(),r.outputFolder);if(!ce__default.default.existsSync(n))try{ce__default.default.mkdirSync(n,{recursive:!0}),pe||`${r.outputFolder}`;}catch(t){pe||`${t.message}`;}let u=V__default.default.join(process.cwd(),".gitignore");if(ce__default.default.existsSync(u)&&(ce__default.default.readFileSync(u,"utf-8").includes(r.outputFolder)||ce__default.default.appendFileSync(u,`
|
|
786
861
|
# OpenAPI Sync generated files
|
|
787
862
|
${r.outputFolder}
|
|
788
|
-
`)),
|
|
789
|
-
\u274C Error during sync:`,
|
|
790
|
-
\u274C Error during setup:`,r.message),process.exit(1)),r}})}var
|
|
863
|
+
`)),pe||(`${e}`,r.generateClient&&r.clientType&&(r.clientType==="axios"||r.clientType==="react-query"||r.clientType==="swr"||r.clientType),r.enableValidation&&r.validationLibrary&&(r.generateClient,`${r.validationLibrary}`)),r.runSync&&!pe)try{let{Init:t,GenerateClient:f}=yield Promise.resolve().then(()=>(Gt(),Lt));yield t({refetchInterval:r.refetchInterval}),r.generateClient&&r.clientType&&(yield f({type:r.clientType,apiName:r.apiName}));}catch(t){console.error(`
|
|
864
|
+
\u274C Error during sync:`,t.message),t.stack&&process.env.DEBUG&&console.error(t.stack);}else pe||(r.generateClient||r.enableValidation,r.generateClient&&r.clientType&&(r.generateClient||r.enableValidation,`${r.clientType}`));pe||(`${r.outputFolder}${r.apiName}`,r.generateClient&&`${r.outputFolder}${r.apiName}`,r.generateClient&&r.clientType&&`${r.clientType}`);}catch(r){throw pe||(console.error(`
|
|
865
|
+
\u274C Error during setup:`,r.message),process.exit(1)),r}})}var pe,Ft=de(()=>{pe=process.env.NODE_ENV==="test"||process.env.JEST_WORKER_ID!==void 0;});var Lt={};ht(Lt,{GenerateClient:()=>exports.GenerateClient,Init:()=>exports.Init,InteractiveInit:()=>exports.InteractiveInit,JSONStringify:()=>exports.JSONStringify,capitalize:()=>exports.capitalize,createCustomCodeMarker:()=>exports.createCustomCodeMarker,extractCustomCode:()=>exports.extractCustomCode,getEndpointDetails:()=>exports.getEndpointDetails,getNestedValue:()=>Yt,isJson:()=>exports.isJson,isYamlString:()=>exports.isYamlString,mergeCustomCode:()=>exports.mergeCustomCode,renderTypeRefMD:()=>exports.renderTypeRefMD,variableName:()=>exports.variableName,variableNameChar:()=>exports.variableNameChar,yamlStringToJson:()=>exports.yamlStringToJson});var Me,Mt;exports.Init=void 0;exports.GenerateClient=void 0;exports.InteractiveInit=void 0;var Gt=de(()=>{Pt();Ye();Ze();Rt();kt();Ne();ze();Me=process.cwd(),Mt=()=>{let r;try{ve("esbuild-register");}catch(u){throw u}let o=V__default.default.join(Me,"openapi.sync.js"),p=V__default.default.join(Me,"openapi.sync.ts"),e=V__default.default.join(Me,"openapi.sync.json"),i=[o,p,e];try{for(let u of i)ce__default.default.existsSync(u)&&(r=ve(u),Object.keys(r).length===1&&r.default&&(r=r.default));}catch(u){}typeof r=="function"&&(r=r());let n=r;if(!n)throw new Error("No config found");return n},exports.Init=r=>ie(null,null,function*(){let o=Mt(),p=Object.keys(o.api),e=r&&"refetchInterval"in r&&!isNaN(r==null?void 0:r.refetchInterval)?r.refetchInterval:o.refetchInterval;Ve();for(let i=0;i<p.length;i+=1){let n=p[i],u=o.api[n];yield en(u,n,o,e);}}),exports.GenerateClient=r=>ie(null,null,function*(){let o=Mt(),p=r.apiName?[r.apiName]:Object.keys(o.api);for(let i of p)if(!o.api[i])throw new Error(`API "${i}" not found in configuration. Available APIs: ${Object.keys(o.api).join(", ")}`);Ve();for(let i of p){let n=o.api[i];yield en(n,i,o);}let e=(o==null?void 0:o.folder)||"api";for(let i of p){let n=At(i);if(n.length===0){continue}`${n.length}${i}`;let u=X(X(X(X(ae(X({enabled:true},o.clientGeneration||{}),{type:r.type}),r.outputDir&&{outputDir:r.outputDir}),r.baseURL&&{baseURL:r.baseURL}),r.tags&&{tags:r.tags}),r.endpoints&&{endpoints:r.endpoints});yield qt(n,o,u,i,V__default.default.join(Me,e));}}),exports.InteractiveInit=()=>ie(null,null,function*(){let{interactiveInit:r}=yield Promise.resolve().then(()=>(Ft(),Nt));yield r();});});Gt();exports.getNestedValue=Yt;
|