openapi-sync 3.0.2 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,66 +1,84 @@
1
- import z from'fs';import F from'path';import*as te from'js-yaml';import ut from'lodash.isequal';import st from'lodash.get';import yt from'axios';import ct from'axios-retry';import ht from'@apidevtools/swagger-parser';import {CurlGenerator}from'curl-generator';var X=(n=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(n,{get:(i,e)=>(typeof require!="undefined"?require:i)[e]}):n)(function(n){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});var _=(n,i,e)=>new Promise((O,$)=>{var I=f=>{try{p(e.next(f));}catch(x){$(x);}},o=f=>{try{p(e.throw(f));}catch(x){$(x);}},p=f=>f.done?O(f.value):Promise.resolve(f.value).then(I,o);p((e=e.apply(n,i)).next());});var Ot=/^[A-Za-z_$][A-Za-z0-9_$]*$/,Qe=/[A-Za-z0-9_$]/;var ge=n=>["object"].includes(typeof n)&&!(n instanceof Blob),pt=n=>{try{return te.load(n),!0}catch(i){let e=i;if(e instanceof te.YAMLException)return false;throw e}},De=n=>{if(pt(n)){let i=te.load(n),e=JSON.stringify(i,null,2);return JSON.parse(e)}},W=n=>n.substring(0,1).toUpperCase()+n.substring(1),He=(n,i)=>{let e=n.split("/"),O=`${W(i)}`,$=[];return e.forEach(I=>{if(I[0]==="{"&&I[I.length-1]==="}"){let p=I.replace(/{/,"").replace(/}/,"");$.push(p),I=`$${p}`;}else if(I[0]==="<"&&I[I.length-1]===">"){let p=I.replace(/</,"").replace(/>/,"");$.push(p),I=`$${p}`;}else if(I[0]===":"){let p=I.replace(/:/,"");$.push(p),I=`$${p}`;}let o="";I.split("").forEach(p=>{let f=p;Qe.test(p)||(f="/"),o+=f;}),o.split("/").forEach(p=>{O+=W(p);});}),{name:O,variables:$,pathParts:e}},ee=(n,i=1)=>{let e="{",O=Object.keys(n);for(let $=0;$<O.length;$++){let I=O[$],o=n[I];if(e+=`
2
- `+" ".repeat(i)+I+": ",Array.isArray(o)){e+="[";for(let p=0;p<o.length;p++){let f=o[p];typeof f=="object"&&f!==null?e+=ee(f,i+1):e+=typeof f=="string"?`"${f}"`:f,p<o.length-1&&(e+=", ");}e+="]";}else typeof o=="object"&&o!==null?e+=""+ee(o,i+1):e+=o.split(`
3
- `).filter(p=>p.trim()!=="").join(`
4
- ${" ".repeat(i)}`);$<O.length-1&&(e+=", ");}return e+=`
5
- ${" ".repeat(i-1)}}`,e},le=(n,i=1)=>`
1
+ import U from'fs';import M from'path';import*as ae from'js-yaml';import Kt from'lodash.isequal';import xe from'lodash.get';import Wt from'axios';import Dt from'axios-retry';import Qt from'@apidevtools/swagger-parser';import {CurlGenerator}from'curl-generator';var re=(u=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(u,{get:(d,e)=>(typeof require!="undefined"?require:d)[e]}):u)(function(u){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+u+'" is not supported')});var ne=(u,d,e)=>new Promise((j,b)=>{var v=O=>{try{y(e.next(O));}catch(E){b(E);}},m=O=>{try{y(e.throw(O));}catch(E){b(E);}},y=O=>O.done?j(O.value):Promise.resolve(O.value).then(v,m);y((e=e.apply(u,d)).next());});var Xt=/^[A-Za-z_$][A-Za-z0-9_$]*$/,Et=/[A-Za-z0-9_$]/;var ct=u=>["object"].includes(typeof u)&&!(u instanceof Blob),Gt=u=>{try{return ae.load(u),!0}catch(d){let e=d;if(e instanceof ae.YAMLException)return false;throw e}},Tt=u=>{if(Gt(u)){let d=ae.load(u),e=JSON.stringify(d,null,2);return JSON.parse(e)}},K=u=>u.substring(0,1).toUpperCase()+u.substring(1),St=(u,d)=>{let e=u.split("/"),j=`${K(d)}`,b=[];return e.forEach(v=>{if(v[0]==="{"&&v[v.length-1]==="}"){let y=v.replace(/{/,"").replace(/}/,"");b.push(y),v=`$${y}`;}else if(v[0]==="<"&&v[v.length-1]===">"){let y=v.replace(/</,"").replace(/>/,"");b.push(y),v=`$${y}`;}else if(v[0]===":"){let y=v.replace(/:/,"");b.push(y),v=`$${y}`;}let m="";v.split("").forEach(y=>{let O=y;Et.test(y)||(O="/"),m+=O;}),m.split("/").forEach(y=>{j+=K(y);});}),{name:j,variables:b,pathParts:e}},se=(u,d=1)=>{let e="{",j=Object.keys(u);for(let b=0;b<j.length;b++){let v=j[b],m=u[v];if(e+=`
2
+ `+" ".repeat(d)+v+": ",Array.isArray(m)){e+="[";for(let y=0;y<m.length;y++){let O=m[y];typeof O=="object"&&O!==null?e+=se(O,d+1):e+=typeof O=="string"?`"${O}"`:O,y<m.length-1&&(e+=", ");}e+="]";}else typeof m=="object"&&m!==null?e+=""+se(m,d+1):e+=m.split(`
3
+ `).filter(y=>y.trim()!=="").join(`
4
+ ${" ".repeat(d)}`);b<j.length-1&&(e+=", ");}return e+=`
5
+ ${" ".repeat(d-1)}}`,e},ue=(u,d=1)=>`
6
6
  \`\`\`typescript
7
- ${" ".repeat(i)} ${n.split(`
7
+ ${" ".repeat(d)} ${u.split(`
8
8
  `).filter(e=>e.trim()!=="").join(`
9
- ${" ".repeat(i)} `)}
10
- \`\`\``;function xt(n,i){return i.split(".").reduce((O,$)=>O&&O[$]!==void 0?O[$]:void 0,n)}var dt=(n,i="CUSTOM CODE")=>{let e=`// \u{1F512} ${i} START`,O=`// \u{1F512} ${i} END`,$={beforeGenerated:"",afterGenerated:""},I=0,o=[];for(;I<n.length;){let p=n.indexOf(e,I);if(p===-1)break;let f=n.indexOf(O,p);if(f===-1)break;let x=f+O.length,B=n.substring(x,x+100),R=B.match(/^\s*\n\s*(\/\/ =+)/);if(R){let oe=B.indexOf(`
11
- `,R.index+1);oe!==-1?x+=oe+1:x+=R[0].length;}let Q=p,M=n.substring(Math.max(0,p-200),p).lastIndexOf("// ==========");M!==-1&&(Q=Math.max(0,p-200)+M);let U=n.substring(Q,x);o.push({start:Q,end:x,content:U}),I=x;}return o.length>0&&(n.substring(0,o[0].start).split(`
12
- `).filter(x=>{let B=x.trim();return B.length>0&&!B.startsWith("//")}).join("").length===0?($.beforeGenerated=o[0].content,o.length>1&&($.afterGenerated=o[1].content)):($.afterGenerated=o[0].content,o.length>1&&!$.beforeGenerated&&($.beforeGenerated=o[1].content))),$},Ze=(n,i="CUSTOM CODE",e=true)=>{let O=e?`// ${n==="top"?"Add your custom code below this line":"Add your custom code above this line"}
9
+ ${" ".repeat(d)} `)}
10
+ \`\`\``;function er(u,d){return d.split(".").reduce((j,b)=>j&&j[b]!==void 0?j[b]:void 0,u)}var Ut=(u,d="CUSTOM CODE")=>{let e=`// \u{1F512} ${d} START`,j=`// \u{1F512} ${d} END`,b={beforeGenerated:"",afterGenerated:""},v=0,m=[];for(;v<u.length;){let y=u.indexOf(e,v);if(y===-1)break;let O=u.indexOf(j,y);if(O===-1)break;let E=O+j.length,P=u.substring(E,E+100),B=P.match(/^\s*\n\s*(\/\/ =+)/);if(B){let ie=P.indexOf(`
11
+ `,B.index+1);ie!==-1?E+=ie+1:E+=B[0].length;}let _=y,L=u.substring(Math.max(0,y-200),y).lastIndexOf("// ==========");L!==-1&&(_=Math.max(0,y-200)+L);let V=u.substring(_,E);m.push({start:_,end:E,content:V}),v=E;}return m.length>0&&(u.substring(0,m[0].start).split(`
12
+ `).filter(E=>{let P=E.trim();return P.length>0&&!P.startsWith("//")}).join("").length===0?(b.beforeGenerated=m[0].content,m.length>1&&(b.afterGenerated=m[1].content)):(b.afterGenerated=m[0].content,m.length>1&&!b.beforeGenerated&&(b.beforeGenerated=m[1].content))),b},At=(u,d="CUSTOM CODE",e=true)=>{let j=e?`// ${u==="top"?"Add your custom code below this line":"Add your custom code above this line"}
13
13
  // This section will be preserved during regeneration
14
14
  `:"";return `// ${"=".repeat(60)}
15
- // \u{1F512} ${i} START
16
- ${O}// ${"=".repeat(60)}
15
+ // \u{1F512} ${d} START
16
+ ${j}// ${"=".repeat(60)}
17
17
 
18
- // \u{1F512} ${i} END
19
- // ${"=".repeat(60)}`},Xe=(n,i,e={})=>{let{position:O="bottom",markerText:$="CUSTOM CODE",includeInstructions:I=true}=e,o={beforeGenerated:"",afterGenerated:""};i&&(o=dt(i,$)),!o.beforeGenerated&&!o.afterGenerated&&((O==="top"||O==="both")&&(o.beforeGenerated=Ze("top",$,I)),(O==="bottom"||O==="both")&&(o.afterGenerated=Ze("bottom",$,I)));let p=[];return o.beforeGenerated&&(p.push(o.beforeGenerated),p.push("")),p.push(n),o.afterGenerated&&(p.push(""),p.push(o.afterGenerated)),p.join(`
20
- `)};var pe=F.join(__dirname,"../","../db.json");z.existsSync(pe)||z.writeFileSync(pe,"{}");var ye={};try{ye=X(pe);}catch(n){ye={};}var re=ye||{},_e=n=>{z.writeFileSync(pe,JSON.stringify(n));},et=(n,i)=>{re[n]=i,_e(re);},tt=n=>re[n],rt=()=>{re={},_e(re);};var se=process.cwd(),ce={},nt=yt.create({timeout:6e4});ct(nt,{retries:20,retryCondition:n=>n.code==="ECONNABORTED"||n.message.includes("Network Error"),retryDelay:n=>n*1e3});var ne=(n,i,e)=>_(null,null,function*(){var o,p,f,x;if(!(((o=e==null?void 0:e.customCode)==null?void 0:o.enabled)!==false)){yield z.promises.writeFile(n,i);return}let $=null;try{$=yield z.promises.readFile(n,"utf-8");}catch(B){}let I=Xe(i,$,{position:((p=e==null?void 0:e.customCode)==null?void 0:p.position)||"bottom",markerText:(f=e==null?void 0:e.customCode)==null?void 0:f.markerText,includeInstructions:(x=e==null?void 0:e.customCode)==null?void 0:x.includeInstructions});yield z.promises.writeFile(n,I);}),ot=(n,i,e,O)=>_(null,null,function*(){var be,Oe,Ie,Ce,xe,je;let $=yield nt.get(n),I=ge($.data)?$.data:De($.data),o;try{o=yield ht.parse(I);}catch(s){let r=s instanceof Error?s.message:String(s);throw new Error(`Failed to parse OpenAPI spec for ${i}: ${r}`)}let p=F.join((e==null?void 0:e.folder)||"",i),f={},x=s=>{var r,j;if((r=e==null?void 0:e.folderSplit)!=null&&r.customFolder){let b=e.folderSplit.customFolder(s);if(console.log("customFolder",b),b)return b}return (j=e==null?void 0:e.folderSplit)!=null&&j.byTags&&s.tags&&s.tags.length>0?s.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},B=typeof(e==null?void 0:e.server)=="string"?e==null?void 0:e.server:((Oe=(be=o==null?void 0:o.servers)==null?void 0:be[(e==null?void 0:e.server)||0])==null?void 0:Oe.url)||"",R=typeof((Ce=(Ie=e==null?void 0:e.types)==null?void 0:Ie.name)==null?void 0:Ce.prefix)=="string"?e==null?void 0:e.types.name.prefix:"I",Q=typeof((je=(xe=e==null?void 0:e.endpoints)==null?void 0:xe.name)==null?void 0:je.prefix)=="string"?e==null?void 0:e.endpoints.name.prefix:"",de=(s,r)=>{var b,a;let j=W(s);if((a=(b=e==null?void 0:e.types)==null?void 0:b.name)!=null&&a.format){let m=e==null?void 0:e.types.name.format("shared",{name:s},j);if(m)return `${R}${m}`}return `${R}${j}`},M=(s,r,j,b,a,m=0)=>{let C="",l="",d="";if(r)if(r.$ref)if(r.$ref[0]==="#"){let u=(r.$ref||"").split("/");u.shift(),[...u].pop();let w=st(s,u,null);if(w){w!=null&&w.name&&(C=w.name),l=u[u.length-1];let N=de(l);N.includes(".")&&(N=N.split(".").map((J,K)=>K===0?J:`["${J}"]`).join("")),d+=`${a!=null&&a.noSharedImport?"":"Shared."}${N}`;}}else d+="";else if(r.anyOf)d+=`(${r.anyOf.map(u=>M(s,u,"",b,a)).filter(u=>!!u).join("|")})`;else if(r.oneOf)d+=`(${r.oneOf.map(u=>M(s,u,"",b,a)).filter(u=>!!u).join("|")})`;else if(r.allOf)d+=`(${r.allOf.map(u=>M(s,u,"",b,a)).filter(u=>!!u).join("&")})`;else if(r.items)d+=`${M(s,r.items,"",false,a)}[]`;else if(r.properties){let u=Object.keys(r.properties),E=r.required||[],S="";u.forEach(w=>{var g,J,K,Y,ae,D;let N="";!((J=(g=e==null?void 0:e.types)==null?void 0:g.doc)!=null&&J.disable)&&((Y=(K=r.properties)==null?void 0:K[w])!=null&&Y.description)&&(N=" * "+((ae=r.properties)==null?void 0:ae[w].description.split(`
21
- `).filter(ie=>ie.trim()!=="").join(`
22
- *${" ".repeat(1)}`))),S+=(N?`/**
23
- ${N}
18
+ // \u{1F512} ${d} END
19
+ // ${"=".repeat(60)}`},wt=(u,d,e={})=>{let{position:j="bottom",markerText:b="CUSTOM CODE",includeInstructions:v=true}=e,m={beforeGenerated:"",afterGenerated:""};d&&(m=Ut(d,b)),!m.beforeGenerated&&!m.afterGenerated&&((j==="top"||j==="both")&&(m.beforeGenerated=At("top",b,v)),(j==="bottom"||j==="both")&&(m.afterGenerated=At("bottom",b,v)));let y=[];return m.beforeGenerated&&(y.push(m.beforeGenerated),y.push("")),y.push(u),m.afterGenerated&&(y.push(""),y.push(m.afterGenerated)),y.join(`
20
+ `)};var me=M.join(__dirname,"../","../db.json");U.existsSync(me)||U.writeFileSync(me,"{}");var $e={};try{$e=re(me);}catch(u){$e={};}var oe=$e||{},zt=u=>{U.writeFileSync(me,JSON.stringify(u));},Nt=(u,d)=>{oe[u]=d,zt(oe);},kt=u=>oe[u],Rt=()=>{oe={},zt(oe);};var Y=process.cwd(),Oe={},Jt=Wt.create({timeout:6e4});Dt(Jt,{retries:20,retryCondition:u=>u.code==="ECONNABORTED"||u.message.includes("Network Error"),retryDelay:u=>u*1e3});var Z=(u,d,e)=>ne(null,null,function*(){var m,y,O,E;if(!(((m=e==null?void 0:e.customCode)==null?void 0:m.enabled)!==false)){yield U.promises.writeFile(u,d);return}let b=null;try{b=yield U.promises.readFile(u,"utf-8");}catch(P){}let v=wt(d,b,{position:((y=e==null?void 0:e.customCode)==null?void 0:y.position)||"bottom",markerText:(O=e==null?void 0:e.customCode)==null?void 0:O.markerText,includeInstructions:(E=e==null?void 0:e.customCode)==null?void 0:E.includeInstructions});yield U.promises.writeFile(u,v);}),Mt=(u,d,e,j)=>ne(null,null,function*(){var je,ve,Ce,Ee,Ae,ce,Te,Se,we,ze;let b=yield Jt.get(u),v=ct(b.data)?b.data:Tt(b.data),m;try{m=yield Qt.parse(v);}catch(t){let r=t instanceof Error?t.message:String(t);throw new Error(`Failed to parse OpenAPI spec for ${d}: ${r}`)}let y=M.join((e==null?void 0:e.folder)||"",d),O={},E=t=>{var r,f;if((r=e==null?void 0:e.folderSplit)!=null&&r.customFolder){let l=e.folderSplit.customFolder(t);if(l)return l}return (f=e==null?void 0:e.folderSplit)!=null&&f.byTags&&t.tags&&t.tags.length>0?t.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},P=typeof(e==null?void 0:e.server)=="string"?e==null?void 0:e.server:((ve=(je=m==null?void 0:m.servers)==null?void 0:je[(e==null?void 0:e.server)||0])==null?void 0:ve.url)||"",B=typeof((Ee=(Ce=e==null?void 0:e.types)==null?void 0:Ce.name)==null?void 0:Ee.prefix)=="string"?e==null?void 0:e.types.name.prefix:"I",_=typeof((ce=(Ae=e==null?void 0:e.endpoints)==null?void 0:Ae.name)==null?void 0:ce.prefix)=="string"?e==null?void 0:e.endpoints.name.prefix:"",de=(t,r)=>{var l,a;let f=K(t);if((a=(l=e==null?void 0:e.types)==null?void 0:l.name)!=null&&a.format){let o=e==null?void 0:e.types.name.format("shared",{name:t},f);if(o)return `${B}${o}`}return `${B}${f}`},L=(t,r,f,l,a,o=0)=>{let s="",p="",i="";if(r)if(r.$ref)if(r.$ref[0]==="#"){let $=(r.$ref||"").split("/");$.shift(),[...$].pop();let k=xe(t,$,null);if(k){k!=null&&k.name&&(s=k.name),p=$[$.length-1];let R=de(p);R.includes(".")&&(R=R.split(".").map((W,Q)=>Q===0?W:`["${W}"]`).join("")),i+=`${a!=null&&a.noSharedImport?"":"Shared."}${R}`;}}else i+="";else if(r.anyOf)i+=`(${r.anyOf.map($=>L(t,$,"",l,a)).filter($=>!!$).join("|")})`;else if(r.oneOf)i+=`(${r.oneOf.map($=>L(t,$,"",l,a)).filter($=>!!$).join("|")})`;else if(r.allOf)i+=`(${r.allOf.map($=>L(t,$,"",l,a)).filter($=>!!$).join("&")})`;else if(r.items)i+=`${L(t,r.items,"",false,a)}[]`;else if(r.properties){let $=Object.keys(r.properties),C=r.required||[],N="";$.forEach(k=>{var ee,W,Q,X,le,te;let R="";!((W=(ee=e==null?void 0:e.types)==null?void 0:ee.doc)!=null&&W.disable)&&((X=(Q=r.properties)==null?void 0:Q[k])!=null&&X.description)&&(R=" * "+((le=r.properties)==null?void 0:le[k].description.split(`
21
+ `).filter(pe=>pe.trim()!=="").join(`
22
+ *${" ".repeat(1)}`))),N+=(R?`/**
23
+ ${R}
24
24
  */
25
- `:"")+`${M(s,(D=r.properties)==null?void 0:D[w],w,E.includes(w),a,m+1)}`;}),S.length>0?d+=`{
26
- ${" ".repeat(m)}${S}${" ".repeat(m)}}`:d+="{[k: string]: any}";}else if(r.enum&&r.enum.length>0)r.enum.length>1&&(d+="("),r.enum.map(u=>JSON.stringify(u)).filter(u=>!!u).forEach((u,E)=>{d+=`${E===0?"":"|"}${u}`;}),r.enum.length>1&&(d+=")");else if(r.type){let u=E=>{let S="";if(typeof E=="string")["string","integer","number","array","boolean","null"].includes(E)?["integer","number"].includes(E)?S+="number":E==="array"?S+="any[]":S+=E:E==="object"&&(r.additionalProperties?S+=`{[k: string]: ${M(s,r.additionalProperties,"",true,a)||"any"}}`:S+="{[k: string]: any}");else if(Array.isArray(E)){let w=E.map(N=>u(N));w.filter(N=>N!==""),w.length>1&&(S+="("+w.join("|")+")");}else S+="any";return S};d=u(r.type);}else d+="any";else d="string";let c=C||j;a!=null&&a.useComponentName&&!c&&(c=l);let T=c?` "${c}"${b?"":"?"}: `:"",t=r!=null&&r.nullable?" | null":"";return d.length>0?`${T}${d}${t}${c?`;
27
- `:""}`:""},U=(s,r)=>{let a="";if(r)if(r.$ref)if(r.$ref[0]==="#"){let m=(r.$ref||"").split("/");m.shift();let l=st(s,m,null);l&&(l!=null&&l.name&&(l.name),m[m.length-1],a+=U(s,l));}else a+="";else if(r.anyOf)a+=U(s,r.anyOf[0]);else if(r.oneOf)a+=U(s,r.oneOf[0]);else if(r.allOf)a+=`{${r.allOf.map(m=>`...(${U(s,m)})`).join(",")}}`;else if(r.items)a+=`[${U(s,r.items)}]`;else if(r.properties){let l=Object.keys(r.properties).map(d=>{var c;return ` "${d}": ${U(s,(c=r.properties)==null?void 0:c[d])}`}).join(`,
28
- `);l.length>0?a+=`{
29
- ${l}
30
- }`:a+="{}";}else if(r.enum&&r.enum.length>0)r.enum.length>1&&(a+=r.enum[0]);else if(r.type)if(r.example)a+=JSON.stringify(r.example);else {let m=C=>{let l="";if(typeof C=="string")["string","integer","number","array","boolean","null"].includes(C)?["integer","number"].includes(C)?l+="123":C==="array"?l+="[]":C==="boolean"?l+="true":C==="null"?l+="null":l+=`"${C}"`:C==="object"&&(l+="{}");else if(Array.isArray(C)){let d=C.map(c=>m(c));d.filter(c=>c!==""),d.length>1&&(l+=d.join("|"));}else l+="any";return l};a=m(r.type);}else a+="any";else a="string";return a};O&&!isNaN(O)&&O>0&&(process.env.NODE_ENV&&["production","prod","test","staging"].includes(process.env.NODE_ENV)||(ce[i]&&clearTimeout(ce[i]),ce[i]=setTimeout(()=>ot(n,i,e,O),O)));let oe=tt(i);if(ut(oe,o))return;et(i,o);let me="",Z="",V={};o.components&&Object.keys(o.components).forEach(s=>{if(["schemas","responses","parameters","examples","requestBodies","headers","links","callbacks"].includes(s)){let r=o.components[s],j={},b={};Object.keys(r).forEach(m=>{var d;let C=(d=r[m])!=null&&d.schema?r[m].schema:r[m],l=`${M(o,C,"",true,{noSharedImport:true,useComponentName:["parameters"].includes(s)})}`;if(l){let c=m.split("."),T=j,t=b;for(let u=0;u<c.length;u++){let E=c[u];u<c.length-1?(E in T||(T[E]={},t[E]={}),T=T[E],t=t[E]):(T[E]=l,t[E]=C);}}}),Object.keys(j).forEach(m=>{var c,T,t,u;let C=de(m),l=j[m],d="";!((T=(c=e==null?void 0:e.types)==null?void 0:c.doc)!=null&&T.disable)&&m in r&&((t=r[m])!=null&&t.description)&&(d=" * "+r[m].description.split(`
31
- `).filter(E=>E.trim()!=="").join(`
32
- *${" ".repeat(1)}`)),V[m]=((u=V[m])!=null?u:"")+(d?`/**
33
- ${d}
25
+ `:"")+`${L(t,(te=r.properties)==null?void 0:te[k],k,C.includes(k),a,o+1)}`;}),N.length>0?i+=`{
26
+ ${" ".repeat(o)}${N}${" ".repeat(o)}}`:i+="{[k: string]: any}";}else if(r.enum&&r.enum.length>0)r.enum.length>1&&(i+="("),r.enum.map($=>JSON.stringify($)).filter($=>!!$).forEach(($,C)=>{i+=`${C===0?"":"|"}${$}`;}),r.enum.length>1&&(i+=")");else if(r.type){let $=C=>{let N="";if(typeof C=="string")["string","integer","number","array","boolean","null"].includes(C)?["integer","number"].includes(C)?N+="number":C==="array"?N+="any[]":N+=C:C==="object"&&(r.additionalProperties?N+=`{[k: string]: ${L(t,r.additionalProperties,"",true,a)||"any"}}`:N+="{[k: string]: any}");else if(Array.isArray(C)){let k=C.map(R=>$(R));k.filter(R=>R!==""),k.length>1&&(N+="("+k.join("|")+")");}else N+="any";return N};i=$(r.type);}else i+="any";else i="string";let h=s||f;a!=null&&a.useComponentName&&!h&&(h=p);let z=h?` "${h}"${l?"":"?"}: `:"",n=r!=null&&r.nullable?" | null":"";return i.length>0?`${z}${i}${n}${h?`;
27
+ `:""}`:""},V=(t,r)=>{let a="";if(r)if(r.$ref)if(r.$ref[0]==="#"){let o=(r.$ref||"").split("/");o.shift();let p=xe(t,o,null);p&&(p!=null&&p.name&&(p.name),o[o.length-1],a+=V(t,p));}else a+="";else if(r.anyOf)a+=V(t,r.anyOf[0]);else if(r.oneOf)a+=V(t,r.oneOf[0]);else if(r.allOf)a+=`{${r.allOf.map(o=>`...(${V(t,o)})`).join(",")}}`;else if(r.items)a+=`[${V(t,r.items)}]`;else if(r.properties){let p=Object.keys(r.properties).map(i=>{var h;return ` "${i}": ${V(t,(h=r.properties)==null?void 0:h[i])}`}).join(`,
28
+ `);p.length>0?a+=`{
29
+ ${p}
30
+ }`:a+="{}";}else if(r.enum&&r.enum.length>0)r.enum.length>1&&(a+=r.enum[0]);else if(r.type)if(r.example)a+=JSON.stringify(r.example);else {let o=s=>{let p="";if(typeof s=="string")["string","integer","number","array","boolean","null"].includes(s)?["integer","number"].includes(s)?p+="123":s==="array"?p+="[]":s==="boolean"?p+="true":s==="null"?p+="null":p+=`"${s}"`:s==="object"&&(p+="{}");else if(Array.isArray(s)){let i=s.map(h=>o(h));i.filter(h=>h!==""),i.length>1&&(p+=i.join("|"));}else p+="any";return p};a=o(r.type);}else a+="any";else a="string";return a};j&&!isNaN(j)&&j>0&&(process.env.NODE_ENV&&["production","prod","test","staging"].includes(process.env.NODE_ENV)||(Oe[d]&&clearTimeout(Oe[d]),Oe[d]=setTimeout(()=>Mt(u,d,e,j),j)));let ie=kt(d);if(Kt(ie,m))return;Nt(d,m);let ye="",g="",H={};m.components&&Object.keys(m.components).forEach(t=>{if(["schemas","responses","parameters","examples","requestBodies","headers","links","callbacks"].includes(t)){let r=m.components[t],f={},l={};Object.keys(r).forEach(o=>{var i;let s=(i=r[o])!=null&&i.schema?r[o].schema:r[o],p=`${L(m,s,"",true,{noSharedImport:true,useComponentName:["parameters"].includes(t)})}`;if(p){let h=o.split("."),z=f,n=l;for(let $=0;$<h.length;$++){let C=h[$];$<h.length-1?(C in z||(z[C]={},n[C]={}),z=z[C],n=n[C]):(z[C]=p,n[C]=s);}}}),Object.keys(f).forEach(o=>{var h,z,n,$;let s=de(o),p=f[o],i="";!((z=(h=e==null?void 0:e.types)==null?void 0:h.doc)!=null&&z.disable)&&o in r&&((n=r[o])!=null&&n.description)&&(i=" * "+r[o].description.split(`
31
+ `).filter(C=>C.trim()!=="").join(`
32
+ *${" ".repeat(1)}`)),H[o]=(($=H[o])!=null?$:"")+(i?`/**
33
+ ${i}
34
34
  */
35
- `:"")+"export type "+C+" = "+(typeof l=="string"?l:ee(l))+`;
36
- `;});}});let fe=s=>{let r="";if(s.content){let j=Object.keys(s.content);j[0]&&s.content[j[0]].schema&&(r+=`${M(o,s.content[j[0]].schema,"")}`);}return r},it=s=>{var r,j,b,a,m;if((j=(r=e==null?void 0:e.endpoints)==null?void 0:r.value)!=null&&j.replaceWords&&Array.isArray(e==null?void 0:e.endpoints.value.replaceWords)){let C=s;return (m=(a=(b=e==null?void 0:e.endpoints)==null?void 0:b.value)==null?void 0:a.replaceWords)==null||m.forEach((l,d)=>{let c=new RegExp(l.replace,"g");C=C.replace(c,l.with||"");}),C}else return s},lt=(s,r,j=[])=>{var m,C;let b=(m=e==null?void 0:e.endpoints)==null?void 0:m.exclude,a=(C=e==null?void 0:e.endpoints)==null?void 0:C.include;if(a){let l=a.tags&&a.tags.length>0?j.some(c=>a.tags.includes(c)):true,d=a.endpoints&&a.endpoints.length>0?a.endpoints.some(c=>{let T=!c.method||c.method.toLowerCase()===r.toLowerCase();return c.path?s===c.path&&T:c.regex?new RegExp(c.regex).test(s)&&T:false}):true;if(!l||!d)return true}return !!(b&&(b.tags&&b.tags.length>0&&j.some(d=>b.tags.includes(d))||b.endpoints&&b.endpoints.length>0&&b.endpoints.some(d=>{let c=!d.method||d.method.toLowerCase()===r.toLowerCase();return d.path?s===d.path&&c:d.regex?new RegExp(d.regex).test(s)&&c:false})))};if(Object.keys(o.paths||{}).forEach(s=>{let r=o.paths[s];Object.keys(r).forEach(b=>{var ie,Ee,Ae,Te,Se,we,Ne,ke,ve,Re,Be,Me,Fe,Ge,Pe,qe,Ue,Je,Le,ze,Ke,We,Ve,Ye;let a=b,m=He(s,a),C=((ie=r[a])==null?void 0:ie.tags)||[];if(lt(s,a,C))return;let l=r[a],d=x({method:a,path:s,summary:l==null?void 0:l.summary,operationId:l==null?void 0:l.operationId,tags:C,parameters:l==null?void 0:l.parameters,requestBody:l==null?void 0:l.requestBody,responses:l==null?void 0:l.responses});f[d]||(f[d]={endpoints:"",types:""});let c=((Ae=(Ee=e==null?void 0:e.endpoints)==null?void 0:Ee.value)!=null&&Ae.includeServer?B:"")+m.pathParts.map(h=>(h[0]==="{"&&h[h.length-1]==="}"?h=`\${${h.replace(/{/,"").replace(/}/,"")}}`:h[0]==="<"&&h[h.length-1]===">"?h=`\${${h.replace(/</,"").replace(/>/,"")}}`:h[0]===":"&&(h=`\${${h.replace(/:/,"")}}`),h)).join("/"),T=`"${c}"`;m.variables.length>0&&(T=`(${m.variables.map(y=>`${y}:string`).join(",")})=> \`${c}\``),T=it(T);let t=r[a],u="";if(t!=null&&t.parameters&&((t==null?void 0:t.parameters).forEach((y,k)=>{(y.$ref||y.in==="query"&&y.name)&&(u+=`${M(o,y.$ref?y:y.schema,y.name||"",y.required)}`);}),u)){u=`{
37
- ${u}}`;let y=`${m.name}Query`;if((Se=(Te=e==null?void 0:e.types)==null?void 0:Te.name)!=null&&Se.useOperationId&&(t!=null&&t.operationId)&&(y=`${t.operationId}Query`),y=W(`${R}${y}`),(Ne=(we=e==null?void 0:e.types)==null?void 0:we.name)!=null&&Ne.format){let P=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"query",method:a,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},y);P&&(y=`${R}${P}`);}let k=`export type ${y} = ${u};
38
- `;e!=null&&e.folderSplit?f[d].types+=k:Z+=k;}let E=t==null?void 0:t.requestBody,S="";if(E&&(S=fe(E),S)){let h=`${m.name}DTO`;if((ve=(ke=e==null?void 0:e.types)==null?void 0:ke.name)!=null&&ve.useOperationId&&(t!=null&&t.operationId)&&(h=`${t.operationId}DTO`),h=W(`${R}${h}`),(Be=(Re=e==null?void 0:e.types)==null?void 0:Re.name)!=null&&Be.format){let k=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"dto",method:a,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},h);k&&(h=`${R}${k}`);}let y=`export type ${h} = ${S};
39
- `;e!=null&&e.folderSplit?f[d].types+=y:Z+=y;}let w={},N="";if(t!=null&&t.responses){let h=t==null?void 0:t.responses;Object.keys(h).forEach(k=>{var P,q,v,G;if(N=fe(h[k]),w[k]=N,N){let A=`${m.name}${k}Response`;if((q=(P=e==null?void 0:e.types)==null?void 0:P.name)!=null&&q.useOperationId&&(t!=null&&t.operationId)&&(A=`${t.operationId}${k}Response`),A=W(`${R}${A}`),(G=(v=e==null?void 0:e.types)==null?void 0:v.name)!=null&&G.format){let H=e==null?void 0:e.types.name.format("endpoint",{code:k,type:"response",method:a,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},A);H&&(A=`${R}${H}`);}let L=`export type ${A} = ${N};
40
- `;e!=null&&e.folderSplit?f[d].types+=L:Z+=L;}});}let g=h=>!h||!h.length?"":h.map(y=>Object.entries(y).map(([P,q])=>{let v=P,G="";return Array.isArray(q)&&q.length&&(G=`
41
- - Scopes: [\`${q.join("`, `")}\`]`,v=`**${v}**`),`
42
- - ${v}${G}`}).join("")).join(`
43
- `),J=t!=null&&t.security?g(t.security):"",K="";if(!((Fe=(Me=e==null?void 0:e.endpoints)==null?void 0:Me.doc)!=null&&Fe.disable)){let h="";if((Pe=(Ge=e==null?void 0:e.endpoints)==null?void 0:Ge.doc)!=null&&Pe.showCurl){let y={},k="",P="";(qe=t.requestBody)!=null&&qe.content&&Object.keys(t.requestBody.content).forEach(G=>{let A=t.requestBody.content[G].schema;if(A){Array.isArray(y["Content-type"])?y["Content-type"].push(G):y["Content-type"]=[G];let L=U(o,A);L&&(k=L);}}),t!=null&&t.security&&t.security.forEach(v=>{Object.keys(v).forEach(G=>{var L,H;let A=(H=(L=o.components)==null?void 0:L.securitySchemes)==null?void 0:H[G];A&&(A.type==="mutualTLS"?P+=`
44
- --cert client-certificate.crt --key client-private-key.key --cacert ca-certificate.crt`:A.type==="apiKey"?y[(A==null?void 0:A.name)||"X-API-KEY"]="{API_KEY_VALUE}":y.Authorization=`${(A==null?void 0:A.scheme)==="basic"?"Basic":"Bearer"} {${(A==null?void 0:A.scheme)==="basic"?"VALUE":"TOKEN"}}`);});});let q={};Object.keys(y).forEach(v=>{Array.isArray(y[v])?q[v]=y[v].join("; "):q[v]=y[v];}),h=`
35
+ `:"")+"export type "+s+" = "+(typeof p=="string"?p:se(p))+`;
36
+ `;});}});let be=t=>{let r="";if(t.content){let f=Object.keys(t.content);f[0]&&t.content[f[0]].schema&&(r+=`${L(m,t.content[f[0]].schema,"")}`);}return r},G=(t,r,f=0)=>{if(!t)return r==="joi"?"Joi.any()":r==="yup"?"yup.mixed()":"z.any()";if(t.$ref){if(t.$ref[0]==="#"){let l=t.$ref.split("/");l.shift();let a=l.join("."),o=xe(m,a);if(o)return G(o,r,f)}return r==="joi"?"Joi.any()":r==="yup"?"yup.mixed()":"z.any()"}if(t.anyOf||t.oneOf){let l=t.anyOf||t.oneOf;if(l.every(o=>o.enum!==void 0&&Array.isArray(o.enum))){let o=[],s=false;if(l.forEach(p=>{p.enum&&p.enum.forEach(i=>{i===null?s=true:o.includes(i)||o.push(i);});}),o.length>0){let p=o.map(i=>JSON.stringify(i)).join(", ");if(r==="zod"){let i=`z.enum([${p}])`;return s&&(i+=".nullable()"),i}else if(r==="yup"){let i=`yup.mixed().oneOf([${p}])`;return s&&(i+=".nullable()"),i}else return s?`Joi.valid(${p}, null)`:`Joi.valid(${p})`}else if(s)return r==="zod"?"z.null()":r==="yup"?"yup.mixed().nullable()":"Joi.valid(null)"}return r==="zod"?`z.union([${l.map(p=>G(p,r,f+1)).join(", ")}])`:r==="yup"?`yup.mixed().oneOf([${l.map(p=>G(p,r,f+1)).join(", ")}])`:`Joi.alternatives().try(${l.map(s=>G(s,r,f+1)).join(", ")})`}if(t.allOf)if(r==="zod"){let l=t.allOf.map(o=>G(o,r,f+1)),a=l[0];for(let o=1;o<l.length;o++)a=`${a}.merge(${l[o]})`;return a}else return G(t.allOf[0],r,f+1);if(t.items){let l=G(t.items,r,f+1);if(r==="zod"){let a=`z.array(${l})`;return t.minItems!==void 0&&(a+=`.min(${t.minItems})`),t.maxItems!==void 0&&(a+=`.max(${t.maxItems})`),a}else if(r==="yup"){let a=`yup.array().of(${l})`;return t.minItems!==void 0&&(a+=`.min(${t.minItems})`),t.maxItems!==void 0&&(a+=`.max(${t.maxItems})`),a}else {let a=`Joi.array().items(${l})`;return t.minItems!==void 0&&(a+=`.min(${t.minItems})`),t.maxItems!==void 0&&(a+=`.max(${t.maxItems})`),a}}if(t.properties){let l=t.required||[],a=" ".repeat(f+1),o=Object.entries(t.properties).map(([s,p])=>{let i=l.includes(s),h=G(p,r,f+1);return i||(h+=".optional()"),`${a}${s}: ${h}`}).join(`,
37
+ `);return r==="zod"?`z.object({
38
+ ${o}
39
+ ${" ".repeat(f)}})`:r==="yup"?`yup.object({
40
+ ${o}
41
+ ${" ".repeat(f)}})`:`Joi.object({
42
+ ${o}
43
+ ${" ".repeat(f)}})`}if(t.enum&&t.enum.length>0){let l=[],a=false;t.enum.forEach(s=>{s===null?a=true:l.includes(s)||l.push(s);});let o=l.map(s=>JSON.stringify(s)).join(", ");if(console.log("zod enum 3 here",{schema:t,enumValues:o}),r==="zod"){let s=`z.enum([${o}])`;return a&&(s+=".nullable()"),s}else if(r==="yup"){let s=`yup.mixed().oneOf([${o}])`;return a&&(s+=".nullable()"),s}else {let s=`Joi.valid(${o})`;return a&&(s+=".allow(null)"),s}}if(t.type){let a=(o=>{switch(o){case "string":if(r==="zod"){let s="z.string()";return t.format==="email"?s+=".email()":t.format==="uuid"?s+=".uuid()":t.format==="url"||t.format==="uri"?s+=".url()":t.format==="date-time"?s+=".datetime()":t.format==="date"&&(s+=".date()"),t.minLength&&(s+=`.min(${t.minLength})`),t.maxLength&&(s+=`.max(${t.maxLength})`),t.pattern&&(s+=`.regex(/${t.pattern}/)`),s}else if(r==="yup"){let s="yup.string()";return t.format==="email"?s+=".email()":(t.format==="url"||t.format==="uri")&&(s+=".url()"),t.minLength&&(s+=`.min(${t.minLength})`),t.maxLength&&(s+=`.max(${t.maxLength})`),t.pattern&&(s+=`.matches(/${t.pattern}/)`),s}else {let s="Joi.string()";return t.format==="email"?s+=".email()":t.format==="url"||t.format==="uri"?s+=".uri()":t.format==="uuid"?s+=".guid({ version: 'uuidv4' })":t.format==="date-time"&&(s+=".isoDate()"),t.minLength&&(s+=`.min(${t.minLength})`),t.maxLength&&(s+=`.max(${t.maxLength})`),t.pattern&&(s+=`.pattern(/${t.pattern}/)`),s}case "integer":case "number":if(r==="zod"){let s="z.number()";return o==="integer"&&(s+=".int()"),t.minimum!==void 0&&(t.exclusiveMinimum?s+=`.gt(${t.minimum})`:s+=`.min(${t.minimum})`),t.maximum!==void 0&&(t.exclusiveMaximum?s+=`.lt(${t.maximum})`:s+=`.max(${t.maximum})`),s}else if(r==="yup"){let s="yup.number()";return o==="integer"&&(s+=".integer()"),t.minimum!==void 0&&(s+=`.min(${t.minimum})`),t.maximum!==void 0&&(s+=`.max(${t.maximum})`),s}else {let s="Joi.number()";return o==="integer"&&(s+=".integer()"),t.minimum!==void 0&&(t.exclusiveMinimum?s+=`.greater(${t.minimum})`:s+=`.min(${t.minimum})`),t.maximum!==void 0&&(t.exclusiveMaximum?s+=`.less(${t.maximum})`:s+=`.max(${t.maximum})`),s}case "boolean":return r==="joi"?"Joi.boolean()":r==="yup"?"yup.boolean()":"z.boolean()";case "null":return r==="joi"?"Joi.any().allow(null)":r==="yup"?"yup.mixed().nullable()":"z.null()";default:return r==="joi"?"Joi.any()":r==="yup"?"yup.mixed()":"z.any()"}})(typeof t.type=="string"?t.type:t.type[0]);return t.nullable&&r!=="joi"?a+=".nullable()":t.nullable&&r==="joi"&&(a+=".allow(null)"),a}return r==="joi"?"Joi.any()":r==="yup"?"yup.mixed()":"z.any()"},Bt=t=>{var r,f,l,a,o;if((f=(r=e==null?void 0:e.endpoints)==null?void 0:r.value)!=null&&f.replaceWords&&Array.isArray(e==null?void 0:e.endpoints.value.replaceWords)){let s=t;return (o=(a=(l=e==null?void 0:e.endpoints)==null?void 0:l.value)==null?void 0:a.replaceWords)==null||o.forEach((p,i)=>{let h=new RegExp(p.replace,"g");s=s.replace(h,p.with||"");}),s}else return t},Pt=(t,r,f=[])=>{var o,s;let l=(o=e==null?void 0:e.endpoints)==null?void 0:o.exclude,a=(s=e==null?void 0:e.endpoints)==null?void 0:s.include;if(a){let p=a.tags&&a.tags.length>0?f.some(h=>a.tags.includes(h)):true,i=a.endpoints&&a.endpoints.length>0?a.endpoints.some(h=>{let z=!h.method||h.method.toLowerCase()===r.toLowerCase();return h.path?t===h.path&&z:h.regex?new RegExp(h.regex).test(t)&&z:false}):true;if(!p||!i)return true}return !!(l&&(l.tags&&l.tags.length>0&&f.some(i=>l.tags.includes(i))||l.endpoints&&l.endpoints.length>0&&l.endpoints.some(i=>{let h=!i.method||i.method.toLowerCase()===r.toLowerCase();return i.path?t===i.path&&h:i.regex?new RegExp(i.regex).test(t)&&h:false})))};if(Object.keys(m.paths||{}).forEach(t=>{let r=m.paths[t];Object.keys(r).forEach(l=>{var pe,Ne,ke,Re,Je,Me,qe,Be,Pe,Le,Fe,Ge,Ue,Ve,Ke,We,De,Qe,Ye,Ze,He,Xe,_e,ge,et,tt,rt,nt,st,at,ot,it,lt,pt,ut,mt,dt,yt,ft,$t,xt,Ot,It,ht,bt,jt,vt,Ct;let a=l,o=St(t,a),s=((pe=r[a])==null?void 0:pe.tags)||[];if(Pt(t,a,s))return;let p=r[a],i=E({method:a,path:t,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId,tags:s,parameters:p==null?void 0:p.parameters,requestBody:p==null?void 0:p.requestBody,responses:p==null?void 0:p.responses});O[i]||(O[i]={endpoints:"",types:"",validation:""});let h=((ke=(Ne=e==null?void 0:e.endpoints)==null?void 0:Ne.value)!=null&&ke.includeServer?P:"")+o.pathParts.map(x=>(x[0]==="{"&&x[x.length-1]==="}"?x=`\${${x.replace(/{/,"").replace(/}/,"")}}`:x[0]==="<"&&x[x.length-1]===">"?x=`\${${x.replace(/</,"").replace(/>/,"")}}`:x[0]===":"&&(x=`\${${x.replace(/:/,"")}}`),x)).join("/"),z=`"${h}"`;o.variables.length>0&&(z=`(${o.variables.map(I=>`${I}:string`).join(",")})=> \`${h}\``),z=Bt(z);let n=r[a],$="";if(n!=null&&n.parameters&&((n==null?void 0:n.parameters).forEach((I,A)=>{(I.$ref||I.in==="query"&&I.name)&&($+=`${L(m,I.$ref?I:I.schema,I.name||"",I.required)}`);}),$)){$=`{
44
+ ${$}}`;let I=`${o.name}Query`;if((Je=(Re=e==null?void 0:e.types)==null?void 0:Re.name)!=null&&Je.useOperationId&&(n!=null&&n.operationId)&&(I=`${n.operationId}Query`),I=K(`${B}${I}`),(qe=(Me=e==null?void 0:e.types)==null?void 0:Me.name)!=null&&qe.format){let S=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"query",method:a,path:t,summary:n==null?void 0:n.summary,operationId:n==null?void 0:n.operationId},I);S&&(I=`${B}${S}`);}let A=`export type ${I} = ${$};
45
+ `;e!=null&&e.folderSplit?O[i].types+=A:g+=A;}if(((Be=e==null?void 0:e.validations)==null?void 0:Be.disable)!==true&&((Le=(Pe=e==null?void 0:e.validations)==null?void 0:Pe.generate)==null?void 0:Le.query)!==false&&(n!=null&&n.parameters)){let x=((Fe=e.validations)==null?void 0:Fe.library)||"zod",A=n.parameters.filter(S=>!S.$ref&&S.in==="query"&&S.name);if(A.length>0){let S=((Ge=e==null?void 0:e.validations)==null?void 0:Ge.name)||((Ue=e==null?void 0:e.types)==null?void 0:Ue.name),J=typeof(S==null?void 0:S.prefix)=="string"?S.prefix:"I",c=typeof((Ke=(Ve=e==null?void 0:e.validations)==null?void 0:Ve.name)==null?void 0:Ke.suffix)=="string"?e.validations.name.suffix:"Schema",w=`${o.name}Query`;if(S!=null&&S.useOperationId&&(n!=null&&n.operationId)&&(w=`${n.operationId}Query`),w=K(`${J}${w}${c}`),(De=(We=e==null?void 0:e.validations)==null?void 0:We.name)!=null&&De.format){let F=e.validations.name.format({code:"",type:"query",method:a,path:t,summary:n==null?void 0:n.summary,operationId:n==null?void 0:n.operationId},w);F&&(w=`${J}${F}${c}`);}else if((Ye=(Qe=e==null?void 0:e.types)==null?void 0:Qe.name)!=null&&Ye.format){let F=e.types.name.format("endpoint",{code:"",type:"query",method:a,path:t,summary:n==null?void 0:n.summary,operationId:n==null?void 0:n.operationId},w);F&&(w=`${J}${F}${c}`);}let T=A.map(F=>{let Lt=F!=null&&F.schema?G(F.schema,x):x==="joi"?"Joi.string()":x==="yup"?"yup.string()":"z.string()",Ft=F.required?"":".optional()";return ` ${F.name}: ${Lt}${Ft}`}).join(`,
46
+ `),D=`export const ${w} = ${x==="joi"?"Joi.object":x==="yup"?"yup.object":"z.object"}({
47
+ ${T}
48
+ });
49
+
50
+ `;e!=null&&e.folderSplit||O[i]||(O[i]={endpoints:"",types:"",validation:""}),O[i].validation+=D;}}let C=n==null?void 0:n.requestBody,N="";if(C&&(N=be(C),N)){let x=`${o.name}DTO`;if((He=(Ze=e==null?void 0:e.types)==null?void 0:Ze.name)!=null&&He.useOperationId&&(n!=null&&n.operationId)&&(x=`${n.operationId}DTO`),x=K(`${B}${x}`),(_e=(Xe=e==null?void 0:e.types)==null?void 0:Xe.name)!=null&&_e.format){let A=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"dto",method:a,path:t,summary:n==null?void 0:n.summary,operationId:n==null?void 0:n.operationId},x);A&&(x=`${B}${A}`);}let I=`export type ${x} = ${N};
51
+ `;e!=null&&e.folderSplit?O[i].types+=I:g+=I;}if(((ge=e==null?void 0:e.validations)==null?void 0:ge.disable)!==true&&((tt=(et=e==null?void 0:e.validations)==null?void 0:et.generate)==null?void 0:tt.dto)!==false&&C){let x=((rt=e.validations)==null?void 0:rt.library)||"zod";if(C.content){let I=Object.keys(C.content);if(I[0]&&C.content[I[0]].schema){let A=((nt=e==null?void 0:e.validations)==null?void 0:nt.name)||((st=e==null?void 0:e.types)==null?void 0:st.name),S=typeof(A==null?void 0:A.prefix)=="string"?A.prefix:"I",J=typeof((ot=(at=e==null?void 0:e.validations)==null?void 0:at.name)==null?void 0:ot.suffix)=="string"?e.validations.name.suffix:"Schema",c=`${o.name}DTO`;if(A!=null&&A.useOperationId&&(n!=null&&n.operationId)&&(c=`${n.operationId}DTO`),c=K(`${S}${c}${J}`),(lt=(it=e==null?void 0:e.validations)==null?void 0:it.name)!=null&&lt.format){let q=e.validations.name.format({code:"",type:"dto",method:a,path:t,summary:n==null?void 0:n.summary,operationId:n==null?void 0:n.operationId},c);q&&(c=`${S}${q}${J}`);}else if((ut=(pt=e==null?void 0:e.types)==null?void 0:pt.name)!=null&&ut.format){let q=e.types.name.format("endpoint",{code:"",type:"dto",method:a,path:t,summary:n==null?void 0:n.summary,operationId:n==null?void 0:n.operationId},c);q&&(c=`${S}${q}${J}`);}let w=G(C.content[I[0]].schema,x),T=`export const ${c} = ${w};
52
+
53
+ `;e!=null&&e.folderSplit||O[i]||(O[i]={endpoints:"",types:"",validation:""}),O[i].validation+=T;}}}let k={},R="";if(n!=null&&n.responses){let x=n==null?void 0:n.responses;Object.keys(x).forEach(A=>{var S,J,c,w;if(R=be(x[A]),k[A]=R,R){let T=`${o.name}${A}Response`;if((J=(S=e==null?void 0:e.types)==null?void 0:S.name)!=null&&J.useOperationId&&(n!=null&&n.operationId)&&(T=`${n.operationId}${A}Response`),T=K(`${B}${T}`),(w=(c=e==null?void 0:e.types)==null?void 0:c.name)!=null&&w.format){let D=e==null?void 0:e.types.name.format("endpoint",{code:A,type:"response",method:a,path:t,summary:n==null?void 0:n.summary,operationId:n==null?void 0:n.operationId},T);D&&(T=`${B}${D}`);}let q=`export type ${T} = ${R};
54
+ `;e!=null&&e.folderSplit?O[i].types+=q:g+=q;}});}let ee=x=>!x||!x.length?"":x.map(I=>Object.entries(I).map(([S,J])=>{let c=S,w="";return Array.isArray(J)&&J.length&&(w=`
55
+ - Scopes: [\`${J.join("`, `")}\`]`,c=`**${c}**`),`
56
+ - ${c}${w}`}).join("")).join(`
57
+ `),W=n!=null&&n.security?ee(n.security):"",Q="";if(!((dt=(mt=e==null?void 0:e.endpoints)==null?void 0:mt.doc)!=null&&dt.disable)){let x="";if((ft=(yt=e==null?void 0:e.endpoints)==null?void 0:yt.doc)!=null&&ft.showCurl){let I={},A="",S="";($t=n.requestBody)!=null&&$t.content&&Object.keys(n.requestBody.content).forEach(w=>{let T=n.requestBody.content[w].schema;if(T){Array.isArray(I["Content-type"])?I["Content-type"].push(w):I["Content-type"]=[w];let q=V(m,T);q&&(A=q);}}),n!=null&&n.security&&n.security.forEach(c=>{Object.keys(c).forEach(w=>{var q,D;let T=(D=(q=m.components)==null?void 0:q.securitySchemes)==null?void 0:D[w];T&&(T.type==="mutualTLS"?S+=`
58
+ --cert client-certificate.crt --key client-private-key.key --cacert ca-certificate.crt`:T.type==="apiKey"?I[(T==null?void 0:T.name)||"X-API-KEY"]="{API_KEY_VALUE}":I.Authorization=`${(T==null?void 0:T.scheme)==="basic"?"Basic":"Bearer"} {${(T==null?void 0:T.scheme)==="basic"?"VALUE":"TOKEN"}}`);});});let J={};Object.keys(I).forEach(c=>{Array.isArray(I[c])?J[c]=I[c].join("; "):J[c]=I[c];}),x=`
45
59
  \`\`\`bash
46
- ${CurlGenerator({url:B+s,method:a.toUpperCase(),headers:q,body:k})}${P}
47
- \`\`\``;}K=`/**${t!=null&&t.description?`
48
- * ${t==null?void 0:t.description} `:""}
60
+ ${CurlGenerator({url:P+t,method:a.toUpperCase(),headers:J,body:A})}${S}
61
+ \`\`\``;}Q=`/**${n!=null&&n.description?`
62
+ * ${n==null?void 0:n.description} `:""}
49
63
  * **Method**: \`${a.toUpperCase()}\`
50
- * **Summary**: ${(t==null?void 0:t.summary)||""}
51
- * **Tags**: [${((Ue=t==null?void 0:t.tags)==null?void 0:Ue.join(", "))||""}]
52
- * **OperationId**: ${(t==null?void 0:t.operationId)||""} ${u?`
53
- * **Query**: ${le(u)} `:""}${S?`
54
- * **DTO**: ${le(S)} `:""}${N?`
55
- * **Response**: ${Object.entries(w).map(([y,k])=>`
56
- - **${y}**: ${le(k,2)} `).join("")}`:""}${J?`
57
- * **Security**: ${J}
58
- `:""}${h}
64
+ * **Summary**: ${(n==null?void 0:n.summary)||""}
65
+ * **Tags**: [${((xt=n==null?void 0:n.tags)==null?void 0:xt.join(", "))||""}]
66
+ * **OperationId**: ${(n==null?void 0:n.operationId)||""} ${$?`
67
+ * **Query**: ${ue($)} `:""}${N?`
68
+ * **DTO**: ${ue(N)} `:""}${R?`
69
+ * **Response**: ${Object.entries(k).map(([I,A])=>`
70
+ - **${I}**: ${ue(A,2)} `).join("")}`:""}${W?`
71
+ * **Security**: ${W}
72
+ `:""}${x}
59
73
  */
60
- `;}let Y=(Le=(Je=e==null?void 0:e.endpoints)==null?void 0:Je.name)!=null&&Le.useOperationId&&((ze=t==null?void 0:t.operationId)==null?void 0:ze.length)>0?t.operationId:`${m.name}`;if((We=(Ke=e==null?void 0:e.endpoints)==null?void 0:Ke.name)!=null&&We.format){let h=e==null?void 0:e.endpoints.name.format({method:a,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},Y);h&&(Y=h);}let ae={method:`"${a}"`,operationId:`"${t==null?void 0:t.operationId}"`,url:T,tags:(t==null?void 0:t.tags)||[]},D=`${K}export const ${Q}${Y} = ${((Ye=(Ve=e==null?void 0:e.endpoints)==null?void 0:Ve.value)==null?void 0:Ye.type)==="object"?ee(ae):T};
61
- `;e!=null&&e.folderSplit?f[d].endpoints+=D:me+=D;});}),e!=null&&e.folderSplit){for(let[s,r]of Object.entries(f))if(r.endpoints||r.types){let j=F.join(p,s);if(r.endpoints){let b=F.join(se,j,"endpoints.ts");yield z.promises.mkdir(F.dirname(b),{recursive:true}),yield ne(b,r.endpoints,e);}if(r.types){let b=F.join(se,j,"types.ts");yield z.promises.mkdir(F.dirname(b),{recursive:true});let a=Object.values(V).length>0?`import * as Shared from "../shared";
74
+ `;}let X=(It=(Ot=e==null?void 0:e.endpoints)==null?void 0:Ot.name)!=null&&It.useOperationId&&((ht=n==null?void 0:n.operationId)==null?void 0:ht.length)>0?n.operationId:`${o.name}`;if((jt=(bt=e==null?void 0:e.endpoints)==null?void 0:bt.name)!=null&&jt.format){let x=e==null?void 0:e.endpoints.name.format({method:a,path:t,summary:n==null?void 0:n.summary,operationId:n==null?void 0:n.operationId},X);x&&(X=x);}let le={method:`"${a}"`,operationId:`"${n==null?void 0:n.operationId}"`,url:z,tags:(n==null?void 0:n.tags)||[]},te=`${Q}export const ${_}${X} = ${((Ct=(vt=e==null?void 0:e.endpoints)==null?void 0:vt.value)==null?void 0:Ct.type)==="object"?se(le):z};
75
+ `;e!=null&&e.folderSplit?O[i].endpoints+=te:ye+=te;});}),e!=null&&e.folderSplit){for(let[t,r]of Object.entries(O))if(r.endpoints||r.types){let f=M.join(y,t);if(r.endpoints){let l=M.join(Y,f,"endpoints.ts");yield U.promises.mkdir(M.dirname(l),{recursive:true}),yield Z(l,r.endpoints,e);}if(r.types){let l=M.join(Y,f,"types.ts");yield U.promises.mkdir(M.dirname(l),{recursive:true});let a=Object.values(H).length>0?`import * as Shared from "../shared";
76
+
77
+ ${r.types}`:r.types;yield Z(l,a,e);}if(((Te=e==null?void 0:e.validations)==null?void 0:Te.disable)!==true&&r.validation){let l=((Se=e.validations)==null?void 0:Se.library)||"zod",a=l==="joi"?'import Joi from "joi";':l==="yup"?'import * as yup from "yup";':'import { z } from "zod";',o=M.join(Y,f,"validations.ts");yield U.promises.mkdir(M.dirname(o),{recursive:true}),yield Z(o,`${a}
78
+
79
+ ${r.validation}`,e);}}}if(ye.length>0){let t=M.join(Y,y,"endpoints.ts");yield U.promises.mkdir(M.dirname(t),{recursive:true}),yield Z(t,ye,e);}if(Object.values(H).length>0){let t=M.join(Y,y,e!=null&&e.folderSplit?"":"types","shared.ts");yield U.promises.mkdir(M.dirname(t),{recursive:true}),yield Z(t,Object.values(H).join(`
80
+ `),e);}if(g.length>0){let t=M.join(Y,y,"types","index.ts");yield U.promises.mkdir(M.dirname(t),{recursive:true}),yield Z(t,`${Object.values(H).length>0?`import * as Shared from "./shared";
62
81
 
63
- ${r.types}`:r.types;yield ne(b,a,e);}}}if(me.length>0){let s=F.join(se,p,"endpoints.ts");yield z.promises.mkdir(F.dirname(s),{recursive:true}),yield ne(s,me,e);}if(Object.values(V).length>0){let s=F.join(se,p,e!=null&&e.folderSplit?"":"types","shared.ts");yield z.promises.mkdir(F.dirname(s),{recursive:true}),yield ne(s,Object.values(V).join(`
64
- `),e);}if(Z.length>0){let s=F.join(se,p,"types","index.ts");yield z.promises.mkdir(F.dirname(s),{recursive:true}),yield ne(s,`${Object.values(V).length>0?`import * as Shared from "./shared";
82
+ `:""}${g}`,e);}if(((we=e==null?void 0:e.validations)==null?void 0:we.disable)!==true){let t=((ze=e.validations)==null?void 0:ze.library)||"zod",r=t==="joi"?'import Joi from "joi";':t==="yup"?'import * as yup from "yup";':'import { z } from "zod";',f=Object.values(O).map(l=>l.validation).filter(l=>l.length>0).join("");if(f){let l=M.join(Y,y,"validations.ts");yield U.promises.mkdir(M.dirname(l),{recursive:true}),yield Z(l,`${r}
65
83
 
66
- `:""}${Z}`,e);}}),at=ot;var $e=process.cwd(),Vt=n=>_(null,null,function*(){let i;try{X("esbuild-register");}catch(x){throw x}let e=F.join($e,"openapi.sync.js"),O=F.join($e,"openapi.sync.ts"),$=F.join($e,"openapi.sync.json"),I=[e,O,$];try{for(let x of I)z.existsSync(x)&&(i=X(x),Object.keys(i).length===1&&i.default&&(i=i.default));}catch(x){console.log(x);}typeof i=="function"&&(i=i());let o=i;if(!o)throw new Error("No config found");let p=Object.keys(o.api),f=n&&"refetchInterval"in n&&!isNaN(n==null?void 0:n.refetchInterval)?n.refetchInterval:o.refetchInterval;rt();for(let x=0;x<p.length;x+=1){let B=p[x],R=o.api[B];at(R,B,o,f);}});export{Vt as Init,ee as JSONStringify,W as capitalize,Ze as createCustomCodeMarker,dt as extractCustomCode,He as getEndpointDetails,xt as getNestedValue,ge as isJson,pt as isYamlString,Xe as mergeCustomCode,le as renderTypeRefMD,Ot as variableName,Qe as variableNameChar,De as yamlStringToJson};
84
+ ${f}`,e);}}}),qt=Mt;var he=process.cwd(),Cr=u=>ne(null,null,function*(){let d;try{re("esbuild-register");}catch(E){throw E}let e=M.join(he,"openapi.sync.js"),j=M.join(he,"openapi.sync.ts"),b=M.join(he,"openapi.sync.json"),v=[e,j,b];try{for(let E of v)U.existsSync(E)&&(d=re(E),Object.keys(d).length===1&&d.default&&(d=d.default));}catch(E){console.log(E);}typeof d=="function"&&(d=d());let m=d;if(!m)throw new Error("No config found");let y=Object.keys(m.api),O=u&&"refetchInterval"in u&&!isNaN(u==null?void 0:u.refetchInterval)?u.refetchInterval:m.refetchInterval;Rt();for(let E=0;E<y.length;E+=1){let P=y[E],B=m.api[P];qt(B,P,m,O);}});export{Cr as Init,se as JSONStringify,K as capitalize,At as createCustomCodeMarker,Ut as extractCustomCode,St as getEndpointDetails,er as getNestedValue,ct as isJson,Gt as isYamlString,wt as mergeCustomCode,ue as renderTypeRefMD,Xt as variableName,Et as variableNameChar,Tt as yamlStringToJson};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "openapi-sync",
3
- "version": "3.0.2",
4
- "description": "A developer-friendly tool designed to keep your API up-to-date by leveraging OpenAPI schemas. It automates the generation of endpoint URIs and type definitions, including shared types, directly from your OpenAPI specification.",
3
+ "version": "4.0.0",
4
+ "description": "A powerful developer tool that automates API documentation synchronization with your codebase using OpenAPI specifications. Generates TypeScript types, endpoint definitions, runtime validation schemas (Zod, Yup, Joi), and comprehensive documentation",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "bin": {
@@ -15,6 +15,12 @@
15
15
  "typescript",
16
16
  "ts",
17
17
  "dts",
18
+ "zod",
19
+ "yup",
20
+ "joi",
21
+ "validation schema",
22
+ "validation schema generation",
23
+ "validation schema generator",
18
24
  "node",
19
25
  "codegen",
20
26
  "generation",
@@ -28,31 +34,24 @@
28
34
  "dist/**/*.d.ts",
29
35
  "dist/**/*.d.mts",
30
36
  "!dist/**/*.map",
31
- "db.json",
32
37
  "LICENSE",
33
38
  "README.md",
34
- "package.json"
39
+ "package.json",
40
+ "!website/**/*"
35
41
  ],
36
42
  "repository": {
37
43
  "type": "git",
38
44
  "url": "https://github.com/akintomiwa-fisayo/openapi-sync"
39
45
  },
40
- "homepage": "https://github.com/akintomiwa-fisayo/openapi-sync#readme",
46
+ "homepage": "https://openapi-sync.com",
41
47
  "bugs": {
42
48
  "url": "https://github.com/akintomiwa-fisayo/openapi-sync/issues"
43
49
  },
44
50
  "scripts": {
45
- "build-tsc": "rm -rf dist db.json && tsc && echo '{}' > db.json",
46
51
  "build": "rm -rf dist db.json && tsup && echo '{}' > db.json",
47
52
  "publish-package": "npm run build && npm publish",
48
53
  "test": "jest",
49
- "test:watch": "jest --watch",
50
- "test:coverage": "jest --coverage",
51
- "test:ci": "jest --ci --coverage --watchAll=false",
52
- "analyze:size": "npm run build && du -sh dist/* | sort -h",
53
- "analyze:detailed": "npm run build && du -h dist/* && echo '\nšŸ“Š Total dist size:' && du -sh dist",
54
- "analyze:deps": "npm list --depth=0 --production",
55
- "analyze:bundle": "npm run build && node scripts/analyze-bundle.js"
54
+ "test:coverage": "jest --coverage"
56
55
  },
57
56
  "author": "P-Technologies",
58
57
  "license": "ISC",
@@ -79,5 +78,21 @@
79
78
  "lodash.get": "^4.4.2",
80
79
  "lodash.isequal": "^4.5.0",
81
80
  "yargs": "^17.7.2"
81
+ },
82
+ "peerDependencies": {
83
+ "zod": "^3.22.0",
84
+ "yup": "^1.3.0",
85
+ "joi": "^17.11.0"
86
+ },
87
+ "peerDependenciesMeta": {
88
+ "zod": {
89
+ "optional": true
90
+ },
91
+ "yup": {
92
+ "optional": true
93
+ },
94
+ "joi": {
95
+ "optional": true
96
+ }
82
97
  }
83
98
  }
package/db.json DELETED
@@ -1 +0,0 @@
1
- {}