openapi-sync 5.0.3 → 5.0.4
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.d.mts
CHANGED
|
@@ -496,6 +496,7 @@ declare const JSONStringify: (obj: Record<string, any>, indent?: number) => stri
|
|
|
496
496
|
* Render TypeScript type reference as markdown code block
|
|
497
497
|
*
|
|
498
498
|
* Formats a TypeScript type definition for inclusion in markdown documentation.
|
|
499
|
+
* Converts multiline/JSDoc comments to single-line comments to prevent breaking outer JSDoc.
|
|
499
500
|
*
|
|
500
501
|
* @param {string} typeRef - TypeScript type definition
|
|
501
502
|
* @param {number} [indent=1] - Indentation level
|
package/dist/index.d.ts
CHANGED
|
@@ -496,6 +496,7 @@ declare const JSONStringify: (obj: Record<string, any>, indent?: number) => stri
|
|
|
496
496
|
* Render TypeScript type reference as markdown code block
|
|
497
497
|
*
|
|
498
498
|
* Formats a TypeScript type definition for inclusion in markdown documentation.
|
|
499
|
+
* Converts multiline/JSDoc comments to single-line comments to prevent breaking outer JSDoc.
|
|
499
500
|
*
|
|
500
501
|
* @param {string} typeRef - TypeScript type definition
|
|
501
502
|
* @param {number} [indent=1] - Indentation level
|
package/dist/index.js
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
`+" ".repeat(o)+t+": ",Array.isArray(l)){i+="[";for(let n=0;n<l.length;n++){let y=l[n];typeof y=="object"&&y!==null?i+=exports.JSONStringify(y,o+1):i+=typeof y=="string"?`"${y}"`:y,n<l.length-1&&(i+=", ");}i+="]";}else typeof l=="object"&&l!==null?i+=""+exports.JSONStringify(l,o+1):i+=l.split(`
|
|
3
3
|
`).filter(n=>n.trim()!=="").join(`
|
|
4
4
|
${" ".repeat(o)}`);a<e.length-1&&(i+=", ");}return i+=`
|
|
5
|
-
${" ".repeat(o-1)}}`,i},exports.renderTypeRefMD=(r,o=1)
|
|
5
|
+
${" ".repeat(o-1)}}`,i},exports.renderTypeRefMD=(r,o=1)=>{let i=r.replace(/\/\*\*?[\s\S]*?\*\//g,e=>e.replace(/^\/\*\*?\s*/,"").replace(/\s*\*\/$/,"").split(`
|
|
6
|
+
`).map(t=>t.replace(/^\s*\*\s?/,"").trim()).filter(t=>t.length>0).map(t=>`// ${t}`).join(`
|
|
7
|
+
`));return `
|
|
6
8
|
\`\`\`typescript
|
|
7
|
-
${" ".repeat(o)} ${
|
|
8
|
-
`).filter(
|
|
9
|
+
${" ".repeat(o)} ${i.split(`
|
|
10
|
+
`).filter(e=>e.trim()!=="").join(`
|
|
9
11
|
${" ".repeat(o)} `)}
|
|
10
|
-
|
|
12
|
+
\`\`\``};exports.extractCustomCode=(r,o="CUSTOM CODE")=>{let i=`// \u{1F512} ${o} START`,e=`// \u{1F512} ${o} END`,a={beforeGenerated:"",afterGenerated:""},t=0,l=[];for(;t<r.length;){let n=r.indexOf(i,t);if(n===-1)break;let y=r.indexOf(e,n);if(y===-1)break;let c=y+e.length,f=r.substring(c,c+100),S=f.match(/^\s*\n\s*(\/\/ =+)/);if(S){let j=f.indexOf(`
|
|
11
13
|
`,S.index+1);j!==-1?c+=j+1:c+=S[0].length;}let q=n,E=r.substring(Math.max(0,n-200),n).lastIndexOf("// ==========");E!==-1&&(q=Math.max(0,n-200)+E);let v=r.substring(q,c);l.push({start:q,end:c,content:v}),t=c;}return l.length>0&&(r.substring(0,l[0].start).split(`
|
|
12
14
|
`).filter(c=>{let f=c.trim();return f.length>0&&!f.startsWith("//")}).join("").length===0?(a.beforeGenerated=l[0].content,l.length>1&&(a.afterGenerated=l[1].content)):(a.afterGenerated=l[0].content,l.length>1&&!a.beforeGenerated&&(a.beforeGenerated=l[1].content))),a},exports.createCustomCodeMarker=(r,o="CUSTOM CODE",i=true)=>{let e=i?`// ${r==="top"?"Add your custom code below this line":"Add your custom code above this line"}
|
|
13
15
|
// This section will be preserved during regeneration
|
|
@@ -17,41 +19,41 @@ ${e}// ${"=".repeat(60)}
|
|
|
17
19
|
|
|
18
20
|
// \u{1F512} ${o} END
|
|
19
21
|
// ${"=".repeat(60)}`},exports.mergeCustomCode=(r,o,i={})=>{let{position:e="bottom",markerText:a="CUSTOM CODE",includeInstructions:t=true}=i,l={beforeGenerated:"",afterGenerated:""};o&&(l=exports.extractCustomCode(o,a)),!l.beforeGenerated&&!l.afterGenerated&&((e==="top"||e==="both")&&(l.beforeGenerated=exports.createCustomCodeMarker("top",a,t)),(e==="bottom"||e==="both")&&(l.afterGenerated=exports.createCustomCodeMarker("bottom",a,t)));let n=[];return l.beforeGenerated&&(n.push(l.beforeGenerated),n.push("")),n.push(r),l.afterGenerated&&(n.push(""),n.push(l.afterGenerated)),n.join(`
|
|
20
|
-
`)};});var Ue,Je,Se,mn,dn,fn,He,Ke=pe(()=>{Ue=D__default.default.join(__dirname,"../","../db.json");le__default.default.existsSync(Ue)||le__default.default.writeFileSync(Ue,"{}");Je={};try{Je=Ae(Ue);}catch(r){Je={};}Se=Je||{},mn=r=>{le__default.default.writeFileSync(Ue,JSON.stringify(r));},dn=(r,o)=>{Se[r]=o,mn(Se);},fn=r=>Se[r],He=()=>{Se={},mn(Se);};});var yn,gn,hn,_e=pe(()=>{yn={},gn=(r,o)=>{yn[r]=o;},hn=r=>yn[r]||[];});var fe,Ye,$n,$e,Cn,Hn,Ze,bn=pe(()=>{ke();Ke();_e();fe=process.cwd(),Ye={},$n=zn__default.default.create({timeout:6e4});Wn__default.default($n,{retries:20,retryCondition:r=>r.code==="ECONNABORTED"||r.message.includes("Network Error"),retryDelay:r=>r*1e3});$e=(r,o,i)=>re(null,null,function*(){var l,n,y,c;if(!(((l=i==null?void 0:i.customCode)==null?void 0:l.enabled)!==false)){yield le__default.default.promises.writeFile(r,o);return}let a=null;try{a=yield le__default.default.promises.readFile(r,"utf-8");}catch(f){}let t=exports.mergeCustomCode(o,a,{position:((n=i==null?void 0:i.customCode)==null?void 0:n.position)||"bottom",markerText:(y=i==null?void 0:i.customCode)==null?void 0:y.markerText,includeInstructions:(c=i==null?void 0:i.customCode)==null?void 0:c.includeInstructions});yield le__default.default.promises.writeFile(r,t);}),Cn=(r,o,i,e)=>re(null,null,function*(){let a=yield Hn(r,o,i,e);return e&&!isNaN(e)&&e>0&&(process.env.NODE_ENV&&["production","prod","test","staging"].includes(process.env.NODE_ENV)||(Ye[o]&&clearTimeout(Ye[o]),Ye[o]=setTimeout(()=>{console.info(`\u{1F504} Auto syncing ${o}`),Cn(r,o,i,e);},e))),a}),Hn=(...r)=>re(null,null,function*(){var ce,Ee,xe,Re,rt,ot,st,at,it,lt;let[o,i,e]=r,a=s=>s.startsWith("http://")||s.startsWith("https://"),t;try{if(a(o))t=(yield $n.get(o)).data;else {let s=D__default.default.isAbsolute(o)?o:D__default.default.join(fe,o);`${s}`,t=yield le__default.default.promises.readFile(s,"utf-8");}}catch(s){console.error(`Failed to load OpenAPI spec for ${i}:`,s);return}if(!t)return;let l=exports.isJson(t)?t:exports.yamlStringToJson(t),n;try{n=yield Dn__default.default.parse(l);}catch(s){let u=s instanceof Error?s.message:String(s);throw new Error(`Failed to parse OpenAPI spec for ${i}: ${u}`)}let y=D__default.default.join((e==null?void 0:e.folder)||"",i),c={},f=s=>{var u,
|
|
22
|
+
`)};});var Ue,Je,Se,mn,dn,fn,He,Ke=pe(()=>{Ue=D__default.default.join(__dirname,"../","../db.json");le__default.default.existsSync(Ue)||le__default.default.writeFileSync(Ue,"{}");Je={};try{Je=Ae(Ue);}catch(r){Je={};}Se=Je||{},mn=r=>{le__default.default.writeFileSync(Ue,JSON.stringify(r));},dn=(r,o)=>{Se[r]=o,mn(Se);},fn=r=>Se[r],He=()=>{Se={},mn(Se);};});var yn,gn,hn,_e=pe(()=>{yn={},gn=(r,o)=>{yn[r]=o;},hn=r=>yn[r]||[];});var fe,Ye,$n,$e,Cn,Hn,Ze,bn=pe(()=>{ke();Ke();_e();fe=process.cwd(),Ye={},$n=zn__default.default.create({timeout:6e4});Wn__default.default($n,{retries:20,retryCondition:r=>r.code==="ECONNABORTED"||r.message.includes("Network Error"),retryDelay:r=>r*1e3});$e=(r,o,i)=>re(null,null,function*(){var l,n,y,c;if(!(((l=i==null?void 0:i.customCode)==null?void 0:l.enabled)!==false)){yield le__default.default.promises.writeFile(r,o);return}let a=null;try{a=yield le__default.default.promises.readFile(r,"utf-8");}catch(f){}let t=exports.mergeCustomCode(o,a,{position:((n=i==null?void 0:i.customCode)==null?void 0:n.position)||"bottom",markerText:(y=i==null?void 0:i.customCode)==null?void 0:y.markerText,includeInstructions:(c=i==null?void 0:i.customCode)==null?void 0:c.includeInstructions});yield le__default.default.promises.writeFile(r,t);}),Cn=(r,o,i,e)=>re(null,null,function*(){let a=yield Hn(r,o,i,e);return e&&!isNaN(e)&&e>0&&(process.env.NODE_ENV&&["production","prod","test","staging"].includes(process.env.NODE_ENV)||(Ye[o]&&clearTimeout(Ye[o]),Ye[o]=setTimeout(()=>{console.info(`\u{1F504} Auto syncing ${o}`),Cn(r,o,i,e);},e))),a}),Hn=(...r)=>re(null,null,function*(){var ce,Ee,xe,Re,rt,ot,st,at,it,lt;let[o,i,e]=r,a=s=>s.startsWith("http://")||s.startsWith("https://"),t;try{if(a(o))t=(yield $n.get(o)).data;else {let s=D__default.default.isAbsolute(o)?o:D__default.default.join(fe,o);`${s}`,t=yield le__default.default.promises.readFile(s,"utf-8");}}catch(s){console.error(`Failed to load OpenAPI spec for ${i}:`,s);return}if(!t)return;let l=exports.isJson(t)?t:exports.yamlStringToJson(t),n;try{n=yield Dn__default.default.parse(l);}catch(s){let u=s instanceof Error?s.message:String(s);throw new Error(`Failed to parse OpenAPI spec for ${i}: ${u}`)}let y=D__default.default.join((e==null?void 0:e.folder)||"",i),c={},f=s=>{var u,T;if((u=e==null?void 0:e.folderSplit)!=null&&u.customFolder){let $=e.folderSplit.customFolder(s);if($)return $}return (T=e==null?void 0:e.folderSplit)!=null&&T.byTags&&s.tags&&s.tags.length>0?s.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},S=typeof(e==null?void 0:e.server)=="string"?e==null?void 0:e.server:((Ee=(ce=n==null?void 0:n.servers)==null?void 0:ce[(e==null?void 0:e.server)||0])==null?void 0:Ee.url)||"",q=typeof((Re=(xe=e==null?void 0:e.types)==null?void 0:xe.name)==null?void 0:Re.prefix)=="string"?e==null?void 0:e.types.name.prefix:"I",P=typeof((ot=(rt=e==null?void 0:e.endpoints)==null?void 0:rt.name)==null?void 0:ot.prefix)=="string"?e==null?void 0:e.endpoints.name.prefix:"",E=(s,u)=>{var $,d;let T=exports.capitalize(s);if((d=($=e==null?void 0:e.types)==null?void 0:$.name)!=null&&d.format){let g=e==null?void 0:e.types.name.format("shared",{name:s},T);if(g)return `${q}${g}`}return `${q}${T}`},v=(s,u,T,$,d,g=0)=>{let m="",C="",h="";if(u)if(u.$ref)if(u.$ref[0]==="#"){let O=(u.$ref||"").split("/");O.shift();O[0]==="definitions";[...O].pop();let W=Ve__default.default(s,O,null);if(W){W!=null&&W.name&&(m=W.name),C=O[O.length-1];let oe=E(C);oe.includes(".")&&(oe=oe.split(".").map((ye,ge)=>ge===0?ye:`["${ye}"]`).join("")),h+=`${d!=null&&d.noSharedImport?"":"Shared."}${oe}`;}}else h+="";else if(u.anyOf)h+=`(${u.anyOf.map(O=>v(s,O,"",$,ie(ee({},d),{useComponentName:false}))).filter(O=>!!O).join("|")})`;else if(u.oneOf)h+=`(${u.oneOf.map(O=>v(s,O,"",$,ie(ee({},d),{useComponentName:false}))).filter(O=>!!O).join("|")})`;else if(u.allOf)h+=`(${u.allOf.map(O=>v(s,O,"",$,ie(ee({},d),{useComponentName:false}))).filter(O=>!!O).join("&")})`;else if(u.items)h+=`${v(s,u.items,"",false,ie(ee({},d),{useComponentName:false}))}[]`;else if(u.properties){let O=Object.keys(u.properties),M=u.required||[],L="";O.forEach(z=>{var oe,Te,ye,ge,ve,he;let W="";!((Te=(oe=e==null?void 0:e.types)==null?void 0:oe.doc)!=null&&Te.disable)&&((ge=(ye=u.properties)==null?void 0:ye[z])!=null&&ge.description)&&(W=" * "+((ve=u.properties)==null?void 0:ve[z].description.split(`
|
|
21
23
|
`).filter(Me=>Me.trim()!=="").join(`
|
|
22
24
|
*${" ".repeat(1)}`))),L+=(W?`/**
|
|
23
25
|
${W}
|
|
24
26
|
*/
|
|
25
27
|
`:"")+`${v(s,(he=u.properties)==null?void 0:he[z],z,M.includes(z),d,g+1)}`;}),L.length>0?h+=`{
|
|
26
|
-
${" ".repeat(g)}${L}${" ".repeat(g)}}`:h+="{[k: string]: any}";}else if(u.enum&&u.enum.length>0){let O=u.enum.includes(null),M=u.enum.filter(z=>z!==null).map(z=>JSON.stringify(z)).filter(z=>z!==void 0),L=M.length>1||M.length>0&&O;L&&(h+="("),M.forEach((z,W)=>{h+=`${W===0?"":"|"}${z}`;}),O&&(h+=`${M.length>0?"|":""}null`),L&&(h+=")");}else if(u.type){let O=M=>{let L="";if(typeof M=="string")["string","integer","number","array","boolean","null"].includes(M)?["integer","number"].includes(M)?L+="number":M==="array"?L+="any[]":L+=M:M==="object"&&(u.additionalProperties?L+=`{[k: string]: ${v(s,u.additionalProperties,"",true,ie(ee({},d),{useComponentName:false}))||"any"}}`:L+="{[k: string]: any}");else if(Array.isArray(M)){let z=M.map(W=>O(W));z.filter(W=>W!==""),z.length>1&&(L+="("+z.join("|")+")");}else L+="any";return L};h=O(u.type);}else h+="any";else h="string";let A=m||
|
|
28
|
+
${" ".repeat(g)}${L}${" ".repeat(g)}}`:h+="{[k: string]: any}";}else if(u.enum&&u.enum.length>0){let O=u.enum.includes(null),M=u.enum.filter(z=>z!==null).map(z=>JSON.stringify(z)).filter(z=>z!==void 0),L=M.length>1||M.length>0&&O;L&&(h+="("),M.forEach((z,W)=>{h+=`${W===0?"":"|"}${z}`;}),O&&(h+=`${M.length>0?"|":""}null`),L&&(h+=")");}else if(u.type){let O=M=>{let L="";if(typeof M=="string")["string","integer","number","array","boolean","null"].includes(M)?["integer","number"].includes(M)?L+="number":M==="array"?L+="any[]":L+=M:M==="object"&&(u.additionalProperties?L+=`{[k: string]: ${v(s,u.additionalProperties,"",true,ie(ee({},d),{useComponentName:false}))||"any"}}`:L+="{[k: string]: any}");else if(Array.isArray(M)){let z=M.map(W=>O(W));z.filter(W=>W!==""),z.length>1&&(L+="("+z.join("|")+")");}else L+="any";return L};h=O(u.type);}else h+="any";else h="string";let A=m||T;d!=null&&d.useComponentName&&!A&&(A=C);let J=A?` "${A}"${$?"":"?"}: `:"",p=(u==null?void 0:u.enum)&&u.enum.includes(null),Z=u!=null&&u.nullable&&!p?" | null":"";return h.length>0?`${J}${h}${Z}${A?`;
|
|
27
29
|
`:""}`:""},j=(s,u)=>{let d="";if(u)if(u.$ref)if(u.$ref[0]==="#"){let g=(u.$ref||"").split("/");g.shift();let C=Ve__default.default(s,g,null);C&&(C!=null&&C.name&&(C.name),g[g.length-1],d+=j(s,C));}else d+="";else if(u.anyOf)d+=j(s,u.anyOf[0]);else if(u.oneOf)d+=j(s,u.oneOf[0]);else if(u.allOf)d+=`{${u.allOf.map(g=>`...(${j(s,g)})`).join(",")}}`;else if(u.items)d+=`[${j(s,u.items)}]`;else if(u.properties){let C=Object.keys(u.properties).map(h=>{var A;return ` "${h}": ${j(s,(A=u.properties)==null?void 0:A[h])}`}).join(`,
|
|
28
30
|
`);C.length>0?d+=`{
|
|
29
31
|
${C}
|
|
30
|
-
}`:d+="{}";}else if(u.enum&&u.enum.length>0)u.enum.length>1&&(d+=u.enum[0]);else if(u.type)if(u.example)d+=JSON.stringify(u.example);else {let g=m=>{let C="";if(typeof m=="string")["string","integer","number","array","boolean","null"].includes(m)?["integer","number"].includes(m)?C+="123":m==="array"?C+="[]":m==="boolean"?C+="true":m==="null"?C+="null":C+=`"${m}"`:m==="object"&&(C+="{}");else if(Array.isArray(m)){let h=m.map(A=>g(A));h.filter(A=>A!==""),h.length>1&&(C+=h.join("|"));}else C+="any";return C};d=g(u.type);}else d+="any";else d="string";return d},k=fn(i);if(Bn__default.default(k,n))return;dn(i,n);let H="",
|
|
32
|
+
}`:d+="{}";}else if(u.enum&&u.enum.length>0)u.enum.length>1&&(d+=u.enum[0]);else if(u.type)if(u.example)d+=JSON.stringify(u.example);else {let g=m=>{let C="";if(typeof m=="string")["string","integer","number","array","boolean","null"].includes(m)?["integer","number"].includes(m)?C+="123":m==="array"?C+="[]":m==="boolean"?C+="true":m==="null"?C+="null":C+=`"${m}"`:m==="object"&&(C+="{}");else if(Array.isArray(m)){let h=m.map(A=>g(A));h.filter(A=>A!==""),h.length>1&&(C+=h.join("|"));}else C+="any";return C};d=g(u.type);}else d+="any";else d="string";return d},k=fn(i);if(Bn__default.default(k,n))return;dn(i,n);let H="",w="",b={},Y=[],F=(s,u)=>{let T={},$={};Object.keys(s).forEach(g=>{var h;let m=(h=s[g])!=null&&h.schema?s[g].schema:s[g],C=`${v(n,m,"",true,{noSharedImport:true,useComponentName:false})}`;if(C){let A=g.split("."),J=T,p=$;for(let Z=0;Z<A.length;Z++){let O=A[Z];Z<A.length-1?(O in J||(J[O]={},p[O]={}),J=J[O],p=p[O]):(J[O]=C,p[O]=m);}}}),Object.keys(T).forEach(g=>{var A,J,p,Z;let m=E(g),C=T[g],h="";!((J=(A=e==null?void 0:e.types)==null?void 0:A.doc)!=null&&J.disable)&&g in s&&((p=s[g])!=null&&p.description)&&(h=" * "+s[g].description.split(`
|
|
31
33
|
`).filter(O=>O.trim()!=="").join(`
|
|
32
34
|
*${" ".repeat(1)}`)),b[g]=((Z=b[g])!=null?Z:"")+(h?`/**
|
|
33
35
|
${h}
|
|
34
36
|
*/
|
|
35
37
|
`:"")+"export type "+m+" = "+(typeof C=="string"?C:exports.JSONStringify(C))+`;
|
|
36
|
-
`;});};n.definitions&&F(n.definitions),n.components&&Object.keys(n.components).forEach(s=>{if(["schemas","responses","parameters","examples","requestBodies","headers","links","callbacks"].includes(s)){let u=n.components[s];F(u);}});let Q=s=>{let u="";if(s.content){let
|
|
38
|
+
`;});};n.definitions&&F(n.definitions),n.components&&Object.keys(n.components).forEach(s=>{if(["schemas","responses","parameters","examples","requestBodies","headers","links","callbacks"].includes(s)){let u=n.components[s];F(u);}});let Q=s=>{let u="";if(s.content){let T=Object.keys(s.content);T[0]&&s.content[T[0]].schema&&(u+=`${v(n,s.content[T[0]].schema,"")}`);}return u},K=(s,u,T=0)=>{if(!s)return u==="joi"?"Joi.any()":u==="yup"?"yup.mixed()":"z.any()";if(s.$ref){if(s.$ref[0]==="#"){let $=s.$ref.split("/");$.shift();let d=$.join("."),g=Ve__default.default(n,d);if(g)return K(g,u,T)}return u==="joi"?"Joi.any()":u==="yup"?"yup.mixed()":"z.any()"}if(s.anyOf||s.oneOf){let $=s.anyOf||s.oneOf;if($.every(g=>g.enum!==void 0&&Array.isArray(g.enum))){let g=[],m=false;if($.forEach(C=>{C.enum&&C.enum.forEach(h=>{h===null?m=true:g.includes(h)||g.push(h);});}),g.length>0){let C=g.map(h=>JSON.stringify(h)).join(", ");if(u==="zod"){let h=`z.enum([${C}])`;return m&&(h+=".nullable()"),h}else if(u==="yup"){let h=`yup.mixed().oneOf([${C}])`;return m&&(h+=".nullable()"),h}else return m?`Joi.valid(${C}, null)`:`Joi.valid(${C})`}else if(m)return u==="zod"?"z.null()":u==="yup"?"yup.mixed().nullable()":"Joi.valid(null)"}return u==="zod"?`z.union([${$.map(C=>K(C,u,T+1)).join(", ")}])`:u==="yup"?`yup.mixed().oneOf([${$.map(C=>K(C,u,T+1)).join(", ")}])`:`Joi.alternatives().try(${$.map(m=>K(m,u,T+1)).join(", ")})`}if(s.allOf)if(u==="zod"){let $=s.allOf.map(g=>K(g,u,T+1)),d=$[0];for(let g=1;g<$.length;g++)d=`${d}.merge(${$[g]})`;return d}else return K(s.allOf[0],u,T+1);if(s.items){let $=K(s.items,u,T+1);if(u==="zod"){let d=`z.array(${$})`;return s.minItems!==void 0&&(d+=`.min(${s.minItems})`),s.maxItems!==void 0&&(d+=`.max(${s.maxItems})`),d}else if(u==="yup"){let d=`yup.array().of(${$})`;return s.minItems!==void 0&&(d+=`.min(${s.minItems})`),s.maxItems!==void 0&&(d+=`.max(${s.maxItems})`),d}else {let d=`Joi.array().items(${$})`;return s.minItems!==void 0&&(d+=`.min(${s.minItems})`),s.maxItems!==void 0&&(d+=`.max(${s.maxItems})`),d}}if(s.properties){let $=s.required||[],d=" ".repeat(T+1),g=Object.entries(s.properties).map(([m,C])=>{let h=$.includes(m),A=K(C,u,T+1);return h||(A+=".optional()"),`${d}${m}: ${A}`}).join(`,
|
|
37
39
|
`);return u==="zod"?`z.object({
|
|
38
40
|
${g}
|
|
39
|
-
${" ".repeat(
|
|
41
|
+
${" ".repeat(T)}})`:u==="yup"?`yup.object({
|
|
40
42
|
${g}
|
|
41
|
-
${" ".repeat(
|
|
43
|
+
${" ".repeat(T)}})`:`Joi.object({
|
|
42
44
|
${g}
|
|
43
|
-
${" ".repeat(
|
|
45
|
+
${" ".repeat(T)}})`}if(s.enum&&s.enum.length>0){let $=[],d=false;s.enum.forEach(m=>{m===null?d=true:$.includes(m)||$.push(m);});let g=$.map(m=>JSON.stringify(m)).join(", ");if(u==="zod"){let m=`z.enum([${g}])`;return d&&(m+=".nullable()"),m}else if(u==="yup"){let m=`yup.mixed().oneOf([${g}])`;return d&&(m+=".nullable()"),m}else {let m=`Joi.valid(${g})`;return d&&(m+=".allow(null)"),m}}if(s.type){let d=(g=>{switch(g){case "string":if(u==="zod"){let m="z.string()";return s.format==="email"?m+=".email()":s.format==="uuid"?m+=".uuid()":s.format==="url"||s.format==="uri"?m+=".url()":s.format==="date-time"?m+=".datetime()":s.format==="date"&&(m+=".date()"),s.minLength&&(m+=`.min(${s.minLength})`),s.maxLength&&(m+=`.max(${s.maxLength})`),s.pattern&&(m+=`.regex(/${s.pattern}/)`),m}else if(u==="yup"){let m="yup.string()";return s.format==="email"?m+=".email()":(s.format==="url"||s.format==="uri")&&(m+=".url()"),s.minLength&&(m+=`.min(${s.minLength})`),s.maxLength&&(m+=`.max(${s.maxLength})`),s.pattern&&(m+=`.matches(/${s.pattern}/)`),m}else {let m="Joi.string()";return s.format==="email"?m+=".email()":s.format==="url"||s.format==="uri"?m+=".uri()":s.format==="uuid"?m+=".guid({ version: 'uuidv4' })":s.format==="date-time"&&(m+=".isoDate()"),s.minLength&&(m+=`.min(${s.minLength})`),s.maxLength&&(m+=`.max(${s.maxLength})`),s.pattern&&(m+=`.pattern(/${s.pattern}/)`),m}case "integer":case "number":if(u==="zod"){let m="z.number()";return g==="integer"&&(m+=".int()"),s.minimum!==void 0&&(s.exclusiveMinimum?m+=`.gt(${s.minimum})`:m+=`.min(${s.minimum})`),s.maximum!==void 0&&(s.exclusiveMaximum?m+=`.lt(${s.maximum})`:m+=`.max(${s.maximum})`),m}else if(u==="yup"){let m="yup.number()";return g==="integer"&&(m+=".integer()"),s.minimum!==void 0&&(m+=`.min(${s.minimum})`),s.maximum!==void 0&&(m+=`.max(${s.maximum})`),m}else {let m="Joi.number()";return g==="integer"&&(m+=".integer()"),s.minimum!==void 0&&(s.exclusiveMinimum?m+=`.greater(${s.minimum})`:m+=`.min(${s.minimum})`),s.maximum!==void 0&&(s.exclusiveMaximum?m+=`.less(${s.maximum})`:m+=`.max(${s.maximum})`),m}case "boolean":return u==="joi"?"Joi.boolean()":u==="yup"?"yup.boolean()":"z.boolean()";case "null":return u==="joi"?"Joi.any().allow(null)":u==="yup"?"yup.mixed().nullable()":"z.null()";default:return u==="joi"?"Joi.any()":u==="yup"?"yup.mixed()":"z.any()"}})(typeof s.type=="string"?s.type:s.type[0]);return s.nullable&&u!=="joi"?d+=".nullable()":s.nullable&&u==="joi"&&(d+=".allow(null)"),d}return u==="joi"?"Joi.any()":u==="yup"?"yup.mixed()":"z.any()"},me=s=>{var u,T,$,d,g;if((T=(u=e==null?void 0:e.endpoints)==null?void 0:u.value)!=null&&T.replaceWords&&Array.isArray(e==null?void 0:e.endpoints.value.replaceWords)){let m=s;return (g=(d=($=e==null?void 0:e.endpoints)==null?void 0:$.value)==null?void 0:d.replaceWords)==null||g.forEach((C,h)=>{let A=new RegExp(C.replace,"g");m=m.replace(A,C.with||"");}),m}else return s},se=(s,u,T=[])=>{var g,m;let $=(g=e==null?void 0:e.endpoints)==null?void 0:g.exclude,d=(m=e==null?void 0:e.endpoints)==null?void 0:m.include;if(d){let C=d.tags&&d.tags.length>0?T.some(A=>d.tags.includes(A)):true,h=d.endpoints&&d.endpoints.length>0?d.endpoints.some(A=>{let J=!A.method||A.method.toLowerCase()===u.toLowerCase();return A.path?s===A.path&&J:A.regex?new RegExp(A.regex).test(s)&&J:false}):true;if(!C||!h)return true}return !!($&&($.tags&&$.tags.length>0&&T.some(h=>$.tags.includes(h))||$.endpoints&&$.endpoints.length>0&&$.endpoints.some(h=>{let A=!h.method||h.method.toLowerCase()===u.toLowerCase();return h.path?s===h.path&&A:h.regex?new RegExp(h.regex).test(s)&&A:false})))};if(Object.keys(n.paths||{}).forEach(s=>{let u=n.paths[s];Object.keys(u).forEach($=>{var ut,ct,mt,dt,ft,yt,gt,ht,$t,Ct,bt,It,xt,Tt,wt,Et,vt,At,Ot,Pt,qt,St,jt,Rt,kt,Ut,Nt,Ft,Mt,Gt,Lt,Qt,Bt,zt,Wt,Dt,Jt,Ht,Kt,_t,Vt,Yt,Zt,Xt,en,tn,nn,rn,on;let d=$,g=exports.getEndpointDetails(s,d),m=((ut=u[d])==null?void 0:ut.tags)||[];if(se(s,d,m))return;let C=u[d],h=f({method:d,path:s,summary:C==null?void 0:C.summary,operationId:C==null?void 0:C.operationId,tags:m,parameters:C==null?void 0:C.parameters,requestBody:C==null?void 0:C.requestBody,responses:C==null?void 0:C.responses});c[h]||(c[h]={endpoints:"",types:"",validation:""});let A=((mt=(ct=e==null?void 0:e.endpoints)==null?void 0:ct.value)!=null&&mt.includeServer?S:"")+g.pathParts.map(I=>(I[0]==="{"&&I[I.length-1]==="}"?I=`\${${I.replace(/{/,"").replace(/}/,"")}}`:I[0]==="<"&&I[I.length-1]===">"?I=`\${${I.replace(/</,"").replace(/>/,"")}}`:I[0]===":"&&(I=`\${${I.replace(/:/,"")}}`),I)).join("/"),J=`"${A}"`;g.variables.length>0&&(J=`(${g.variables.map(x=>`${x}:string`).join(",")})=> \`${A}\``),J=me(J);let p=u[d],Z="",O;if(p!=null&&p.parameters&&((p==null?void 0:p.parameters).forEach((x,R)=>{(x.$ref||x.in==="query"&&x.name)&&(Z+=`${v(n,x.$ref?x:x.schema,x.name||"",x.required)}`);}),Z)){Z=`{
|
|
44
46
|
${Z}}`;let x=`${g.name}Query`;if((ft=(dt=e==null?void 0:e.types)==null?void 0:dt.name)!=null&&ft.useOperationId&&(p!=null&&p.operationId)&&(x=`${p.operationId}Query`),x=exports.capitalize(`${q}${x}`),(gt=(yt=e==null?void 0:e.types)==null?void 0:yt.name)!=null&>.format){let G=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"query",method:d,path:s,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId},x);G&&(x=`${q}${G}`);}O=x;let R=`export type ${x} = ${Z};
|
|
45
|
-
`;e!=null&&e.folderSplit?c[h].types+=R:
|
|
47
|
+
`;e!=null&&e.folderSplit?c[h].types+=R:w+=R;}if(((ht=e==null?void 0:e.validations)==null?void 0:ht.disable)!==true&&((Ct=($t=e==null?void 0:e.validations)==null?void 0:$t.generate)==null?void 0:Ct.query)!==false&&(p!=null&&p.parameters)){let I=((bt=e.validations)==null?void 0:bt.library)||"zod",R=p.parameters.filter(G=>!G.$ref&&G.in==="query"&&G.name);if(R.length>0){let G=((It=e==null?void 0:e.validations)==null?void 0:It.name)||((xt=e==null?void 0:e.types)==null?void 0:xt.name),_=typeof(G==null?void 0:G.prefix)=="string"?G.prefix:"I",N=typeof((wt=(Tt=e==null?void 0:e.validations)==null?void 0:Tt.name)==null?void 0:wt.suffix)=="string"?e.validations.name.suffix:"Schema",B=`${g.name}Query`;if(G!=null&&G.useOperationId&&(p!=null&&p.operationId)&&(B=`${p.operationId}Query`),B=exports.capitalize(`${_}${B}${N}`),(vt=(Et=e==null?void 0:e.validations)==null?void 0:Et.name)!=null&&vt.format){let ne=e.validations.name.format({code:"",type:"query",method:d,path:s,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId},B);ne&&(B=`${_}${ne}${N}`);}else if((Ot=(At=e==null?void 0:e.types)==null?void 0:At.name)!=null&&Ot.format){let ne=e.types.name.format("endpoint",{code:"",type:"query",method:d,path:s,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId},B);ne&&(B=`${_}${ne}${N}`);}let U=R.map(ne=>{let Rn=ne!=null&&ne.schema?K(ne.schema,I):I==="joi"?"Joi.string()":I==="yup"?"yup.string()":"z.string()",kn=ne.required?"":".optional()";return ` ${ne.name}: ${Rn}${kn}`}).join(`,
|
|
46
48
|
`),de=`export const ${B} = ${I==="joi"?"Joi.object":I==="yup"?"yup.object":"z.object"}({
|
|
47
49
|
${U}
|
|
48
50
|
});
|
|
49
51
|
|
|
50
52
|
`;e!=null&&e.folderSplit||c[h]||(c[h]={endpoints:"",types:"",validation:""}),c[h].validation+=de;}}let M=p==null?void 0:p.requestBody,L="",z;if(M&&(L=Q(M),L)){let I=`${g.name}DTO`;if((qt=(Pt=e==null?void 0:e.types)==null?void 0:Pt.name)!=null&&qt.useOperationId&&(p!=null&&p.operationId)&&(I=`${p.operationId}DTO`),I=exports.capitalize(`${q}${I}`),(jt=(St=e==null?void 0:e.types)==null?void 0:St.name)!=null&&jt.format){let R=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"dto",method:d,path:s,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId},I);R&&(I=`${q}${R}`);}z=I;let x=`export type ${I} = ${L};
|
|
51
|
-
`;e!=null&&e.folderSplit?c[h].types+=x:
|
|
53
|
+
`;e!=null&&e.folderSplit?c[h].types+=x:w+=x;}if(((Rt=e==null?void 0:e.validations)==null?void 0:Rt.disable)!==true&&((Ut=(kt=e==null?void 0:e.validations)==null?void 0:kt.generate)==null?void 0:Ut.dto)!==false&&M){let I=((Nt=e.validations)==null?void 0:Nt.library)||"zod";if(M.content){let x=Object.keys(M.content);if(x[0]&&M.content[x[0]].schema){let R=((Ft=e==null?void 0:e.validations)==null?void 0:Ft.name)||((Mt=e==null?void 0:e.types)==null?void 0:Mt.name),G=typeof(R==null?void 0:R.prefix)=="string"?R.prefix:"I",_=typeof((Lt=(Gt=e==null?void 0:e.validations)==null?void 0:Gt.name)==null?void 0:Lt.suffix)=="string"?e.validations.name.suffix:"Schema",N=`${g.name}DTO`;if(R!=null&&R.useOperationId&&(p!=null&&p.operationId)&&(N=`${p.operationId}DTO`),N=exports.capitalize(`${G}${N}${_}`),(Bt=(Qt=e==null?void 0:e.validations)==null?void 0:Qt.name)!=null&&Bt.format){let te=e.validations.name.format({code:"",type:"dto",method:d,path:s,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId},N);te&&(N=`${G}${te}${_}`);}else if((Wt=(zt=e==null?void 0:e.types)==null?void 0:zt.name)!=null&&Wt.format){let te=e.types.name.format("endpoint",{code:"",type:"dto",method:d,path:s,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId},N);te&&(N=`${G}${te}${_}`);}let B=K(M.content[x[0]].schema,I),U=`export const ${N} = ${B};
|
|
52
54
|
|
|
53
|
-
`;e!=null&&e.folderSplit||c[h]||(c[h]={endpoints:"",types:"",validation:""}),c[h].validation+=U;}}}let W={},oe="",
|
|
54
|
-
`;e!=null&&e.folderSplit?c[h].types+=te:
|
|
55
|
+
`;e!=null&&e.folderSplit||c[h]||(c[h]={endpoints:"",types:"",validation:""}),c[h].validation+=U;}}}let W={},oe="",Te="";if(p!=null&&p.responses){let I=p==null?void 0:p.responses;Object.keys(I).forEach(R=>{var G,_,N,B;if(oe=Q(I[R]),W[R]=oe,oe){let U=`${g.name}${R}Response`;if((_=(G=e==null?void 0:e.types)==null?void 0:G.name)!=null&&_.useOperationId&&(p!=null&&p.operationId)&&(U=`${p.operationId}${R}Response`),U=exports.capitalize(`${q}${U}`),(B=(N=e==null?void 0:e.types)==null?void 0:N.name)!=null&&B.format){let ne=e==null?void 0:e.types.name.format("endpoint",{code:R,type:"response",method:d,path:s,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId},U);ne&&(U=`${q}${ne}`);}let te=`export type ${U} = ${oe};
|
|
56
|
+
`;e!=null&&e.folderSplit?c[h].types+=te:w+=te,W[R]=U;let de=parseInt(R);de>=200&&de<300&&(Te=U);}});}let ye=I=>!I||!I.length?"":I.map(x=>Object.entries(x).map(([G,_])=>{let N=G,B="";return Array.isArray(_)&&_.length&&(B=`
|
|
55
57
|
- Scopes: [\`${_.join("`, `")}\`]`,N=`**${N}**`),`
|
|
56
58
|
- ${N}${B}`}).join("")).join(`
|
|
57
59
|
`),ge=p!=null&&p.security?ye(p.security):"",ve="";if(!((Jt=(Dt=e==null?void 0:e.endpoints)==null?void 0:Dt.doc)!=null&&Jt.disable)){let I="";if((Kt=(Ht=e==null?void 0:e.endpoints)==null?void 0:Ht.doc)!=null&&Kt.showCurl){let x={},R="",G="";(_t=p.requestBody)!=null&&_t.content&&Object.keys(p.requestBody.content).forEach(B=>{let U=p.requestBody.content[B].schema;if(U){Array.isArray(x["Content-type"])?x["Content-type"].push(B):x["Content-type"]=[B];let te=j(n,U);te&&(R=te);}}),p!=null&&p.security&&p.security.forEach(N=>{Object.keys(N).forEach(B=>{var te,de;let U=(de=(te=n.components)==null?void 0:te.securitySchemes)==null?void 0:de[B];U&&(U.type==="mutualTLS"?G+=`
|
|
@@ -72,16 +74,16 @@ ${curlGenerator.CurlGenerator({url:S+s,method:d.toUpperCase(),headers:_,body:R})
|
|
|
72
74
|
`:""}${I}
|
|
73
75
|
*/
|
|
74
76
|
`;}let he=(Zt=(Yt=e==null?void 0:e.endpoints)==null?void 0:Yt.name)!=null&&Zt.useOperationId&&((Xt=p==null?void 0:p.operationId)==null?void 0:Xt.length)>0?p.operationId:`${g.name}`;if((tn=(en=e==null?void 0:e.endpoints)==null?void 0:en.name)!=null&&tn.format){let I=e==null?void 0:e.endpoints.name.format({method:d,path:s,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId},he);I&&(he=I);}let Me={method:`"${d}"`,operationId:`"${p==null?void 0:p.operationId}"`,url:J,tags:(p==null?void 0:p.tags)||[]},pt=`${ve}export const ${P}${he} = ${((rn=(nn=e==null?void 0:e.endpoints)==null?void 0:nn.value)==null?void 0:rn.type)==="object"?exports.JSONStringify(Me):J};
|
|
75
|
-
`;e!=null&&e.folderSplit?c[h].endpoints+=pt:H+=pt;let jn={name:`${P}${he}`,method:d,path:s,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId,tags:m,parameters:(on=p==null?void 0:p.parameters)==null?void 0:on.filter(I=>!I.$ref&&I.in&&I.name).map(I=>{var x;return {name:I.name,in:I.in,required:I.required,type:((x=I.schema)==null?void 0:x.type)||"string"}}),requestBody:M?{type:L,required:M.required}:void 0,responses:W?Object.entries(W).reduce((I,[x,R])=>(I[x]={type:R},I),{}):void 0,queryType:O,dtoType:z,responseType:
|
|
77
|
+
`;e!=null&&e.folderSplit?c[h].endpoints+=pt:H+=pt;let jn={name:`${P}${he}`,method:d,path:s,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId,tags:m,parameters:(on=p==null?void 0:p.parameters)==null?void 0:on.filter(I=>!I.$ref&&I.in&&I.name).map(I=>{var x;return {name:I.name,in:I.in,required:I.required,type:((x=I.schema)==null?void 0:x.type)||"string"}}),requestBody:M?{type:L,required:M.required}:void 0,responses:W?Object.entries(W).reduce((I,[x,R])=>(I[x]={type:R},I),{}):void 0,queryType:O,dtoType:z,responseType:Te||void 0};Y.push(jn);});}),e!=null&&e.folderSplit){for(let[s,u]of Object.entries(c))if(u.endpoints||u.types){let T=D__default.default.join(y,s);if(u.endpoints){let $=D__default.default.join(fe,T,"endpoints.ts");yield le__default.default.promises.mkdir(D__default.default.dirname($),{recursive:true}),yield $e($,u.endpoints,e);}if(u.types){let $=D__default.default.join(fe,T,"types.ts");yield le__default.default.promises.mkdir(D__default.default.dirname($),{recursive:true});let d=Object.values(b).length>0?`import * as Shared from "../shared";
|
|
76
78
|
|
|
77
|
-
${u.types}`:u.types;yield $e($,d,e);}if(((st=e==null?void 0:e.validations)==null?void 0:st.disable)!==true&&u.validation){let $=((at=e.validations)==null?void 0:at.library)||"zod",d=$==="joi"?'import Joi from "joi";':$==="yup"?'import * as yup from "yup";':'import { z } from "zod";',g=D__default.default.join(fe,
|
|
79
|
+
${u.types}`:u.types;yield $e($,d,e);}if(((st=e==null?void 0:e.validations)==null?void 0:st.disable)!==true&&u.validation){let $=((at=e.validations)==null?void 0:at.library)||"zod",d=$==="joi"?'import Joi from "joi";':$==="yup"?'import * as yup from "yup";':'import { z } from "zod";',g=D__default.default.join(fe,T,"validations.ts");yield le__default.default.promises.mkdir(D__default.default.dirname(g),{recursive:true}),yield $e(g,`${d}
|
|
78
80
|
|
|
79
81
|
${u.validation}`,e);}}}if(H.length>0){let s=D__default.default.join(fe,y,"endpoints.ts");yield le__default.default.promises.mkdir(D__default.default.dirname(s),{recursive:true}),yield $e(s,H,e);}if(Object.values(b).length>0){let s=D__default.default.join(fe,y,e!=null&&e.folderSplit?"":"types","shared.ts");yield le__default.default.promises.mkdir(D__default.default.dirname(s),{recursive:true}),yield $e(s,Object.values(b).join(`
|
|
80
|
-
`),e);}if(
|
|
82
|
+
`),e);}if(w.length>0){let s=D__default.default.join(fe,y,"types","index.ts");yield le__default.default.promises.mkdir(D__default.default.dirname(s),{recursive:true}),yield $e(s,`${Object.values(b).length>0?`import * as Shared from "./shared";
|
|
81
83
|
|
|
82
|
-
`:""}${
|
|
84
|
+
`:""}${w}`,e);}if(((it=e==null?void 0:e.validations)==null?void 0:it.disable)!==true&&!(e!=null&&e.folderSplit)){let s=((lt=e.validations)==null?void 0:lt.library)||"zod",u=s==="joi"?'import Joi from "joi";':s==="yup"?'import * as yup from "yup";':'import { z } from "zod";',T=Object.values(c).map($=>$.validation).filter($=>$.length>0).join("");if(T){let $=D__default.default.join(fe,y,"validations.ts");yield le__default.default.promises.mkdir(D__default.default.dirname($),{recursive:true}),yield $e($,`${u}
|
|
83
85
|
|
|
84
|
-
${
|
|
86
|
+
${T}`,e);}}return gn(i,Y),console.info(`\u2705 Successfully synced ${i}`),{success:true}}),Ze=Cn;});var In,Xe,Ce,et,tt,nt,xn=pe(()=>{In=(r,o)=>{let i=r;return o.tags&&o.tags.length>0&&(i=i.filter(e=>!e.tags||e.tags.length===0?false:e.tags.some(a=>o.tags.includes(a)))),o.endpoints&&o.endpoints.length>0&&(i=i.filter(e=>o.endpoints.includes(e.name))),i},Xe=(r,o,i=false)=>{var n,y;let e=o.baseURL||"";o.auth;let t=`// Generated Fetch API Client
|
|
85
87
|
`;t+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
86
88
|
|
|
87
89
|
`,t+=`import type {
|
|
@@ -142,7 +144,7 @@ ${w}`,e);}}return gn(i,Y),console.info(`\u2705 Successfully synced ${i}`),{succe
|
|
|
142
144
|
`,t+=` return response.json();
|
|
143
145
|
`,t+=`}
|
|
144
146
|
|
|
145
|
-
`,r.forEach(c=>{var H,
|
|
147
|
+
`,r.forEach(c=>{var H,w;let f=c.name,S=((H=c.parameters)==null?void 0:H.filter(b=>b.in==="path"))||[],q=((w=c.parameters)==null?void 0:w.filter(b=>b.in==="query"))||[],P=S.length>0,E=q.length>0,v=!!c.requestBody,j=c.responseType||"any";if(t+=`/**
|
|
146
148
|
`,c.summary&&(t+=` * ${c.summary}
|
|
147
149
|
`),t+=` * @method ${c.method.toUpperCase()}
|
|
148
150
|
`,t+=` * @path ${c.path}
|
|
@@ -236,7 +238,7 @@ ${w}`,e);}}return gn(i,Y),console.info(`\u2705 Successfully synced ${i}`),{succe
|
|
|
236
238
|
`,t+=` Object.assign(this.client.defaults, config);
|
|
237
239
|
`,t+=` }
|
|
238
240
|
|
|
239
|
-
`,r.forEach(c=>{var k,H;let f=c.name,S=((k=c.parameters)==null?void 0:k.filter(
|
|
241
|
+
`,r.forEach(c=>{var k,H;let f=c.name,S=((k=c.parameters)==null?void 0:k.filter(w=>w.in==="path"))||[],q=((H=c.parameters)==null?void 0:H.filter(w=>w.in==="query"))||[],P=S.length>0,E=q.length>0,v=!!c.requestBody,j=c.responseType||"any";if(t+=` /**
|
|
240
242
|
`,c.summary&&(t+=` * ${c.summary}
|
|
241
243
|
`),t+=` * @method ${c.method.toUpperCase()}
|
|
242
244
|
`,t+=` * @path ${c.path}
|
|
@@ -244,13 +246,13 @@ ${w}`,e);}}return gn(i,Y),console.info(`\u2705 Successfully synced ${i}`),{succe
|
|
|
244
246
|
`),t+=` */
|
|
245
247
|
`,t+=` async ${f}(`,(P||E||v)&&(t+=`params: {
|
|
246
248
|
`,P&&(t+=` url: {
|
|
247
|
-
`,S.forEach(
|
|
249
|
+
`,S.forEach(w=>{let Y={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[w.type||"string"]||"any",F=w.required?"":"?";t+=` ${w.name}${F}: ${Y};
|
|
248
250
|
`;}),t+=` };
|
|
249
251
|
`),E&&(t+=` query: ${c.queryType||"Record<string, any>"};
|
|
250
252
|
`),v&&(t+=` data: ${c.dtoType||"any"};
|
|
251
253
|
`),t+=" }"),t+=`): Promise<${j}> {
|
|
252
|
-
`,P||E||v){let
|
|
253
|
-
`;}if(P){let
|
|
254
|
+
`,P||E||v){let w=[];P&&w.push("url"),E&&w.push("query"),v&&w.push("data"),t+=` const { ${w.join(", ")} } = params;
|
|
255
|
+
`;}if(P){let w=S.map(b=>`url.${b.name}`).join(", ");t+=` const _url = ${c.name}(${w});
|
|
254
256
|
`;}else t+=` const _url = ${c.name};
|
|
255
257
|
`;t+=` const config: AxiosRequestConfig = {};
|
|
256
258
|
`,E&&(t+=` config.params = { ...query };
|
|
@@ -285,7 +287,7 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
285
287
|
`;let n=new Set;return r.forEach(f=>{f.queryType&&n.add(f.queryType),f.dtoType&&n.add(f.dtoType),f.responseType&&n.add(f.responseType);}),n.forEach(f=>{t+=` ${f},
|
|
286
288
|
`;}),t+=`} from '../types';
|
|
287
289
|
|
|
288
|
-
`,r.forEach(f=>{var b,Y;let S=f.method.toUpperCase(),q=S==="GET",P=["POST","PUT","PATCH","DELETE"].includes(S),E=((b=f.parameters)==null?void 0:b.filter(F=>F.in==="path"))||[],v=((Y=f.parameters)==null?void 0:Y.filter(F=>F.in==="query"))||[],j=E.length>0,k=v.length>0,H=!!f.requestBody,
|
|
290
|
+
`,r.forEach(f=>{var b,Y;let S=f.method.toUpperCase(),q=S==="GET",P=["POST","PUT","PATCH","DELETE"].includes(S),E=((b=f.parameters)==null?void 0:b.filter(F=>F.in==="path"))||[],v=((Y=f.parameters)==null?void 0:Y.filter(F=>F.in==="query"))||[],j=E.length>0,k=v.length>0,H=!!f.requestBody,w=f.responseType||"any";if(q){let F=v.map(se=>se.name.toLowerCase()),K=(F.includes("page")||F.includes("cursor")||F.includes("cursorid")||F.includes("after")||F.includes("before"))&&a,me=`use${f.name.charAt(0).toUpperCase()+f.name.slice(1)}`;if(t+=`/**
|
|
289
291
|
`,f.summary&&(t+=` * ${f.summary}
|
|
290
292
|
`),t+=` * @method ${S}
|
|
291
293
|
`,t+=` * @path ${f.path}
|
|
@@ -298,7 +300,7 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
298
300
|
`;}),t+=` };
|
|
299
301
|
`),k&&(t+=` query: ${f.queryType||"Record<string, any>"};
|
|
300
302
|
`),t+=` },
|
|
301
|
-
`,t+=` options?: Omit<UseQueryOptions<${
|
|
303
|
+
`,t+=` options?: Omit<UseQueryOptions<${w}>, 'queryKey' | 'queryFn'>
|
|
302
304
|
`,t+=`) {
|
|
303
305
|
`,t+=` return useQuery({
|
|
304
306
|
`,t+=` queryKey: ['${f.name}', params],
|
|
@@ -308,7 +310,7 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
308
310
|
`,t+=`}
|
|
309
311
|
|
|
310
312
|
`):(t+=`export function ${me}(
|
|
311
|
-
`,t+=` options?: Omit<UseQueryOptions<${
|
|
313
|
+
`,t+=` options?: Omit<UseQueryOptions<${w}>, 'queryKey' | 'queryFn'>
|
|
312
314
|
`,t+=`) {
|
|
313
315
|
`,t+=` return useQuery({
|
|
314
316
|
`,t+=` queryKey: ['${f.name}'],
|
|
@@ -324,7 +326,7 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
324
326
|
`;}),t+=` };
|
|
325
327
|
`),k&&(t+=` query: ${f.queryType||"Record<string, any>"};
|
|
326
328
|
`),t+=` },
|
|
327
|
-
`,t+=` options?: Omit<UseInfiniteQueryOptions<${
|
|
329
|
+
`,t+=` options?: Omit<UseInfiniteQueryOptions<${w}, Error, ${w}>, 'queryKey' | 'queryFn'>
|
|
328
330
|
`,t+=`) {
|
|
329
331
|
`,t+=` return useInfiniteQuery({
|
|
330
332
|
`,t+=` queryKey: ['${f.name}', params],
|
|
@@ -335,7 +337,7 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
335
337
|
`,t+=`}
|
|
336
338
|
|
|
337
339
|
`):(t+=`export function ${se}(
|
|
338
|
-
`,t+=` options?: Omit<UseInfiniteQueryOptions<${
|
|
340
|
+
`,t+=` options?: Omit<UseInfiniteQueryOptions<${w}, Error, ${w}>, 'queryKey' | 'queryFn'>
|
|
339
341
|
`,t+=`) {
|
|
340
342
|
`,t+=` return useInfiniteQuery({
|
|
341
343
|
`,t+=` queryKey: ['${f.name}'],
|
|
@@ -358,7 +360,7 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
358
360
|
`),k&&(Q+=` query: ${f.queryType||"Record<string, any>"};
|
|
359
361
|
`),H&&(Q+=` data: ${f.dtoType||"any"};
|
|
360
362
|
`),Q+=" }"),t+=`export function ${F}(
|
|
361
|
-
`,t+=` options?: Omit<UseMutationOptions<${
|
|
363
|
+
`,t+=` options?: Omit<UseMutationOptions<${w}, Error, ${Q}>, 'mutationFn'>
|
|
362
364
|
`,t+=`) {
|
|
363
365
|
`,t+=` return useMutation({
|
|
364
366
|
`,t+=" mutationFn: (",Q!=="void"&&(t+=`variables: ${Q}`),t+=`) => {
|
|
@@ -570,13 +572,13 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
570
572
|
`;let t=new Set;return r.forEach(n=>{n.queryType&&t.add(n.queryType),n.dtoType&&t.add(n.dtoType),n.responseType&&t.add(n.responseType);}),t.forEach(n=>{e+=` ${n},
|
|
571
573
|
`;}),e+=`} from '../types';
|
|
572
574
|
|
|
573
|
-
`,r.forEach(n=>{var k,H;let y=n.method.toUpperCase(),c=y==="GET",f=["POST","PUT","PATCH","DELETE"].includes(y),S=((k=n.parameters)==null?void 0:k.filter(
|
|
575
|
+
`,r.forEach(n=>{var k,H;let y=n.method.toUpperCase(),c=y==="GET",f=["POST","PUT","PATCH","DELETE"].includes(y),S=((k=n.parameters)==null?void 0:k.filter(w=>w.in==="path"))||[],q=((H=n.parameters)==null?void 0:H.filter(w=>w.in==="query"))||[],P=S.length>0,E=q.length>0,v=!!n.requestBody,j=n.responseType||"any";if(c){let w=`use${n.name.charAt(0).toUpperCase()+n.name.slice(1)}`;e+=`/**
|
|
574
576
|
`,n.summary&&(e+=` * ${n.summary}
|
|
575
577
|
`),e+=` * @method ${y}
|
|
576
578
|
`,e+=` * @path ${n.path}
|
|
577
579
|
`,n.tags&&n.tags.length>0&&(e+=` * @tags ${n.tags.join(", ")}
|
|
578
580
|
`),e+=` */
|
|
579
|
-
`,P||E?(e+=`export function ${
|
|
581
|
+
`,P||E?(e+=`export function ${w}(
|
|
580
582
|
`,e+=` params: {
|
|
581
583
|
`,P&&(e+=` url: {
|
|
582
584
|
`,S.forEach(b=>{let F={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[b.type||"string"]||"any",Q=b.required?"":"?";e+=` ${b.name}${Q}: ${F};
|
|
@@ -590,7 +592,7 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
590
592
|
`,e+=` () => apiClient.${n.name}(params),
|
|
591
593
|
`,e+=` config
|
|
592
594
|
`,e+=` );
|
|
593
|
-
`):(e+=`export function ${
|
|
595
|
+
`):(e+=`export function ${w}(
|
|
594
596
|
`,e+=` config?: SWRConfiguration<${j}>
|
|
595
597
|
`,e+=`) {
|
|
596
598
|
`,e+=` return useSWR(
|
|
@@ -600,7 +602,7 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
600
602
|
`,e+=` );
|
|
601
603
|
`),e+=`}
|
|
602
604
|
|
|
603
|
-
`;}else if(f&&i){let
|
|
605
|
+
`;}else if(f&&i){let w=`use${n.name.charAt(0).toUpperCase()+n.name.slice(1)}`;e+=`/**
|
|
604
606
|
`,n.summary&&(e+=` * ${n.summary}
|
|
605
607
|
`),e+=` * @method ${y}
|
|
606
608
|
`,e+=` * @path ${n.path}
|
|
@@ -612,7 +614,7 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
612
614
|
`;}),b+=` };
|
|
613
615
|
`),E&&(b+=` query: ${n.queryType||"Record<string, any>"};
|
|
614
616
|
`),v&&(b+=` data: ${n.dtoType||"any"};
|
|
615
|
-
`),b+=" }",Y=`{ arg: ${b} }`),e+=`export function ${
|
|
617
|
+
`),b+=" }",Y=`{ arg: ${b} }`),e+=`export function ${w}(
|
|
616
618
|
`,e+=` config?: SWRMutationConfiguration<${j}, Error, string, ${b}>
|
|
617
619
|
`,e+=`) {
|
|
618
620
|
`,e+=` return useSWRMutation(
|
|
@@ -652,7 +654,7 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
652
654
|
`),a+=` }),
|
|
653
655
|
`,a+=` tagTypes: [${[...new Set(r.flatMap(n=>n.tags||[]))].map(n=>`'${n}'`).join(", ")}],
|
|
654
656
|
`,a+=` endpoints: (builder) => ({
|
|
655
|
-
`,r.forEach((n,y)=>{var H,
|
|
657
|
+
`,r.forEach((n,y)=>{var H,w;let c=n.method.toUpperCase(),f=c==="GET",S=((H=n.parameters)==null?void 0:H.filter(b=>b.in==="path"))||[],q=((w=n.parameters)==null?void 0:w.filter(b=>b.in==="query"))||[],P=S.length>0,E=q.length>0,v=!!n.requestBody,j=n.responseType||"any";a+=` ${n.name}: builder.${f?"query":"mutation"}<
|
|
656
658
|
`,a+=` ${j},
|
|
657
659
|
`;let k="void";if((P||E||v)&&(k=`{
|
|
658
660
|
`,P&&(k+=` url: {
|
|
@@ -680,7 +682,7 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
680
682
|
|
|
681
683
|
`,a+=`export default ${i}Api;
|
|
682
684
|
|
|
683
|
-
`,a};});var Kn,
|
|
685
|
+
`,a};});var Kn,Tn,X,_n,Vn,wn=pe(()=>{xn();ke();Kn=(r,o)=>{var i,e;if((i=o==null?void 0:o.folderSplit)!=null&&i.customFolder){let a=o.folderSplit.customFolder({method:r.method,path:r.path,tags:r.tags,operationId:r.operationId,summary:r.summary});if(a)return a}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"},Tn=(r,o,i,e,a)=>re(null,null,function*(){let t=In(r,i);if(t.length===0)return;let l=i.type||"fetch";i.outputDir||D__default.default.join(a,e,"client");let y=!!(o!=null&&o.folderSplit&&(o.folderSplit.byTags||o.folderSplit.customFolder));if(`${l}${t.length}`,y){let f={};t.forEach(P=>{let E=Kn(P,o);f[E]||(f[E]=[]),f[E].push(P);});let S=Object.keys(f);for(let[P,E]of Object.entries(f)){let v=D__default.default.join(a,e,P);yield le__default.default.promises.mkdir(v,{recursive:true}),`${l}${P}${E.length}`,yield _n(E,o,i,v,l,P,true);}let q=D__default.default.join(a,e);yield Vn(q,S,l,o);return}let c=D__default.default.join(a,e);switch(yield le__default.default.promises.mkdir(c,{recursive:true}),l){case "fetch":let f=Xe(t,i);f=f.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield X(D__default.default.join(c,"clients.ts"),f,o);break;case "axios":let S=Ce(t,i,false);S=S.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield X(D__default.default.join(c,"clients.ts"),S,o);break;case "react-query":let q=Ce(t,i,false);q=q.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield X(D__default.default.join(c,"clients.ts"),q,o);let P=et(t,i);P=P.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';").replace("import apiClient from './client';","import apiClient from './clients';"),yield X(D__default.default.join(c,"hooks.ts"),P,o);break;case "swr":let E=Ce(t,i,false);E=E.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield X(D__default.default.join(c,"clients.ts"),E,o);let v=tt(t,i);v=v.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';").replace("import apiClient from './client';","import apiClient from './clients';"),yield X(D__default.default.join(c,"hooks.ts"),v,o);break;case "rtk-query":let j=nt(t,i);j=j.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield X(D__default.default.join(c,"api.ts"),j,o);break;default:throw new Error(`Unknown client type: ${l}`)}}),X=(r,o,i)=>re(null,null,function*(){var l,n,y,c;if(!(((l=i==null?void 0:i.customCode)==null?void 0:l.enabled)!==false)){yield le__default.default.promises.writeFile(r,o);return}let a=null;try{a=yield le__default.default.promises.readFile(r,"utf-8");}catch(f){}let t=exports.mergeCustomCode(o,a,{position:((n=i==null?void 0:i.customCode)==null?void 0:n.position)||"bottom",markerText:(y=i==null?void 0:i.customCode)==null?void 0:y.markerText,includeInstructions:(c=i==null?void 0:i.customCode)==null?void 0:c.includeInstructions});yield le__default.default.promises.writeFile(r,t);}),_n=(r,o,i,e,a,t,l=false)=>re(null,null,function*(){let n="",y="",c=l?"./types":"../types",f=l?"./endpoints":"../endpoints";switch(a){case "fetch":n=Xe(r,i,l),n=n.replace("} from '../types';",`} from '${c}';`).replace("} from '../endpoints';",`} from '${f}';`),yield X(D__default.default.join(e,"client.ts"),n,o);break;case "axios":n=Ce(r,i,l),n=n.replace("} from '../types';",`} from '${c}';`).replace("} from '../endpoints';",`} from '${f}';`),yield X(D__default.default.join(e,"client.ts"),n,o);break;case "react-query":if(n=Ce(r,i,l),n=n.replace("} from '../types';",`} from '${c}';`).replace("} from '../endpoints';",`} from '${f}';`),yield X(D__default.default.join(e,"client.ts"),n,o),y=et(r,i),y=y.replace("} from '../types';",`} from '${c}';`).replace("} from '../endpoints';",`} from '${f}';`),l){let q=t.replace(/-/g,"_");y=y.replace("import apiClient from './client';",`import { ${q}Client as apiClient } from '../clients';`);}yield X(D__default.default.join(e,"hooks.ts"),y,o);break;case "swr":if(n=Ce(r,i,l),n=n.replace("} from '../types';",`} from '${c}';`).replace("} from '../endpoints';",`} from '${f}';`),yield X(D__default.default.join(e,"client.ts"),n,o),y=tt(r,i),y=y.replace("} from '../types';",`} from '${c}';`).replace("} from '../endpoints';",`} from '${f}';`),l){let q=t.replace(/-/g,"_");y=y.replace("import apiClient from './client';",`import { ${q}Client as apiClient } from '../clients';`);}yield X(D__default.default.join(e,"hooks.ts"),y,o);break;case "rtk-query":let S=l?ie(ee({},i),{rtkQuery:ie(ee({},i.rtkQuery),{apiName:t.replace(/-/g,"_")})}):i;y=nt(r,S),y=y.replace("} from '../types';",`} from '${c}';`).replace("} from '../endpoints';",`} from '${f}';`),yield X(D__default.default.join(e,"api.ts"),y,o);break;default:throw new Error(`Unknown client type: ${a}`)}}),Vn=(r,o,i,e)=>re(null,null,function*(){var t;if(i==="rtk-query"){let l=`// Generated RTK Query APIs
|
|
684
686
|
`;l+=`// This file was auto-generated.
|
|
685
687
|
`,l+=`// Aggregates all API slices for easy Redux store setup
|
|
686
688
|
|
|
@@ -785,4 +787,4 @@ export default config;
|
|
|
785
787
|
${r.outputFolder}
|
|
786
788
|
`)),ae||(`${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&&!ae)try{let{Init:n,GenerateClient:y}=yield Promise.resolve().then(()=>(qn(),Pn));yield n({refetchInterval:r.refetchInterval}),r.generateClient&&r.clientType&&(yield y({type:r.clientType,apiName:r.apiName}));}catch(n){console.error(`
|
|
787
789
|
\u274C Error during sync:`,n.message),n.stack&&process.env.DEBUG&&console.error(n.stack);}else ae||(r.generateClient||r.enableValidation,r.generateClient&&r.clientType&&(r.generateClient||r.enableValidation,`${r.clientType}`));ae||(`${r.outputFolder}${r.apiName}`,r.generateClient&&`${r.outputFolder}${r.apiName}`,r.generateClient&&r.clientType&&`${r.clientType}`);}catch(r){throw ae||(console.error(`
|
|
788
|
-
\u274C Error during setup:`,r.message),process.exit(1)),r}})}var ae,On=pe(()=>{ae=process.env.NODE_ENV==="test"||process.env.JEST_WORKER_ID!==void 0;});var Pn={};pn(Pn,{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:()=>Ln,isJson:()=>exports.isJson,isYamlString:()=>exports.isYamlString,mergeCustomCode:()=>exports.mergeCustomCode,renderTypeRefMD:()=>exports.renderTypeRefMD,variableName:()=>exports.variableName,variableNameChar:()=>exports.variableNameChar,yamlStringToJson:()=>exports.yamlStringToJson});var Fe,Sn;exports.Init=void 0;exports.GenerateClient=void 0;exports.InteractiveInit=void 0;var qn=pe(()=>{bn();Ke();_e();
|
|
790
|
+
\u274C Error during setup:`,r.message),process.exit(1)),r}})}var ae,On=pe(()=>{ae=process.env.NODE_ENV==="test"||process.env.JEST_WORKER_ID!==void 0;});var Pn={};pn(Pn,{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:()=>Ln,isJson:()=>exports.isJson,isYamlString:()=>exports.isYamlString,mergeCustomCode:()=>exports.mergeCustomCode,renderTypeRefMD:()=>exports.renderTypeRefMD,variableName:()=>exports.variableName,variableNameChar:()=>exports.variableNameChar,yamlStringToJson:()=>exports.yamlStringToJson});var Fe,Sn;exports.Init=void 0;exports.GenerateClient=void 0;exports.InteractiveInit=void 0;var qn=pe(()=>{bn();Ke();_e();wn();En();ke();Le();Fe=process.cwd(),Sn=()=>{let r;try{Ae("esbuild-register");}catch(l){throw l}let o=D__default.default.join(Fe,"openapi.sync.js"),i=D__default.default.join(Fe,"openapi.sync.ts"),e=D__default.default.join(Fe,"openapi.sync.json"),a=[o,i,e];try{for(let l of a)le__default.default.existsSync(l)&&(r=Ae(l),Object.keys(r).length===1&&r.default&&(r=r.default));}catch(l){}typeof r=="function"&&(r=r());let t=r;if(!t)throw new Error("No config found");return t},exports.Init=r=>re(null,null,function*(){let o=Sn(),i=Object.keys(o.api),e=r&&"refetchInterval"in r&&!isNaN(r==null?void 0:r.refetchInterval)?r.refetchInterval:o.refetchInterval;He();for(let a=0;a<i.length;a+=1){let t=i[a],l=o.api[t];yield Ze(l,t,o,e);}}),exports.GenerateClient=r=>re(null,null,function*(){let o=Sn(),i=r.apiName?[r.apiName]:Object.keys(o.api);for(let a of i)if(!o.api[a])throw new Error(`API "${a}" not found in configuration. Available APIs: ${Object.keys(o.api).join(", ")}`);He();for(let a of i){let t=o.api[a];yield Ze(t,a,o);}let e=(o==null?void 0:o.folder)||"api";for(let a of i){let t=hn(a);if(t.length===0){continue}`${t.length}${a}`;let l=ee(ee(ee(ee(ie(ee({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 Tn(t,o,l,a,D__default.default.join(Fe,e));}}),exports.InteractiveInit=()=>re(null,null,function*(){let{interactiveInit:r}=yield Promise.resolve().then(()=>(On(),An));yield r();});});qn();exports.getNestedValue=Ln;
|
package/dist/index.mjs
CHANGED
|
@@ -2,13 +2,15 @@ import {c,d,a,b}from'./chunk-PUWCZVB7.mjs';import ie from'fs';import J from'path
|
|
|
2
2
|
`+" ".repeat(o)+t+": ",Array.isArray(i)){p+="[";for(let n=0;n<i.length;n++){let g=i[n];typeof g=="object"&&g!==null?p+=Ee(g,o+1):p+=typeof g=="string"?`"${g}"`:g,n<i.length-1&&(p+=", ");}p+="]";}else typeof i=="object"&&i!==null?p+=""+Ee(i,o+1):p+=i.split(`
|
|
3
3
|
`).filter(n=>n.trim()!=="").join(`
|
|
4
4
|
${" ".repeat(o)}`);s<e.length-1&&(p+=", ");}return p+=`
|
|
5
|
-
${" ".repeat(o-1)}}`,p},ve=(l,o=1)
|
|
5
|
+
${" ".repeat(o-1)}}`,p},ve=(l,o=1)=>{let p=l.replace(/\/\*\*?[\s\S]*?\*\//g,e=>e.replace(/^\/\*\*?\s*/,"").replace(/\s*\*\/$/,"").split(`
|
|
6
|
+
`).map(t=>t.replace(/^\s*\*\s?/,"").trim()).filter(t=>t.length>0).map(t=>`// ${t}`).join(`
|
|
7
|
+
`));return `
|
|
6
8
|
\`\`\`typescript
|
|
7
|
-
${" ".repeat(o)} ${
|
|
8
|
-
`).filter(
|
|
9
|
+
${" ".repeat(o)} ${p.split(`
|
|
10
|
+
`).filter(e=>e.trim()!=="").join(`
|
|
9
11
|
${" ".repeat(o)} `)}
|
|
10
|
-
|
|
11
|
-
`,
|
|
12
|
+
\`\`\``};function vn(l,o){return o.split(".").reduce((e,s)=>e&&e[s]!==void 0?e[s]:void 0,l)}var dn=(l,o="CUSTOM CODE")=>{let p=`// \u{1F512} ${o} START`,e=`// \u{1F512} ${o} END`,s={beforeGenerated:"",afterGenerated:""},t=0,i=[];for(;t<l.length;){let n=l.indexOf(p,t);if(n===-1)break;let g=l.indexOf(e,n);if(g===-1)break;let m=g+e.length,f=l.substring(m,m+100),O=f.match(/^\s*\n\s*(\/\/ =+)/);if(O){let k=f.indexOf(`
|
|
13
|
+
`,O.index+1);k!==-1?m+=k+1:m+=O[0].length;}let q=n,w=l.substring(Math.max(0,n-200),n).lastIndexOf("// ==========");w!==-1&&(q=Math.max(0,n-200)+w);let A=l.substring(q,m);i.push({start:q,end:m,content:A}),t=m;}return i.length>0&&(l.substring(0,i[0].start).split(`
|
|
12
14
|
`).filter(m=>{let f=m.trim();return f.length>0&&!f.startsWith("//")}).join("").length===0?(s.beforeGenerated=i[0].content,i.length>1&&(s.afterGenerated=i[1].content)):(s.afterGenerated=i[0].content,i.length>1&&!s.beforeGenerated&&(s.beforeGenerated=i[1].content))),s},Ht=(l,o="CUSTOM CODE",p=true)=>{let e=p?`// ${l==="top"?"Add your custom code below this line":"Add your custom code above this line"}
|
|
13
15
|
// This section will be preserved during regeneration
|
|
14
16
|
`:"";return `// ${"=".repeat(60)}
|
|
@@ -16,8 +18,8 @@ ${" ".repeat(o)} `)}
|
|
|
16
18
|
${e}// ${"=".repeat(60)}
|
|
17
19
|
|
|
18
20
|
// \u{1F512} ${o} END
|
|
19
|
-
// ${"=".repeat(60)}`},
|
|
20
|
-
`)};var
|
|
21
|
+
// ${"=".repeat(60)}`},je=(l,o,p={})=>{let{position:e="bottom",markerText:s="CUSTOM CODE",includeInstructions:t=true}=p,i={beforeGenerated:"",afterGenerated:""};o&&(i=dn(o,s)),!i.beforeGenerated&&!i.afterGenerated&&((e==="top"||e==="both")&&(i.beforeGenerated=Ht("top",s,t)),(e==="bottom"||e==="both")&&(i.afterGenerated=Ht("bottom",s,t)));let n=[];return i.beforeGenerated&&(n.push(i.beforeGenerated),n.push("")),n.push(l),i.afterGenerated&&(n.push(""),n.push(i.afterGenerated)),n.join(`
|
|
22
|
+
`)};var qe=J.join(__dirname,"../","../db.json");ie.existsSync(qe)||ie.writeFileSync(qe,"{}");var Ue={};try{Ue=c(qe);}catch(l){Ue={};}var we=Ue||{},Yt=l=>{ie.writeFileSync(qe,JSON.stringify(l));},Zt=(l,o)=>{we[l]=o,Yt(we);},Xt=l=>we[l],Me=()=>{we={},Yt(we);};var en={},tn=(l,o)=>{en[l]=o;},nn=l=>en[l]||[];var ce=process.cwd(),Ne={},rn=gn.create({timeout:6e4});hn(rn,{retries:20,retryCondition:l=>l.code==="ECONNABORTED"||l.message.includes("Network Error"),retryDelay:l=>l*1e3});var ge=(l,o,p)=>d(null,null,function*(){var i,n,g,m;if(!(((i=p==null?void 0:p.customCode)==null?void 0:i.enabled)!==false)){yield ie.promises.writeFile(l,o);return}let s=null;try{s=yield ie.promises.readFile(l,"utf-8");}catch(f){}let t=je(o,s,{position:((n=p==null?void 0:p.customCode)==null?void 0:n.position)||"bottom",markerText:(g=p==null?void 0:p.customCode)==null?void 0:g.markerText,includeInstructions:(m=p==null?void 0:p.customCode)==null?void 0:m.includeInstructions});yield ie.promises.writeFile(l,t);}),sn=(l,o,p,e)=>d(null,null,function*(){let s=yield bn(l,o,p,e);return e&&!isNaN(e)&&e>0&&(process.env.NODE_ENV&&["production","prod","test","staging"].includes(process.env.NODE_ENV)||(Ne[o]&&clearTimeout(Ne[o]),Ne[o]=setTimeout(()=>{console.info(`\u{1F504} Auto syncing ${o}`),sn(l,o,p,e);},e))),s}),bn=(...l)=>d(null,null,function*(){var le,be,$e,Pe,De,Je,We,He,Ke,_e;let[o,p,e]=l,s=r=>r.startsWith("http://")||r.startsWith("https://"),t;try{if(s(o))t=(yield rn.get(o)).data;else {let r=J.isAbsolute(o)?o:J.join(ce,o);`${r}`,t=yield ie.promises.readFile(r,"utf-8");}}catch(r){console.error(`Failed to load OpenAPI spec for ${p}:`,r);return}if(!t)return;let i=Kt(t)?t:_t(t),n;try{n=yield $n.parse(i);}catch(r){let u=r instanceof Error?r.message:String(r);throw new Error(`Failed to parse OpenAPI spec for ${p}: ${u}`)}let g=J.join((e==null?void 0:e.folder)||"",p),m={},f=r=>{var u,E;if((u=e==null?void 0:e.folderSplit)!=null&&u.customFolder){let $=e.folderSplit.customFolder(r);if($)return $}return (E=e==null?void 0:e.folderSplit)!=null&&E.byTags&&r.tags&&r.tags.length>0?r.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},O=typeof(e==null?void 0:e.server)=="string"?e==null?void 0:e.server:((be=(le=n==null?void 0:n.servers)==null?void 0:le[(e==null?void 0:e.server)||0])==null?void 0:be.url)||"",q=typeof((Pe=($e=e==null?void 0:e.types)==null?void 0:$e.name)==null?void 0:Pe.prefix)=="string"?e==null?void 0:e.types.name.prefix:"I",j=typeof((Je=(De=e==null?void 0:e.endpoints)==null?void 0:De.name)==null?void 0:Je.prefix)=="string"?e==null?void 0:e.endpoints.name.prefix:"",w=(r,u)=>{var $,d;let E=ue(r);if((d=($=e==null?void 0:e.types)==null?void 0:$.name)!=null&&d.format){let y=e==null?void 0:e.types.name.format("shared",{name:r},E);if(y)return `${q}${y}`}return `${q}${E}`},A=(r,u,E,$,d,y=0)=>{let c="",C="",h="";if(u)if(u.$ref)if(u.$ref[0]==="#"){let v=(u.$ref||"").split("/");v.shift();v[0]==="definitions";[...v].pop();let D=Ge(r,v,null);if(D){D!=null&&D.name&&(c=D.name),C=v[v.length-1];let re=w(C);re.includes(".")&&(re=re.split(".").map((de,fe)=>fe===0?de:`["${de}"]`).join("")),h+=`${d!=null&&d.noSharedImport?"":"Shared."}${re}`;}}else h+="";else if(u.anyOf)h+=`(${u.anyOf.map(v=>A(r,v,"",$,b(a({},d),{useComponentName:false}))).filter(v=>!!v).join("|")})`;else if(u.oneOf)h+=`(${u.oneOf.map(v=>A(r,v,"",$,b(a({},d),{useComponentName:false}))).filter(v=>!!v).join("|")})`;else if(u.allOf)h+=`(${u.allOf.map(v=>A(r,v,"",$,b(a({},d),{useComponentName:false}))).filter(v=>!!v).join("&")})`;else if(u.items)h+=`${A(r,u.items,"",false,b(a({},d),{useComponentName:false}))}[]`;else if(u.properties){let v=Object.keys(u.properties),N=u.required||[],F="";v.forEach(z=>{var re,Ce,de,fe,Ie,ye;let D="";!((Ce=(re=e==null?void 0:e.types)==null?void 0:re.doc)!=null&&Ce.disable)&&((fe=(de=u.properties)==null?void 0:de[z])!=null&&fe.description)&&(D=" * "+((Ie=u.properties)==null?void 0:Ie[z].description.split(`
|
|
21
23
|
`).filter(Re=>Re.trim()!=="").join(`
|
|
22
24
|
*${" ".repeat(1)}`))),F+=(D?`/**
|
|
23
25
|
${D}
|
|
@@ -40,24 +42,24 @@ ${" ".repeat(E)}})`:u==="yup"?`yup.object({
|
|
|
40
42
|
${y}
|
|
41
43
|
${" ".repeat(E)}})`:`Joi.object({
|
|
42
44
|
${y}
|
|
43
|
-
${" ".repeat(E)}})`}if(r.enum&&r.enum.length>0){let $=[],d=false;r.enum.forEach(c=>{c===null?d=true:$.includes(c)||$.push(c);});let y=$.map(c=>JSON.stringify(c)).join(", ");if(u==="zod"){let c=`z.enum([${y}])`;return d&&(c+=".nullable()"),c}else if(u==="yup"){let c=`yup.mixed().oneOf([${y}])`;return d&&(c+=".nullable()"),c}else {let c=`Joi.valid(${y})`;return d&&(c+=".allow(null)"),c}}if(r.type){let d=(y=>{switch(y){case "string":if(u==="zod"){let c="z.string()";return r.format==="email"?c+=".email()":r.format==="uuid"?c+=".uuid()":r.format==="url"||r.format==="uri"?c+=".url()":r.format==="date-time"?c+=".datetime()":r.format==="date"&&(c+=".date()"),r.minLength&&(c+=`.min(${r.minLength})`),r.maxLength&&(c+=`.max(${r.maxLength})`),r.pattern&&(c+=`.regex(/${r.pattern}/)`),c}else if(u==="yup"){let c="yup.string()";return r.format==="email"?c+=".email()":(r.format==="url"||r.format==="uri")&&(c+=".url()"),r.minLength&&(c+=`.min(${r.minLength})`),r.maxLength&&(c+=`.max(${r.maxLength})`),r.pattern&&(c+=`.matches(/${r.pattern}/)`),c}else {let c="Joi.string()";return r.format==="email"?c+=".email()":r.format==="url"||r.format==="uri"?c+=".uri()":r.format==="uuid"?c+=".guid({ version: 'uuidv4' })":r.format==="date-time"&&(c+=".isoDate()"),r.minLength&&(c+=`.min(${r.minLength})`),r.maxLength&&(c+=`.max(${r.maxLength})`),r.pattern&&(c+=`.pattern(/${r.pattern}/)`),c}case "integer":case "number":if(u==="zod"){let c="z.number()";return y==="integer"&&(c+=".int()"),r.minimum!==void 0&&(r.exclusiveMinimum?c+=`.gt(${r.minimum})`:c+=`.min(${r.minimum})`),r.maximum!==void 0&&(r.exclusiveMaximum?c+=`.lt(${r.maximum})`:c+=`.max(${r.maximum})`),c}else if(u==="yup"){let c="yup.number()";return y==="integer"&&(c+=".integer()"),r.minimum!==void 0&&(c+=`.min(${r.minimum})`),r.maximum!==void 0&&(c+=`.max(${r.maximum})`),c}else {let c="Joi.number()";return y==="integer"&&(c+=".integer()"),r.minimum!==void 0&&(r.exclusiveMinimum?c+=`.greater(${r.minimum})`:c+=`.min(${r.minimum})`),r.maximum!==void 0&&(r.exclusiveMaximum?c+=`.less(${r.maximum})`:c+=`.max(${r.maximum})`),c}case "boolean":return u==="joi"?"Joi.boolean()":u==="yup"?"yup.boolean()":"z.boolean()";case "null":return u==="joi"?"Joi.any().allow(null)":u==="yup"?"yup.mixed().nullable()":"z.null()";default:return u==="joi"?"Joi.any()":u==="yup"?"yup.mixed()":"z.any()"}})(typeof r.type=="string"?r.type:r.type[0]);return r.nullable&&u!=="joi"?d+=".nullable()":r.nullable&&u==="joi"&&(d+=".allow(null)"),d}return u==="joi"?"Joi.any()":u==="yup"?"yup.mixed()":"z.any()"},pe=r=>{var u,E,$,d,y;if((E=(u=e==null?void 0:e.endpoints)==null?void 0:u.value)!=null&&E.replaceWords&&Array.isArray(e==null?void 0:e.endpoints.value.replaceWords)){let c=r;return (y=(d=($=e==null?void 0:e.endpoints)==null?void 0:$.value)==null?void 0:d.replaceWords)==null||y.forEach((C,h)=>{let P=new RegExp(C.replace,"g");c=c.replace(P,C.with||"");}),c}else return r},oe=(r,u,E=[])=>{var y,c;let $=(y=e==null?void 0:e.endpoints)==null?void 0:y.exclude,d=(c=e==null?void 0:e.endpoints)==null?void 0:c.include;if(d){let C=d.tags&&d.tags.length>0?E.some(P=>d.tags.includes(P)):true,h=d.endpoints&&d.endpoints.length>0?d.endpoints.some(P=>{let W=!P.method||P.method.toLowerCase()===u.toLowerCase();return P.path?r===P.path&&W:P.regex?new RegExp(P.regex).test(r)&&W:false}):true;if(!C||!h)return true}return !!($&&($.tags&&$.tags.length>0&&E.some(h=>$.tags.includes(h))||$.endpoints&&$.endpoints.length>0&&$.endpoints.some(h=>{let P=!h.method||h.method.toLowerCase()===u.toLowerCase();return h.path?r===h.path&&P:h.regex?new RegExp(h.regex).test(r)&&P:false})))};if(Object.keys(n.paths||{}).forEach(r=>{let u=n.paths[r];Object.keys(u).forEach($=>{var Ye,Ze,Xe,et,tt,nt,rt,st,ot,at,it,lt,ut,pt,mt,ct,dt,ft,yt,gt,ht,$t,Ct,bt,It,xt,Et,Tt,wt,At,Pt,vt,qt,Ot,
|
|
44
|
-
${Z}}`;let x=`${y.name}Query`;if((tt=(et=e==null?void 0:e.types)==null?void 0:et.name)!=null&&tt.useOperationId&&(a!=null&&a.operationId)&&(x=`${a.operationId}Query`),x=ue(`${
|
|
45
|
+
${" ".repeat(E)}})`}if(r.enum&&r.enum.length>0){let $=[],d=false;r.enum.forEach(c=>{c===null?d=true:$.includes(c)||$.push(c);});let y=$.map(c=>JSON.stringify(c)).join(", ");if(u==="zod"){let c=`z.enum([${y}])`;return d&&(c+=".nullable()"),c}else if(u==="yup"){let c=`yup.mixed().oneOf([${y}])`;return d&&(c+=".nullable()"),c}else {let c=`Joi.valid(${y})`;return d&&(c+=".allow(null)"),c}}if(r.type){let d=(y=>{switch(y){case "string":if(u==="zod"){let c="z.string()";return r.format==="email"?c+=".email()":r.format==="uuid"?c+=".uuid()":r.format==="url"||r.format==="uri"?c+=".url()":r.format==="date-time"?c+=".datetime()":r.format==="date"&&(c+=".date()"),r.minLength&&(c+=`.min(${r.minLength})`),r.maxLength&&(c+=`.max(${r.maxLength})`),r.pattern&&(c+=`.regex(/${r.pattern}/)`),c}else if(u==="yup"){let c="yup.string()";return r.format==="email"?c+=".email()":(r.format==="url"||r.format==="uri")&&(c+=".url()"),r.minLength&&(c+=`.min(${r.minLength})`),r.maxLength&&(c+=`.max(${r.maxLength})`),r.pattern&&(c+=`.matches(/${r.pattern}/)`),c}else {let c="Joi.string()";return r.format==="email"?c+=".email()":r.format==="url"||r.format==="uri"?c+=".uri()":r.format==="uuid"?c+=".guid({ version: 'uuidv4' })":r.format==="date-time"&&(c+=".isoDate()"),r.minLength&&(c+=`.min(${r.minLength})`),r.maxLength&&(c+=`.max(${r.maxLength})`),r.pattern&&(c+=`.pattern(/${r.pattern}/)`),c}case "integer":case "number":if(u==="zod"){let c="z.number()";return y==="integer"&&(c+=".int()"),r.minimum!==void 0&&(r.exclusiveMinimum?c+=`.gt(${r.minimum})`:c+=`.min(${r.minimum})`),r.maximum!==void 0&&(r.exclusiveMaximum?c+=`.lt(${r.maximum})`:c+=`.max(${r.maximum})`),c}else if(u==="yup"){let c="yup.number()";return y==="integer"&&(c+=".integer()"),r.minimum!==void 0&&(c+=`.min(${r.minimum})`),r.maximum!==void 0&&(c+=`.max(${r.maximum})`),c}else {let c="Joi.number()";return y==="integer"&&(c+=".integer()"),r.minimum!==void 0&&(r.exclusiveMinimum?c+=`.greater(${r.minimum})`:c+=`.min(${r.minimum})`),r.maximum!==void 0&&(r.exclusiveMaximum?c+=`.less(${r.maximum})`:c+=`.max(${r.maximum})`),c}case "boolean":return u==="joi"?"Joi.boolean()":u==="yup"?"yup.boolean()":"z.boolean()";case "null":return u==="joi"?"Joi.any().allow(null)":u==="yup"?"yup.mixed().nullable()":"z.null()";default:return u==="joi"?"Joi.any()":u==="yup"?"yup.mixed()":"z.any()"}})(typeof r.type=="string"?r.type:r.type[0]);return r.nullable&&u!=="joi"?d+=".nullable()":r.nullable&&u==="joi"&&(d+=".allow(null)"),d}return u==="joi"?"Joi.any()":u==="yup"?"yup.mixed()":"z.any()"},pe=r=>{var u,E,$,d,y;if((E=(u=e==null?void 0:e.endpoints)==null?void 0:u.value)!=null&&E.replaceWords&&Array.isArray(e==null?void 0:e.endpoints.value.replaceWords)){let c=r;return (y=(d=($=e==null?void 0:e.endpoints)==null?void 0:$.value)==null?void 0:d.replaceWords)==null||y.forEach((C,h)=>{let P=new RegExp(C.replace,"g");c=c.replace(P,C.with||"");}),c}else return r},oe=(r,u,E=[])=>{var y,c;let $=(y=e==null?void 0:e.endpoints)==null?void 0:y.exclude,d=(c=e==null?void 0:e.endpoints)==null?void 0:c.include;if(d){let C=d.tags&&d.tags.length>0?E.some(P=>d.tags.includes(P)):true,h=d.endpoints&&d.endpoints.length>0?d.endpoints.some(P=>{let W=!P.method||P.method.toLowerCase()===u.toLowerCase();return P.path?r===P.path&&W:P.regex?new RegExp(P.regex).test(r)&&W:false}):true;if(!C||!h)return true}return !!($&&($.tags&&$.tags.length>0&&E.some(h=>$.tags.includes(h))||$.endpoints&&$.endpoints.length>0&&$.endpoints.some(h=>{let P=!h.method||h.method.toLowerCase()===u.toLowerCase();return h.path?r===h.path&&P:h.regex?new RegExp(h.regex).test(r)&&P:false})))};if(Object.keys(n.paths||{}).forEach(r=>{let u=n.paths[r];Object.keys(u).forEach($=>{var Ye,Ze,Xe,et,tt,nt,rt,st,ot,at,it,lt,ut,pt,mt,ct,dt,ft,yt,gt,ht,$t,Ct,bt,It,xt,Et,Tt,wt,At,Pt,vt,jt,qt,Ot,kt,Rt,St,Ut,Mt,Gt,Nt,Lt,Ft,Qt,Bt,zt,Dt,Jt;let d=$,y=Vt(r,d),c=((Ye=u[d])==null?void 0:Ye.tags)||[];if(oe(r,d,c))return;let C=u[d],h=f({method:d,path:r,summary:C==null?void 0:C.summary,operationId:C==null?void 0:C.operationId,tags:c,parameters:C==null?void 0:C.parameters,requestBody:C==null?void 0:C.requestBody,responses:C==null?void 0:C.responses});m[h]||(m[h]={endpoints:"",types:"",validation:""});let P=((Xe=(Ze=e==null?void 0:e.endpoints)==null?void 0:Ze.value)!=null&&Xe.includeServer?O:"")+y.pathParts.map(I=>(I[0]==="{"&&I[I.length-1]==="}"?I=`\${${I.replace(/{/,"").replace(/}/,"")}}`:I[0]==="<"&&I[I.length-1]===">"?I=`\${${I.replace(/</,"").replace(/>/,"")}}`:I[0]===":"&&(I=`\${${I.replace(/:/,"")}}`),I)).join("/"),W=`"${P}"`;y.variables.length>0&&(W=`(${y.variables.map(x=>`${x}:string`).join(",")})=> \`${P}\``),W=pe(W);let a=u[d],Z="",v;if(a!=null&&a.parameters&&((a==null?void 0:a.parameters).forEach((x,R)=>{(x.$ref||x.in==="query"&&x.name)&&(Z+=`${A(n,x.$ref?x:x.schema,x.name||"",x.required)}`);}),Z)){Z=`{
|
|
46
|
+
${Z}}`;let x=`${y.name}Query`;if((tt=(et=e==null?void 0:e.types)==null?void 0:et.name)!=null&&tt.useOperationId&&(a!=null&&a.operationId)&&(x=`${a.operationId}Query`),x=ue(`${q}${x}`),(rt=(nt=e==null?void 0:e.types)==null?void 0:nt.name)!=null&&rt.format){let L=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"query",method:d,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},x);L&&(x=`${q}${L}`);}v=x;let R=`export type ${x} = ${Z};
|
|
45
47
|
`;e!=null&&e.folderSplit?m[h].types+=R:T+=R;}if(((st=e==null?void 0:e.validations)==null?void 0:st.disable)!==true&&((at=(ot=e==null?void 0:e.validations)==null?void 0:ot.generate)==null?void 0:at.query)!==false&&(a!=null&&a.parameters)){let I=((it=e.validations)==null?void 0:it.library)||"zod",R=a.parameters.filter(L=>!L.$ref&&L.in==="query"&&L.name);if(R.length>0){let L=((lt=e==null?void 0:e.validations)==null?void 0:lt.name)||((ut=e==null?void 0:e.types)==null?void 0:ut.name),_=typeof(L==null?void 0:L.prefix)=="string"?L.prefix:"I",M=typeof((mt=(pt=e==null?void 0:e.validations)==null?void 0:pt.name)==null?void 0:mt.suffix)=="string"?e.validations.name.suffix:"Schema",B=`${y.name}Query`;if(L!=null&&L.useOperationId&&(a!=null&&a.operationId)&&(B=`${a.operationId}Query`),B=ue(`${_}${B}${M}`),(dt=(ct=e==null?void 0:e.validations)==null?void 0:ct.name)!=null&&dt.format){let ne=e.validations.name.format({code:"",type:"query",method:d,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},B);ne&&(B=`${_}${ne}${M}`);}else if((yt=(ft=e==null?void 0:e.types)==null?void 0:ft.name)!=null&&yt.format){let ne=e.types.name.format("endpoint",{code:"",type:"query",method:d,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},B);ne&&(B=`${_}${ne}${M}`);}let U=R.map(ne=>{let pn=ne!=null&&ne.schema?K(ne.schema,I):I==="joi"?"Joi.string()":I==="yup"?"yup.string()":"z.string()",mn=ne.required?"":".optional()";return ` ${ne.name}: ${pn}${mn}`}).join(`,
|
|
46
48
|
`),me=`export const ${B} = ${I==="joi"?"Joi.object":I==="yup"?"yup.object":"z.object"}({
|
|
47
49
|
${U}
|
|
48
50
|
});
|
|
49
51
|
|
|
50
|
-
`;e!=null&&e.folderSplit||m[h]||(m[h]={endpoints:"",types:"",validation:""}),m[h].validation+=me;}}let N=a==null?void 0:a.requestBody,F="",z;if(N&&(F=Q(N),F)){let I=`${y.name}DTO`;if((ht=(gt=e==null?void 0:e.types)==null?void 0:gt.name)!=null&&ht.useOperationId&&(a!=null&&a.operationId)&&(I=`${a.operationId}DTO`),I=ue(`${
|
|
51
|
-
`;e!=null&&e.folderSplit?m[h].types+=x:T+=x;}if(((bt=e==null?void 0:e.validations)==null?void 0:bt.disable)!==true&&((xt=(It=e==null?void 0:e.validations)==null?void 0:It.generate)==null?void 0:xt.dto)!==false&&N){let I=((Et=e.validations)==null?void 0:Et.library)||"zod";if(N.content){let x=Object.keys(N.content);if(x[0]&&N.content[x[0]].schema){let R=((Tt=e==null?void 0:e.validations)==null?void 0:Tt.name)||((wt=e==null?void 0:e.types)==null?void 0:wt.name),L=typeof(R==null?void 0:R.prefix)=="string"?R.prefix:"I",_=typeof((Pt=(At=e==null?void 0:e.validations)==null?void 0:At.name)==null?void 0:Pt.suffix)=="string"?e.validations.name.suffix:"Schema",M=`${y.name}DTO`;if(R!=null&&R.useOperationId&&(a!=null&&a.operationId)&&(M=`${a.operationId}DTO`),M=ue(`${L}${M}${_}`),(
|
|
52
|
+
`;e!=null&&e.folderSplit||m[h]||(m[h]={endpoints:"",types:"",validation:""}),m[h].validation+=me;}}let N=a==null?void 0:a.requestBody,F="",z;if(N&&(F=Q(N),F)){let I=`${y.name}DTO`;if((ht=(gt=e==null?void 0:e.types)==null?void 0:gt.name)!=null&&ht.useOperationId&&(a!=null&&a.operationId)&&(I=`${a.operationId}DTO`),I=ue(`${q}${I}`),(Ct=($t=e==null?void 0:e.types)==null?void 0:$t.name)!=null&&Ct.format){let R=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"dto",method:d,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},I);R&&(I=`${q}${R}`);}z=I;let x=`export type ${I} = ${F};
|
|
53
|
+
`;e!=null&&e.folderSplit?m[h].types+=x:T+=x;}if(((bt=e==null?void 0:e.validations)==null?void 0:bt.disable)!==true&&((xt=(It=e==null?void 0:e.validations)==null?void 0:It.generate)==null?void 0:xt.dto)!==false&&N){let I=((Et=e.validations)==null?void 0:Et.library)||"zod";if(N.content){let x=Object.keys(N.content);if(x[0]&&N.content[x[0]].schema){let R=((Tt=e==null?void 0:e.validations)==null?void 0:Tt.name)||((wt=e==null?void 0:e.types)==null?void 0:wt.name),L=typeof(R==null?void 0:R.prefix)=="string"?R.prefix:"I",_=typeof((Pt=(At=e==null?void 0:e.validations)==null?void 0:At.name)==null?void 0:Pt.suffix)=="string"?e.validations.name.suffix:"Schema",M=`${y.name}DTO`;if(R!=null&&R.useOperationId&&(a!=null&&a.operationId)&&(M=`${a.operationId}DTO`),M=ue(`${L}${M}${_}`),(jt=(vt=e==null?void 0:e.validations)==null?void 0:vt.name)!=null&&jt.format){let te=e.validations.name.format({code:"",type:"dto",method:d,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},M);te&&(M=`${L}${te}${_}`);}else if((Ot=(qt=e==null?void 0:e.types)==null?void 0:qt.name)!=null&&Ot.format){let te=e.types.name.format("endpoint",{code:"",type:"dto",method:d,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},M);te&&(M=`${L}${te}${_}`);}let B=K(N.content[x[0]].schema,I),U=`export const ${M} = ${B};
|
|
52
54
|
|
|
53
|
-
`;e!=null&&e.folderSplit||m[h]||(m[h]={endpoints:"",types:"",validation:""}),m[h].validation+=U;}}}let D={},re="",Ce="";if(a!=null&&a.responses){let I=a==null?void 0:a.responses;Object.keys(I).forEach(R=>{var L,_,M,B;if(re=Q(I[R]),D[R]=re,re){let U=`${y.name}${R}Response`;if((_=(L=e==null?void 0:e.types)==null?void 0:L.name)!=null&&_.useOperationId&&(a!=null&&a.operationId)&&(U=`${a.operationId}${R}Response`),U=ue(`${
|
|
55
|
+
`;e!=null&&e.folderSplit||m[h]||(m[h]={endpoints:"",types:"",validation:""}),m[h].validation+=U;}}}let D={},re="",Ce="";if(a!=null&&a.responses){let I=a==null?void 0:a.responses;Object.keys(I).forEach(R=>{var L,_,M,B;if(re=Q(I[R]),D[R]=re,re){let U=`${y.name}${R}Response`;if((_=(L=e==null?void 0:e.types)==null?void 0:L.name)!=null&&_.useOperationId&&(a!=null&&a.operationId)&&(U=`${a.operationId}${R}Response`),U=ue(`${q}${U}`),(B=(M=e==null?void 0:e.types)==null?void 0:M.name)!=null&&B.format){let ne=e==null?void 0:e.types.name.format("endpoint",{code:R,type:"response",method:d,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},U);ne&&(U=`${q}${ne}`);}let te=`export type ${U} = ${re};
|
|
54
56
|
`;e!=null&&e.folderSplit?m[h].types+=te:T+=te,D[R]=U;let me=parseInt(R);me>=200&&me<300&&(Ce=U);}});}let de=I=>!I||!I.length?"":I.map(x=>Object.entries(x).map(([L,_])=>{let M=L,B="";return Array.isArray(_)&&_.length&&(B=`
|
|
55
57
|
- Scopes: [\`${_.join("`, `")}\`]`,M=`**${M}**`),`
|
|
56
58
|
- ${M}${B}`}).join("")).join(`
|
|
57
59
|
`),fe=a!=null&&a.security?de(a.security):"",Ie="";if(!((Rt=(kt=e==null?void 0:e.endpoints)==null?void 0:kt.doc)!=null&&Rt.disable)){let I="";if((Ut=(St=e==null?void 0:e.endpoints)==null?void 0:St.doc)!=null&&Ut.showCurl){let x={},R="",L="";(Mt=a.requestBody)!=null&&Mt.content&&Object.keys(a.requestBody.content).forEach(B=>{let U=a.requestBody.content[B].schema;if(U){Array.isArray(x["Content-type"])?x["Content-type"].push(B):x["Content-type"]=[B];let te=k(n,U);te&&(R=te);}}),a!=null&&a.security&&a.security.forEach(M=>{Object.keys(M).forEach(B=>{var te,me;let U=(me=(te=n.components)==null?void 0:te.securitySchemes)==null?void 0:me[B];U&&(U.type==="mutualTLS"?L+=`
|
|
58
60
|
--cert client-certificate.crt --key client-private-key.key --cacert ca-certificate.crt`:U.type==="apiKey"?x[(U==null?void 0:U.name)||"X-API-KEY"]="{API_KEY_VALUE}":x.Authorization=`${(U==null?void 0:U.scheme)==="basic"?"Basic":"Bearer"} {${(U==null?void 0:U.scheme)==="basic"?"VALUE":"TOKEN"}}`);});});let _={};Object.keys(x).forEach(M=>{Array.isArray(x[M])?_[M]=x[M].join("; "):_[M]=x[M];}),I=`
|
|
59
61
|
\`\`\`bash
|
|
60
|
-
${CurlGenerator({url:
|
|
62
|
+
${CurlGenerator({url:O+r,method:d.toUpperCase(),headers:_,body:R})}${L}
|
|
61
63
|
\`\`\``;}Ie=`/**${a!=null&&a.description?`
|
|
62
64
|
* ${a==null?void 0:a.description} `:""}
|
|
63
65
|
* **Method**: \`${d.toUpperCase()}\`
|
|
@@ -71,8 +73,8 @@ ${CurlGenerator({url:j+r,method:d.toUpperCase(),headers:_,body:R})}${L}
|
|
|
71
73
|
* **Security**: ${fe}
|
|
72
74
|
`:""}${I}
|
|
73
75
|
*/
|
|
74
|
-
`;}let ye=(Lt=(Nt=e==null?void 0:e.endpoints)==null?void 0:Nt.name)!=null&&Lt.useOperationId&&((Ft=a==null?void 0:a.operationId)==null?void 0:Ft.length)>0?a.operationId:`${y.name}`;if((Bt=(Qt=e==null?void 0:e.endpoints)==null?void 0:Qt.name)!=null&&Bt.format){let I=e==null?void 0:e.endpoints.name.format({method:d,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},ye);I&&(ye=I);}let Re={method:`"${d}"`,operationId:`"${a==null?void 0:a.operationId}"`,url:W,tags:(a==null?void 0:a.tags)||[]},Ve=`${Ie}export const ${
|
|
75
|
-
`;e!=null&&e.folderSplit?m[h].endpoints+=Ve:H+=Ve;let un={name:`${
|
|
76
|
+
`;}let ye=(Lt=(Nt=e==null?void 0:e.endpoints)==null?void 0:Nt.name)!=null&&Lt.useOperationId&&((Ft=a==null?void 0:a.operationId)==null?void 0:Ft.length)>0?a.operationId:`${y.name}`;if((Bt=(Qt=e==null?void 0:e.endpoints)==null?void 0:Qt.name)!=null&&Bt.format){let I=e==null?void 0:e.endpoints.name.format({method:d,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId},ye);I&&(ye=I);}let Re={method:`"${d}"`,operationId:`"${a==null?void 0:a.operationId}"`,url:W,tags:(a==null?void 0:a.tags)||[]},Ve=`${Ie}export const ${j}${ye} = ${((Dt=(zt=e==null?void 0:e.endpoints)==null?void 0:zt.value)==null?void 0:Dt.type)==="object"?Ee(Re):W};
|
|
77
|
+
`;e!=null&&e.folderSplit?m[h].endpoints+=Ve:H+=Ve;let un={name:`${j}${ye}`,method:d,path:r,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId,tags:c,parameters:(Jt=a==null?void 0:a.parameters)==null?void 0:Jt.filter(I=>!I.$ref&&I.in&&I.name).map(I=>{var x;return {name:I.name,in:I.in,required:I.required,type:((x=I.schema)==null?void 0:x.type)||"string"}}),requestBody:N?{type:F,required:N.required}:void 0,responses:D?Object.entries(D).reduce((I,[x,R])=>(I[x]={type:R},I),{}):void 0,queryType:v,dtoType:z,responseType:Ce||void 0};Y.push(un);});}),e!=null&&e.folderSplit){for(let[r,u]of Object.entries(m))if(u.endpoints||u.types){let E=J.join(g,r);if(u.endpoints){let $=J.join(ce,E,"endpoints.ts");yield ie.promises.mkdir(J.dirname($),{recursive:true}),yield ge($,u.endpoints,e);}if(u.types){let $=J.join(ce,E,"types.ts");yield ie.promises.mkdir(J.dirname($),{recursive:true});let d=Object.values(b$1).length>0?`import * as Shared from "../shared";
|
|
76
78
|
|
|
77
79
|
${u.types}`:u.types;yield ge($,d,e);}if(((We=e==null?void 0:e.validations)==null?void 0:We.disable)!==true&&u.validation){let $=((He=e.validations)==null?void 0:He.library)||"zod",d=$==="joi"?'import Joi from "joi";':$==="yup"?'import * as yup from "yup";':'import { z } from "zod";',y=J.join(ce,E,"validations.ts");yield ie.promises.mkdir(J.dirname(y),{recursive:true}),yield ge(y,`${d}
|
|
78
80
|
|
|
@@ -142,23 +144,23 @@ ${E}`,e);}}return tn(p,Y),console.info(`\u2705 Successfully synced ${p}`),{succe
|
|
|
142
144
|
`,t+=` return response.json();
|
|
143
145
|
`,t+=`}
|
|
144
146
|
|
|
145
|
-
`,l.forEach(m=>{var H,T;let f=m.name,
|
|
147
|
+
`,l.forEach(m=>{var H,T;let f=m.name,O=((H=m.parameters)==null?void 0:H.filter(b=>b.in==="path"))||[],q=((T=m.parameters)==null?void 0:T.filter(b=>b.in==="query"))||[],j=O.length>0,w=q.length>0,A=!!m.requestBody,k=m.responseType||"any";if(t+=`/**
|
|
146
148
|
`,m.summary&&(t+=` * ${m.summary}
|
|
147
149
|
`),t+=` * @method ${m.method.toUpperCase()}
|
|
148
150
|
`,t+=` * @path ${m.path}
|
|
149
151
|
`,m.tags&&m.tags.length>0&&(t+=` * @tags ${m.tags.join(", ")}
|
|
150
152
|
`),t+=` */
|
|
151
|
-
`,t+=`export async function ${f}(`,(
|
|
152
|
-
`,
|
|
153
|
-
`,
|
|
153
|
+
`,t+=`export async function ${f}(`,(j||w||A)&&(t+=`params: {
|
|
154
|
+
`,j&&(t+=` url: {
|
|
155
|
+
`,O.forEach(b=>{let G={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[b.type||"string"]||"any",Q=b.required?"":"?";t+=` ${b.name}${Q}: ${G};
|
|
154
156
|
`;}),t+=` };
|
|
155
157
|
`),w&&(t+=` query: ${m.queryType||"Record<string, any>"};
|
|
156
158
|
`),A&&(t+=` data: ${m.dtoType||"any"};
|
|
157
159
|
`),t+=`}
|
|
158
160
|
`),t+=`): Promise<${k}> {
|
|
159
|
-
`,
|
|
160
|
-
`;}let S;if(
|
|
161
|
-
`,
|
|
161
|
+
`,j||w||A){let b=[];j&&b.push("url"),w&&b.push("query"),A&&b.push("data"),t+=` const { ${b.join(", ")} } = params;
|
|
162
|
+
`;}let S;if(j){let b=O.map(Y=>`url.${Y.name}`).join(", ");S=`${m.name}_endpoint(${b})`;}else S=`${m.name}_endpoint`;w?(t+=` const queryParams = new URLSearchParams();
|
|
163
|
+
`,q.forEach(b=>{b.required?t+=` queryParams.append('${b.name}', String(query.${b.name}));
|
|
162
164
|
`:(t+=` if (query.${b.name} !== undefined) {
|
|
163
165
|
`,t+=` queryParams.append('${b.name}', String(query.${b.name}));
|
|
164
166
|
`,t+=` }
|
|
@@ -236,21 +238,21 @@ ${E}`,e);}}return tn(p,Y),console.info(`\u2705 Successfully synced ${p}`),{succe
|
|
|
236
238
|
`,t+=` Object.assign(this.client.defaults, config);
|
|
237
239
|
`,t+=` }
|
|
238
240
|
|
|
239
|
-
`,l.forEach(m=>{var S,H;let f=m.name,
|
|
241
|
+
`,l.forEach(m=>{var S,H;let f=m.name,O=((S=m.parameters)==null?void 0:S.filter(T=>T.in==="path"))||[],q=((H=m.parameters)==null?void 0:H.filter(T=>T.in==="query"))||[],j=O.length>0,w=q.length>0,A=!!m.requestBody,k=m.responseType||"any";if(t+=` /**
|
|
240
242
|
`,m.summary&&(t+=` * ${m.summary}
|
|
241
243
|
`),t+=` * @method ${m.method.toUpperCase()}
|
|
242
244
|
`,t+=` * @path ${m.path}
|
|
243
245
|
`,m.tags&&m.tags.length>0&&(t+=` * @tags ${m.tags.join(", ")}
|
|
244
246
|
`),t+=` */
|
|
245
|
-
`,t+=` async ${f}(`,(
|
|
246
|
-
`,
|
|
247
|
-
`,
|
|
247
|
+
`,t+=` async ${f}(`,(j||w||A)&&(t+=`params: {
|
|
248
|
+
`,j&&(t+=` url: {
|
|
249
|
+
`,O.forEach(T=>{let Y={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[T.type||"string"]||"any",G=T.required?"":"?";t+=` ${T.name}${G}: ${Y};
|
|
248
250
|
`;}),t+=` };
|
|
249
251
|
`),w&&(t+=` query: ${m.queryType||"Record<string, any>"};
|
|
250
252
|
`),A&&(t+=` data: ${m.dtoType||"any"};
|
|
251
253
|
`),t+=" }"),t+=`): Promise<${k}> {
|
|
252
|
-
`,
|
|
253
|
-
`;}if(
|
|
254
|
+
`,j||w||A){let T=[];j&&T.push("url"),w&&T.push("query"),A&&T.push("data"),t+=` const { ${T.join(", ")} } = params;
|
|
255
|
+
`;}if(j){let T=O.map(b=>`url.${b.name}`).join(", ");t+=` const _url = ${m.name}(${T});
|
|
254
256
|
`;}else t+=` const _url = ${m.name};
|
|
255
257
|
`;t+=` const config: AxiosRequestConfig = {};
|
|
256
258
|
`,w&&(t+=` config.params = { ...query };
|
|
@@ -285,9 +287,9 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
285
287
|
`;let n=new Set;return l.forEach(f=>{f.queryType&&n.add(f.queryType),f.dtoType&&n.add(f.dtoType),f.responseType&&n.add(f.responseType);}),n.forEach(f=>{t+=` ${f},
|
|
286
288
|
`;}),t+=`} from '../types';
|
|
287
289
|
|
|
288
|
-
`,l.forEach(f=>{var b,Y;let
|
|
290
|
+
`,l.forEach(f=>{var b,Y;let O=f.method.toUpperCase(),q=O==="GET",j=["POST","PUT","PATCH","DELETE"].includes(O),w=((b=f.parameters)==null?void 0:b.filter(G=>G.in==="path"))||[],A=((Y=f.parameters)==null?void 0:Y.filter(G=>G.in==="query"))||[],k=w.length>0,S=A.length>0,H=!!f.requestBody,T=f.responseType||"any";if(q){let G=A.map(oe=>oe.name.toLowerCase()),K=(G.includes("page")||G.includes("cursor")||G.includes("cursorid")||G.includes("after")||G.includes("before"))&&s,pe=`use${f.name.charAt(0).toUpperCase()+f.name.slice(1)}`;if(t+=`/**
|
|
289
291
|
`,f.summary&&(t+=` * ${f.summary}
|
|
290
|
-
`),t+=` * @method ${
|
|
292
|
+
`),t+=` * @method ${O}
|
|
291
293
|
`,t+=` * @path ${f.path}
|
|
292
294
|
`,f.tags&&f.tags.length>0&&(t+=` * @tags ${f.tags.join(", ")}
|
|
293
295
|
`),t+=` */
|
|
@@ -345,9 +347,9 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
345
347
|
`,t+=` });
|
|
346
348
|
`,t+=`}
|
|
347
349
|
|
|
348
|
-
`);}}else if(
|
|
350
|
+
`);}}else if(j&&e){let G=`use${f.name.charAt(0).toUpperCase()+f.name.slice(1)}`;t+=`/**
|
|
349
351
|
`,f.summary&&(t+=` * ${f.summary}
|
|
350
|
-
`),t+=` * @method ${
|
|
352
|
+
`),t+=` * @method ${O}
|
|
351
353
|
`,t+=` * @path ${f.path}
|
|
352
354
|
`,f.tags&&f.tags.length>0&&(t+=` * @tags ${f.tags.join(", ")}
|
|
353
355
|
`),t+=` */
|
|
@@ -570,16 +572,16 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
570
572
|
`;let t=new Set;return l.forEach(n=>{n.queryType&&t.add(n.queryType),n.dtoType&&t.add(n.dtoType),n.responseType&&t.add(n.responseType);}),t.forEach(n=>{e+=` ${n},
|
|
571
573
|
`;}),e+=`} from '../types';
|
|
572
574
|
|
|
573
|
-
`,l.forEach(n=>{var S,H;let g=n.method.toUpperCase(),m=g==="GET",f=["POST","PUT","PATCH","DELETE"].includes(g),
|
|
575
|
+
`,l.forEach(n=>{var S,H;let g=n.method.toUpperCase(),m=g==="GET",f=["POST","PUT","PATCH","DELETE"].includes(g),O=((S=n.parameters)==null?void 0:S.filter(T=>T.in==="path"))||[],q=((H=n.parameters)==null?void 0:H.filter(T=>T.in==="query"))||[],j=O.length>0,w=q.length>0,A=!!n.requestBody,k=n.responseType||"any";if(m){let T=`use${n.name.charAt(0).toUpperCase()+n.name.slice(1)}`;e+=`/**
|
|
574
576
|
`,n.summary&&(e+=` * ${n.summary}
|
|
575
577
|
`),e+=` * @method ${g}
|
|
576
578
|
`,e+=` * @path ${n.path}
|
|
577
579
|
`,n.tags&&n.tags.length>0&&(e+=` * @tags ${n.tags.join(", ")}
|
|
578
580
|
`),e+=` */
|
|
579
|
-
`,
|
|
581
|
+
`,j||w?(e+=`export function ${T}(
|
|
580
582
|
`,e+=` params: {
|
|
581
|
-
`,
|
|
582
|
-
`,
|
|
583
|
+
`,j&&(e+=` url: {
|
|
584
|
+
`,O.forEach(b=>{let G={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[b.type||"string"]||"any",Q=b.required?"":"?";e+=` ${b.name}${Q}: ${G};
|
|
583
585
|
`;}),e+=` };
|
|
584
586
|
`),w&&(e+=` query: ${n.queryType||"Record<string, any>"};
|
|
585
587
|
`),e+=` },
|
|
@@ -606,9 +608,9 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
606
608
|
`,e+=` * @path ${n.path}
|
|
607
609
|
`,n.tags&&n.tags.length>0&&(e+=` * @tags ${n.tags.join(", ")}
|
|
608
610
|
`),e+=` */
|
|
609
|
-
`;let b="void",Y="void";(
|
|
610
|
-
`,
|
|
611
|
-
`,
|
|
611
|
+
`;let b="void",Y="void";(j||w||A)&&(b=`{
|
|
612
|
+
`,j&&(b+=` url: {
|
|
613
|
+
`,O.forEach(G=>{let K={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[G.type||"string"]||"any",pe=G.required?"":"?";b+=` ${G.name}${pe}: ${K};
|
|
612
614
|
`;}),b+=` };
|
|
613
615
|
`),w&&(b+=` query: ${n.queryType||"Record<string, any>"};
|
|
614
616
|
`),A&&(b+=` data: ${n.dtoType||"any"};
|
|
@@ -652,18 +654,18 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
652
654
|
`),s+=` }),
|
|
653
655
|
`,s+=` tagTypes: [${[...new Set(l.flatMap(n=>n.tags||[]))].map(n=>`'${n}'`).join(", ")}],
|
|
654
656
|
`,s+=` endpoints: (builder) => ({
|
|
655
|
-
`,l.forEach((n,g)=>{var H,T;let m=n.method.toUpperCase(),f=m==="GET",
|
|
657
|
+
`,l.forEach((n,g)=>{var H,T;let m=n.method.toUpperCase(),f=m==="GET",O=((H=n.parameters)==null?void 0:H.filter(b=>b.in==="path"))||[],q=((T=n.parameters)==null?void 0:T.filter(b=>b.in==="query"))||[],j=O.length>0,w=q.length>0,A=!!n.requestBody,k=n.responseType||"any";s+=` ${n.name}: builder.${f?"query":"mutation"}<
|
|
656
658
|
`,s+=` ${k},
|
|
657
|
-
`;let S="void";if((
|
|
658
|
-
`,
|
|
659
|
-
`,
|
|
659
|
+
`;let S="void";if((j||w||A)&&(S=`{
|
|
660
|
+
`,j&&(S+=` url: {
|
|
661
|
+
`,O.forEach(b=>{let G={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[b.type||"string"]||"any",Q=b.required?"":"?";S+=` ${b.name}${Q}: ${G};
|
|
660
662
|
`;}),S+=` };
|
|
661
663
|
`),w&&(S+=` query: ${n.queryType||"Record<string, any>"};
|
|
662
664
|
`),A&&(S+=` data: ${n.dtoType||"any"};
|
|
663
665
|
`),S+=" }"),s+=` ${S}
|
|
664
666
|
`,s+=` >({
|
|
665
667
|
`,s+=" query: (",S!=="void"&&(s+="arg"),s+=`) => {
|
|
666
|
-
`,
|
|
668
|
+
`,j){let b=O.map(Y=>`arg.url.${Y.name}`).join(", ");s+=` const url = ${n.name}(${b});
|
|
667
669
|
`;}else s+=` const url = ${n.name};
|
|
668
670
|
`;s+=` return {
|
|
669
671
|
`,s+=` url,
|
|
@@ -680,7 +682,7 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
680
682
|
|
|
681
683
|
`,s+=`export default ${p}Api;
|
|
682
684
|
|
|
683
|
-
`,s};var In=(l,o)=>{var p,e;if((p=o==null?void 0:o.folderSplit)!=null&&p.customFolder){let s=o.folderSplit.customFolder({method:l.method,path:l.path,tags:l.tags,operationId:l.operationId,summary:l.summary});if(s)return s}return (e=o==null?void 0:o.folderSplit)!=null&&e.byTags&&l.tags&&l.tags.length>0?l.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},an=(l,o,p,e,s)=>d(null,null,function*(){let t=on(l,p);if(t.length===0)return;let i=p.type||"fetch";p.outputDir||J.join(s,e,"client");let g=!!(o!=null&&o.folderSplit&&(o.folderSplit.byTags||o.folderSplit.customFolder));if(`${i}${t.length}`,g){let f={};t.forEach(
|
|
685
|
+
`,s};var In=(l,o)=>{var p,e;if((p=o==null?void 0:o.folderSplit)!=null&&p.customFolder){let s=o.folderSplit.customFolder({method:l.method,path:l.path,tags:l.tags,operationId:l.operationId,summary:l.summary});if(s)return s}return (e=o==null?void 0:o.folderSplit)!=null&&e.byTags&&l.tags&&l.tags.length>0?l.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},an=(l,o,p,e,s)=>d(null,null,function*(){let t=on(l,p);if(t.length===0)return;let i=p.type||"fetch";p.outputDir||J.join(s,e,"client");let g=!!(o!=null&&o.folderSplit&&(o.folderSplit.byTags||o.folderSplit.customFolder));if(`${i}${t.length}`,g){let f={};t.forEach(j=>{let w=In(j,o);f[w]||(f[w]=[]),f[w].push(j);});let O=Object.keys(f);for(let[j,w]of Object.entries(f)){let A=J.join(s,e,j);yield ie.promises.mkdir(A,{recursive:true}),`${i}${j}${w.length}`,yield xn(w,o,p,A,i,j,true);}let q=J.join(s,e);yield En(q,O,i,o);return}let m=J.join(s,e);switch(yield ie.promises.mkdir(m,{recursive:true}),i){case "fetch":let f=Fe(t,p);f=f.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield X(J.join(m,"clients.ts"),f,o);break;case "axios":let O=he(t,p,false);O=O.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield X(J.join(m,"clients.ts"),O,o);break;case "react-query":let q=he(t,p,false);q=q.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield X(J.join(m,"clients.ts"),q,o);let j=Qe(t,p);j=j.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';").replace("import apiClient from './client';","import apiClient from './clients';"),yield X(J.join(m,"hooks.ts"),j,o);break;case "swr":let w=he(t,p,false);w=w.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield X(J.join(m,"clients.ts"),w,o);let A=Be(t,p);A=A.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';").replace("import apiClient from './client';","import apiClient from './clients';"),yield X(J.join(m,"hooks.ts"),A,o);break;case "rtk-query":let k=ze(t,p);k=k.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield X(J.join(m,"api.ts"),k,o);break;default:throw new Error(`Unknown client type: ${i}`)}}),X=(l,o,p)=>d(null,null,function*(){var i,n,g,m;if(!(((i=p==null?void 0:p.customCode)==null?void 0:i.enabled)!==false)){yield ie.promises.writeFile(l,o);return}let s=null;try{s=yield ie.promises.readFile(l,"utf-8");}catch(f){}let t=je(o,s,{position:((n=p==null?void 0:p.customCode)==null?void 0:n.position)||"bottom",markerText:(g=p==null?void 0:p.customCode)==null?void 0:g.markerText,includeInstructions:(m=p==null?void 0:p.customCode)==null?void 0:m.includeInstructions});yield ie.promises.writeFile(l,t);});var xn=(l,o,p,e,s,t,i=false)=>d(null,null,function*(){let n="",g="",m=i?"./types":"../types",f=i?"./endpoints":"../endpoints";switch(s){case "fetch":n=Fe(l,p,i),n=n.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${f}';`),yield X(J.join(e,"client.ts"),n,o);break;case "axios":n=he(l,p,i),n=n.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${f}';`),yield X(J.join(e,"client.ts"),n,o);break;case "react-query":if(n=he(l,p,i),n=n.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${f}';`),yield X(J.join(e,"client.ts"),n,o),g=Qe(l,p),g=g.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${f}';`),i){let q=t.replace(/-/g,"_");g=g.replace("import apiClient from './client';",`import { ${q}Client as apiClient } from '../clients';`);}yield X(J.join(e,"hooks.ts"),g,o);break;case "swr":if(n=he(l,p,i),n=n.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${f}';`),yield X(J.join(e,"client.ts"),n,o),g=Be(l,p),g=g.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${f}';`),i){let q=t.replace(/-/g,"_");g=g.replace("import apiClient from './client';",`import { ${q}Client as apiClient } from '../clients';`);}yield X(J.join(e,"hooks.ts"),g,o);break;case "rtk-query":let O=i?b(a({},p),{rtkQuery:b(a({},p.rtkQuery),{apiName:t.replace(/-/g,"_")})}):p;g=ze(l,O),g=g.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${f}';`),yield X(J.join(e,"api.ts"),g,o);break;default:throw new Error(`Unknown client type: ${s}`)}}),En=(l,o,p,e)=>d(null,null,function*(){var t;if(p==="rtk-query"){let i=`// Generated RTK Query APIs
|
|
684
686
|
`;i+=`// This file was auto-generated.
|
|
685
687
|
`,i+=`// Aggregates all API slices for easy Redux store setup
|
|
686
688
|
|
|
@@ -774,4 +776,4 @@ import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
|
774
776
|
`;}),i+=`
|
|
775
777
|
// Example usage:
|
|
776
778
|
`,i+=`// import { useGetSomething } from './hooks';
|
|
777
|
-
`,yield X(J.join(l,"hooks.ts"),i,e);}});var ke=process.cwd(),ln=()=>{let l;try{c("esbuild-register");}catch(i){throw i}let o=J.join(ke,"openapi.sync.js"),p=J.join(ke,"openapi.sync.ts"),e=J.join(ke,"openapi.sync.json"),s=[o,p,e];try{for(let i of s)ie.existsSync(i)&&(l=c(i),Object.keys(l).length===1&&l.default&&(l=l.default));}catch(i){}typeof l=="function"&&(l=l());let t=l;if(!t)throw new Error("No config found");return t},mr=l=>d(null,null,function*(){let o=ln(),p=Object.keys(o.api),e=l&&"refetchInterval"in l&&!isNaN(l==null?void 0:l.refetchInterval)?l.refetchInterval:o.refetchInterval;Me();for(let s=0;s<p.length;s+=1){let t=p[s],i=o.api[t];yield Le(i,t,o,e);}}),cr=l=>d(null,null,function*(){let o=ln(),p=l.apiName?[l.apiName]:Object.keys(o.api);for(let s of p)if(!o.api[s])throw new Error(`API "${s}" not found in configuration. Available APIs: ${Object.keys(o.api).join(", ")}`);Me();for(let s of p){let t=o.api[s];yield Le(t,s,o);}let e=(o==null?void 0:o.folder)||"api";for(let s of p){let t=nn(s);if(t.length===0){continue}`${t.length}${s}`;let i=a(a(a(a(b(a({enabled:true},o.clientGeneration||{}),{type:l.type}),l.outputDir&&{outputDir:l.outputDir}),l.baseURL&&{baseURL:l.baseURL}),l.tags&&{tags:l.tags}),l.endpoints&&{endpoints:l.endpoints});yield an(t,o,i,s,J.join(ke,e));}}),dr=()=>d(null,null,function*(){let{interactiveInit:l}=yield import('./interactive-init-
|
|
779
|
+
`,yield X(J.join(l,"hooks.ts"),i,e);}});var ke=process.cwd(),ln=()=>{let l;try{c("esbuild-register");}catch(i){throw i}let o=J.join(ke,"openapi.sync.js"),p=J.join(ke,"openapi.sync.ts"),e=J.join(ke,"openapi.sync.json"),s=[o,p,e];try{for(let i of s)ie.existsSync(i)&&(l=c(i),Object.keys(l).length===1&&l.default&&(l=l.default));}catch(i){}typeof l=="function"&&(l=l());let t=l;if(!t)throw new Error("No config found");return t},mr=l=>d(null,null,function*(){let o=ln(),p=Object.keys(o.api),e=l&&"refetchInterval"in l&&!isNaN(l==null?void 0:l.refetchInterval)?l.refetchInterval:o.refetchInterval;Me();for(let s=0;s<p.length;s+=1){let t=p[s],i=o.api[t];yield Le(i,t,o,e);}}),cr=l=>d(null,null,function*(){let o=ln(),p=l.apiName?[l.apiName]:Object.keys(o.api);for(let s of p)if(!o.api[s])throw new Error(`API "${s}" not found in configuration. Available APIs: ${Object.keys(o.api).join(", ")}`);Me();for(let s of p){let t=o.api[s];yield Le(t,s,o);}let e=(o==null?void 0:o.folder)||"api";for(let s of p){let t=nn(s);if(t.length===0){continue}`${t.length}${s}`;let i=a(a(a(a(b(a({enabled:true},o.clientGeneration||{}),{type:l.type}),l.outputDir&&{outputDir:l.outputDir}),l.baseURL&&{baseURL:l.baseURL}),l.tags&&{tags:l.tags}),l.endpoints&&{endpoints:l.endpoints});yield an(t,o,i,s,J.join(ke,e));}}),dr=()=>d(null,null,function*(){let{interactiveInit:l}=yield import('./interactive-init-GI3DBKYN.mjs');yield l();});export{cr as GenerateClient,mr as Init,dr as InteractiveInit,Ee as JSONStringify,ue as capitalize,Ht as createCustomCodeMarker,dn as extractCustomCode,Vt as getEndpointDetails,vn as getNestedValue,Kt as isJson,cn as isYamlString,je as mergeCustomCode,ve as renderTypeRefMD,wn as variableName,Wt as variableNameChar,_t as yamlStringToJson};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openapi-sync",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.4",
|
|
4
4
|
"description": "A powerful developer tool that automates API documentation synchronization with your codebase using OpenAPI specifications. Generates TypeScript types, fully-typed API clients (Fetch, Axios, React Query, SWR, RTK Query), endpoint definitions, runtime validation schemas (Zod, Yup, Joi), and comprehensive documentation with enterprise-grade reliability",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
File without changes
|