openapi-sync 5.0.0 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -1
- package/dist/index.d.mts +18 -1
- package/dist/index.d.ts +18 -1
- package/dist/index.js +397 -398
- package/dist/index.mjs +497 -498
- package/package.json +1 -1
- /package/dist/{interactive-init-4LMPMPGI.mjs → interactive-init-B7AFNUFL.mjs} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,375 +1,374 @@
|
|
|
1
|
-
import {c,d,a,b}from'./chunk-PUWCZVB7.mjs';import
|
|
2
|
-
`+" ".repeat(
|
|
3
|
-
`).filter(
|
|
4
|
-
${" ".repeat(
|
|
5
|
-
${" ".repeat(
|
|
1
|
+
import {c,d,a,b}from'./chunk-PUWCZVB7.mjs';import se from'fs';import D from'path';import*as Te from'js-yaml';import cn from'lodash.isequal';import Ge from'lodash.get';import yn from'axios';import fn from'axios-retry';import hn from'@apidevtools/swagger-parser';import {CurlGenerator}from'curl-generator';var xn=/^[A-Za-z_$][A-Za-z0-9_$]*$/,Dt=/[A-Za-z0-9_$]/;var Wt=u=>["object"].includes(typeof u)&&!(u instanceof Blob),pn=u=>{try{return Te.load(u),!0}catch(i){let n=i;if(n instanceof Te.YAMLException)return false;throw n}},Ht=u=>{if(pn(u)){let i=Te.load(u),n=JSON.stringify(i,null,2);return JSON.parse(n)}},ue=u=>u.substring(0,1).toUpperCase()+u.substring(1),Kt=(u,i)=>{let n=u.split("/"),e=`${ue(i)}`,s=[];return n.forEach(t=>{if(t[0]==="{"&&t[t.length-1]==="}"){let r=t.replace(/{/,"").replace(/}/,"");s.push(r),t=`$${r}`;}else if(t[0]==="<"&&t[t.length-1]===">"){let r=t.replace(/</,"").replace(/>/,"");s.push(r),t=`$${r}`;}else if(t[0]===":"){let r=t.replace(/:/,"");s.push(r),t=`$${r}`;}let o="";t.split("").forEach(r=>{let f=r;Dt.test(r)||(f="/"),o+=f;}),o.split("/").forEach(r=>{e+=ue(r);});}),{name:e,variables:s,pathParts:n}},Ee=(u,i=1)=>{let n="{",e=Object.keys(u);for(let s=0;s<e.length;s++){let t=e[s],o=u[t];if(n+=`
|
|
2
|
+
`+" ".repeat(i)+t+": ",Array.isArray(o)){n+="[";for(let r=0;r<o.length;r++){let f=o[r];typeof f=="object"&&f!==null?n+=Ee(f,i+1):n+=typeof f=="string"?`"${f}"`:f,r<o.length-1&&(n+=", ");}n+="]";}else typeof o=="object"&&o!==null?n+=""+Ee(o,i+1):n+=o.split(`
|
|
3
|
+
`).filter(r=>r.trim()!=="").join(`
|
|
4
|
+
${" ".repeat(i)}`);s<e.length-1&&(n+=", ");}return n+=`
|
|
5
|
+
${" ".repeat(i-1)}}`,n},ve=(u,i=1)=>`
|
|
6
6
|
\`\`\`typescript
|
|
7
|
-
${" ".repeat(
|
|
8
|
-
`).filter(
|
|
9
|
-
${" ".repeat(
|
|
10
|
-
\`\`\``;function wn(
|
|
11
|
-
`,
|
|
12
|
-
`).filter(
|
|
7
|
+
${" ".repeat(i)} ${u.split(`
|
|
8
|
+
`).filter(n=>n.trim()!=="").join(`
|
|
9
|
+
${" ".repeat(i)} `)}
|
|
10
|
+
\`\`\``;function wn(u,i){return i.split(".").reduce((e,s)=>e&&e[s]!==void 0?e[s]:void 0,u)}var mn=(u,i="CUSTOM CODE")=>{let n=`// \u{1F512} ${i} START`,e=`// \u{1F512} ${i} END`,s={beforeGenerated:"",afterGenerated:""},t=0,o=[];for(;t<u.length;){let r=u.indexOf(n,t);if(r===-1)break;let f=u.indexOf(e,r);if(f===-1)break;let m=f+e.length,y=u.substring(m,m+100),A=y.match(/^\s*\n\s*(\/\/ =+)/);if(A){let G=y.indexOf(`
|
|
11
|
+
`,A.index+1);G!==-1?m+=G+1:m+=A[0].length;}let S=r,x=u.substring(Math.max(0,r-200),r).lastIndexOf("// ==========");x!==-1&&(S=Math.max(0,r-200)+x);let v=u.substring(S,m);o.push({start:S,end:m,content:v}),t=m;}return o.length>0&&(u.substring(0,o[0].start).split(`
|
|
12
|
+
`).filter(m=>{let y=m.trim();return y.length>0&&!y.startsWith("//")}).join("").length===0?(s.beforeGenerated=o[0].content,o.length>1&&(s.afterGenerated=o[1].content)):(s.afterGenerated=o[0].content,o.length>1&&!s.beforeGenerated&&(s.beforeGenerated=o[1].content))),s},Jt=(u,i="CUSTOM CODE",n=true)=>{let e=n?`// ${u==="top"?"Add your custom code below this line":"Add your custom code above this line"}
|
|
13
13
|
// This section will be preserved during regeneration
|
|
14
14
|
`:"";return `// ${"=".repeat(60)}
|
|
15
|
-
// \u{1F512} ${
|
|
15
|
+
// \u{1F512} ${i} START
|
|
16
16
|
${e}// ${"=".repeat(60)}
|
|
17
17
|
|
|
18
|
-
// \u{1F512} ${
|
|
19
|
-
// ${"=".repeat(60)}`},
|
|
20
|
-
`)};var
|
|
21
|
-
`).filter(
|
|
22
|
-
*${" ".repeat(1)}`))),
|
|
23
|
-
${
|
|
18
|
+
// \u{1F512} ${i} END
|
|
19
|
+
// ${"=".repeat(60)}`},qe=(u,i,n={})=>{let{position:e="bottom",markerText:s="CUSTOM CODE",includeInstructions:t=true}=n,o={beforeGenerated:"",afterGenerated:""};i&&(o=mn(i,s)),!o.beforeGenerated&&!o.afterGenerated&&((e==="top"||e==="both")&&(o.beforeGenerated=Jt("top",s,t)),(e==="bottom"||e==="both")&&(o.afterGenerated=Jt("bottom",s,t)));let r=[];return o.beforeGenerated&&(r.push(o.beforeGenerated),r.push("")),r.push(u),o.afterGenerated&&(r.push(""),r.push(o.afterGenerated)),r.join(`
|
|
20
|
+
`)};var je=D.join(__dirname,"../","../db.json");se.existsSync(je)||se.writeFileSync(je,"{}");var Ue={};try{Ue=c(je);}catch(u){Ue={};}var we=Ue||{},_t=u=>{se.writeFileSync(je,JSON.stringify(u));},Vt=(u,i)=>{we[u]=i,_t(we);},Yt=u=>we[u],Me=()=>{we={},_t(we);};var Zt={},Xt=(u,i)=>{Zt[u]=i;},en=u=>Zt[u]||[];var ce=process.cwd(),Ne={},tn=yn.create({timeout:6e4});fn(tn,{retries:20,retryCondition:u=>u.code==="ECONNABORTED"||u.message.includes("Network Error"),retryDelay:u=>u*1e3});var ye=(u,i,n)=>d(null,null,function*(){var o,r,f,m;if(!(((o=n==null?void 0:n.customCode)==null?void 0:o.enabled)!==false)){yield se.promises.writeFile(u,i);return}let s=null;try{s=yield se.promises.readFile(u,"utf-8");}catch(y){}let t=qe(i,s,{position:((r=n==null?void 0:n.customCode)==null?void 0:r.position)||"bottom",markerText:(f=n==null?void 0:n.customCode)==null?void 0:f.markerText,includeInstructions:(m=n==null?void 0:n.customCode)==null?void 0:m.includeInstructions});yield se.promises.writeFile(u,t);}),nn=(u,i,n,e)=>d(null,null,function*(){var oe,te,ie,ge,he,Pe,De,Je,We,He;let s=yield tn.get(u),t=Wt(s.data)?s.data:Ht(s.data),o;try{o=yield hn.parse(t);}catch(a){let p=a instanceof Error?a.message:String(a);throw new Error(`Failed to parse OpenAPI spec for ${i}: ${p}`)}let r=D.join((n==null?void 0:n.folder)||"",i),f={},m=a=>{var p,w;if((p=n==null?void 0:n.folderSplit)!=null&&p.customFolder){let g=n.folderSplit.customFolder(a);if(g)return g}return (w=n==null?void 0:n.folderSplit)!=null&&w.byTags&&a.tags&&a.tags.length>0?a.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},y=typeof(n==null?void 0:n.server)=="string"?n==null?void 0:n.server:((te=(oe=o==null?void 0:o.servers)==null?void 0:oe[(n==null?void 0:n.server)||0])==null?void 0:te.url)||"",A=typeof((ge=(ie=n==null?void 0:n.types)==null?void 0:ie.name)==null?void 0:ge.prefix)=="string"?n==null?void 0:n.types.name.prefix:"I",S=typeof((Pe=(he=n==null?void 0:n.endpoints)==null?void 0:he.name)==null?void 0:Pe.prefix)=="string"?n==null?void 0:n.endpoints.name.prefix:"",j=(a,p)=>{var g,c;let w=ue(a);if((c=(g=n==null?void 0:n.types)==null?void 0:g.name)!=null&&c.format){let h=n==null?void 0:n.types.name.format("shared",{name:a},w);if(h)return `${A}${h}`}return `${A}${w}`},x=(a,p,w,g,c,h=0)=>{let d="",C="",$="";if(p)if(p.$ref)if(p.$ref[0]==="#"){let q=(p.$ref||"").split("/");q.shift(),[...q].pop();let L=Ge(a,q,null);if(L){L!=null&&L.name&&(d=L.name),C=q[q.length-1];let H=j(C);H.includes(".")&&(H=H.split(".").map((pe,$e)=>$e===0?pe:`["${pe}"]`).join("")),$+=`${c!=null&&c.noSharedImport?"":"Shared."}${H}`;}}else $+="";else if(p.anyOf)$+=`(${p.anyOf.map(q=>x(a,q,"",g,c)).filter(q=>!!q).join("|")})`;else if(p.oneOf)$+=`(${p.oneOf.map(q=>x(a,q,"",g,c)).filter(q=>!!q).join("|")})`;else if(p.allOf)$+=`(${p.allOf.map(q=>x(a,q,"",g,c)).filter(q=>!!q).join("&")})`;else if(p.items)$+=`${x(a,p.items,"",false,c)}[]`;else if(p.properties){let q=Object.keys(p.properties),N=p.required||[],Q="";q.forEach(L=>{var le,pe,$e,Ce,be,de;let H="";!((pe=(le=n==null?void 0:n.types)==null?void 0:le.doc)!=null&&pe.disable)&&((Ce=($e=p.properties)==null?void 0:$e[L])!=null&&Ce.description)&&(H=" * "+((be=p.properties)==null?void 0:be[L].description.split(`
|
|
21
|
+
`).filter(Re=>Re.trim()!=="").join(`
|
|
22
|
+
*${" ".repeat(1)}`))),Q+=(H?`/**
|
|
23
|
+
${H}
|
|
24
24
|
*/
|
|
25
|
-
`:"")+`${x(a,(
|
|
26
|
-
${" ".repeat(
|
|
27
|
-
`:""}`:""},
|
|
28
|
-
`);
|
|
29
|
-
${
|
|
30
|
-
}`:c+="{}";}else if(
|
|
31
|
-
`).filter(
|
|
32
|
-
*${" ".repeat(1)}`)),
|
|
33
|
-
${
|
|
25
|
+
`:"")+`${x(a,(de=p.properties)==null?void 0:de[L],L,N.includes(L),c,h+1)}`;}),Q.length>0?$+=`{
|
|
26
|
+
${" ".repeat(h)}${Q}${" ".repeat(h)}}`:$+="{[k: string]: any}";}else if(p.enum&&p.enum.length>0){let q=p.enum.includes(null),N=p.enum.filter(L=>L!==null).map(L=>JSON.stringify(L)).filter(L=>L!==void 0),Q=N.length>1||N.length>0&&q;Q&&($+="("),N.forEach((L,H)=>{$+=`${H===0?"":"|"}${L}`;}),q&&($+=`${N.length>0?"|":""}null`),Q&&($+=")");}else if(p.type){let q=N=>{let Q="";if(typeof N=="string")["string","integer","number","array","boolean","null"].includes(N)?["integer","number"].includes(N)?Q+="number":N==="array"?Q+="any[]":Q+=N:N==="object"&&(p.additionalProperties?Q+=`{[k: string]: ${x(a,p.additionalProperties,"",true,c)||"any"}}`:Q+="{[k: string]: any}");else if(Array.isArray(N)){let L=N.map(H=>q(H));L.filter(H=>H!==""),L.length>1&&(Q+="("+L.join("|")+")");}else Q+="any";return Q};$=q(p.type);}else $+="any";else $="string";let P=d||w;c!=null&&c.useComponentName&&!P&&(P=C);let W=P?` "${P}"${g?"":"?"}: `:"",l=(p==null?void 0:p.enum)&&p.enum.includes(null),V=p!=null&&p.nullable&&!l?" | null":"";return $.length>0?`${W}${$}${V}${P?`;
|
|
27
|
+
`:""}`:""},v=(a,p)=>{let c="";if(p)if(p.$ref)if(p.$ref[0]==="#"){let h=(p.$ref||"").split("/");h.shift();let C=Ge(a,h,null);C&&(C!=null&&C.name&&(C.name),h[h.length-1],c+=v(a,C));}else c+="";else if(p.anyOf)c+=v(a,p.anyOf[0]);else if(p.oneOf)c+=v(a,p.oneOf[0]);else if(p.allOf)c+=`{${p.allOf.map(h=>`...(${v(a,h)})`).join(",")}}`;else if(p.items)c+=`[${v(a,p.items)}]`;else if(p.properties){let C=Object.keys(p.properties).map($=>{var P;return ` "${$}": ${v(a,(P=p.properties)==null?void 0:P[$])}`}).join(`,
|
|
28
|
+
`);C.length>0?c+=`{
|
|
29
|
+
${C}
|
|
30
|
+
}`:c+="{}";}else if(p.enum&&p.enum.length>0)p.enum.length>1&&(c+=p.enum[0]);else if(p.type)if(p.example)c+=JSON.stringify(p.example);else {let h=d=>{let C="";if(typeof d=="string")["string","integer","number","array","boolean","null"].includes(d)?["integer","number"].includes(d)?C+="123":d==="array"?C+="[]":d==="boolean"?C+="true":d==="null"?C+="null":C+=`"${d}"`:d==="object"&&(C+="{}");else if(Array.isArray(d)){let $=d.map(P=>h(P));$.filter(P=>P!==""),$.length>1&&(C+=$.join("|"));}else C+="any";return C};c=h(p.type);}else c+="any";else c="string";return c};e&&!isNaN(e)&&e>0&&(process.env.NODE_ENV&&["production","prod","test","staging"].includes(process.env.NODE_ENV)||(Ne[i]&&clearTimeout(Ne[i]),Ne[i]=setTimeout(()=>nn(u,i,n,e),e)));let G=Yt(i);if(cn(G,o))return;Vt(i,o);let R="",J="",T={},I=[];o.components&&Object.keys(o.components).forEach(a=>{if(["schemas","responses","parameters","examples","requestBodies","headers","links","callbacks"].includes(a)){let p=o.components[a],w={},g={};Object.keys(p).forEach(h=>{var $;let d=($=p[h])!=null&&$.schema?p[h].schema:p[h],C=`${x(o,d,"",true,{noSharedImport:true,useComponentName:["parameters"].includes(a)})}`;if(C){let P=h.split("."),W=w,l=g;for(let V=0;V<P.length;V++){let q=P[V];V<P.length-1?(q in W||(W[q]={},l[q]={}),W=W[q],l=l[q]):(W[q]=C,l[q]=d);}}}),Object.keys(w).forEach(h=>{var P,W,l,V;let d=j(h),C=w[h],$="";!((W=(P=n==null?void 0:n.types)==null?void 0:P.doc)!=null&&W.disable)&&h in p&&((l=p[h])!=null&&l.description)&&($=" * "+p[h].description.split(`
|
|
31
|
+
`).filter(q=>q.trim()!=="").join(`
|
|
32
|
+
*${" ".repeat(1)}`)),T[h]=((V=T[h])!=null?V:"")+($?`/**
|
|
33
|
+
${$}
|
|
34
34
|
*/
|
|
35
|
-
`:"")+"export type "+d+" = "+(typeof
|
|
36
|
-
`;});}});let
|
|
37
|
-
`);return
|
|
38
|
-
${
|
|
39
|
-
${" ".repeat(
|
|
40
|
-
${
|
|
41
|
-
${" ".repeat(
|
|
42
|
-
${
|
|
43
|
-
${" ".repeat(
|
|
44
|
-
${
|
|
45
|
-
`;
|
|
46
|
-
`),
|
|
47
|
-
${
|
|
35
|
+
`:"")+"export type "+d+" = "+(typeof C=="string"?C:Ee(C))+`;
|
|
36
|
+
`;});}});let _=a=>{let p="";if(a.content){let w=Object.keys(a.content);w[0]&&a.content[w[0]].schema&&(p+=`${x(o,a.content[w[0]].schema,"")}`);}return p},O=(a,p,w=0)=>{if(!a)return p==="joi"?"Joi.any()":p==="yup"?"yup.mixed()":"z.any()";if(a.$ref){if(a.$ref[0]==="#"){let g=a.$ref.split("/");g.shift();let c=g.join("."),h=Ge(o,c);if(h)return O(h,p,w)}return p==="joi"?"Joi.any()":p==="yup"?"yup.mixed()":"z.any()"}if(a.anyOf||a.oneOf){let g=a.anyOf||a.oneOf;if(g.every(h=>h.enum!==void 0&&Array.isArray(h.enum))){let h=[],d=false;if(g.forEach(C=>{C.enum&&C.enum.forEach($=>{$===null?d=true:h.includes($)||h.push($);});}),h.length>0){let C=h.map($=>JSON.stringify($)).join(", ");if(p==="zod"){let $=`z.enum([${C}])`;return d&&($+=".nullable()"),$}else if(p==="yup"){let $=`yup.mixed().oneOf([${C}])`;return d&&($+=".nullable()"),$}else return d?`Joi.valid(${C}, null)`:`Joi.valid(${C})`}else if(d)return p==="zod"?"z.null()":p==="yup"?"yup.mixed().nullable()":"Joi.valid(null)"}return p==="zod"?`z.union([${g.map(C=>O(C,p,w+1)).join(", ")}])`:p==="yup"?`yup.mixed().oneOf([${g.map(C=>O(C,p,w+1)).join(", ")}])`:`Joi.alternatives().try(${g.map(d=>O(d,p,w+1)).join(", ")})`}if(a.allOf)if(p==="zod"){let g=a.allOf.map(h=>O(h,p,w+1)),c=g[0];for(let h=1;h<g.length;h++)c=`${c}.merge(${g[h]})`;return c}else return O(a.allOf[0],p,w+1);if(a.items){let g=O(a.items,p,w+1);if(p==="zod"){let c=`z.array(${g})`;return a.minItems!==void 0&&(c+=`.min(${a.minItems})`),a.maxItems!==void 0&&(c+=`.max(${a.maxItems})`),c}else if(p==="yup"){let c=`yup.array().of(${g})`;return a.minItems!==void 0&&(c+=`.min(${a.minItems})`),a.maxItems!==void 0&&(c+=`.max(${a.maxItems})`),c}else {let c=`Joi.array().items(${g})`;return a.minItems!==void 0&&(c+=`.min(${a.minItems})`),a.maxItems!==void 0&&(c+=`.max(${a.maxItems})`),c}}if(a.properties){let g=a.required||[],c=" ".repeat(w+1),h=Object.entries(a.properties).map(([d,C])=>{let $=g.includes(d),P=O(C,p,w+1);return $||(P+=".optional()"),`${c}${d}: ${P}`}).join(`,
|
|
37
|
+
`);return p==="zod"?`z.object({
|
|
38
|
+
${h}
|
|
39
|
+
${" ".repeat(w)}})`:p==="yup"?`yup.object({
|
|
40
|
+
${h}
|
|
41
|
+
${" ".repeat(w)}})`:`Joi.object({
|
|
42
|
+
${h}
|
|
43
|
+
${" ".repeat(w)}})`}if(a.enum&&a.enum.length>0){let g=[],c=false;a.enum.forEach(d=>{d===null?c=true:g.includes(d)||g.push(d);});let h=g.map(d=>JSON.stringify(d)).join(", ");if(p==="zod"){let d=`z.enum([${h}])`;return c&&(d+=".nullable()"),d}else if(p==="yup"){let d=`yup.mixed().oneOf([${h}])`;return c&&(d+=".nullable()"),d}else {let d=`Joi.valid(${h})`;return c&&(d+=".allow(null)"),d}}if(a.type){let c=(h=>{switch(h){case "string":if(p==="zod"){let d="z.string()";return a.format==="email"?d+=".email()":a.format==="uuid"?d+=".uuid()":a.format==="url"||a.format==="uri"?d+=".url()":a.format==="date-time"?d+=".datetime()":a.format==="date"&&(d+=".date()"),a.minLength&&(d+=`.min(${a.minLength})`),a.maxLength&&(d+=`.max(${a.maxLength})`),a.pattern&&(d+=`.regex(/${a.pattern}/)`),d}else if(p==="yup"){let d="yup.string()";return a.format==="email"?d+=".email()":(a.format==="url"||a.format==="uri")&&(d+=".url()"),a.minLength&&(d+=`.min(${a.minLength})`),a.maxLength&&(d+=`.max(${a.maxLength})`),a.pattern&&(d+=`.matches(/${a.pattern}/)`),d}else {let d="Joi.string()";return a.format==="email"?d+=".email()":a.format==="url"||a.format==="uri"?d+=".uri()":a.format==="uuid"?d+=".guid({ version: 'uuidv4' })":a.format==="date-time"&&(d+=".isoDate()"),a.minLength&&(d+=`.min(${a.minLength})`),a.maxLength&&(d+=`.max(${a.maxLength})`),a.pattern&&(d+=`.pattern(/${a.pattern}/)`),d}case "integer":case "number":if(p==="zod"){let d="z.number()";return h==="integer"&&(d+=".int()"),a.minimum!==void 0&&(a.exclusiveMinimum?d+=`.gt(${a.minimum})`:d+=`.min(${a.minimum})`),a.maximum!==void 0&&(a.exclusiveMaximum?d+=`.lt(${a.maximum})`:d+=`.max(${a.maximum})`),d}else if(p==="yup"){let d="yup.number()";return h==="integer"&&(d+=".integer()"),a.minimum!==void 0&&(d+=`.min(${a.minimum})`),a.maximum!==void 0&&(d+=`.max(${a.maximum})`),d}else {let d="Joi.number()";return h==="integer"&&(d+=".integer()"),a.minimum!==void 0&&(a.exclusiveMinimum?d+=`.greater(${a.minimum})`:d+=`.min(${a.minimum})`),a.maximum!==void 0&&(a.exclusiveMaximum?d+=`.less(${a.maximum})`:d+=`.max(${a.maximum})`),d}case "boolean":return p==="joi"?"Joi.boolean()":p==="yup"?"yup.boolean()":"z.boolean()";case "null":return p==="joi"?"Joi.any().allow(null)":p==="yup"?"yup.mixed().nullable()":"z.null()";default:return p==="joi"?"Joi.any()":p==="yup"?"yup.mixed()":"z.any()"}})(typeof a.type=="string"?a.type:a.type[0]);return a.nullable&&p!=="joi"?c+=".nullable()":a.nullable&&p==="joi"&&(c+=".allow(null)"),c}return p==="joi"?"Joi.any()":p==="yup"?"yup.mixed()":"z.any()"},z=a=>{var p,w,g,c,h;if((w=(p=n==null?void 0:n.endpoints)==null?void 0:p.value)!=null&&w.replaceWords&&Array.isArray(n==null?void 0:n.endpoints.value.replaceWords)){let d=a;return (h=(c=(g=n==null?void 0:n.endpoints)==null?void 0:g.value)==null?void 0:c.replaceWords)==null||h.forEach((C,$)=>{let P=new RegExp(C.replace,"g");d=d.replace(P,C.with||"");}),d}else return a},ae=(a,p,w=[])=>{var h,d;let g=(h=n==null?void 0:n.endpoints)==null?void 0:h.exclude,c=(d=n==null?void 0:n.endpoints)==null?void 0:d.include;if(c){let C=c.tags&&c.tags.length>0?w.some(P=>c.tags.includes(P)):true,$=c.endpoints&&c.endpoints.length>0?c.endpoints.some(P=>{let W=!P.method||P.method.toLowerCase()===p.toLowerCase();return P.path?a===P.path&&W:P.regex?new RegExp(P.regex).test(a)&&W:false}):true;if(!C||!$)return true}return !!(g&&(g.tags&&g.tags.length>0&&w.some($=>g.tags.includes($))||g.endpoints&&g.endpoints.length>0&&g.endpoints.some($=>{let P=!$.method||$.method.toLowerCase()===p.toLowerCase();return $.path?a===$.path&&P:$.regex?new RegExp($.regex).test(a)&&P:false})))};if(Object.keys(o.paths||{}).forEach(a=>{let p=o.paths[a];Object.keys(p).forEach(g=>{var _e,Ve,Ye,Ze,Xe,et,tt,nt,rt,st,at,ot,it,lt,ut,pt,mt,dt,ct,yt,ft,ht,$t,gt,Ct,bt,It,xt,Et,Tt,wt,At,Pt,vt,qt,jt,Ot,kt,Rt,St,Ut,Mt,Gt,Nt,Lt,Ft,Qt,Bt,zt;let c=g,h=Kt(a,c),d=((_e=p[c])==null?void 0:_e.tags)||[];if(ae(a,c,d))return;let C=p[c],$=m({method:c,path:a,summary:C==null?void 0:C.summary,operationId:C==null?void 0:C.operationId,tags:d,parameters:C==null?void 0:C.parameters,requestBody:C==null?void 0:C.requestBody,responses:C==null?void 0:C.responses});f[$]||(f[$]={endpoints:"",types:"",validation:""});let P=((Ye=(Ve=n==null?void 0:n.endpoints)==null?void 0:Ve.value)!=null&&Ye.includeServer?y:"")+h.pathParts.map(b=>(b[0]==="{"&&b[b.length-1]==="}"?b=`\${${b.replace(/{/,"").replace(/}/,"")}}`:b[0]==="<"&&b[b.length-1]===">"?b=`\${${b.replace(/</,"").replace(/>/,"")}}`:b[0]===":"&&(b=`\${${b.replace(/:/,"")}}`),b)).join("/"),W=`"${P}"`;h.variables.length>0&&(W=`(${h.variables.map(E=>`${E}:string`).join(",")})=> \`${P}\``),W=z(W);let l=p[c],V="",q;if(l!=null&&l.parameters&&((l==null?void 0:l.parameters).forEach((E,k)=>{(E.$ref||E.in==="query"&&E.name)&&(V+=`${x(o,E.$ref?E:E.schema,E.name||"",E.required)}`);}),V)){V=`{
|
|
44
|
+
${V}}`;let E=`${h.name}Query`;if((Xe=(Ze=n==null?void 0:n.types)==null?void 0:Ze.name)!=null&&Xe.useOperationId&&(l!=null&&l.operationId)&&(E=`${l.operationId}Query`),E=ue(`${A}${E}`),(tt=(et=n==null?void 0:n.types)==null?void 0:et.name)!=null&&tt.format){let F=n==null?void 0:n.types.name.format("endpoint",{code:"",type:"query",method:c,path:a,summary:l==null?void 0:l.summary,operationId:l==null?void 0:l.operationId},E);F&&(E=`${A}${F}`);}q=E;let k=`export type ${E} = ${V};
|
|
45
|
+
`;n!=null&&n.folderSplit?f[$].types+=k:J+=k;}if(((nt=n==null?void 0:n.validations)==null?void 0:nt.disable)!==true&&((st=(rt=n==null?void 0:n.validations)==null?void 0:rt.generate)==null?void 0:st.query)!==false&&(l!=null&&l.parameters)){let b=((at=n.validations)==null?void 0:at.library)||"zod",k=l.parameters.filter(F=>!F.$ref&&F.in==="query"&&F.name);if(k.length>0){let F=((ot=n==null?void 0:n.validations)==null?void 0:ot.name)||((it=n==null?void 0:n.types)==null?void 0:it.name),K=typeof(F==null?void 0:F.prefix)=="string"?F.prefix:"I",M=typeof((ut=(lt=n==null?void 0:n.validations)==null?void 0:lt.name)==null?void 0:ut.suffix)=="string"?n.validations.name.suffix:"Schema",B=`${h.name}Query`;if(F!=null&&F.useOperationId&&(l!=null&&l.operationId)&&(B=`${l.operationId}Query`),B=ue(`${K}${B}${M}`),(mt=(pt=n==null?void 0:n.validations)==null?void 0:pt.name)!=null&&mt.format){let ee=n.validations.name.format({code:"",type:"query",method:c,path:a,summary:l==null?void 0:l.summary,operationId:l==null?void 0:l.operationId},B);ee&&(B=`${K}${ee}${M}`);}else if((ct=(dt=n==null?void 0:n.types)==null?void 0:dt.name)!=null&&ct.format){let ee=n.types.name.format("endpoint",{code:"",type:"query",method:c,path:a,summary:l==null?void 0:l.summary,operationId:l==null?void 0:l.operationId},B);ee&&(B=`${K}${ee}${M}`);}let U=k.map(ee=>{let ln=ee!=null&&ee.schema?O(ee.schema,b):b==="joi"?"Joi.string()":b==="yup"?"yup.string()":"z.string()",un=ee.required?"":".optional()";return ` ${ee.name}: ${ln}${un}`}).join(`,
|
|
46
|
+
`),me=`export const ${B} = ${b==="joi"?"Joi.object":b==="yup"?"yup.object":"z.object"}({
|
|
47
|
+
${U}
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
`;
|
|
51
|
-
`;
|
|
50
|
+
`;n!=null&&n.folderSplit||f[$]||(f[$]={endpoints:"",types:"",validation:""}),f[$].validation+=me;}}let N=l==null?void 0:l.requestBody,Q="",L;if(N&&(Q=_(N),Q)){let b=`${h.name}DTO`;if((ft=(yt=n==null?void 0:n.types)==null?void 0:yt.name)!=null&&ft.useOperationId&&(l!=null&&l.operationId)&&(b=`${l.operationId}DTO`),b=ue(`${A}${b}`),($t=(ht=n==null?void 0:n.types)==null?void 0:ht.name)!=null&&$t.format){let k=n==null?void 0:n.types.name.format("endpoint",{code:"",type:"dto",method:c,path:a,summary:l==null?void 0:l.summary,operationId:l==null?void 0:l.operationId},b);k&&(b=`${A}${k}`);}L=b;let E=`export type ${b} = ${Q};
|
|
51
|
+
`;n!=null&&n.folderSplit?f[$].types+=E:J+=E;}if(((gt=n==null?void 0:n.validations)==null?void 0:gt.disable)!==true&&((bt=(Ct=n==null?void 0:n.validations)==null?void 0:Ct.generate)==null?void 0:bt.dto)!==false&&N){let b=((It=n.validations)==null?void 0:It.library)||"zod";if(N.content){let E=Object.keys(N.content);if(E[0]&&N.content[E[0]].schema){let k=((xt=n==null?void 0:n.validations)==null?void 0:xt.name)||((Et=n==null?void 0:n.types)==null?void 0:Et.name),F=typeof(k==null?void 0:k.prefix)=="string"?k.prefix:"I",K=typeof((wt=(Tt=n==null?void 0:n.validations)==null?void 0:Tt.name)==null?void 0:wt.suffix)=="string"?n.validations.name.suffix:"Schema",M=`${h.name}DTO`;if(k!=null&&k.useOperationId&&(l!=null&&l.operationId)&&(M=`${l.operationId}DTO`),M=ue(`${F}${M}${K}`),(Pt=(At=n==null?void 0:n.validations)==null?void 0:At.name)!=null&&Pt.format){let X=n.validations.name.format({code:"",type:"dto",method:c,path:a,summary:l==null?void 0:l.summary,operationId:l==null?void 0:l.operationId},M);X&&(M=`${F}${X}${K}`);}else if((qt=(vt=n==null?void 0:n.types)==null?void 0:vt.name)!=null&&qt.format){let X=n.types.name.format("endpoint",{code:"",type:"dto",method:c,path:a,summary:l==null?void 0:l.summary,operationId:l==null?void 0:l.operationId},M);X&&(M=`${F}${X}${K}`);}let B=O(N.content[E[0]].schema,b),U=`export const ${M} = ${B};
|
|
52
52
|
|
|
53
|
-
`;
|
|
54
|
-
`;
|
|
55
|
-
- Scopes: [\`${
|
|
56
|
-
- ${
|
|
57
|
-
`),
|
|
58
|
-
--cert client-certificate.crt --key client-private-key.key --cacert ca-certificate.crt`:
|
|
53
|
+
`;n!=null&&n.folderSplit||f[$]||(f[$]={endpoints:"",types:"",validation:""}),f[$].validation+=U;}}}let H={},le="",pe="";if(l!=null&&l.responses){let b=l==null?void 0:l.responses;Object.keys(b).forEach(k=>{var F,K,M,B;if(le=_(b[k]),H[k]=le,le){let U=`${h.name}${k}Response`;if((K=(F=n==null?void 0:n.types)==null?void 0:F.name)!=null&&K.useOperationId&&(l!=null&&l.operationId)&&(U=`${l.operationId}${k}Response`),U=ue(`${A}${U}`),(B=(M=n==null?void 0:n.types)==null?void 0:M.name)!=null&&B.format){let ee=n==null?void 0:n.types.name.format("endpoint",{code:k,type:"response",method:c,path:a,summary:l==null?void 0:l.summary,operationId:l==null?void 0:l.operationId},U);ee&&(U=`${A}${ee}`);}let X=`export type ${U} = ${le};
|
|
54
|
+
`;n!=null&&n.folderSplit?f[$].types+=X:J+=X,H[k]=U;let me=parseInt(k);me>=200&&me<300&&(pe=U);}});}let $e=b=>!b||!b.length?"":b.map(E=>Object.entries(E).map(([F,K])=>{let M=F,B="";return Array.isArray(K)&&K.length&&(B=`
|
|
55
|
+
- Scopes: [\`${K.join("`, `")}\`]`,M=`**${M}**`),`
|
|
56
|
+
- ${M}${B}`}).join("")).join(`
|
|
57
|
+
`),Ce=l!=null&&l.security?$e(l.security):"",be="";if(!((Ot=(jt=n==null?void 0:n.endpoints)==null?void 0:jt.doc)!=null&&Ot.disable)){let b="";if((Rt=(kt=n==null?void 0:n.endpoints)==null?void 0:kt.doc)!=null&&Rt.showCurl){let E={},k="",F="";(St=l.requestBody)!=null&&St.content&&Object.keys(l.requestBody.content).forEach(B=>{let U=l.requestBody.content[B].schema;if(U){Array.isArray(E["Content-type"])?E["Content-type"].push(B):E["Content-type"]=[B];let X=v(o,U);X&&(k=X);}}),l!=null&&l.security&&l.security.forEach(M=>{Object.keys(M).forEach(B=>{var X,me;let U=(me=(X=o.components)==null?void 0:X.securitySchemes)==null?void 0:me[B];U&&(U.type==="mutualTLS"?F+=`
|
|
58
|
+
--cert client-certificate.crt --key client-private-key.key --cacert ca-certificate.crt`:U.type==="apiKey"?E[(U==null?void 0:U.name)||"X-API-KEY"]="{API_KEY_VALUE}":E.Authorization=`${(U==null?void 0:U.scheme)==="basic"?"Basic":"Bearer"} {${(U==null?void 0:U.scheme)==="basic"?"VALUE":"TOKEN"}}`);});});let K={};Object.keys(E).forEach(M=>{Array.isArray(E[M])?K[M]=E[M].join("; "):K[M]=E[M];}),b=`
|
|
59
59
|
\`\`\`bash
|
|
60
|
-
${CurlGenerator({url:
|
|
61
|
-
\`\`\``;}
|
|
60
|
+
${CurlGenerator({url:y+a,method:c.toUpperCase(),headers:K,body:k})}${F}
|
|
61
|
+
\`\`\``;}be=`/**${l!=null&&l.description?`
|
|
62
62
|
* ${l==null?void 0:l.description} `:""}
|
|
63
63
|
* **Method**: \`${c.toUpperCase()}\`
|
|
64
64
|
* **Summary**: ${(l==null?void 0:l.summary)||""}
|
|
65
|
-
* **Tags**: [${((
|
|
66
|
-
* **OperationId**: ${(l==null?void 0:l.operationId)||""} ${
|
|
67
|
-
* **Query**: ${
|
|
68
|
-
* **DTO**: ${
|
|
69
|
-
* **Response**: ${Object.entries(
|
|
70
|
-
- **${
|
|
71
|
-
* **Security**: ${
|
|
72
|
-
`:""}${
|
|
65
|
+
* **Tags**: [${((Ut=l==null?void 0:l.tags)==null?void 0:Ut.join(", "))||""}]
|
|
66
|
+
* **OperationId**: ${(l==null?void 0:l.operationId)||""} ${V?`
|
|
67
|
+
* **Query**: ${ve(V)} `:""}${Q?`
|
|
68
|
+
* **DTO**: ${ve(Q)} `:""}${le?`
|
|
69
|
+
* **Response**: ${Object.entries(H).map(([E,k])=>`
|
|
70
|
+
- **${E}**: ${ve(k,2)} `).join("")}`:""}${Ce?`
|
|
71
|
+
* **Security**: ${Ce}
|
|
72
|
+
`:""}${b}
|
|
73
73
|
*/
|
|
74
|
-
`;}let
|
|
75
|
-
`;
|
|
76
|
-
|
|
77
|
-
${
|
|
78
|
-
|
|
79
|
-
${
|
|
80
|
-
`),
|
|
81
|
-
|
|
82
|
-
`:""}${
|
|
83
|
-
|
|
84
|
-
${
|
|
85
|
-
`;
|
|
86
|
-
|
|
87
|
-
`,
|
|
88
|
-
`;let o=new Set;return
|
|
89
|
-
`;}),
|
|
90
|
-
|
|
91
|
-
`,
|
|
92
|
-
`,
|
|
93
|
-
`;}),
|
|
94
|
-
|
|
95
|
-
`,
|
|
96
|
-
`,
|
|
97
|
-
`,
|
|
98
|
-
`,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
`,
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
`,
|
|
105
|
-
`,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
`,
|
|
109
|
-
`,
|
|
110
|
-
|
|
111
|
-
`,
|
|
112
|
-
`,
|
|
113
|
-
`,
|
|
114
|
-
`,
|
|
115
|
-
`,
|
|
116
|
-
`,
|
|
117
|
-
`,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
`,
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
`,
|
|
124
|
-
`,
|
|
125
|
-
`,
|
|
126
|
-
`,
|
|
127
|
-
`,
|
|
128
|
-
|
|
129
|
-
`,n+=` ...
|
|
130
|
-
`,
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
`,
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
`,
|
|
137
|
-
`,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
`,
|
|
144
|
-
|
|
145
|
-
`,
|
|
146
|
-
`,
|
|
147
|
-
|
|
148
|
-
`,
|
|
149
|
-
`,
|
|
150
|
-
`)
|
|
151
|
-
|
|
152
|
-
`,
|
|
153
|
-
`,
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
`),
|
|
158
|
-
|
|
159
|
-
`,
|
|
160
|
-
`),
|
|
161
|
-
`,
|
|
162
|
-
|
|
163
|
-
`,
|
|
164
|
-
|
|
165
|
-
`),
|
|
166
|
-
`)
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
`,
|
|
170
|
-
|
|
171
|
-
`,
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
`,
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
`,
|
|
180
|
-
`),n
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
`,
|
|
186
|
-
|
|
187
|
-
`;}),
|
|
188
|
-
|
|
189
|
-
`,
|
|
190
|
-
|
|
191
|
-
`;
|
|
192
|
-
|
|
193
|
-
`,
|
|
194
|
-
|
|
195
|
-
`,
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
`,
|
|
200
|
-
`,
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
`,
|
|
204
|
-
`,
|
|
205
|
-
`,
|
|
206
|
-
`,
|
|
207
|
-
`,
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
`,
|
|
214
|
-
`,
|
|
215
|
-
`,
|
|
216
|
-
`,
|
|
217
|
-
`,
|
|
218
|
-
`,
|
|
219
|
-
`,
|
|
220
|
-
`,
|
|
221
|
-
`,
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
`,
|
|
225
|
-
|
|
226
|
-
`,
|
|
227
|
-
`,
|
|
228
|
-
`,
|
|
229
|
-
`,
|
|
230
|
-
|
|
231
|
-
`,
|
|
232
|
-
`,
|
|
233
|
-
`,
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
`,
|
|
237
|
-
`,
|
|
238
|
-
|
|
239
|
-
`,
|
|
240
|
-
`,
|
|
241
|
-
`)
|
|
242
|
-
`,
|
|
243
|
-
`,
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
`,
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
`,
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
`,
|
|
257
|
-
|
|
258
|
-
`,
|
|
259
|
-
|
|
260
|
-
`,r&&(n+=` private authToken?: string;
|
|
261
|
-
|
|
262
|
-
`,n+=` setAuthToken(token: string) {
|
|
263
|
-
`,n+=` this.authToken = token;
|
|
264
|
-
`,n+=` }
|
|
265
|
-
|
|
266
|
-
`,n+=` getAuthToken(): string | undefined {
|
|
267
|
-
`,n+=` return this.authToken;
|
|
268
|
-
`,n+=` }
|
|
269
|
-
|
|
270
|
-
`),n+=` updateConfig(config: Partial<ApiConfig>) {
|
|
271
|
-
`,n+=` Object.assign(this.client.defaults, config);
|
|
272
|
-
`,n+=` }
|
|
273
|
-
|
|
274
|
-
`,p.forEach(i=>{var M,D;let w=i.name,P=((M=i.parameters)==null?void 0:M.filter(v=>v.in==="path"))||[],R=((D=i.parameters)==null?void 0:D.filter(v=>v.in==="query"))||[],k=P.length>0,x=R.length>0,A=!!i.requestBody,N=i.responseType||"any";if(n+=` /**
|
|
275
|
-
`,i.summary&&(n+=` * ${i.summary}
|
|
276
|
-
`),n+=` * @method ${i.method.toUpperCase()}
|
|
277
|
-
`,n+=` * @path ${i.path}
|
|
278
|
-
`,i.tags&&i.tags.length>0&&(n+=` * @tags ${i.tags.join(", ")}
|
|
279
|
-
`),n+=` */
|
|
280
|
-
`,n+=` async ${w}(`,(k||x||A)&&(n+=`params: {
|
|
281
|
-
`,k&&(n+=` url: {
|
|
282
|
-
`,P.forEach(v=>{let F={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[v.type||"string"]||"any",O=v.required?"":"?";n+=` ${v.name}${O}: ${F};
|
|
283
|
-
`;}),n+=` };
|
|
284
|
-
`),x&&(n+=` query: ${i.queryType||"Record<string, any>"};
|
|
285
|
-
`),A&&(n+=` data: ${i.dtoType||"any"};
|
|
286
|
-
`),n+=" }"),n+=`): Promise<${N}> {
|
|
287
|
-
`,k||x||A){let v=[];k&&v.push("url"),x&&v.push("query"),A&&v.push("data"),n+=` const { ${v.join(", ")} } = params;
|
|
288
|
-
`;}if(k){let v=P.map(b=>`url.${b.name}`).join(", ");n+=` const _url = ${i.name}(${v});
|
|
289
|
-
`;}else n+=` const _url = ${i.name};
|
|
290
|
-
`;n+=` const config: AxiosRequestConfig = {};
|
|
291
|
-
`,x&&(n+=` config.params = { ...query };
|
|
292
|
-
`),n+=` const response = await this.client.${i.method.toLowerCase()}<${N}>(
|
|
293
|
-
`,n+=` _url,
|
|
294
|
-
`,A?n+=` data,
|
|
74
|
+
`;}let de=(Gt=(Mt=n==null?void 0:n.endpoints)==null?void 0:Mt.name)!=null&&Gt.useOperationId&&((Nt=l==null?void 0:l.operationId)==null?void 0:Nt.length)>0?l.operationId:`${h.name}`;if((Ft=(Lt=n==null?void 0:n.endpoints)==null?void 0:Lt.name)!=null&&Ft.format){let b=n==null?void 0:n.endpoints.name.format({method:c,path:a,summary:l==null?void 0:l.summary,operationId:l==null?void 0:l.operationId},de);b&&(de=b);}let Re={method:`"${c}"`,operationId:`"${l==null?void 0:l.operationId}"`,url:W,tags:(l==null?void 0:l.tags)||[]},Ke=`${be}export const ${S}${de} = ${((Bt=(Qt=n==null?void 0:n.endpoints)==null?void 0:Qt.value)==null?void 0:Bt.type)==="object"?Ee(Re):W};
|
|
75
|
+
`;n!=null&&n.folderSplit?f[$].endpoints+=Ke:R+=Ke;let on={name:`${S}${de}`,method:c,path:a,summary:l==null?void 0:l.summary,operationId:l==null?void 0:l.operationId,tags:d,parameters:(zt=l==null?void 0:l.parameters)==null?void 0:zt.filter(b=>!b.$ref&&b.in&&b.name).map(b=>{var E;return {name:b.name,in:b.in,required:b.required,type:((E=b.schema)==null?void 0:E.type)||"string"}}),requestBody:N?{type:Q,required:N.required}:void 0,responses:H?Object.entries(H).reduce((b,[E,k])=>(b[E]={type:k},b),{}):void 0,queryType:q,dtoType:L,responseType:pe||void 0};I.push(on);});}),n!=null&&n.folderSplit){for(let[a,p]of Object.entries(f))if(p.endpoints||p.types){let w=D.join(r,a);if(p.endpoints){let g=D.join(ce,w,"endpoints.ts");yield se.promises.mkdir(D.dirname(g),{recursive:true}),yield ye(g,p.endpoints,n);}if(p.types){let g=D.join(ce,w,"types.ts");yield se.promises.mkdir(D.dirname(g),{recursive:true});let c=Object.values(T).length>0?`import * as Shared from "../shared";
|
|
76
|
+
|
|
77
|
+
${p.types}`:p.types;yield ye(g,c,n);}if(((De=n==null?void 0:n.validations)==null?void 0:De.disable)!==true&&p.validation){let g=((Je=n.validations)==null?void 0:Je.library)||"zod",c=g==="joi"?'import Joi from "joi";':g==="yup"?'import * as yup from "yup";':'import { z } from "zod";',h=D.join(ce,w,"validations.ts");yield se.promises.mkdir(D.dirname(h),{recursive:true}),yield ye(h,`${c}
|
|
78
|
+
|
|
79
|
+
${p.validation}`,n);}}}if(R.length>0){let a=D.join(ce,r,"endpoints.ts");yield se.promises.mkdir(D.dirname(a),{recursive:true}),yield ye(a,R,n);}if(Object.values(T).length>0){let a=D.join(ce,r,n!=null&&n.folderSplit?"":"types","shared.ts");yield se.promises.mkdir(D.dirname(a),{recursive:true}),yield ye(a,Object.values(T).join(`
|
|
80
|
+
`),n);}if(J.length>0){let a=D.join(ce,r,"types","index.ts");yield se.promises.mkdir(D.dirname(a),{recursive:true}),yield ye(a,`${Object.values(T).length>0?`import * as Shared from "./shared";
|
|
81
|
+
|
|
82
|
+
`:""}${J}`,n);}if(((We=n==null?void 0:n.validations)==null?void 0:We.disable)!==true&&!(n!=null&&n.folderSplit)){let a=((He=n.validations)==null?void 0:He.library)||"zod",p=a==="joi"?'import Joi from "joi";':a==="yup"?'import * as yup from "yup";':'import { z } from "zod";',w=Object.values(f).map(g=>g.validation).filter(g=>g.length>0).join("");if(w){let g=D.join(ce,r,"validations.ts");yield se.promises.mkdir(D.dirname(g),{recursive:true}),yield ye(g,`${p}
|
|
83
|
+
|
|
84
|
+
${w}`,n);}}Xt(i,I);}),Le=nn;var rn=(u,i)=>{let n=u;return i.tags&&i.tags.length>0&&(n=n.filter(e=>!e.tags||e.tags.length===0?false:e.tags.some(s=>i.tags.includes(s)))),i.endpoints&&i.endpoints.length>0&&(n=n.filter(e=>i.endpoints.includes(e.name))),n};var Fe=(u,i,n=false)=>{var r,f;let e=i.baseURL||"";i.auth;let t=`// Generated Fetch API Client
|
|
85
|
+
`;t+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
86
|
+
|
|
87
|
+
`,t+=`import type {
|
|
88
|
+
`;let o=new Set;return u.forEach(m=>{m.queryType&&o.add(m.queryType),m.dtoType&&o.add(m.dtoType),m.responseType&&o.add(m.responseType);}),o.forEach(m=>{t+=` ${m},
|
|
89
|
+
`;}),t+=`} from '../types';
|
|
90
|
+
|
|
91
|
+
`,t+=`import {
|
|
92
|
+
`,u.forEach(m=>{t+=` ${m.name} as ${m.name}_endpoint,
|
|
93
|
+
`;}),t+=`} from '../endpoints';
|
|
94
|
+
|
|
95
|
+
`,t+=`export interface ApiConfig {
|
|
96
|
+
`,t+=` baseURL?: string;
|
|
97
|
+
`,t+=` headers?: Record<string, string>;
|
|
98
|
+
`,t+=`}
|
|
99
|
+
|
|
100
|
+
`,t+=`let globalConfig: ApiConfig = {
|
|
101
|
+
`,t+=` baseURL: "${e}",
|
|
102
|
+
`,t+=`};
|
|
103
|
+
|
|
104
|
+
`,t+=`export const setApiConfig = (config: Partial<ApiConfig>) => {
|
|
105
|
+
`,t+=` globalConfig = { ...globalConfig, ...config };
|
|
106
|
+
`,t+=`};
|
|
107
|
+
|
|
108
|
+
`,(r=i.errorHandling)!=null&&r.generateErrorClasses&&(t+=`export class ApiError extends Error {
|
|
109
|
+
`,t+=` constructor(
|
|
110
|
+
`,t+=` message: string,
|
|
111
|
+
`,t+=` public statusCode: number,
|
|
112
|
+
`,t+=` public response?: any
|
|
113
|
+
`,t+=` ) {
|
|
114
|
+
`,t+=` super(message);
|
|
115
|
+
`,t+=` this.name = 'ApiError';
|
|
116
|
+
`,t+=` }
|
|
117
|
+
`,t+=`}
|
|
118
|
+
|
|
119
|
+
`),t+=`async function fetchAPI<T>(
|
|
120
|
+
`,t+=` url: string,
|
|
121
|
+
`,t+=` options: RequestInit = {}
|
|
122
|
+
`,t+=`): Promise<T> {
|
|
123
|
+
`,t+=` const headers: Record<string, string> = {
|
|
124
|
+
`,t+=` 'Content-Type': 'application/json',
|
|
125
|
+
`,t+=` ...globalConfig.headers,
|
|
126
|
+
`,t+=` ...(options.headers as Record<string, string>),
|
|
127
|
+
`,t+=` };
|
|
128
|
+
|
|
129
|
+
`,t+=" const response = await fetch(`${globalConfig.baseURL}${url}`, {\n",t+=` ...options,
|
|
130
|
+
`,t+=` headers,
|
|
131
|
+
`,t+=` });
|
|
132
|
+
|
|
133
|
+
`,t+=` if (!response.ok) {
|
|
134
|
+
`,(f=i.errorHandling)!=null&&f.generateErrorClasses?(t+=` const errorData = await response.json().catch(() => ({}));
|
|
135
|
+
`,t+=` throw new ApiError(
|
|
136
|
+
`,t+=` errorData.message || response.statusText,
|
|
137
|
+
`,t+=` response.status,
|
|
138
|
+
`,t+=` errorData
|
|
139
|
+
`,t+=` );
|
|
140
|
+
`):t+=" throw new Error(`HTTP error! status: ${response.status}`);\n",t+=` }
|
|
141
|
+
|
|
142
|
+
`,t+=` return response.json();
|
|
143
|
+
`,t+=`}
|
|
144
|
+
|
|
145
|
+
`,u.forEach(m=>{var J,T;let y=m.name,A=((J=m.parameters)==null?void 0:J.filter(I=>I.in==="path"))||[],S=((T=m.parameters)==null?void 0:T.filter(I=>I.in==="query"))||[],j=A.length>0,x=S.length>0,v=!!m.requestBody,G=m.responseType||"any";if(t+=`/**
|
|
146
|
+
`,m.summary&&(t+=` * ${m.summary}
|
|
147
|
+
`),t+=` * @method ${m.method.toUpperCase()}
|
|
148
|
+
`,t+=` * @path ${m.path}
|
|
149
|
+
`,m.tags&&m.tags.length>0&&(t+=` * @tags ${m.tags.join(", ")}
|
|
150
|
+
`),t+=` */
|
|
151
|
+
`,t+=`export async function ${y}(`,(j||x||v)&&(t+=`params: {
|
|
152
|
+
`,j&&(t+=` url: {
|
|
153
|
+
`,A.forEach(I=>{let O={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[I.type||"string"]||"any",z=I.required?"":"?";t+=` ${I.name}${z}: ${O};
|
|
154
|
+
`;}),t+=` };
|
|
155
|
+
`),x&&(t+=` query: ${m.queryType||"Record<string, any>"};
|
|
156
|
+
`),v&&(t+=` data: ${m.dtoType||"any"};
|
|
157
|
+
`),t+=`}
|
|
158
|
+
`),t+=`): Promise<${G}> {
|
|
159
|
+
`,j||x||v){let I=[];j&&I.push("url"),x&&I.push("query"),v&&I.push("data"),t+=` const { ${I.join(", ")} } = params;
|
|
160
|
+
`;}let R;if(j){let I=A.map(_=>`url.${_.name}`).join(", ");R=`${m.name}_endpoint(${I})`;}else R=`${m.name}_endpoint`;x?(t+=` const queryParams = new URLSearchParams();
|
|
161
|
+
`,S.forEach(I=>{I.required?t+=` queryParams.append('${I.name}', String(query.${I.name}));
|
|
162
|
+
`:(t+=` if (query.${I.name} !== undefined) {
|
|
163
|
+
`,t+=` queryParams.append('${I.name}', String(query.${I.name}));
|
|
164
|
+
`,t+=` }
|
|
165
|
+
`);}),t+=` const _url = \`\${${R}}?\${queryParams.toString()}\`;
|
|
166
|
+
`):t+=` const _url = ${R};
|
|
167
|
+
`,t+=` return fetchAPI<${G}>(_url, {
|
|
168
|
+
`,t+=` method: '${m.method.toUpperCase()}',
|
|
169
|
+
`,v&&(t+=` body: JSON.stringify(data),
|
|
170
|
+
`),t+=` });
|
|
171
|
+
`,t+=`}
|
|
172
|
+
|
|
173
|
+
`;}),n&&(t+=`// Export all functions as a default object
|
|
174
|
+
`,t+=`const apiClient = {
|
|
175
|
+
`,t+=` setApiConfig,
|
|
176
|
+
`,u.forEach(m=>{t+=` ${m.name},
|
|
177
|
+
`;}),t+=`};
|
|
178
|
+
|
|
179
|
+
`,t+=`export default apiClient;
|
|
180
|
+
`),t},fe=(u,i,n=false)=>{var r,f;let e=i.baseURL||"";i.auth;let t=`// Generated Axios API Client
|
|
181
|
+
`;t+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
182
|
+
|
|
183
|
+
`,t+=`import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
184
|
+
|
|
185
|
+
`,t+=`import type {
|
|
186
|
+
`;let o=new Set;return u.forEach(m=>{m.queryType&&o.add(m.queryType),m.dtoType&&o.add(m.dtoType),m.responseType&&o.add(m.responseType);}),o.forEach(m=>{t+=` ${m},
|
|
187
|
+
`;}),t+=`} from '../types';
|
|
188
|
+
|
|
189
|
+
`,t+=`import {
|
|
190
|
+
`,u.forEach(m=>{t+=` ${m.name},
|
|
191
|
+
`;}),t+=`} from '../endpoints';
|
|
192
|
+
|
|
193
|
+
`,t+=`export interface ApiConfig {
|
|
194
|
+
`,t+=` baseURL?: string;
|
|
195
|
+
`,t+=` headers?: Record<string, string>;
|
|
196
|
+
`,t+=` timeout?: number;
|
|
197
|
+
`,t+=`}
|
|
198
|
+
|
|
199
|
+
`,(r=i.errorHandling)!=null&&r.generateErrorClasses&&(t+=`export class ApiError extends Error {
|
|
200
|
+
`,t+=` constructor(
|
|
201
|
+
`,t+=` message: string,
|
|
202
|
+
`,t+=` public statusCode: number,
|
|
203
|
+
`,t+=` public response?: any
|
|
204
|
+
`,t+=` ) {
|
|
205
|
+
`,t+=` super(message);
|
|
206
|
+
`,t+=` this.name = 'ApiError';
|
|
207
|
+
`,t+=` }
|
|
208
|
+
`,t+=`}
|
|
209
|
+
|
|
210
|
+
`),t+=`class ApiClient {
|
|
211
|
+
`,t+=` private client: AxiosInstance;
|
|
212
|
+
|
|
213
|
+
`,t+=` constructor(config: ApiConfig = {}) {
|
|
214
|
+
`,t+=` this.client = axios.create({
|
|
215
|
+
`,t+=` baseURL: config.baseURL || "${e}",
|
|
216
|
+
`,t+=` timeout: config.timeout || 30000,
|
|
217
|
+
`,t+=` headers: {
|
|
218
|
+
`,t+=` 'Content-Type': 'application/json',
|
|
219
|
+
`,t+=` ...config.headers,
|
|
220
|
+
`,t+=` },
|
|
221
|
+
`,t+=` });
|
|
222
|
+
|
|
223
|
+
`,t+=` // Response interceptor for error handling
|
|
224
|
+
`,t+=` this.client.interceptors.response.use(
|
|
225
|
+
`,t+=` (response) => response,
|
|
226
|
+
`,t+=` (error) => {
|
|
227
|
+
`,(f=i.errorHandling)!=null&&f.generateErrorClasses?(t+=` const message = error.response?.data?.message || error.message;
|
|
228
|
+
`,t+=` const statusCode = error.response?.status || 500;
|
|
229
|
+
`,t+=` throw new ApiError(message, statusCode, error.response?.data);
|
|
230
|
+
`):t+=` return Promise.reject(error);
|
|
231
|
+
`,t+=` }
|
|
232
|
+
`,t+=` );
|
|
233
|
+
`,t+=` }
|
|
234
|
+
|
|
235
|
+
`,t+=` updateConfig(config: Partial<ApiConfig>) {
|
|
236
|
+
`,t+=` Object.assign(this.client.defaults, config);
|
|
237
|
+
`,t+=` }
|
|
238
|
+
|
|
239
|
+
`,u.forEach(m=>{var R,J;let y=m.name,A=((R=m.parameters)==null?void 0:R.filter(T=>T.in==="path"))||[],S=((J=m.parameters)==null?void 0:J.filter(T=>T.in==="query"))||[],j=A.length>0,x=S.length>0,v=!!m.requestBody,G=m.responseType||"any";if(t+=` /**
|
|
240
|
+
`,m.summary&&(t+=` * ${m.summary}
|
|
241
|
+
`),t+=` * @method ${m.method.toUpperCase()}
|
|
242
|
+
`,t+=` * @path ${m.path}
|
|
243
|
+
`,m.tags&&m.tags.length>0&&(t+=` * @tags ${m.tags.join(", ")}
|
|
244
|
+
`),t+=` */
|
|
245
|
+
`,t+=` async ${y}(`,(j||x||v)&&(t+=`params: {
|
|
246
|
+
`,j&&(t+=` url: {
|
|
247
|
+
`,A.forEach(T=>{let _={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[T.type||"string"]||"any",O=T.required?"":"?";t+=` ${T.name}${O}: ${_};
|
|
248
|
+
`;}),t+=` };
|
|
249
|
+
`),x&&(t+=` query: ${m.queryType||"Record<string, any>"};
|
|
250
|
+
`),v&&(t+=` data: ${m.dtoType||"any"};
|
|
251
|
+
`),t+=" }"),t+=`): Promise<${G}> {
|
|
252
|
+
`,j||x||v){let T=[];j&&T.push("url"),x&&T.push("query"),v&&T.push("data"),t+=` const { ${T.join(", ")} } = params;
|
|
253
|
+
`;}if(j){let T=A.map(I=>`url.${I.name}`).join(", ");t+=` const _url = ${m.name}(${T});
|
|
254
|
+
`;}else t+=` const _url = ${m.name};
|
|
255
|
+
`;t+=` const config: AxiosRequestConfig = {};
|
|
256
|
+
`,x&&(t+=` config.params = { ...query };
|
|
257
|
+
`),t+=` const response = await this.client.${m.method.toLowerCase()}<${G}>(
|
|
258
|
+
`,t+=` _url,
|
|
259
|
+
`,v?t+=` data,
|
|
295
260
|
config
|
|
296
|
-
`:
|
|
297
|
-
`,
|
|
298
|
-
`,
|
|
299
|
-
`,
|
|
261
|
+
`:t+=` config
|
|
262
|
+
`,t+=` );
|
|
263
|
+
`,t+=` return response.data;
|
|
264
|
+
`,t+=` }
|
|
300
265
|
|
|
301
|
-
`;}),
|
|
266
|
+
`;}),t+=`}
|
|
302
267
|
|
|
303
|
-
`,t
|
|
304
|
-
`:(
|
|
305
|
-
`,
|
|
306
|
-
`),
|
|
307
|
-
`;
|
|
268
|
+
`,n?t+=`export default ApiClient;
|
|
269
|
+
`:(t+=`export const apiClient = new ApiClient();
|
|
270
|
+
`,t+=`export default apiClient;
|
|
271
|
+
`),t},Qe=(u,i)=>{var f,m;let n=((f=i.reactQuery)==null?void 0:f.version)||5,e=((m=i.reactQuery)==null?void 0:m.mutations)!==false,s=!!(i.reactQuery&&i.reactQuery.infiniteQueries&&!i.reactQuery.infiniteQueries.disable),t=`// Generated React Query Hooks
|
|
272
|
+
`;t+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
308
273
|
|
|
309
|
-
`;let
|
|
274
|
+
`;let o=e&&u.some(y=>["POST","PUT","PATCH","DELETE"].includes(y.method.toUpperCase()));if(n===5){let y=o?`import { useQuery, useMutation, UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
310
275
|
`:`import { useQuery, UseQueryOptions } from '@tanstack/react-query';
|
|
311
|
-
|
|
276
|
+
`;s&&(y=y.replace("@tanstack/react-query';\\n",`@tanstack/react-query';
|
|
277
|
+
import { useInfiniteQuery, UseInfiniteQueryOptions } from '@tanstack/react-query';
|
|
278
|
+
`)),t+=y;}else {let y=o?`import { useQuery, useMutation, UseQueryOptions, UseMutationOptions } from 'react-query';
|
|
312
279
|
`:`import { useQuery, UseQueryOptions } from 'react-query';
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
`,
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
`,
|
|
326
|
-
|
|
327
|
-
`,
|
|
328
|
-
`,
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
`,
|
|
335
|
-
`,
|
|
336
|
-
`,
|
|
337
|
-
`,
|
|
338
|
-
`,
|
|
339
|
-
|
|
340
|
-
`,
|
|
341
|
-
`,
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
`,
|
|
345
|
-
`,
|
|
346
|
-
`,
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
`,
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
`,
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
`),
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
`,
|
|
363
|
-
`,
|
|
364
|
-
`,
|
|
365
|
-
`,
|
|
366
|
-
`,
|
|
367
|
-
`,
|
|
368
|
-
`,
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
280
|
+
`;s&&(y=y.replace("react-query';\\n",`react-query';
|
|
281
|
+
import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
282
|
+
`)),t+=y;}t+=`
|
|
283
|
+
`,t+=`import apiClient from './client';
|
|
284
|
+
`,t+=`import type {
|
|
285
|
+
`;let r=new Set;return u.forEach(y=>{y.queryType&&r.add(y.queryType),y.dtoType&&r.add(y.dtoType),y.responseType&&r.add(y.responseType);}),r.forEach(y=>{t+=` ${y},
|
|
286
|
+
`;}),t+=`} from '../types';
|
|
287
|
+
|
|
288
|
+
`,u.forEach(y=>{var I,_;let A=y.method.toUpperCase(),S=A==="GET",j=["POST","PUT","PATCH","DELETE"].includes(A),x=((I=y.parameters)==null?void 0:I.filter(O=>O.in==="path"))||[],v=((_=y.parameters)==null?void 0:_.filter(O=>O.in==="query"))||[],G=x.length>0,R=v.length>0,J=!!y.requestBody,T=y.responseType||"any";if(S){let O=v.map(te=>te.name.toLowerCase()),ae=(O.includes("page")||O.includes("cursor")||O.includes("cursorid")||O.includes("after")||O.includes("before"))&&s,oe=`use${y.name.charAt(0).toUpperCase()+y.name.slice(1)}`;if(t+=`/**
|
|
289
|
+
`,y.summary&&(t+=` * ${y.summary}
|
|
290
|
+
`),t+=` * @method ${A}
|
|
291
|
+
`,t+=` * @path ${y.path}
|
|
292
|
+
`,y.tags&&y.tags.length>0&&(t+=` * @tags ${y.tags.join(", ")}
|
|
293
|
+
`),t+=` */
|
|
294
|
+
`,G||R?(t+=`export function ${oe}(
|
|
295
|
+
`,t+=` params: {
|
|
296
|
+
`,G&&(t+=` url: {
|
|
297
|
+
`,x.forEach(te=>{let ge={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[te.type||"string"]||"any",he=te.required?"":"?";t+=` ${te.name}${he}: ${ge};
|
|
298
|
+
`;}),t+=` };
|
|
299
|
+
`),R&&(t+=` query: ${y.queryType||"Record<string, any>"};
|
|
300
|
+
`),t+=` },
|
|
301
|
+
`,t+=` options?: Omit<UseQueryOptions<${T}>, 'queryKey' | 'queryFn'>
|
|
302
|
+
`,t+=`) {
|
|
303
|
+
`,t+=` return useQuery({
|
|
304
|
+
`,t+=` queryKey: ['${y.name}', params],
|
|
305
|
+
`,t+=` queryFn: () => apiClient.${y.name}(params),
|
|
306
|
+
`,t+=` ...options,
|
|
307
|
+
`,t+=` });
|
|
308
|
+
`,t+=`}
|
|
309
|
+
|
|
310
|
+
`):(t+=`export function ${oe}(
|
|
311
|
+
`,t+=` options?: Omit<UseQueryOptions<${T}>, 'queryKey' | 'queryFn'>
|
|
312
|
+
`,t+=`) {
|
|
313
|
+
`,t+=` return useQuery({
|
|
314
|
+
`,t+=` queryKey: ['${y.name}'],
|
|
315
|
+
`,t+=` queryFn: () => apiClient.${y.name}(),
|
|
316
|
+
`,t+=` ...options,
|
|
317
|
+
`,t+=` });
|
|
318
|
+
`,t+=`}
|
|
319
|
+
|
|
320
|
+
`),ae){let te=`${oe}Infinite`;G||R?(t+=`export function ${te}(
|
|
321
|
+
`,t+=` params: {
|
|
322
|
+
`,G&&(t+=` url: {
|
|
323
|
+
`,x.forEach(ie=>{let he={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[ie.type||"string"]||"any",Pe=ie.required?"":"?";t+=` ${ie.name}${Pe}: ${he};
|
|
324
|
+
`;}),t+=` };
|
|
325
|
+
`),R&&(t+=` query: ${y.queryType||"Record<string, any>"};
|
|
326
|
+
`),t+=` },
|
|
327
|
+
`,t+=` options?: Omit<UseInfiniteQueryOptions<${T}, Error, ${T}>, 'queryKey' | 'queryFn'>
|
|
328
|
+
`,t+=`) {
|
|
329
|
+
`,t+=` return useInfiniteQuery({
|
|
330
|
+
`,t+=` queryKey: ['${y.name}', params],
|
|
331
|
+
`,t+=` queryFn: ({ pageParam = 1 }) => apiClient.${y.name}({ ...params, query: { ...(params.query || {}), page: pageParam } }),
|
|
332
|
+
`,t+=` getNextPageParam: (lastPage) => lastPage?.nextPage ?? lastPage?.nextCursor ?? null,
|
|
333
|
+
`,t+=` ...options,
|
|
334
|
+
`,t+=` });
|
|
335
|
+
`,t+=`}
|
|
336
|
+
|
|
337
|
+
`):(t+=`export function ${te}(
|
|
338
|
+
`,t+=` options?: Omit<UseInfiniteQueryOptions<${T}, Error, ${T}>, 'queryKey' | 'queryFn'>
|
|
339
|
+
`,t+=`) {
|
|
340
|
+
`,t+=` return useInfiniteQuery({
|
|
341
|
+
`,t+=` queryKey: ['${y.name}'],
|
|
342
|
+
`,t+=` queryFn: ({ pageParam = 1 }) => apiClient.${y.name}({ query: { page: pageParam } }),
|
|
343
|
+
`,t+=` getNextPageParam: (lastPage) => lastPage?.nextPage ?? lastPage?.nextCursor ?? null,
|
|
344
|
+
`,t+=` ...options,
|
|
345
|
+
`,t+=` });
|
|
346
|
+
`,t+=`}
|
|
347
|
+
|
|
348
|
+
`);}}else if(j&&e){let O=`use${y.name.charAt(0).toUpperCase()+y.name.slice(1)}`;t+=`/**
|
|
349
|
+
`,y.summary&&(t+=` * ${y.summary}
|
|
350
|
+
`),t+=` * @method ${A}
|
|
351
|
+
`,t+=` * @path ${y.path}
|
|
352
|
+
`,y.tags&&y.tags.length>0&&(t+=` * @tags ${y.tags.join(", ")}
|
|
353
|
+
`),t+=` */
|
|
354
|
+
`;let z="void";(G||R||J)&&(z=`{
|
|
355
|
+
`,G&&(z+=` url: {
|
|
356
|
+
`,x.forEach(ae=>{let te={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[ae.type||"string"]||"any",ie=ae.required?"":"?";z+=` ${ae.name}${ie}: ${te};
|
|
357
|
+
`;}),z+=` };
|
|
358
|
+
`),R&&(z+=` query: ${y.queryType||"Record<string, any>"};
|
|
359
|
+
`),J&&(z+=` data: ${y.dtoType||"any"};
|
|
360
|
+
`),z+=" }"),t+=`export function ${O}(
|
|
361
|
+
`,t+=` options?: Omit<UseMutationOptions<${T}, Error, ${z}>, 'mutationFn'>
|
|
362
|
+
`,t+=`) {
|
|
363
|
+
`,t+=` return useMutation({
|
|
364
|
+
`,t+=" mutationFn: (",z!=="void"&&(t+=`variables: ${z}`),t+=`) => {
|
|
365
|
+
`,t+=` return apiClient.${y.name}(${z!=="void"?"variables":""});
|
|
366
|
+
`,t+=` },
|
|
367
|
+
`,t+=` ...options,
|
|
368
|
+
`,t+=` });
|
|
369
|
+
`,t+=`}
|
|
370
|
+
|
|
371
|
+
`;}}),t},Be=(u,i)=>{var o;let n=((o=i.swr)==null?void 0:o.mutations)!==false,e=`// Generated SWR Hooks
|
|
373
372
|
`;e+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
374
373
|
|
|
375
374
|
`,e+=`/**
|
|
@@ -564,131 +563,131 @@ ${T}`,t);}}Xt(u,b);}),Se=tn;var nn=(p,u)=>{let t=p;return u.tags&&u.tags.length>
|
|
|
564
563
|
`,e+=` */
|
|
565
564
|
|
|
566
565
|
`,e+=`import useSWR, { SWRConfiguration } from 'swr';
|
|
567
|
-
`,
|
|
566
|
+
`,n&&u.some(r=>["POST","PUT","PATCH","DELETE"].includes(r.method.toUpperCase()))&&(e+=`import useSWRMutation, { SWRMutationConfiguration } from 'swr/mutation';
|
|
568
567
|
`),e+=`
|
|
569
568
|
`,e+=`import apiClient from './client';
|
|
570
569
|
`,e+=`import type {
|
|
571
|
-
`;let
|
|
570
|
+
`;let t=new Set;return u.forEach(r=>{r.queryType&&t.add(r.queryType),r.dtoType&&t.add(r.dtoType),r.responseType&&t.add(r.responseType);}),t.forEach(r=>{e+=` ${r},
|
|
572
571
|
`;}),e+=`} from '../types';
|
|
573
572
|
|
|
574
|
-
`,
|
|
575
|
-
`,
|
|
576
|
-
`),e+=` * @method ${
|
|
577
|
-
`,e+=` * @path ${
|
|
578
|
-
`,
|
|
573
|
+
`,u.forEach(r=>{var R,J;let f=r.method.toUpperCase(),m=f==="GET",y=["POST","PUT","PATCH","DELETE"].includes(f),A=((R=r.parameters)==null?void 0:R.filter(T=>T.in==="path"))||[],S=((J=r.parameters)==null?void 0:J.filter(T=>T.in==="query"))||[],j=A.length>0,x=S.length>0,v=!!r.requestBody,G=r.responseType||"any";if(m){let T=`use${r.name.charAt(0).toUpperCase()+r.name.slice(1)}`;e+=`/**
|
|
574
|
+
`,r.summary&&(e+=` * ${r.summary}
|
|
575
|
+
`),e+=` * @method ${f}
|
|
576
|
+
`,e+=` * @path ${r.path}
|
|
577
|
+
`,r.tags&&r.tags.length>0&&(e+=` * @tags ${r.tags.join(", ")}
|
|
579
578
|
`),e+=` */
|
|
580
|
-
`,
|
|
579
|
+
`,j||x?(e+=`export function ${T}(
|
|
581
580
|
`,e+=` params: {
|
|
582
|
-
`,
|
|
583
|
-
`,
|
|
581
|
+
`,j&&(e+=` url: {
|
|
582
|
+
`,A.forEach(I=>{let O={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[I.type||"string"]||"any",z=I.required?"":"?";e+=` ${I.name}${z}: ${O};
|
|
584
583
|
`;}),e+=` };
|
|
585
|
-
`),x&&(e+=` query: ${
|
|
584
|
+
`),x&&(e+=` query: ${r.queryType||"Record<string, any>"};
|
|
586
585
|
`),e+=` },
|
|
587
|
-
`,e+=` config?: SWRConfiguration<${
|
|
586
|
+
`,e+=` config?: SWRConfiguration<${G}>
|
|
588
587
|
`,e+=`) {
|
|
589
588
|
`,e+=` return useSWR(
|
|
590
|
-
`,e+=` ['${
|
|
591
|
-
`,e+=` () => apiClient.${
|
|
589
|
+
`,e+=` ['${r.name}', params],
|
|
590
|
+
`,e+=` () => apiClient.${r.name}(params),
|
|
592
591
|
`,e+=` config
|
|
593
592
|
`,e+=` );
|
|
594
|
-
`):(e+=`export function ${
|
|
595
|
-
`,e+=` config?: SWRConfiguration<${
|
|
593
|
+
`):(e+=`export function ${T}(
|
|
594
|
+
`,e+=` config?: SWRConfiguration<${G}>
|
|
596
595
|
`,e+=`) {
|
|
597
596
|
`,e+=` return useSWR(
|
|
598
|
-
`,e+=` '${
|
|
599
|
-
`,e+=` () => apiClient.${
|
|
597
|
+
`,e+=` '${r.name}',
|
|
598
|
+
`,e+=` () => apiClient.${r.name}(),
|
|
600
599
|
`,e+=` config
|
|
601
600
|
`,e+=` );
|
|
602
601
|
`),e+=`}
|
|
603
602
|
|
|
604
|
-
`;}else if(
|
|
605
|
-
`,
|
|
606
|
-
`),e+=` * @method ${
|
|
607
|
-
`,e+=` * @path ${
|
|
608
|
-
`,
|
|
603
|
+
`;}else if(y&&n){let T=`use${r.name.charAt(0).toUpperCase()+r.name.slice(1)}`;e+=`/**
|
|
604
|
+
`,r.summary&&(e+=` * ${r.summary}
|
|
605
|
+
`),e+=` * @method ${f}
|
|
606
|
+
`,e+=` * @path ${r.path}
|
|
607
|
+
`,r.tags&&r.tags.length>0&&(e+=` * @tags ${r.tags.join(", ")}
|
|
609
608
|
`),e+=` */
|
|
610
|
-
`;let
|
|
611
|
-
`,
|
|
612
|
-
`,
|
|
613
|
-
`;}),
|
|
614
|
-
`),x&&(
|
|
615
|
-
`),
|
|
616
|
-
`),
|
|
617
|
-
`,e+=` config?: SWRMutationConfiguration<${
|
|
609
|
+
`;let I="void",_="void";(j||x||v)&&(I=`{
|
|
610
|
+
`,j&&(I+=` url: {
|
|
611
|
+
`,A.forEach(O=>{let ae={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[O.type||"string"]||"any",oe=O.required?"":"?";I+=` ${O.name}${oe}: ${ae};
|
|
612
|
+
`;}),I+=` };
|
|
613
|
+
`),x&&(I+=` query: ${r.queryType||"Record<string, any>"};
|
|
614
|
+
`),v&&(I+=` data: ${r.dtoType||"any"};
|
|
615
|
+
`),I+=" }",_=`{ arg: ${I} }`),e+=`export function ${T}(
|
|
616
|
+
`,e+=` config?: SWRMutationConfiguration<${G}, Error, string, ${I}>
|
|
618
617
|
`,e+=`) {
|
|
619
618
|
`,e+=` return useSWRMutation(
|
|
620
|
-
`,e+=` '${
|
|
621
|
-
`,e+=" async (_, ",
|
|
622
|
-
`,e+=` return apiClient.${
|
|
619
|
+
`,e+=` '${r.name}',
|
|
620
|
+
`,e+=" async (_, ",I!=="void"&&(e+=`{ arg }: ${_}`),e+=`) => {
|
|
621
|
+
`,e+=` return apiClient.${r.name}(${I!=="void"?"arg":""});
|
|
623
622
|
`,e+=` },
|
|
624
623
|
`,e+=` config
|
|
625
624
|
`,e+=` );
|
|
626
625
|
`,e+=`}
|
|
627
626
|
|
|
628
|
-
`;}}),e},
|
|
629
|
-
`;
|
|
630
|
-
|
|
631
|
-
`,
|
|
632
|
-
|
|
633
|
-
`,
|
|
634
|
-
`;let
|
|
635
|
-
`;}),
|
|
636
|
-
|
|
637
|
-
`,
|
|
638
|
-
`,
|
|
639
|
-
`;}),
|
|
640
|
-
|
|
641
|
-
`,
|
|
642
|
-
`,
|
|
643
|
-
`,
|
|
644
|
-
`,
|
|
645
|
-
`,
|
|
646
|
-
`,
|
|
647
|
-
`,
|
|
648
|
-
`,
|
|
649
|
-
`,
|
|
650
|
-
`),
|
|
651
|
-
`,
|
|
652
|
-
`,
|
|
653
|
-
`),
|
|
654
|
-
`,
|
|
655
|
-
`,
|
|
656
|
-
`,
|
|
657
|
-
`,
|
|
658
|
-
`;let
|
|
659
|
-
`,
|
|
660
|
-
`,
|
|
661
|
-
`;}),
|
|
662
|
-
`),x&&(
|
|
663
|
-
`),
|
|
664
|
-
`),
|
|
665
|
-
`,
|
|
666
|
-
`,
|
|
667
|
-
`,
|
|
668
|
-
`;}else
|
|
669
|
-
`;
|
|
670
|
-
`,
|
|
671
|
-
`,
|
|
672
|
-
`,x&&(
|
|
673
|
-
`),
|
|
674
|
-
`),
|
|
675
|
-
`,
|
|
676
|
-
`,
|
|
677
|
-
`:
|
|
678
|
-
`),
|
|
679
|
-
`;}),
|
|
680
|
-
`,
|
|
681
|
-
|
|
682
|
-
`,
|
|
683
|
-
|
|
684
|
-
`,
|
|
627
|
+
`;}}),e},ze=(u,i)=>{var o;let n=((o=i.rtkQuery)==null?void 0:o.apiName)||"api",e=i.baseURL||"",s=`// Generated RTK Query API Slice
|
|
628
|
+
`;s+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
629
|
+
|
|
630
|
+
`,s+=`import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
|
|
631
|
+
|
|
632
|
+
`,s+=`import type {
|
|
633
|
+
`;let t=new Set;return u.forEach(r=>{r.queryType&&t.add(r.queryType),r.dtoType&&t.add(r.dtoType),r.responseType&&t.add(r.responseType);}),t.forEach(r=>{s+=` ${r},
|
|
634
|
+
`;}),s+=`} from '../types';
|
|
635
|
+
|
|
636
|
+
`,s+=`import {
|
|
637
|
+
`,u.forEach(r=>{s+=` ${r.name},
|
|
638
|
+
`;}),s+=`} from '../endpoints';
|
|
639
|
+
|
|
640
|
+
`,s+=`const ${n}Api = createApi({
|
|
641
|
+
`,s+=` reducerPath: '${n}Api',
|
|
642
|
+
`,s+=` baseQuery: fetchBaseQuery({
|
|
643
|
+
`,s+=` baseUrl: '${e}',
|
|
644
|
+
`,i.auth&&(s+=` prepareHeaders: (headers, { getState }) => {
|
|
645
|
+
`,s+=` // Get token from your auth state
|
|
646
|
+
`,s+=` // const token = (getState() as RootState).auth.token;
|
|
647
|
+
`,s+=` // if (token) {
|
|
648
|
+
`,i.auth.type==="bearer"?s+=" // headers.set('Authorization', `Bearer ${token}`);\n":i.auth.type==="apiKey"&&i.auth.in==="header"&&(s+=` // headers.set('${i.auth.name||"X-API-Key"}', token);
|
|
649
|
+
`),s+=` // }
|
|
650
|
+
`,s+=` return headers;
|
|
651
|
+
`,s+=` },
|
|
652
|
+
`),s+=` }),
|
|
653
|
+
`,s+=` tagTypes: [${[...new Set(u.flatMap(r=>r.tags||[]))].map(r=>`'${r}'`).join(", ")}],
|
|
654
|
+
`,s+=` endpoints: (builder) => ({
|
|
655
|
+
`,u.forEach((r,f)=>{var J,T;let m=r.method.toUpperCase(),y=m==="GET",A=((J=r.parameters)==null?void 0:J.filter(I=>I.in==="path"))||[],S=((T=r.parameters)==null?void 0:T.filter(I=>I.in==="query"))||[],j=A.length>0,x=S.length>0,v=!!r.requestBody,G=r.responseType||"any";s+=` ${r.name}: builder.${y?"query":"mutation"}<
|
|
656
|
+
`,s+=` ${G},
|
|
657
|
+
`;let R="void";if((j||x||v)&&(R=`{
|
|
658
|
+
`,j&&(R+=` url: {
|
|
659
|
+
`,A.forEach(I=>{let O={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[I.type||"string"]||"any",z=I.required?"":"?";R+=` ${I.name}${z}: ${O};
|
|
660
|
+
`;}),R+=` };
|
|
661
|
+
`),x&&(R+=` query: ${r.queryType||"Record<string, any>"};
|
|
662
|
+
`),v&&(R+=` data: ${r.dtoType||"any"};
|
|
663
|
+
`),R+=" }"),s+=` ${R}
|
|
664
|
+
`,s+=` >({
|
|
665
|
+
`,s+=" query: (",R!=="void"&&(s+="arg"),s+=`) => {
|
|
666
|
+
`,j){let I=A.map(_=>`arg.url.${_.name}`).join(", ");s+=` const url = ${r.name}(${I});
|
|
667
|
+
`;}else s+=` const url = ${r.name};
|
|
668
|
+
`;s+=` return {
|
|
669
|
+
`,s+=` url,
|
|
670
|
+
`,s+=` method: '${m}',
|
|
671
|
+
`,x&&(s+=` params: arg.query,
|
|
672
|
+
`),v&&(s+=` body: arg.data,
|
|
673
|
+
`),s+=` };
|
|
674
|
+
`,s+=` },
|
|
675
|
+
`,r.tags&&r.tags.length>0&&(y?s+=` providesTags: ['${r.tags[0]}'],
|
|
676
|
+
`:s+=` invalidatesTags: ['${r.tags[0]}'],
|
|
677
|
+
`),s+=` })${f<u.length-1?",":""}
|
|
678
|
+
`;}),s+=` }),
|
|
679
|
+
`,s+=`});
|
|
680
|
+
|
|
681
|
+
`,s+=`export default ${n}Api;
|
|
682
|
+
|
|
683
|
+
`,s};var gn=(u,i)=>{var n,e;if((n=i==null?void 0:i.folderSplit)!=null&&n.customFolder){let s=i.folderSplit.customFolder({method:u.method,path:u.path,tags:u.tags,operationId:u.operationId,summary:u.summary});if(s)return s}return (e=i==null?void 0:i.folderSplit)!=null&&e.byTags&&u.tags&&u.tags.length>0?u.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},sn=(u,i,n,e,s)=>d(null,null,function*(){let t=rn(u,n);if(t.length===0)return;let o=n.type||"fetch";n.outputDir||D.join(s,e,"client");let f=!!(i!=null&&i.folderSplit&&(i.folderSplit.byTags||i.folderSplit.customFolder));if(`${o}${t.length}`,f){let y={};t.forEach(j=>{let x=gn(j,i);y[x]||(y[x]=[]),y[x].push(j);});let A=Object.keys(y);for(let[j,x]of Object.entries(y)){let v=D.join(s,e,j);yield se.promises.mkdir(v,{recursive:true}),`${o}${j}${x.length}`,yield Cn(x,i,n,v,o,j,true);}let S=D.join(s,e);yield bn(S,A,o,i);return}let m=D.join(s,e);switch(yield se.promises.mkdir(m,{recursive:true}),o){case "fetch":let y=Fe(t,n);y=y.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield Y(D.join(m,"clients.ts"),y,i);break;case "axios":let A=fe(t,n,false);A=A.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield Y(D.join(m,"clients.ts"),A,i);break;case "react-query":let S=fe(t,n,false);S=S.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield Y(D.join(m,"clients.ts"),S,i);let j=Qe(t,n);j=j.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';").replace("import apiClient from './client';","import apiClient from './clients';"),yield Y(D.join(m,"hooks.ts"),j,i);break;case "swr":let x=fe(t,n,false);x=x.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield Y(D.join(m,"clients.ts"),x,i);let v=Be(t,n);v=v.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';").replace("import apiClient from './client';","import apiClient from './clients';"),yield Y(D.join(m,"hooks.ts"),v,i);break;case "rtk-query":let G=ze(t,n);G=G.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield Y(D.join(m,"api.ts"),G,i);break;default:throw new Error(`Unknown client type: ${o}`)}}),Y=(u,i,n)=>d(null,null,function*(){var o,r,f,m;if(!(((o=n==null?void 0:n.customCode)==null?void 0:o.enabled)!==false)){yield se.promises.writeFile(u,i);return}let s=null;try{s=yield se.promises.readFile(u,"utf-8");}catch(y){}let t=qe(i,s,{position:((r=n==null?void 0:n.customCode)==null?void 0:r.position)||"bottom",markerText:(f=n==null?void 0:n.customCode)==null?void 0:f.markerText,includeInstructions:(m=n==null?void 0:n.customCode)==null?void 0:m.includeInstructions});yield se.promises.writeFile(u,t);});var Cn=(u,i,n,e,s,t,o=false)=>d(null,null,function*(){let r="",f="",m=o?"./types":"../types",y=o?"./endpoints":"../endpoints";switch(s){case "fetch":r=Fe(u,n,o),r=r.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${y}';`),yield Y(D.join(e,"client.ts"),r,i);break;case "axios":r=fe(u,n,o),r=r.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${y}';`),yield Y(D.join(e,"client.ts"),r,i);break;case "react-query":if(r=fe(u,n,o),r=r.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${y}';`),yield Y(D.join(e,"client.ts"),r,i),f=Qe(u,n),f=f.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${y}';`),o){let S=t.replace(/-/g,"_");f=f.replace("import apiClient from './client';",`import { ${S}Client as apiClient } from '../clients';`);}yield Y(D.join(e,"hooks.ts"),f,i);break;case "swr":if(r=fe(u,n,o),r=r.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${y}';`),yield Y(D.join(e,"client.ts"),r,i),f=Be(u,n),f=f.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${y}';`),o){let S=t.replace(/-/g,"_");f=f.replace("import apiClient from './client';",`import { ${S}Client as apiClient } from '../clients';`);}yield Y(D.join(e,"hooks.ts"),f,i);break;case "rtk-query":let A=o?b(a({},n),{rtkQuery:b(a({},n.rtkQuery),{apiName:t.replace(/-/g,"_")})}):n;f=ze(u,A),f=f.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${y}';`),yield Y(D.join(e,"api.ts"),f,i);break;default:throw new Error(`Unknown client type: ${s}`)}}),bn=(u,i,n,e)=>d(null,null,function*(){var t;if(n==="rtk-query"){let o=`// Generated RTK Query APIs
|
|
685
684
|
`;o+=`// This file was auto-generated.
|
|
686
685
|
`,o+=`// Aggregates all API slices for easy Redux store setup
|
|
687
686
|
|
|
688
|
-
`,
|
|
687
|
+
`,i.forEach(r=>{let f=r.replace(/-/g,"_");o+=`import ${f}Api from './${r}/api';
|
|
689
688
|
`;}),o+=`
|
|
690
689
|
// Export all API slices
|
|
691
|
-
`,
|
|
690
|
+
`,i.forEach(r=>{let f=r.replace(/-/g,"_");o+=`export { default as ${f}Api } from './${r}/api';
|
|
692
691
|
`;}),o+=`
|
|
693
692
|
/**
|
|
694
693
|
`,o+=` * Configure Redux store with all API slices
|
|
@@ -705,74 +704,74 @@ ${T}`,t);}}Xt(u,b);}),Se=tn;var nn=(p,u)=>{let t=p;return u.tags&&u.tags.length>
|
|
|
705
704
|
`,o+=` */
|
|
706
705
|
`,o+=`export const setupApiStore = {
|
|
707
706
|
`,o+=` reducer: {
|
|
708
|
-
`,
|
|
707
|
+
`,i.forEach(r=>{let f=r.replace(/-/g,"_");o+=` [${f}Api.reducerPath]: ${f}Api.reducer,
|
|
709
708
|
`;}),o+=` },
|
|
710
709
|
`,o+=` middleware: [
|
|
711
|
-
`,
|
|
710
|
+
`,i.forEach(r=>{let f=r.replace(/-/g,"_");o+=` ${f}Api.middleware,
|
|
712
711
|
`;}),o+=` ],
|
|
713
712
|
`,o+=`};
|
|
714
|
-
`,yield
|
|
715
|
-
`;if(
|
|
716
|
-
`,
|
|
713
|
+
`,yield Y(D.join(u,"apis.ts"),o,e);return}let s=`// Generated API Clients
|
|
714
|
+
`;if(s+=`// This file was auto-generated.
|
|
715
|
+
`,s+=`// Centralized client instances and configuration
|
|
717
716
|
|
|
718
|
-
`,
|
|
719
|
-
`;}):(
|
|
720
|
-
`;}),
|
|
717
|
+
`,n==="fetch"?i.forEach(o=>{let r=o.replace(/-/g,"_");s+=`export { default as ${r}Client } from './${o}/client';
|
|
718
|
+
`;}):(i.forEach(o=>{let r=o.replace(/-/g,"_"),f=`${r.charAt(0).toUpperCase()+r.slice(1)}ApiClient`;s+=`import ${f} from './${o}/client';
|
|
719
|
+
`;}),s+=`
|
|
721
720
|
// Create client instances
|
|
722
|
-
`,
|
|
723
|
-
`;})),
|
|
721
|
+
`,i.forEach(o=>{let r=o.replace(/-/g,"_"),f=`${r.charAt(0).toUpperCase()+r.slice(1)}ApiClient`;s+=`export const ${r}Client = new ${f}();
|
|
722
|
+
`;})),n==="fetch"&&(s+=`
|
|
724
723
|
// Import clients for aggregation
|
|
725
|
-
`,
|
|
726
|
-
`;})),
|
|
724
|
+
`,i.forEach(o=>{let r=o.replace(/-/g,"_");s+=`import ${r}_client from './${o}/client';
|
|
725
|
+
`;})),s+=`
|
|
727
726
|
// Aggregate all client instances
|
|
728
|
-
`,
|
|
729
|
-
`,
|
|
730
|
-
`:
|
|
731
|
-
`;}),
|
|
727
|
+
`,s+=`export const clients = {
|
|
728
|
+
`,i.forEach(o=>{let r=o.replace(/-/g,"_");n==="fetch"?s+=` ${r}: ${r}_client,
|
|
729
|
+
`:s+=` ${r}: ${r}Client,
|
|
730
|
+
`;}),s+=`};
|
|
732
731
|
|
|
733
|
-
`,
|
|
732
|
+
`,n==="axios"?(s+=`
|
|
734
733
|
/**
|
|
735
|
-
`,
|
|
736
|
-
`,
|
|
737
|
-
`,
|
|
738
|
-
`,
|
|
739
|
-
`,
|
|
740
|
-
`,
|
|
741
|
-
`,
|
|
742
|
-
`,
|
|
743
|
-
`,
|
|
744
|
-
`;}),
|
|
745
|
-
|
|
746
|
-
`):
|
|
734
|
+
`,s+=` * Configure all API clients at once
|
|
735
|
+
`,s+=` * @param config - Configuration to apply to all clients
|
|
736
|
+
`,s+=` */
|
|
737
|
+
`,s+=`export const configureAllClients = (config: {
|
|
738
|
+
`,s+=` baseURL?: string;
|
|
739
|
+
`,s+=` headers?: Record<string, string>;
|
|
740
|
+
`,s+=` timeout?: number;
|
|
741
|
+
`,s+=`}) => {
|
|
742
|
+
`,i.forEach(o=>{let r=o.replace(/-/g,"_");s+=` ${r}Client.updateConfig(config);
|
|
743
|
+
`;}),s+=`};
|
|
744
|
+
|
|
745
|
+
`):n==="fetch"&&(s+=`
|
|
747
746
|
/**
|
|
748
|
-
`,
|
|
749
|
-
`,
|
|
750
|
-
`,
|
|
751
|
-
`,
|
|
752
|
-
`,
|
|
753
|
-
`,
|
|
754
|
-
`,
|
|
755
|
-
`,
|
|
756
|
-
`,
|
|
757
|
-
`;}),
|
|
758
|
-
|
|
759
|
-
`),
|
|
760
|
-
`,
|
|
761
|
-
`,
|
|
762
|
-
`,
|
|
763
|
-
`,
|
|
764
|
-
`,
|
|
765
|
-
`,
|
|
766
|
-
`,
|
|
767
|
-
`,
|
|
768
|
-
`,
|
|
769
|
-
`,
|
|
770
|
-
`,yield
|
|
747
|
+
`,s+=` * Configure all API clients at once
|
|
748
|
+
`,s+=` * @param config - Configuration to apply to all clients
|
|
749
|
+
`,s+=` */
|
|
750
|
+
`,s+=`export const configureAllClients = (config: {
|
|
751
|
+
`,s+=` baseURL?: string;
|
|
752
|
+
`,s+=` headers?: Record<string, string>;
|
|
753
|
+
`,s+=` auth?: { token?: string };
|
|
754
|
+
`,s+=`}) => {
|
|
755
|
+
`,i.forEach(o=>{let r=o.replace(/-/g,"_");s+=` ${r}_client.setApiConfig(config);
|
|
756
|
+
`;}),s+=`};
|
|
757
|
+
|
|
758
|
+
`),s+=`// Example usage:
|
|
759
|
+
`,s+=`// import { configureAllClients, clients } from './clients';
|
|
760
|
+
`,s+=`//
|
|
761
|
+
`,s+=`// // Configure all clients at once
|
|
762
|
+
`,s+=`// configureAllClients({
|
|
763
|
+
`,s+=`// baseURL: 'https://api.example.com',
|
|
764
|
+
`,s+=`// timeout: 10000,
|
|
765
|
+
`,s+=`// });
|
|
766
|
+
`,s+=`//
|
|
767
|
+
`,s+=`// // Use specific client
|
|
768
|
+
`,s+=`// const data = await clients.${(t=i[0])==null?void 0:t.replace(/-/g,"_")}.someMethod(...);
|
|
769
|
+
`,yield Y(D.join(u,"clients.ts"),s,e),n==="react-query"||n==="swr"){let o=`// Generated Hooks Aggregator
|
|
771
770
|
`;o+=`// This file was auto-generated.
|
|
772
771
|
`,o+=`// Aggregates all folder-split hooks
|
|
773
772
|
|
|
774
|
-
`,
|
|
773
|
+
`,i.forEach(r=>{o+=`export * from './${r}/hooks';
|
|
775
774
|
`;}),o+=`
|
|
776
775
|
// Example usage:
|
|
777
776
|
`,o+=`// import { useGetSomething } from './hooks';
|
|
778
|
-
`,yield
|
|
777
|
+
`,yield Y(D.join(u,"hooks.ts"),o,e);}});var ke=process.cwd(),an=()=>{let u;try{c("esbuild-register");}catch(o){throw o}let i=D.join(ke,"openapi.sync.js"),n=D.join(ke,"openapi.sync.ts"),e=D.join(ke,"openapi.sync.json"),s=[i,n,e];try{for(let o of s)se.existsSync(o)&&(u=c(o),Object.keys(u).length===1&&u.default&&(u=u.default));}catch(o){}typeof u=="function"&&(u=u());let t=u;if(!t)throw new Error("No config found");return t},lr=u=>d(null,null,function*(){let i=an(),n=Object.keys(i.api),e=u&&"refetchInterval"in u&&!isNaN(u==null?void 0:u.refetchInterval)?u.refetchInterval:i.refetchInterval;Me();for(let s=0;s<n.length;s+=1){let t=n[s],o=i.api[t];yield Le(o,t,i,e);}}),ur=u=>d(null,null,function*(){let i=an(),n=u.apiName?[u.apiName]:Object.keys(i.api);for(let s of n)if(!i.api[s])throw new Error(`API "${s}" not found in configuration. Available APIs: ${Object.keys(i.api).join(", ")}`);Me();for(let s of n){let t=i.api[s];yield Le(t,s,i);}let e=(i==null?void 0:i.folder)||"api";for(let s of n){let t=en(s);if(t.length===0){continue}`${t.length}${s}`;let o=a(a(a(a(b(a({enabled:true},i.clientGeneration||{}),{type:u.type}),u.outputDir&&{outputDir:u.outputDir}),u.baseURL&&{baseURL:u.baseURL}),u.tags&&{tags:u.tags}),u.endpoints&&{endpoints:u.endpoints});yield sn(t,i,o,s,D.join(ke,e));}}),pr=()=>d(null,null,function*(){let{interactiveInit:u}=yield import('./interactive-init-B7AFNUFL.mjs');yield u();});export{ur as GenerateClient,lr as Init,pr as InteractiveInit,Ee as JSONStringify,ue as capitalize,Jt as createCustomCodeMarker,mn as extractCustomCode,Kt as getEndpointDetails,wn as getNestedValue,Wt as isJson,pn as isYamlString,qe as mergeCustomCode,ve as renderTypeRefMD,xn as variableName,Dt as variableNameChar,Ht as yamlStringToJson};
|