openapi-sync 5.0.0 → 5.0.2
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 +501 -502
- package/dist/index.mjs +431 -432
- package/package.json +1 -1
- /package/dist/{interactive-init-4LMPMPGI.mjs → interactive-init-GU7WCWDC.mjs} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,375 +1,374 @@
|
|
|
1
|
-
'use strict';var
|
|
2
|
-
`+" ".repeat(o)+
|
|
3
|
-
`).filter(
|
|
4
|
-
${" ".repeat(o)}`);
|
|
5
|
-
${" ".repeat(o-1)}}`,
|
|
1
|
+
'use strict';var Oe=require('js-yaml'),W=require('path'),ie=require('fs'),Ln=require('lodash.isequal'),Ve=require('lodash.get'),Qn=require('axios'),Bn=require('axios-retry'),zn=require('@apidevtools/swagger-parser'),curlGenerator=require('curl-generator'),Tn=require('prompts');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var Oe__namespace=/*#__PURE__*/_interopNamespace(Oe);var W__default=/*#__PURE__*/_interopDefault(W);var ie__default=/*#__PURE__*/_interopDefault(ie);var Ln__default=/*#__PURE__*/_interopDefault(Ln);var Ve__default=/*#__PURE__*/_interopDefault(Ve);var Qn__default=/*#__PURE__*/_interopDefault(Qn);var Bn__default=/*#__PURE__*/_interopDefault(Bn);var zn__default=/*#__PURE__*/_interopDefault(zn);var Tn__default=/*#__PURE__*/_interopDefault(Tn);var sn=Object.defineProperty,Rn=Object.defineProperties;var kn=Object.getOwnPropertyDescriptors;var rn=Object.getOwnPropertySymbols;var Un=Object.prototype.hasOwnProperty,Fn=Object.prototype.propertyIsEnumerable;var on=(n,o,l)=>o in n?sn(n,o,{enumerable:true,configurable:true,writable:true,value:l}):n[o]=l,oe=(n,o)=>{for(var l in o||(o={}))Un.call(o,l)&&on(n,l,o[l]);if(rn)for(var l of rn(o))Fn.call(o,l)&&on(n,l,o[l]);return n},ve=(n,o)=>Rn(n,kn(o));var Ae=(n=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(n,{get:(o,l)=>(typeof require!="undefined"?require:o)[l]}):n)(function(n){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});var se=(n,o)=>()=>(n&&(o=n(n=0)),o);var an=(n,o)=>{for(var l in o)sn(n,l,{get:o[l],enumerable:true});};var te=(n,o,l)=>new Promise((e,s)=>{var t=d=>{try{r(l.next(d));}catch(c){s(c);}},i=d=>{try{r(l.throw(d));}catch(c){s(c);}},r=d=>d.done?e(d.value):Promise.resolve(d.value).then(t,i);r((l=l.apply(n,o)).next());});exports.variableName=void 0;exports.variableNameChar=void 0;var Le=se(()=>{exports.variableName=/^[A-Za-z_$][A-Za-z0-9_$]*$/,exports.variableNameChar=/[A-Za-z0-9_$]/;});function Gn(n,o){return o.split(".").reduce((e,s)=>e&&e[s]!==void 0?e[s]:void 0,n)}exports.isJson=void 0;exports.isYamlString=void 0;exports.yamlStringToJson=void 0;exports.capitalize=void 0;exports.getEndpointDetails=void 0;exports.JSONStringify=void 0;exports.renderTypeRefMD=void 0;exports.extractCustomCode=void 0;exports.createCustomCodeMarker=void 0;exports.mergeCustomCode=void 0;var ke=se(()=>{Le();exports.isJson=n=>["object"].includes(typeof n)&&!(n instanceof Blob),exports.isYamlString=n=>{try{return Oe__namespace.load(n),!0}catch(o){let l=o;if(l instanceof Oe__namespace.YAMLException)return false;throw l}},exports.yamlStringToJson=n=>{if(exports.isYamlString(n)){let o=Oe__namespace.load(n),l=JSON.stringify(o,null,2);return JSON.parse(l)}},exports.capitalize=n=>n.substring(0,1).toUpperCase()+n.substring(1),exports.getEndpointDetails=(n,o)=>{let l=n.split("/"),e=`${exports.capitalize(o)}`,s=[];return l.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 i="";t.split("").forEach(r=>{let d=r;exports.variableNameChar.test(r)||(d="/"),i+=d;}),i.split("/").forEach(r=>{e+=exports.capitalize(r);});}),{name:e,variables:s,pathParts:l}},exports.JSONStringify=(n,o=1)=>{let l="{",e=Object.keys(n);for(let s=0;s<e.length;s++){let t=e[s],i=n[t];if(l+=`
|
|
2
|
+
`+" ".repeat(o)+t+": ",Array.isArray(i)){l+="[";for(let r=0;r<i.length;r++){let d=i[r];typeof d=="object"&&d!==null?l+=exports.JSONStringify(d,o+1):l+=typeof d=="string"?`"${d}"`:d,r<i.length-1&&(l+=", ");}l+="]";}else typeof i=="object"&&i!==null?l+=""+exports.JSONStringify(i,o+1):l+=i.split(`
|
|
3
|
+
`).filter(r=>r.trim()!=="").join(`
|
|
4
|
+
${" ".repeat(o)}`);s<e.length-1&&(l+=", ");}return l+=`
|
|
5
|
+
${" ".repeat(o-1)}}`,l},exports.renderTypeRefMD=(n,o=1)=>`
|
|
6
6
|
\`\`\`typescript
|
|
7
|
-
${" ".repeat(o)} ${
|
|
8
|
-
`).filter(
|
|
7
|
+
${" ".repeat(o)} ${n.split(`
|
|
8
|
+
`).filter(l=>l.trim()!=="").join(`
|
|
9
9
|
${" ".repeat(o)} `)}
|
|
10
|
-
\`\`\``;exports.extractCustomCode=(
|
|
11
|
-
`,
|
|
12
|
-
`).filter(
|
|
10
|
+
\`\`\``;exports.extractCustomCode=(n,o="CUSTOM CODE")=>{let l=`// \u{1F512} ${o} START`,e=`// \u{1F512} ${o} END`,s={beforeGenerated:"",afterGenerated:""},t=0,i=[];for(;t<n.length;){let r=n.indexOf(l,t);if(r===-1)break;let d=n.indexOf(e,r);if(d===-1)break;let c=d+e.length,y=n.substring(c,c+100),v=y.match(/^\s*\n\s*(\/\/ =+)/);if(v){let N=y.indexOf(`
|
|
11
|
+
`,v.index+1);N!==-1?c+=N+1:c+=v[0].length;}let k=r,x=n.substring(Math.max(0,r-200),r).lastIndexOf("// ==========");x!==-1&&(k=Math.max(0,r-200)+x);let O=n.substring(k,c);i.push({start:k,end:c,content:O}),t=c;}return i.length>0&&(n.substring(0,i[0].start).split(`
|
|
12
|
+
`).filter(c=>{let y=c.trim();return y.length>0&&!y.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},exports.createCustomCodeMarker=(n,o="CUSTOM CODE",l=true)=>{let e=l?`// ${n==="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
15
|
// \u{1F512} ${o} START
|
|
16
16
|
${e}// ${"=".repeat(60)}
|
|
17
17
|
|
|
18
18
|
// \u{1F512} ${o} END
|
|
19
|
-
// ${"=".repeat(60)}`},exports.mergeCustomCode=(
|
|
20
|
-
`)};});var
|
|
21
|
-
`).filter(
|
|
22
|
-
*${" ".repeat(1)}`))),
|
|
23
|
-
${
|
|
19
|
+
// ${"=".repeat(60)}`},exports.mergeCustomCode=(n,o,l={})=>{let{position:e="bottom",markerText:s="CUSTOM CODE",includeInstructions:t=true}=l,i={beforeGenerated:"",afterGenerated:""};o&&(i=exports.extractCustomCode(o,s)),!i.beforeGenerated&&!i.afterGenerated&&((e==="top"||e==="both")&&(i.beforeGenerated=exports.createCustomCodeMarker("top",s,t)),(e==="bottom"||e==="both")&&(i.afterGenerated=exports.createCustomCodeMarker("bottom",s,t)));let r=[];return i.beforeGenerated&&(r.push(i.beforeGenerated),r.push("")),r.push(n),i.afterGenerated&&(r.push(""),r.push(i.afterGenerated)),r.join(`
|
|
20
|
+
`)};});var Ue,Je,je,un,cn,mn,He,Ke=se(()=>{Ue=W__default.default.join(__dirname,"../","../db.json");ie__default.default.existsSync(Ue)||ie__default.default.writeFileSync(Ue,"{}");Je={};try{Je=Ae(Ue);}catch(n){Je={};}je=Je||{},un=n=>{ie__default.default.writeFileSync(Ue,JSON.stringify(n));},cn=(n,o)=>{je[n]=o,un(je);},mn=n=>je[n],He=()=>{je={},un(je);};});var dn,fn,yn,_e=se(()=>{dn={},fn=(n,o)=>{dn[n]=o;},yn=n=>dn[n]||[];});var ye,Ye,gn,ge,hn,Dn,Ze,$n=se(()=>{ke();Ke();_e();ye=process.cwd(),Ye={},gn=Qn__default.default.create({timeout:6e4});Bn__default.default(gn,{retries:20,retryCondition:n=>n.code==="ECONNABORTED"||n.message.includes("Network Error"),retryDelay:n=>n*1e3});ge=(n,o,l)=>te(null,null,function*(){var i,r,d,c;if(!(((i=l==null?void 0:l.customCode)==null?void 0:i.enabled)!==false)){yield ie__default.default.promises.writeFile(n,o);return}let s=null;try{s=yield ie__default.default.promises.readFile(n,"utf-8");}catch(y){}let t=exports.mergeCustomCode(o,s,{position:((r=l==null?void 0:l.customCode)==null?void 0:r.position)||"bottom",markerText:(d=l==null?void 0:l.customCode)==null?void 0:d.markerText,includeInstructions:(c=l==null?void 0:l.customCode)==null?void 0:c.includeInstructions});yield ie__default.default.promises.writeFile(n,t);}),hn=(n,o,l,e)=>te(null,null,function*(){let s=yield Dn(n,o,l,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}`),hn(n,o,l,e);},e))),s}),Dn=(...n)=>te(null,null,function*(){var pe,ne,ue,we,Ce,Re,rt,ot,st,at;let[o,l,e]=n,s=yield gn.get(o).catch(a=>(console.error(a),{data:null}));if(!s.data)return;let t=exports.isJson(s.data)?s.data:exports.yamlStringToJson(s.data),i;try{i=yield zn__default.default.parse(t);}catch(a){let u=a instanceof Error?a.message:String(a);throw new Error(`Failed to parse OpenAPI spec for ${l}: ${u}`)}let r=W__default.default.join((e==null?void 0:e.folder)||"",l),d={},c=a=>{var u,E;if((u=e==null?void 0:e.folderSplit)!=null&&u.customFolder){let $=e.folderSplit.customFolder(a);if($)return $}return (E=e==null?void 0:e.folderSplit)!=null&&E.byTags&&a.tags&&a.tags.length>0?a.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},y=typeof(e==null?void 0:e.server)=="string"?e==null?void 0:e.server:((ne=(pe=i==null?void 0:i.servers)==null?void 0:pe[(e==null?void 0:e.server)||0])==null?void 0:ne.url)||"",v=typeof((we=(ue=e==null?void 0:e.types)==null?void 0:ue.name)==null?void 0:we.prefix)=="string"?e==null?void 0:e.types.name.prefix:"I",k=typeof((Re=(Ce=e==null?void 0:e.endpoints)==null?void 0:Ce.name)==null?void 0:Re.prefix)=="string"?e==null?void 0:e.endpoints.name.prefix:"",q=(a,u)=>{var $,f;let E=exports.capitalize(a);if((f=($=e==null?void 0:e.types)==null?void 0:$.name)!=null&&f.format){let g=e==null?void 0:e.types.name.format("shared",{name:a},E);if(g)return `${v}${g}`}return `${v}${E}`},x=(a,u,E,$,f,g=0)=>{let m="",b="",h="";if(u)if(u.$ref)if(u.$ref[0]==="#"){let P=(u.$ref||"").split("/");P.shift(),[...P].pop();let M=Ve__default.default(a,P,null);if(M){M!=null&&M.name&&(m=M.name),b=P[P.length-1];let H=q(b);H.includes(".")&&(H=H.split(".").map((me,Ie)=>Ie===0?me:`["${me}"]`).join("")),h+=`${f!=null&&f.noSharedImport?"":"Shared."}${H}`;}}else h+="";else if(u.anyOf)h+=`(${u.anyOf.map(P=>x(a,P,"",$,f)).filter(P=>!!P).join("|")})`;else if(u.oneOf)h+=`(${u.oneOf.map(P=>x(a,P,"",$,f)).filter(P=>!!P).join("|")})`;else if(u.allOf)h+=`(${u.allOf.map(P=>x(a,P,"",$,f)).filter(P=>!!P).join("&")})`;else if(u.items)h+=`${x(a,u.items,"",false,f)}[]`;else if(u.properties){let P=Object.keys(u.properties),G=u.required||[],Q="";P.forEach(M=>{var ce,me,Ie,Te,Ee,fe;let H="";!((me=(ce=e==null?void 0:e.types)==null?void 0:ce.doc)!=null&&me.disable)&&((Te=(Ie=u.properties)==null?void 0:Ie[M])!=null&&Te.description)&&(H=" * "+((Ee=u.properties)==null?void 0:Ee[M].description.split(`
|
|
21
|
+
`).filter(Ge=>Ge.trim()!=="").join(`
|
|
22
|
+
*${" ".repeat(1)}`))),Q+=(H?`/**
|
|
23
|
+
${H}
|
|
24
24
|
*/
|
|
25
|
-
`:"")+`${x(
|
|
26
|
-
${" ".repeat(
|
|
27
|
-
`:""}`:""},
|
|
28
|
-
`)
|
|
29
|
-
${
|
|
30
|
-
}`:
|
|
31
|
-
`).filter(
|
|
32
|
-
*${" ".repeat(1)}`)),
|
|
33
|
-
${
|
|
25
|
+
`:"")+`${x(a,(fe=u.properties)==null?void 0:fe[M],M,G.includes(M),f,g+1)}`;}),Q.length>0?h+=`{
|
|
26
|
+
${" ".repeat(g)}${Q}${" ".repeat(g)}}`:h+="{[k: string]: any}";}else if(u.enum&&u.enum.length>0){let P=u.enum.includes(null),G=u.enum.filter(M=>M!==null).map(M=>JSON.stringify(M)).filter(M=>M!==void 0),Q=G.length>1||G.length>0&&P;Q&&(h+="("),G.forEach((M,H)=>{h+=`${H===0?"":"|"}${M}`;}),P&&(h+=`${G.length>0?"|":""}null`),Q&&(h+=")");}else if(u.type){let P=G=>{let Q="";if(typeof G=="string")["string","integer","number","array","boolean","null"].includes(G)?["integer","number"].includes(G)?Q+="number":G==="array"?Q+="any[]":Q+=G:G==="object"&&(u.additionalProperties?Q+=`{[k: string]: ${x(a,u.additionalProperties,"",true,f)||"any"}}`:Q+="{[k: string]: any}");else if(Array.isArray(G)){let M=G.map(H=>P(H));M.filter(H=>H!==""),M.length>1&&(Q+="("+M.join("|")+")");}else Q+="any";return Q};h=P(u.type);}else h+="any";else h="string";let A=m||E;f!=null&&f.useComponentName&&!A&&(A=b);let J=A?` "${A}"${$?"":"?"}: `:"",p=(u==null?void 0:u.enum)&&u.enum.includes(null),V=u!=null&&u.nullable&&!p?" | null":"";return h.length>0?`${J}${h}${V}${A?`;
|
|
27
|
+
`:""}`:""},O=(a,u)=>{let f="";if(u)if(u.$ref)if(u.$ref[0]==="#"){let g=(u.$ref||"").split("/");g.shift();let b=Ve__default.default(a,g,null);b&&(b!=null&&b.name&&(b.name),g[g.length-1],f+=O(a,b));}else f+="";else if(u.anyOf)f+=O(a,u.anyOf[0]);else if(u.oneOf)f+=O(a,u.oneOf[0]);else if(u.allOf)f+=`{${u.allOf.map(g=>`...(${O(a,g)})`).join(",")}}`;else if(u.items)f+=`[${O(a,u.items)}]`;else if(u.properties){let b=Object.keys(u.properties).map(h=>{var A;return ` "${h}": ${O(a,(A=u.properties)==null?void 0:A[h])}`}).join(`,
|
|
28
|
+
`);b.length>0?f+=`{
|
|
29
|
+
${b}
|
|
30
|
+
}`:f+="{}";}else if(u.enum&&u.enum.length>0)u.enum.length>1&&(f+=u.enum[0]);else if(u.type)if(u.example)f+=JSON.stringify(u.example);else {let g=m=>{let b="";if(typeof m=="string")["string","integer","number","array","boolean","null"].includes(m)?["integer","number"].includes(m)?b+="123":m==="array"?b+="[]":m==="boolean"?b+="true":m==="null"?b+="null":b+=`"${m}"`:m==="object"&&(b+="{}");else if(Array.isArray(m)){let h=m.map(A=>g(A));h.filter(A=>A!==""),h.length>1&&(b+=h.join("|"));}else b+="any";return b};f=g(u.type);}else f+="any";else f="string";return f},N=mn(l);if(Ln__default.default(N,i))return;cn(l,i);let R="",D="",T={},I=[];i.components&&Object.keys(i.components).forEach(a=>{if(["schemas","responses","parameters","examples","requestBodies","headers","links","callbacks"].includes(a)){let u=i.components[a],E={},$={};Object.keys(u).forEach(g=>{var h;let m=(h=u[g])!=null&&h.schema?u[g].schema:u[g],b=`${x(i,m,"",true,{noSharedImport:true,useComponentName:["parameters"].includes(a)})}`;if(b){let A=g.split("."),J=E,p=$;for(let V=0;V<A.length;V++){let P=A[V];V<A.length-1?(P in J||(J[P]={},p[P]={}),J=J[P],p=p[P]):(J[P]=b,p[P]=m);}}}),Object.keys(E).forEach(g=>{var A,J,p,V;let m=q(g),b=E[g],h="";!((J=(A=e==null?void 0:e.types)==null?void 0:A.doc)!=null&&J.disable)&&g in u&&((p=u[g])!=null&&p.description)&&(h=" * "+u[g].description.split(`
|
|
31
|
+
`).filter(P=>P.trim()!=="").join(`
|
|
32
|
+
*${" ".repeat(1)}`)),T[g]=((V=T[g])!=null?V:"")+(h?`/**
|
|
33
|
+
${h}
|
|
34
34
|
*/
|
|
35
|
-
`:"")+"export type "+
|
|
36
|
-
`;});}});let
|
|
37
|
-
`);return
|
|
38
|
-
${
|
|
39
|
-
${" ".repeat(
|
|
40
|
-
${
|
|
41
|
-
${" ".repeat(
|
|
42
|
-
${
|
|
43
|
-
${" ".repeat(
|
|
44
|
-
${
|
|
45
|
-
`;
|
|
46
|
-
`),
|
|
47
|
-
${
|
|
35
|
+
`:"")+"export type "+m+" = "+(typeof b=="string"?b:exports.JSONStringify(b))+`;
|
|
36
|
+
`;});}});let _=a=>{let u="";if(a.content){let E=Object.keys(a.content);E[0]&&a.content[E[0]].schema&&(u+=`${x(i,a.content[E[0]].schema,"")}`);}return u},j=(a,u,E=0)=>{if(!a)return u==="joi"?"Joi.any()":u==="yup"?"yup.mixed()":"z.any()";if(a.$ref){if(a.$ref[0]==="#"){let $=a.$ref.split("/");$.shift();let f=$.join("."),g=Ve__default.default(i,f);if(g)return j(g,u,E)}return u==="joi"?"Joi.any()":u==="yup"?"yup.mixed()":"z.any()"}if(a.anyOf||a.oneOf){let $=a.anyOf||a.oneOf;if($.every(g=>g.enum!==void 0&&Array.isArray(g.enum))){let g=[],m=false;if($.forEach(b=>{b.enum&&b.enum.forEach(h=>{h===null?m=true:g.includes(h)||g.push(h);});}),g.length>0){let b=g.map(h=>JSON.stringify(h)).join(", ");if(u==="zod"){let h=`z.enum([${b}])`;return m&&(h+=".nullable()"),h}else if(u==="yup"){let h=`yup.mixed().oneOf([${b}])`;return m&&(h+=".nullable()"),h}else return m?`Joi.valid(${b}, null)`:`Joi.valid(${b})`}else if(m)return u==="zod"?"z.null()":u==="yup"?"yup.mixed().nullable()":"Joi.valid(null)"}return u==="zod"?`z.union([${$.map(b=>j(b,u,E+1)).join(", ")}])`:u==="yup"?`yup.mixed().oneOf([${$.map(b=>j(b,u,E+1)).join(", ")}])`:`Joi.alternatives().try(${$.map(m=>j(m,u,E+1)).join(", ")})`}if(a.allOf)if(u==="zod"){let $=a.allOf.map(g=>j(g,u,E+1)),f=$[0];for(let g=1;g<$.length;g++)f=`${f}.merge(${$[g]})`;return f}else return j(a.allOf[0],u,E+1);if(a.items){let $=j(a.items,u,E+1);if(u==="zod"){let f=`z.array(${$})`;return a.minItems!==void 0&&(f+=`.min(${a.minItems})`),a.maxItems!==void 0&&(f+=`.max(${a.maxItems})`),f}else if(u==="yup"){let f=`yup.array().of(${$})`;return a.minItems!==void 0&&(f+=`.min(${a.minItems})`),a.maxItems!==void 0&&(f+=`.max(${a.maxItems})`),f}else {let f=`Joi.array().items(${$})`;return a.minItems!==void 0&&(f+=`.min(${a.minItems})`),a.maxItems!==void 0&&(f+=`.max(${a.maxItems})`),f}}if(a.properties){let $=a.required||[],f=" ".repeat(E+1),g=Object.entries(a.properties).map(([m,b])=>{let h=$.includes(m),A=j(b,u,E+1);return h||(A+=".optional()"),`${f}${m}: ${A}`}).join(`,
|
|
37
|
+
`);return u==="zod"?`z.object({
|
|
38
|
+
${g}
|
|
39
|
+
${" ".repeat(E)}})`:u==="yup"?`yup.object({
|
|
40
|
+
${g}
|
|
41
|
+
${" ".repeat(E)}})`:`Joi.object({
|
|
42
|
+
${g}
|
|
43
|
+
${" ".repeat(E)}})`}if(a.enum&&a.enum.length>0){let $=[],f=false;a.enum.forEach(m=>{m===null?f=true:$.includes(m)||$.push(m);});let g=$.map(m=>JSON.stringify(m)).join(", ");if(u==="zod"){let m=`z.enum([${g}])`;return f&&(m+=".nullable()"),m}else if(u==="yup"){let m=`yup.mixed().oneOf([${g}])`;return f&&(m+=".nullable()"),m}else {let m=`Joi.valid(${g})`;return f&&(m+=".allow(null)"),m}}if(a.type){let f=(g=>{switch(g){case "string":if(u==="zod"){let m="z.string()";return a.format==="email"?m+=".email()":a.format==="uuid"?m+=".uuid()":a.format==="url"||a.format==="uri"?m+=".url()":a.format==="date-time"?m+=".datetime()":a.format==="date"&&(m+=".date()"),a.minLength&&(m+=`.min(${a.minLength})`),a.maxLength&&(m+=`.max(${a.maxLength})`),a.pattern&&(m+=`.regex(/${a.pattern}/)`),m}else if(u==="yup"){let m="yup.string()";return a.format==="email"?m+=".email()":(a.format==="url"||a.format==="uri")&&(m+=".url()"),a.minLength&&(m+=`.min(${a.minLength})`),a.maxLength&&(m+=`.max(${a.maxLength})`),a.pattern&&(m+=`.matches(/${a.pattern}/)`),m}else {let m="Joi.string()";return a.format==="email"?m+=".email()":a.format==="url"||a.format==="uri"?m+=".uri()":a.format==="uuid"?m+=".guid({ version: 'uuidv4' })":a.format==="date-time"&&(m+=".isoDate()"),a.minLength&&(m+=`.min(${a.minLength})`),a.maxLength&&(m+=`.max(${a.maxLength})`),a.pattern&&(m+=`.pattern(/${a.pattern}/)`),m}case "integer":case "number":if(u==="zod"){let m="z.number()";return g==="integer"&&(m+=".int()"),a.minimum!==void 0&&(a.exclusiveMinimum?m+=`.gt(${a.minimum})`:m+=`.min(${a.minimum})`),a.maximum!==void 0&&(a.exclusiveMaximum?m+=`.lt(${a.maximum})`:m+=`.max(${a.maximum})`),m}else if(u==="yup"){let m="yup.number()";return g==="integer"&&(m+=".integer()"),a.minimum!==void 0&&(m+=`.min(${a.minimum})`),a.maximum!==void 0&&(m+=`.max(${a.maximum})`),m}else {let m="Joi.number()";return g==="integer"&&(m+=".integer()"),a.minimum!==void 0&&(a.exclusiveMinimum?m+=`.greater(${a.minimum})`:m+=`.min(${a.minimum})`),a.maximum!==void 0&&(a.exclusiveMaximum?m+=`.less(${a.maximum})`:m+=`.max(${a.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 a.type=="string"?a.type:a.type[0]);return a.nullable&&u!=="joi"?f+=".nullable()":a.nullable&&u==="joi"&&(f+=".allow(null)"),f}return u==="joi"?"Joi.any()":u==="yup"?"yup.mixed()":"z.any()"},z=a=>{var u,E,$,f,g;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 m=a;return (g=(f=($=e==null?void 0:e.endpoints)==null?void 0:$.value)==null?void 0:f.replaceWords)==null||g.forEach((b,h)=>{let A=new RegExp(b.replace,"g");m=m.replace(A,b.with||"");}),m}else return a},le=(a,u,E=[])=>{var g,m;let $=(g=e==null?void 0:e.endpoints)==null?void 0:g.exclude,f=(m=e==null?void 0:e.endpoints)==null?void 0:m.include;if(f){let b=f.tags&&f.tags.length>0?E.some(A=>f.tags.includes(A)):true,h=f.endpoints&&f.endpoints.length>0?f.endpoints.some(A=>{let J=!A.method||A.method.toLowerCase()===u.toLowerCase();return A.path?a===A.path&&J:A.regex?new RegExp(A.regex).test(a)&&J:false}):true;if(!b||!h)return true}return !!($&&($.tags&&$.tags.length>0&&E.some(h=>$.tags.includes(h))||$.endpoints&&$.endpoints.length>0&&$.endpoints.some(h=>{let A=!h.method||h.method.toLowerCase()===u.toLowerCase();return h.path?a===h.path&&A:h.regex?new RegExp(h.regex).test(a)&&A:false})))};if(Object.keys(i.paths||{}).forEach(a=>{let u=i.paths[a];Object.keys(u).forEach($=>{var lt,pt,ut,ct,mt,dt,ft,yt,gt,ht,$t,bt,Ct,It,xt,wt,Tt,Et,vt,At,Ot,Pt,qt,jt,St,Rt,kt,Ut,Ft,Nt,Gt,Mt,Lt,Qt,Bt,zt,Wt,Dt,Jt,Ht,Kt,_t,Vt,Yt,Zt,Xt,en,tn,nn;let f=$,g=exports.getEndpointDetails(a,f),m=((lt=u[f])==null?void 0:lt.tags)||[];if(le(a,f,m))return;let b=u[f],h=c({method:f,path:a,summary:b==null?void 0:b.summary,operationId:b==null?void 0:b.operationId,tags:m,parameters:b==null?void 0:b.parameters,requestBody:b==null?void 0:b.requestBody,responses:b==null?void 0:b.responses});d[h]||(d[h]={endpoints:"",types:"",validation:""});let A=((ut=(pt=e==null?void 0:e.endpoints)==null?void 0:pt.value)!=null&&ut.includeServer?y:"")+g.pathParts.map(C=>(C[0]==="{"&&C[C.length-1]==="}"?C=`\${${C.replace(/{/,"").replace(/}/,"")}}`:C[0]==="<"&&C[C.length-1]===">"?C=`\${${C.replace(/</,"").replace(/>/,"")}}`:C[0]===":"&&(C=`\${${C.replace(/:/,"")}}`),C)).join("/"),J=`"${A}"`;g.variables.length>0&&(J=`(${g.variables.map(w=>`${w}:string`).join(",")})=> \`${A}\``),J=z(J);let p=u[f],V="",P;if(p!=null&&p.parameters&&((p==null?void 0:p.parameters).forEach((w,S)=>{(w.$ref||w.in==="query"&&w.name)&&(V+=`${x(i,w.$ref?w:w.schema,w.name||"",w.required)}`);}),V)){V=`{
|
|
44
|
+
${V}}`;let w=`${g.name}Query`;if((mt=(ct=e==null?void 0:e.types)==null?void 0:ct.name)!=null&&mt.useOperationId&&(p!=null&&p.operationId)&&(w=`${p.operationId}Query`),w=exports.capitalize(`${v}${w}`),(ft=(dt=e==null?void 0:e.types)==null?void 0:dt.name)!=null&&ft.format){let L=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"query",method:f,path:a,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId},w);L&&(w=`${v}${L}`);}P=w;let S=`export type ${w} = ${V};
|
|
45
|
+
`;e!=null&&e.folderSplit?d[h].types+=S:D+=S;}if(((yt=e==null?void 0:e.validations)==null?void 0:yt.disable)!==true&&((ht=(gt=e==null?void 0:e.validations)==null?void 0:gt.generate)==null?void 0:ht.query)!==false&&(p!=null&&p.parameters)){let C=(($t=e.validations)==null?void 0:$t.library)||"zod",S=p.parameters.filter(L=>!L.$ref&&L.in==="query"&&L.name);if(S.length>0){let L=((bt=e==null?void 0:e.validations)==null?void 0:bt.name)||((Ct=e==null?void 0:e.types)==null?void 0:Ct.name),K=typeof(L==null?void 0:L.prefix)=="string"?L.prefix:"I",F=typeof((xt=(It=e==null?void 0:e.validations)==null?void 0:It.name)==null?void 0:xt.suffix)=="string"?e.validations.name.suffix:"Schema",B=`${g.name}Query`;if(L!=null&&L.useOperationId&&(p!=null&&p.operationId)&&(B=`${p.operationId}Query`),B=exports.capitalize(`${K}${B}${F}`),(Tt=(wt=e==null?void 0:e.validations)==null?void 0:wt.name)!=null&&Tt.format){let ee=e.validations.name.format({code:"",type:"query",method:f,path:a,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId},B);ee&&(B=`${K}${ee}${F}`);}else if((vt=(Et=e==null?void 0:e.types)==null?void 0:Et.name)!=null&&vt.format){let ee=e.types.name.format("endpoint",{code:"",type:"query",method:f,path:a,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId},B);ee&&(B=`${K}${ee}${F}`);}let U=S.map(ee=>{let jn=ee!=null&&ee.schema?j(ee.schema,C):C==="joi"?"Joi.string()":C==="yup"?"yup.string()":"z.string()",Sn=ee.required?"":".optional()";return ` ${ee.name}: ${jn}${Sn}`}).join(`,
|
|
46
|
+
`),de=`export const ${B} = ${C==="joi"?"Joi.object":C==="yup"?"yup.object":"z.object"}({
|
|
47
|
+
${U}
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
`;
|
|
51
|
-
`;
|
|
50
|
+
`;e!=null&&e.folderSplit||d[h]||(d[h]={endpoints:"",types:"",validation:""}),d[h].validation+=de;}}let G=p==null?void 0:p.requestBody,Q="",M;if(G&&(Q=_(G),Q)){let C=`${g.name}DTO`;if((Ot=(At=e==null?void 0:e.types)==null?void 0:At.name)!=null&&Ot.useOperationId&&(p!=null&&p.operationId)&&(C=`${p.operationId}DTO`),C=exports.capitalize(`${v}${C}`),(qt=(Pt=e==null?void 0:e.types)==null?void 0:Pt.name)!=null&&qt.format){let S=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"dto",method:f,path:a,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId},C);S&&(C=`${v}${S}`);}M=C;let w=`export type ${C} = ${Q};
|
|
51
|
+
`;e!=null&&e.folderSplit?d[h].types+=w:D+=w;}if(((jt=e==null?void 0:e.validations)==null?void 0:jt.disable)!==true&&((Rt=(St=e==null?void 0:e.validations)==null?void 0:St.generate)==null?void 0:Rt.dto)!==false&&G){let C=((kt=e.validations)==null?void 0:kt.library)||"zod";if(G.content){let w=Object.keys(G.content);if(w[0]&&G.content[w[0]].schema){let S=((Ut=e==null?void 0:e.validations)==null?void 0:Ut.name)||((Ft=e==null?void 0:e.types)==null?void 0:Ft.name),L=typeof(S==null?void 0:S.prefix)=="string"?S.prefix:"I",K=typeof((Gt=(Nt=e==null?void 0:e.validations)==null?void 0:Nt.name)==null?void 0:Gt.suffix)=="string"?e.validations.name.suffix:"Schema",F=`${g.name}DTO`;if(S!=null&&S.useOperationId&&(p!=null&&p.operationId)&&(F=`${p.operationId}DTO`),F=exports.capitalize(`${L}${F}${K}`),(Lt=(Mt=e==null?void 0:e.validations)==null?void 0:Mt.name)!=null&&Lt.format){let X=e.validations.name.format({code:"",type:"dto",method:f,path:a,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId},F);X&&(F=`${L}${X}${K}`);}else if((Bt=(Qt=e==null?void 0:e.types)==null?void 0:Qt.name)!=null&&Bt.format){let X=e.types.name.format("endpoint",{code:"",type:"dto",method:f,path:a,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId},F);X&&(F=`${L}${X}${K}`);}let B=j(G.content[w[0]].schema,C),U=`export const ${F} = ${B};
|
|
52
52
|
|
|
53
|
-
`;
|
|
54
|
-
`;
|
|
55
|
-
- Scopes: [\`${K.join("`, `")}\`]`,
|
|
56
|
-
- ${
|
|
57
|
-
`),
|
|
58
|
-
--cert client-certificate.crt --key client-private-key.key --cacert ca-certificate.crt`:
|
|
53
|
+
`;e!=null&&e.folderSplit||d[h]||(d[h]={endpoints:"",types:"",validation:""}),d[h].validation+=U;}}}let H={},ce="",me="";if(p!=null&&p.responses){let C=p==null?void 0:p.responses;Object.keys(C).forEach(S=>{var L,K,F,B;if(ce=_(C[S]),H[S]=ce,ce){let U=`${g.name}${S}Response`;if((K=(L=e==null?void 0:e.types)==null?void 0:L.name)!=null&&K.useOperationId&&(p!=null&&p.operationId)&&(U=`${p.operationId}${S}Response`),U=exports.capitalize(`${v}${U}`),(B=(F=e==null?void 0:e.types)==null?void 0:F.name)!=null&&B.format){let ee=e==null?void 0:e.types.name.format("endpoint",{code:S,type:"response",method:f,path:a,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId},U);ee&&(U=`${v}${ee}`);}let X=`export type ${U} = ${ce};
|
|
54
|
+
`;e!=null&&e.folderSplit?d[h].types+=X:D+=X,H[S]=U;let de=parseInt(S);de>=200&&de<300&&(me=U);}});}let Ie=C=>!C||!C.length?"":C.map(w=>Object.entries(w).map(([L,K])=>{let F=L,B="";return Array.isArray(K)&&K.length&&(B=`
|
|
55
|
+
- Scopes: [\`${K.join("`, `")}\`]`,F=`**${F}**`),`
|
|
56
|
+
- ${F}${B}`}).join("")).join(`
|
|
57
|
+
`),Te=p!=null&&p.security?Ie(p.security):"",Ee="";if(!((Wt=(zt=e==null?void 0:e.endpoints)==null?void 0:zt.doc)!=null&&Wt.disable)){let C="";if((Jt=(Dt=e==null?void 0:e.endpoints)==null?void 0:Dt.doc)!=null&&Jt.showCurl){let w={},S="",L="";(Ht=p.requestBody)!=null&&Ht.content&&Object.keys(p.requestBody.content).forEach(B=>{let U=p.requestBody.content[B].schema;if(U){Array.isArray(w["Content-type"])?w["Content-type"].push(B):w["Content-type"]=[B];let X=O(i,U);X&&(S=X);}}),p!=null&&p.security&&p.security.forEach(F=>{Object.keys(F).forEach(B=>{var X,de;let U=(de=(X=i.components)==null?void 0:X.securitySchemes)==null?void 0:de[B];U&&(U.type==="mutualTLS"?L+=`
|
|
58
|
+
--cert client-certificate.crt --key client-private-key.key --cacert ca-certificate.crt`:U.type==="apiKey"?w[(U==null?void 0:U.name)||"X-API-KEY"]="{API_KEY_VALUE}":w.Authorization=`${(U==null?void 0:U.scheme)==="basic"?"Basic":"Bearer"} {${(U==null?void 0:U.scheme)==="basic"?"VALUE":"TOKEN"}}`);});});let K={};Object.keys(w).forEach(F=>{Array.isArray(w[F])?K[F]=w[F].join("; "):K[F]=w[F];}),C=`
|
|
59
59
|
\`\`\`bash
|
|
60
|
-
${curlGenerator.CurlGenerator({url:
|
|
61
|
-
\`\`\``;}
|
|
62
|
-
* ${
|
|
63
|
-
* **Method**: \`${
|
|
64
|
-
* **Summary**: ${(
|
|
65
|
-
* **Tags**: [${((Kt=
|
|
66
|
-
* **OperationId**: ${(
|
|
67
|
-
* **Query**: ${exports.renderTypeRefMD(
|
|
68
|
-
* **DTO**: ${exports.renderTypeRefMD(Q)} `:""}${
|
|
69
|
-
* **Response**: ${Object.entries(
|
|
70
|
-
- **${
|
|
71
|
-
* **Security**: ${
|
|
72
|
-
`:""}${
|
|
60
|
+
${curlGenerator.CurlGenerator({url:y+a,method:f.toUpperCase(),headers:K,body:S})}${L}
|
|
61
|
+
\`\`\``;}Ee=`/**${p!=null&&p.description?`
|
|
62
|
+
* ${p==null?void 0:p.description} `:""}
|
|
63
|
+
* **Method**: \`${f.toUpperCase()}\`
|
|
64
|
+
* **Summary**: ${(p==null?void 0:p.summary)||""}
|
|
65
|
+
* **Tags**: [${((Kt=p==null?void 0:p.tags)==null?void 0:Kt.join(", "))||""}]
|
|
66
|
+
* **OperationId**: ${(p==null?void 0:p.operationId)||""} ${V?`
|
|
67
|
+
* **Query**: ${exports.renderTypeRefMD(V)} `:""}${Q?`
|
|
68
|
+
* **DTO**: ${exports.renderTypeRefMD(Q)} `:""}${ce?`
|
|
69
|
+
* **Response**: ${Object.entries(H).map(([w,S])=>`
|
|
70
|
+
- **${w}**: ${exports.renderTypeRefMD(S,2)} `).join("")}`:""}${Te?`
|
|
71
|
+
* **Security**: ${Te}
|
|
72
|
+
`:""}${C}
|
|
73
73
|
*/
|
|
74
|
-
`;}let
|
|
75
|
-
`;
|
|
76
|
-
|
|
77
|
-
${
|
|
78
|
-
|
|
79
|
-
${
|
|
80
|
-
`),
|
|
81
|
-
|
|
82
|
-
`:""}${
|
|
83
|
-
|
|
84
|
-
${
|
|
85
|
-
`;
|
|
86
|
-
|
|
87
|
-
`,
|
|
88
|
-
`;let i=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
|
-
`,n
|
|
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
|
-
`,n
|
|
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
|
-
`,s.forEach(p=>{var G,W;let E=p.name,j=((G=p.parameters)==null?void 0:G.filter(O=>O.in==="path"))||[],R=((W=p.parameters)==null?void 0:W.filter(O=>O.in==="query"))||[],A=j.length>0,x=R.length>0,v=!!p.requestBody,N=p.responseType||"any";if(n+=` /**
|
|
275
|
-
`,p.summary&&(n+=` * ${p.summary}
|
|
276
|
-
`),n+=` * @method ${p.method.toUpperCase()}
|
|
277
|
-
`,n+=` * @path ${p.path}
|
|
278
|
-
`,p.tags&&p.tags.length>0&&(n+=` * @tags ${p.tags.join(", ")}
|
|
279
|
-
`),n+=` */
|
|
280
|
-
`,n+=` async ${E}(`,(A||x||v)&&(n+=`params: {
|
|
281
|
-
`,A&&(n+=` url: {
|
|
282
|
-
`,j.forEach(O=>{let L={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[O.type||"string"]||"any",P=O.required?"":"?";n+=` ${O.name}${P}: ${L};
|
|
283
|
-
`;}),n+=` };
|
|
284
|
-
`),x&&(n+=` query: ${p.queryType||"Record<string, any>"};
|
|
285
|
-
`),v&&(n+=` data: ${p.dtoType||"any"};
|
|
286
|
-
`),n+=" }"),n+=`): Promise<${N}> {
|
|
287
|
-
`,A||x||v){let O=[];A&&O.push("url"),x&&O.push("query"),v&&O.push("data"),n+=` const { ${O.join(", ")} } = params;
|
|
288
|
-
`;}if(A){let O=j.map(C=>`url.${C.name}`).join(", ");n+=` const _url = ${p.name}(${O});
|
|
289
|
-
`;}else n+=` const _url = ${p.name};
|
|
290
|
-
`;n+=` const config: AxiosRequestConfig = {};
|
|
291
|
-
`,x&&(n+=` config.params = { ...query };
|
|
292
|
-
`),n+=` const response = await this.client.${p.method.toLowerCase()}<${N}>(
|
|
293
|
-
`,n+=` _url,
|
|
294
|
-
`,v?n+=` data,
|
|
74
|
+
`;}let fe=(Vt=(_t=e==null?void 0:e.endpoints)==null?void 0:_t.name)!=null&&Vt.useOperationId&&((Yt=p==null?void 0:p.operationId)==null?void 0:Yt.length)>0?p.operationId:`${g.name}`;if((Xt=(Zt=e==null?void 0:e.endpoints)==null?void 0:Zt.name)!=null&&Xt.format){let C=e==null?void 0:e.endpoints.name.format({method:f,path:a,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId},fe);C&&(fe=C);}let Ge={method:`"${f}"`,operationId:`"${p==null?void 0:p.operationId}"`,url:J,tags:(p==null?void 0:p.tags)||[]},it=`${Ee}export const ${k}${fe} = ${((tn=(en=e==null?void 0:e.endpoints)==null?void 0:en.value)==null?void 0:tn.type)==="object"?exports.JSONStringify(Ge):J};
|
|
75
|
+
`;e!=null&&e.folderSplit?d[h].endpoints+=it:R+=it;let qn={name:`${k}${fe}`,method:f,path:a,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId,tags:m,parameters:(nn=p==null?void 0:p.parameters)==null?void 0:nn.filter(C=>!C.$ref&&C.in&&C.name).map(C=>{var w;return {name:C.name,in:C.in,required:C.required,type:((w=C.schema)==null?void 0:w.type)||"string"}}),requestBody:G?{type:Q,required:G.required}:void 0,responses:H?Object.entries(H).reduce((C,[w,S])=>(C[w]={type:S},C),{}):void 0,queryType:P,dtoType:M,responseType:me||void 0};I.push(qn);});}),e!=null&&e.folderSplit){for(let[a,u]of Object.entries(d))if(u.endpoints||u.types){let E=W__default.default.join(r,a);if(u.endpoints){let $=W__default.default.join(ye,E,"endpoints.ts");yield ie__default.default.promises.mkdir(W__default.default.dirname($),{recursive:true}),yield ge($,u.endpoints,e);}if(u.types){let $=W__default.default.join(ye,E,"types.ts");yield ie__default.default.promises.mkdir(W__default.default.dirname($),{recursive:true});let f=Object.values(T).length>0?`import * as Shared from "../shared";
|
|
76
|
+
|
|
77
|
+
${u.types}`:u.types;yield ge($,f,e);}if(((rt=e==null?void 0:e.validations)==null?void 0:rt.disable)!==true&&u.validation){let $=((ot=e.validations)==null?void 0:ot.library)||"zod",f=$==="joi"?'import Joi from "joi";':$==="yup"?'import * as yup from "yup";':'import { z } from "zod";',g=W__default.default.join(ye,E,"validations.ts");yield ie__default.default.promises.mkdir(W__default.default.dirname(g),{recursive:true}),yield ge(g,`${f}
|
|
78
|
+
|
|
79
|
+
${u.validation}`,e);}}}if(R.length>0){let a=W__default.default.join(ye,r,"endpoints.ts");yield ie__default.default.promises.mkdir(W__default.default.dirname(a),{recursive:true}),yield ge(a,R,e);}if(Object.values(T).length>0){let a=W__default.default.join(ye,r,e!=null&&e.folderSplit?"":"types","shared.ts");yield ie__default.default.promises.mkdir(W__default.default.dirname(a),{recursive:true}),yield ge(a,Object.values(T).join(`
|
|
80
|
+
`),e);}if(D.length>0){let a=W__default.default.join(ye,r,"types","index.ts");yield ie__default.default.promises.mkdir(W__default.default.dirname(a),{recursive:true}),yield ge(a,`${Object.values(T).length>0?`import * as Shared from "./shared";
|
|
81
|
+
|
|
82
|
+
`:""}${D}`,e);}if(((st=e==null?void 0:e.validations)==null?void 0:st.disable)!==true&&!(e!=null&&e.folderSplit)){let a=((at=e.validations)==null?void 0:at.library)||"zod",u=a==="joi"?'import Joi from "joi";':a==="yup"?'import * as yup from "yup";':'import { z } from "zod";',E=Object.values(d).map($=>$.validation).filter($=>$.length>0).join("");if(E){let $=W__default.default.join(ye,r,"validations.ts");yield ie__default.default.promises.mkdir(W__default.default.dirname($),{recursive:true}),yield ge($,`${u}
|
|
83
|
+
|
|
84
|
+
${E}`,e);}}return fn(l,I),console.info(`\u2705 Successfully synced ${l}`),{success:true}}),Ze=hn;});var bn,Xe,he,et,tt,nt,Cn=se(()=>{bn=(n,o)=>{let l=n;return o.tags&&o.tags.length>0&&(l=l.filter(e=>!e.tags||e.tags.length===0?false:e.tags.some(s=>o.tags.includes(s)))),o.endpoints&&o.endpoints.length>0&&(l=l.filter(e=>o.endpoints.includes(e.name))),l},Xe=(n,o,l=false)=>{var r,d;let e=o.baseURL||"";o.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 i=new Set;return n.forEach(c=>{c.queryType&&i.add(c.queryType),c.dtoType&&i.add(c.dtoType),c.responseType&&i.add(c.responseType);}),i.forEach(c=>{t+=` ${c},
|
|
89
|
+
`;}),t+=`} from '../types';
|
|
90
|
+
|
|
91
|
+
`,t+=`import {
|
|
92
|
+
`,n.forEach(c=>{t+=` ${c.name} as ${c.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=o.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
|
+
`,(d=o.errorHandling)!=null&&d.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
|
+
`,n.forEach(c=>{var D,T;let y=c.name,v=((D=c.parameters)==null?void 0:D.filter(I=>I.in==="path"))||[],k=((T=c.parameters)==null?void 0:T.filter(I=>I.in==="query"))||[],q=v.length>0,x=k.length>0,O=!!c.requestBody,N=c.responseType||"any";if(t+=`/**
|
|
146
|
+
`,c.summary&&(t+=` * ${c.summary}
|
|
147
|
+
`),t+=` * @method ${c.method.toUpperCase()}
|
|
148
|
+
`,t+=` * @path ${c.path}
|
|
149
|
+
`,c.tags&&c.tags.length>0&&(t+=` * @tags ${c.tags.join(", ")}
|
|
150
|
+
`),t+=` */
|
|
151
|
+
`,t+=`export async function ${y}(`,(q||x||O)&&(t+=`params: {
|
|
152
|
+
`,q&&(t+=` url: {
|
|
153
|
+
`,v.forEach(I=>{let j={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[I.type||"string"]||"any",z=I.required?"":"?";t+=` ${I.name}${z}: ${j};
|
|
154
|
+
`;}),t+=` };
|
|
155
|
+
`),x&&(t+=` query: ${c.queryType||"Record<string, any>"};
|
|
156
|
+
`),O&&(t+=` data: ${c.dtoType||"any"};
|
|
157
|
+
`),t+=`}
|
|
158
|
+
`),t+=`): Promise<${N}> {
|
|
159
|
+
`,q||x||O){let I=[];q&&I.push("url"),x&&I.push("query"),O&&I.push("data"),t+=` const { ${I.join(", ")} } = params;
|
|
160
|
+
`;}let R;if(q){let I=v.map(_=>`url.${_.name}`).join(", ");R=`${c.name}_endpoint(${I})`;}else R=`${c.name}_endpoint`;x?(t+=` const queryParams = new URLSearchParams();
|
|
161
|
+
`,k.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<${N}>(_url, {
|
|
168
|
+
`,t+=` method: '${c.method.toUpperCase()}',
|
|
169
|
+
`,O&&(t+=` body: JSON.stringify(data),
|
|
170
|
+
`),t+=` });
|
|
171
|
+
`,t+=`}
|
|
172
|
+
|
|
173
|
+
`;}),l&&(t+=`// Export all functions as a default object
|
|
174
|
+
`,t+=`const apiClient = {
|
|
175
|
+
`,t+=` setApiConfig,
|
|
176
|
+
`,n.forEach(c=>{t+=` ${c.name},
|
|
177
|
+
`;}),t+=`};
|
|
178
|
+
|
|
179
|
+
`,t+=`export default apiClient;
|
|
180
|
+
`),t},he=(n,o,l=false)=>{var r,d;let e=o.baseURL||"";o.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 i=new Set;return n.forEach(c=>{c.queryType&&i.add(c.queryType),c.dtoType&&i.add(c.dtoType),c.responseType&&i.add(c.responseType);}),i.forEach(c=>{t+=` ${c},
|
|
187
|
+
`;}),t+=`} from '../types';
|
|
188
|
+
|
|
189
|
+
`,t+=`import {
|
|
190
|
+
`,n.forEach(c=>{t+=` ${c.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=o.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
|
+
`,(d=o.errorHandling)!=null&&d.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
|
+
`,n.forEach(c=>{var R,D;let y=c.name,v=((R=c.parameters)==null?void 0:R.filter(T=>T.in==="path"))||[],k=((D=c.parameters)==null?void 0:D.filter(T=>T.in==="query"))||[],q=v.length>0,x=k.length>0,O=!!c.requestBody,N=c.responseType||"any";if(t+=` /**
|
|
240
|
+
`,c.summary&&(t+=` * ${c.summary}
|
|
241
|
+
`),t+=` * @method ${c.method.toUpperCase()}
|
|
242
|
+
`,t+=` * @path ${c.path}
|
|
243
|
+
`,c.tags&&c.tags.length>0&&(t+=` * @tags ${c.tags.join(", ")}
|
|
244
|
+
`),t+=` */
|
|
245
|
+
`,t+=` async ${y}(`,(q||x||O)&&(t+=`params: {
|
|
246
|
+
`,q&&(t+=` url: {
|
|
247
|
+
`,v.forEach(T=>{let _={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[T.type||"string"]||"any",j=T.required?"":"?";t+=` ${T.name}${j}: ${_};
|
|
248
|
+
`;}),t+=` };
|
|
249
|
+
`),x&&(t+=` query: ${c.queryType||"Record<string, any>"};
|
|
250
|
+
`),O&&(t+=` data: ${c.dtoType||"any"};
|
|
251
|
+
`),t+=" }"),t+=`): Promise<${N}> {
|
|
252
|
+
`,q||x||O){let T=[];q&&T.push("url"),x&&T.push("query"),O&&T.push("data"),t+=` const { ${T.join(", ")} } = params;
|
|
253
|
+
`;}if(q){let T=v.map(I=>`url.${I.name}`).join(", ");t+=` const _url = ${c.name}(${T});
|
|
254
|
+
`;}else t+=` const _url = ${c.name};
|
|
255
|
+
`;t+=` const config: AxiosRequestConfig = {};
|
|
256
|
+
`,x&&(t+=` config.params = { ...query };
|
|
257
|
+
`),t+=` const response = await this.client.${c.method.toLowerCase()}<${N}>(
|
|
258
|
+
`,t+=` _url,
|
|
259
|
+
`,O?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
|
+
`,l?t+=`export default ApiClient;
|
|
269
|
+
`:(t+=`export const apiClient = new ApiClient();
|
|
270
|
+
`,t+=`export default apiClient;
|
|
271
|
+
`),t},et=(n,o)=>{var d,c;let l=((d=o.reactQuery)==null?void 0:d.version)||5,e=((c=o.reactQuery)==null?void 0:c.mutations)!==false,s=!!(o.reactQuery&&o.reactQuery.infiniteQueries&&!o.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 i=e&&n.some(y=>["POST","PUT","PATCH","DELETE"].includes(y.method.toUpperCase()));if(l===5){let y=i?`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=i?`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 n.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
|
+
`,n.forEach(y=>{var I,_;let v=y.method.toUpperCase(),k=v==="GET",q=["POST","PUT","PATCH","DELETE"].includes(v),x=((I=y.parameters)==null?void 0:I.filter(j=>j.in==="path"))||[],O=((_=y.parameters)==null?void 0:_.filter(j=>j.in==="query"))||[],N=x.length>0,R=O.length>0,D=!!y.requestBody,T=y.responseType||"any";if(k){let j=O.map(ne=>ne.name.toLowerCase()),le=(j.includes("page")||j.includes("cursor")||j.includes("cursorid")||j.includes("after")||j.includes("before"))&&s,pe=`use${y.name.charAt(0).toUpperCase()+y.name.slice(1)}`;if(t+=`/**
|
|
289
|
+
`,y.summary&&(t+=` * ${y.summary}
|
|
290
|
+
`),t+=` * @method ${v}
|
|
291
|
+
`,t+=` * @path ${y.path}
|
|
292
|
+
`,y.tags&&y.tags.length>0&&(t+=` * @tags ${y.tags.join(", ")}
|
|
293
|
+
`),t+=` */
|
|
294
|
+
`,N||R?(t+=`export function ${pe}(
|
|
295
|
+
`,t+=` params: {
|
|
296
|
+
`,N&&(t+=` url: {
|
|
297
|
+
`,x.forEach(ne=>{let we={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[ne.type||"string"]||"any",Ce=ne.required?"":"?";t+=` ${ne.name}${Ce}: ${we};
|
|
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 ${pe}(
|
|
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
|
+
`),le){let ne=`${pe}Infinite`;N||R?(t+=`export function ${ne}(
|
|
321
|
+
`,t+=` params: {
|
|
322
|
+
`,N&&(t+=` url: {
|
|
323
|
+
`,x.forEach(ue=>{let Ce={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[ue.type||"string"]||"any",Re=ue.required?"":"?";t+=` ${ue.name}${Re}: ${Ce};
|
|
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 ${ne}(
|
|
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(q&&e){let j=`use${y.name.charAt(0).toUpperCase()+y.name.slice(1)}`;t+=`/**
|
|
349
|
+
`,y.summary&&(t+=` * ${y.summary}
|
|
350
|
+
`),t+=` * @method ${v}
|
|
351
|
+
`,t+=` * @path ${y.path}
|
|
352
|
+
`,y.tags&&y.tags.length>0&&(t+=` * @tags ${y.tags.join(", ")}
|
|
353
|
+
`),t+=` */
|
|
354
|
+
`;let z="void";(N||R||D)&&(z=`{
|
|
355
|
+
`,N&&(z+=` url: {
|
|
356
|
+
`,x.forEach(le=>{let ne={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[le.type||"string"]||"any",ue=le.required?"":"?";z+=` ${le.name}${ue}: ${ne};
|
|
357
|
+
`;}),z+=` };
|
|
358
|
+
`),R&&(z+=` query: ${y.queryType||"Record<string, any>"};
|
|
359
|
+
`),D&&(z+=` data: ${y.dtoType||"any"};
|
|
360
|
+
`),z+=" }"),t+=`export function ${j}(
|
|
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},tt=(n,o)=>{var i;let l=((i=o.swr)==null?void 0:i.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);}}cn(o,C);}),Ke=gn;});var $n,He,ce,_e,Ve,Ye,bn=se(()=>{$n=(s,o)=>{let t
|
|
|
564
563
|
`,e+=` */
|
|
565
564
|
|
|
566
565
|
`,e+=`import useSWR, { SWRConfiguration } from 'swr';
|
|
567
|
-
`,
|
|
566
|
+
`,l&&n.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 n.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
|
+
`,n.forEach(r=>{var R,D;let d=r.method.toUpperCase(),c=d==="GET",y=["POST","PUT","PATCH","DELETE"].includes(d),v=((R=r.parameters)==null?void 0:R.filter(T=>T.in==="path"))||[],k=((D=r.parameters)==null?void 0:D.filter(T=>T.in==="query"))||[],q=v.length>0,x=k.length>0,O=!!r.requestBody,N=r.responseType||"any";if(c){let T=`use${r.name.charAt(0).toUpperCase()+r.name.slice(1)}`;e+=`/**
|
|
574
|
+
`,r.summary&&(e+=` * ${r.summary}
|
|
575
|
+
`),e+=` * @method ${d}
|
|
576
|
+
`,e+=` * @path ${r.path}
|
|
577
|
+
`,r.tags&&r.tags.length>0&&(e+=` * @tags ${r.tags.join(", ")}
|
|
579
578
|
`),e+=` */
|
|
580
|
-
`,
|
|
579
|
+
`,q||x?(e+=`export function ${T}(
|
|
581
580
|
`,e+=` params: {
|
|
582
|
-
`,
|
|
583
|
-
`,
|
|
581
|
+
`,q&&(e+=` url: {
|
|
582
|
+
`,v.forEach(I=>{let j={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[I.type||"string"]||"any",z=I.required?"":"?";e+=` ${I.name}${z}: ${j};
|
|
584
583
|
`;}),e+=` };
|
|
585
|
-
`),x&&(e+=` query: ${
|
|
584
|
+
`),x&&(e+=` query: ${r.queryType||"Record<string, any>"};
|
|
586
585
|
`),e+=` },
|
|
587
586
|
`,e+=` config?: SWRConfiguration<${N}>
|
|
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 ${
|
|
593
|
+
`):(e+=`export function ${T}(
|
|
595
594
|
`,e+=` config?: SWRConfiguration<${N}>
|
|
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&&l){let T=`use${r.name.charAt(0).toUpperCase()+r.name.slice(1)}`;e+=`/**
|
|
604
|
+
`,r.summary&&(e+=` * ${r.summary}
|
|
605
|
+
`),e+=` * @method ${d}
|
|
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<${N}, Error, string, ${
|
|
609
|
+
`;let I="void",_="void";(q||x||O)&&(I=`{
|
|
610
|
+
`,q&&(I+=` url: {
|
|
611
|
+
`,v.forEach(j=>{let le={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[j.type||"string"]||"any",pe=j.required?"":"?";I+=` ${j.name}${pe}: ${le};
|
|
612
|
+
`;}),I+=` };
|
|
613
|
+
`),x&&(I+=` query: ${r.queryType||"Record<string, any>"};
|
|
614
|
+
`),O&&(I+=` data: ${r.dtoType||"any"};
|
|
615
|
+
`),I+=" }",_=`{ arg: ${I} }`),e+=`export function ${T}(
|
|
616
|
+
`,e+=` config?: SWRMutationConfiguration<${N}, 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
|
-
`,o.auth&&(
|
|
646
|
-
`,
|
|
647
|
-
`,
|
|
648
|
-
`,
|
|
649
|
-
`,o.auth.type==="bearer"?
|
|
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},nt=(n,o)=>{var i;let l=((i=o.rtkQuery)==null?void 0:i.apiName)||"api",e=o.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 n.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
|
+
`,n.forEach(r=>{s+=` ${r.name},
|
|
638
|
+
`;}),s+=`} from '../endpoints';
|
|
639
|
+
|
|
640
|
+
`,s+=`const ${l}Api = createApi({
|
|
641
|
+
`,s+=` reducerPath: '${l}Api',
|
|
642
|
+
`,s+=` baseQuery: fetchBaseQuery({
|
|
643
|
+
`,s+=` baseUrl: '${e}',
|
|
644
|
+
`,o.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
|
+
`,o.auth.type==="bearer"?s+=" // headers.set('Authorization', `Bearer ${token}`);\n":o.auth.type==="apiKey"&&o.auth.in==="header"&&(s+=` // headers.set('${o.auth.name||"X-API-Key"}', token);
|
|
649
|
+
`),s+=` // }
|
|
650
|
+
`,s+=` return headers;
|
|
651
|
+
`,s+=` },
|
|
652
|
+
`),s+=` }),
|
|
653
|
+
`,s+=` tagTypes: [${[...new Set(n.flatMap(r=>r.tags||[]))].map(r=>`'${r}'`).join(", ")}],
|
|
654
|
+
`,s+=` endpoints: (builder) => ({
|
|
655
|
+
`,n.forEach((r,d)=>{var D,T;let c=r.method.toUpperCase(),y=c==="GET",v=((D=r.parameters)==null?void 0:D.filter(I=>I.in==="path"))||[],k=((T=r.parameters)==null?void 0:T.filter(I=>I.in==="query"))||[],q=v.length>0,x=k.length>0,O=!!r.requestBody,N=r.responseType||"any";s+=` ${r.name}: builder.${y?"query":"mutation"}<
|
|
656
|
+
`,s+=` ${N},
|
|
657
|
+
`;let R="void";if((q||x||O)&&(R=`{
|
|
658
|
+
`,q&&(R+=` url: {
|
|
659
|
+
`,v.forEach(I=>{let j={string:"string",number:"number",integer:"number",boolean:"boolean",array:"any[]",object:"any"}[I.type||"string"]||"any",z=I.required?"":"?";R+=` ${I.name}${z}: ${j};
|
|
660
|
+
`;}),R+=` };
|
|
661
|
+
`),x&&(R+=` query: ${r.queryType||"Record<string, any>"};
|
|
662
|
+
`),O&&(R+=` data: ${r.dtoType||"any"};
|
|
663
|
+
`),R+=" }"),s+=` ${R}
|
|
664
|
+
`,s+=` >({
|
|
665
|
+
`,s+=" query: (",R!=="void"&&(s+="arg"),s+=`) => {
|
|
666
|
+
`,q){let I=v.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: '${c}',
|
|
671
|
+
`,x&&(s+=` params: arg.query,
|
|
672
|
+
`),O&&(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+=` })${d<n.length-1?",":""}
|
|
678
|
+
`;}),s+=` }),
|
|
679
|
+
`,s+=`});
|
|
680
|
+
|
|
681
|
+
`,s+=`export default ${l}Api;
|
|
682
|
+
|
|
683
|
+
`,s};});var Jn,In,Y,Hn,Kn,xn=se(()=>{Cn();ke();Jn=(n,o)=>{var l,e;if((l=o==null?void 0:o.folderSplit)!=null&&l.customFolder){let s=o.folderSplit.customFolder({method:n.method,path:n.path,tags:n.tags,operationId:n.operationId,summary:n.summary});if(s)return s}return (e=o==null?void 0:o.folderSplit)!=null&&e.byTags&&n.tags&&n.tags.length>0?n.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},In=(n,o,l,e,s)=>te(null,null,function*(){let t=bn(n,l);if(t.length===0)return;let i=l.type||"fetch";l.outputDir||W__default.default.join(s,e,"client");let d=!!(o!=null&&o.folderSplit&&(o.folderSplit.byTags||o.folderSplit.customFolder));if(`${i}${t.length}`,d){let y={};t.forEach(q=>{let x=Jn(q,o);y[x]||(y[x]=[]),y[x].push(q);});let v=Object.keys(y);for(let[q,x]of Object.entries(y)){let O=W__default.default.join(s,e,q);yield ie__default.default.promises.mkdir(O,{recursive:true}),`${i}${q}${x.length}`,yield Hn(x,o,l,O,i,q,true);}let k=W__default.default.join(s,e);yield Kn(k,v,i,o);return}let c=W__default.default.join(s,e);switch(yield ie__default.default.promises.mkdir(c,{recursive:true}),i){case "fetch":let y=Xe(t,l);y=y.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield Y(W__default.default.join(c,"clients.ts"),y,o);break;case "axios":let v=he(t,l,false);v=v.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield Y(W__default.default.join(c,"clients.ts"),v,o);break;case "react-query":let k=he(t,l,false);k=k.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield Y(W__default.default.join(c,"clients.ts"),k,o);let q=et(t,l);q=q.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';").replace("import apiClient from './client';","import apiClient from './clients';"),yield Y(W__default.default.join(c,"hooks.ts"),q,o);break;case "swr":let x=he(t,l,false);x=x.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield Y(W__default.default.join(c,"clients.ts"),x,o);let O=tt(t,l);O=O.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';").replace("import apiClient from './client';","import apiClient from './clients';"),yield Y(W__default.default.join(c,"hooks.ts"),O,o);break;case "rtk-query":let N=nt(t,l);N=N.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield Y(W__default.default.join(c,"api.ts"),N,o);break;default:throw new Error(`Unknown client type: ${i}`)}}),Y=(n,o,l)=>te(null,null,function*(){var i,r,d,c;if(!(((i=l==null?void 0:l.customCode)==null?void 0:i.enabled)!==false)){yield ie__default.default.promises.writeFile(n,o);return}let s=null;try{s=yield ie__default.default.promises.readFile(n,"utf-8");}catch(y){}let t=exports.mergeCustomCode(o,s,{position:((r=l==null?void 0:l.customCode)==null?void 0:r.position)||"bottom",markerText:(d=l==null?void 0:l.customCode)==null?void 0:d.markerText,includeInstructions:(c=l==null?void 0:l.customCode)==null?void 0:c.includeInstructions});yield ie__default.default.promises.writeFile(n,t);}),Hn=(n,o,l,e,s,t,i=false)=>te(null,null,function*(){let r="",d="",c=i?"./types":"../types",y=i?"./endpoints":"../endpoints";switch(s){case "fetch":r=Xe(n,l,i),r=r.replace("} from '../types';",`} from '${c}';`).replace("} from '../endpoints';",`} from '${y}';`),yield Y(W__default.default.join(e,"client.ts"),r,o);break;case "axios":r=he(n,l,i),r=r.replace("} from '../types';",`} from '${c}';`).replace("} from '../endpoints';",`} from '${y}';`),yield Y(W__default.default.join(e,"client.ts"),r,o);break;case "react-query":if(r=he(n,l,i),r=r.replace("} from '../types';",`} from '${c}';`).replace("} from '../endpoints';",`} from '${y}';`),yield Y(W__default.default.join(e,"client.ts"),r,o),d=et(n,l),d=d.replace("} from '../types';",`} from '${c}';`).replace("} from '../endpoints';",`} from '${y}';`),i){let k=t.replace(/-/g,"_");d=d.replace("import apiClient from './client';",`import { ${k}Client as apiClient } from '../clients';`);}yield Y(W__default.default.join(e,"hooks.ts"),d,o);break;case "swr":if(r=he(n,l,i),r=r.replace("} from '../types';",`} from '${c}';`).replace("} from '../endpoints';",`} from '${y}';`),yield Y(W__default.default.join(e,"client.ts"),r,o),d=tt(n,l),d=d.replace("} from '../types';",`} from '${c}';`).replace("} from '../endpoints';",`} from '${y}';`),i){let k=t.replace(/-/g,"_");d=d.replace("import apiClient from './client';",`import { ${k}Client as apiClient } from '../clients';`);}yield Y(W__default.default.join(e,"hooks.ts"),d,o);break;case "rtk-query":let v=i?ve(oe({},l),{rtkQuery:ve(oe({},l.rtkQuery),{apiName:t.replace(/-/g,"_")})}):l;d=nt(n,v),d=d.replace("} from '../types';",`} from '${c}';`).replace("} from '../endpoints';",`} from '${y}';`),yield Y(W__default.default.join(e,"api.ts"),d,o);break;default:throw new Error(`Unknown client type: ${s}`)}}),Kn=(n,o,l,e)=>te(null,null,function*(){var t;if(l==="rtk-query"){let i=`// Generated RTK Query APIs
|
|
685
684
|
`;i+=`// This file was auto-generated.
|
|
686
685
|
`,i+=`// Aggregates all API slices for easy Redux store setup
|
|
687
686
|
|
|
688
|
-
`,o.forEach(
|
|
687
|
+
`,o.forEach(r=>{let d=r.replace(/-/g,"_");i+=`import ${d}Api from './${r}/api';
|
|
689
688
|
`;}),i+=`
|
|
690
689
|
// Export all API slices
|
|
691
|
-
`,o.forEach(
|
|
690
|
+
`,o.forEach(r=>{let d=r.replace(/-/g,"_");i+=`export { default as ${d}Api } from './${r}/api';
|
|
692
691
|
`;}),i+=`
|
|
693
692
|
/**
|
|
694
693
|
`,i+=` * Configure Redux store with all API slices
|
|
@@ -705,85 +704,85 @@ ${T}`,t);}}cn(o,C);}),Ke=gn;});var $n,He,ce,_e,Ve,Ye,bn=se(()=>{$n=(s,o)=>{let t
|
|
|
705
704
|
`,i+=` */
|
|
706
705
|
`,i+=`export const setupApiStore = {
|
|
707
706
|
`,i+=` reducer: {
|
|
708
|
-
`,o.forEach(
|
|
707
|
+
`,o.forEach(r=>{let d=r.replace(/-/g,"_");i+=` [${d}Api.reducerPath]: ${d}Api.reducer,
|
|
709
708
|
`;}),i+=` },
|
|
710
709
|
`,i+=` middleware: [
|
|
711
|
-
`,o.forEach(
|
|
710
|
+
`,o.forEach(r=>{let d=r.replace(/-/g,"_");i+=` ${d}Api.middleware,
|
|
712
711
|
`;}),i+=` ],
|
|
713
712
|
`,i+=`};
|
|
714
|
-
`,yield
|
|
715
|
-
`;if(
|
|
716
|
-
`,
|
|
713
|
+
`,yield Y(W__default.default.join(n,"apis.ts"),i,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
|
-
`;}):(o.forEach(i=>{let
|
|
720
|
-
`;}),
|
|
717
|
+
`,l==="fetch"?o.forEach(i=>{let r=i.replace(/-/g,"_");s+=`export { default as ${r}Client } from './${i}/client';
|
|
718
|
+
`;}):(o.forEach(i=>{let r=i.replace(/-/g,"_"),d=`${r.charAt(0).toUpperCase()+r.slice(1)}ApiClient`;s+=`import ${d} from './${i}/client';
|
|
719
|
+
`;}),s+=`
|
|
721
720
|
// Create client instances
|
|
722
|
-
`,o.forEach(i=>{let
|
|
723
|
-
`;})),
|
|
721
|
+
`,o.forEach(i=>{let r=i.replace(/-/g,"_"),d=`${r.charAt(0).toUpperCase()+r.slice(1)}ApiClient`;s+=`export const ${r}Client = new ${d}();
|
|
722
|
+
`;})),l==="fetch"&&(s+=`
|
|
724
723
|
// Import clients for aggregation
|
|
725
|
-
`,o.forEach(i=>{let
|
|
726
|
-
`;})),
|
|
724
|
+
`,o.forEach(i=>{let r=i.replace(/-/g,"_");s+=`import ${r}_client from './${i}/client';
|
|
725
|
+
`;})),s+=`
|
|
727
726
|
// Aggregate all client instances
|
|
728
|
-
`,
|
|
729
|
-
`,o.forEach(i=>{let
|
|
730
|
-
`:
|
|
731
|
-
`;}),
|
|
727
|
+
`,s+=`export const clients = {
|
|
728
|
+
`,o.forEach(i=>{let r=i.replace(/-/g,"_");l==="fetch"?s+=` ${r}: ${r}_client,
|
|
729
|
+
`:s+=` ${r}: ${r}Client,
|
|
730
|
+
`;}),s+=`};
|
|
732
731
|
|
|
733
|
-
`,
|
|
732
|
+
`,l==="axios"?(s+=`
|
|
734
733
|
/**
|
|
735
|
-
`,
|
|
736
|
-
`,
|
|
737
|
-
`,
|
|
738
|
-
`,
|
|
739
|
-
`,
|
|
740
|
-
`,
|
|
741
|
-
`,
|
|
742
|
-
`,
|
|
743
|
-
`,o.forEach(i=>{let
|
|
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
|
+
`,o.forEach(i=>{let r=i.replace(/-/g,"_");s+=` ${r}Client.updateConfig(config);
|
|
743
|
+
`;}),s+=`};
|
|
744
|
+
|
|
745
|
+
`):l==="fetch"&&(s+=`
|
|
747
746
|
/**
|
|
748
|
-
`,
|
|
749
|
-
`,
|
|
750
|
-
`,
|
|
751
|
-
`,
|
|
752
|
-
`,
|
|
753
|
-
`,
|
|
754
|
-
`,
|
|
755
|
-
`,
|
|
756
|
-
`,o.forEach(i=>{let
|
|
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
|
+
`,o.forEach(i=>{let r=i.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=o[0])==null?void 0:t.replace(/-/g,"_")}.someMethod(...);
|
|
769
|
+
`,yield Y(W__default.default.join(n,"clients.ts"),s,e),l==="react-query"||l==="swr"){let i=`// Generated Hooks Aggregator
|
|
771
770
|
`;i+=`// This file was auto-generated.
|
|
772
771
|
`,i+=`// Aggregates all folder-split hooks
|
|
773
772
|
|
|
774
|
-
`,o.forEach(
|
|
773
|
+
`,o.forEach(r=>{i+=`export * from './${r}/hooks';
|
|
775
774
|
`;}),i+=`
|
|
776
775
|
// Example usage:
|
|
777
776
|
`,i+=`// import { useGetSomething } from './hooks';
|
|
778
|
-
`,yield
|
|
777
|
+
`,yield Y(W__default.default.join(n,"hooks.ts"),i,e);}});});var wn=se(()=>{});var En={};an(En,{interactiveInit:()=>_n});function _n(){return te(this,null,function*(){try{let n=yield Tn__default.default([{type:"select",name:"configFormat",message:"What configuration format would you like to use?",choices:[{title:"TypeScript (openapi.sync.ts)",value:"typescript"},{title:"JSON (openapi.sync.json)",value:"json"},{title:"JavaScript (openapi.sync.js)",value:"javascript"}],initial:0},{type:"select",name:"apiSource",message:"Where is your OpenAPI specification?",choices:[{title:"URL (e.g., https://api.example.com/openapi.json)",value:"url"},{title:"Local file",value:"file"}],initial:0},{type:r=>r==="url"?"text":null,name:"apiUrl",message:"Enter the OpenAPI specification URL:",validate:r=>r.startsWith("http://")||r.startsWith("https://")?!0:"Please enter a valid URL starting with http:// or https://"},{type:(r,d)=>d.apiSource==="file"?"text":null,name:"apiFile",message:"Enter the path to your OpenAPI file:",validate:r=>r.trim()!==""?!0:"Please enter a valid file path"},{type:"text",name:"apiName",message:"What would you like to name this API?",initial:"myapi",validate:r=>/^[a-zA-Z0-9_-]+$/.test(r)?!0:"API name must contain only letters, numbers, hyphens, and underscores"},{type:"text",name:"outputFolder",message:"Where should generated files be saved?",initial:"./src/api",validate:r=>{if(!r||r.trim()==="")return "Output folder cannot be empty";let d=W__default.default.normalize(r);if(d==="/"||d==="C:\\"||d==="\\")return "Cannot use filesystem root directory. Please use a project subfolder like './src/api'";if(W__default.default.isAbsolute(r)){let c=process.cwd();if(!r.startsWith(c))return "\u26A0\uFE0F Warning: Using absolute path outside project directory. Recommended: use relative path like './src/api'"}return !0}},{type:"confirm",name:"enableFolderSplit",message:"Organize generated code into folders by OpenAPI tags?",initial:!1},{type:"confirm",name:"generateClient",message:"Generate API client code?",initial:!0},{type:r=>r?"select":null,name:"clientType",message:"Which client type would you like?",choices:[{title:"React Query (Recommended for React)",value:"react-query"},{title:"RTK Query (Redux Toolkit)",value:"rtk-query"},{title:"SWR",value:"swr"},{title:"Fetch API",value:"fetch"},{title:"Axios",value:"axios"}],initial:0},{type:"confirm",name:"enableValidation",message:"Enable runtime validation schemas?",initial:!0},{type:r=>r?"select":null,name:"validationLibrary",message:"Which validation library?",choices:[{title:"Zod (Recommended)",value:"zod"},{title:"Yup",value:"yup"},{title:"Joi",value:"joi"}],initial:0},{type:"confirm",name:"enableCustomCode",message:"Enable custom code preservation?",initial:!0},{type:"confirm",name:"typesUseOperationId",message:"Use operationId from OpenAPI spec for type names?",initial:!0},{type:"text",name:"typesPrefix",message:"Prefix for TypeScript interface names (leave empty for none):",initial:"I"},{type:"confirm",name:"excludeEndpointsByTags",message:"Exclude endpoints by tags (e.g., deprecated, internal)?",initial:!1},{type:r=>r?"text":null,name:"excludeTags",message:"Enter tags to exclude (comma-separated):",initial:"deprecated,internal"},{type:"confirm",name:"showCurlInDocs",message:"Include cURL examples in generated documentation?",initial:!0},{type:"number",name:"refetchInterval",message:"Refetch interval in milliseconds (0 to disable auto-refresh):",initial:5e3,min:0},{type:"confirm",name:"runSync",message:"Run initial sync after setup?",initial:!0}],{onCancel:()=>{throw re||process.exit(0),new Error("Setup cancelled")}}),o={refetchInterval:n.refetchInterval||void 0,folder:n.outputFolder,api:{[n.apiName]:n.apiUrl||n.apiFile}};n.enableFolderSplit&&(o.folderSplit={byTags:!0}),o.types={name:{prefix:n.typesPrefix||"",useOperationId:n.typesUseOperationId}},o.endpoints={name:{useOperationId:n.typesUseOperationId},doc:{showCurl:n.showCurlInDocs}},n.excludeEndpointsByTags&&n.excludeTags&&(o.endpoints.exclude={tags:n.excludeTags.split(",").map(r=>r.trim())}),n.generateClient&&n.clientType&&(o.clientGeneration={enabled:!0,type:n.clientType,outputDir:W__default.default.join(n.outputFolder,n.apiName,"client")},n.clientType==="react-query"?o.clientGeneration.reactQuery={version:5,mutations:!0}:n.clientType==="swr"&&(o.clientGeneration.swr={mutations:!0})),n.enableValidation&&n.validationLibrary&&(o.validations={library:n.validationLibrary}),n.enableCustomCode&&(o.customCode={enabled:!0,position:"bottom"});let l,e;n.configFormat==="json"?(e="openapi.sync.json",l=JSON.stringify(o,null,2)):n.configFormat==="typescript"?(e="openapi.sync.ts",l=`import { IConfig } from "openapi-sync";
|
|
779
778
|
|
|
780
779
|
const config: IConfig = ${JSON.stringify(o,null,2)};
|
|
781
780
|
|
|
782
781
|
export default config;
|
|
783
|
-
`):(e="openapi.sync.js",
|
|
784
|
-
`);let
|
|
782
|
+
`):(e="openapi.sync.js",l=`module.exports = ${JSON.stringify(o,null,2)};
|
|
783
|
+
`);let s=W__default.default.join(process.cwd(),e);if(ie__default.default.existsSync(s)&&!(yield Tn__default.default({type:"confirm",name:"value",message:`${e} already exists. Overwrite?`,initial:!1})).value)throw re||process.exit(0),new Error("Configuration file not created");ie__default.default.writeFileSync(s,l,"utf-8"),re||`${e}`;let t=W__default.default.isAbsolute(n.outputFolder)?n.outputFolder:W__default.default.join(process.cwd(),n.outputFolder);if(!ie__default.default.existsSync(t))try{ie__default.default.mkdirSync(t,{recursive:!0}),re||`${n.outputFolder}`;}catch(r){re||`${r.message}`;}let i=W__default.default.join(process.cwd(),".gitignore");if(ie__default.default.existsSync(i)&&(ie__default.default.readFileSync(i,"utf-8").includes(n.outputFolder)||ie__default.default.appendFileSync(i,`
|
|
785
784
|
# OpenAPI Sync generated files
|
|
786
|
-
${
|
|
787
|
-
`)),
|
|
788
|
-
\u274C Error during sync:`,
|
|
789
|
-
\u274C Error during setup:`,
|
|
785
|
+
${n.outputFolder}
|
|
786
|
+
`)),re||(`${e}`,n.generateClient&&n.clientType&&(n.clientType==="axios"||n.clientType==="react-query"||n.clientType==="swr"||n.clientType),n.enableValidation&&n.validationLibrary&&(n.generateClient,`${n.validationLibrary}`)),n.runSync&&!re)try{let{Init:r,GenerateClient:d}=yield Promise.resolve().then(()=>(On(),An));yield r({refetchInterval:n.refetchInterval}),n.generateClient&&n.clientType&&(yield d({type:n.clientType,apiName:n.apiName}));}catch(r){console.error(`
|
|
787
|
+
\u274C Error during sync:`,r.message),r.stack&&process.env.DEBUG&&console.error(r.stack);}else re||(n.generateClient||n.enableValidation,n.generateClient&&n.clientType&&(n.generateClient||n.enableValidation,`${n.clientType}`));re||(`${n.outputFolder}${n.apiName}`,n.generateClient&&`${n.outputFolder}${n.apiName}`,n.generateClient&&n.clientType&&`${n.clientType}`);}catch(n){throw re||(console.error(`
|
|
788
|
+
\u274C Error during setup:`,n.message),process.exit(1)),n}})}var re,vn=se(()=>{re=process.env.NODE_ENV==="test"||process.env.JEST_WORKER_ID!==void 0;});var An={};an(An,{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:()=>Gn,isJson:()=>exports.isJson,isYamlString:()=>exports.isYamlString,mergeCustomCode:()=>exports.mergeCustomCode,renderTypeRefMD:()=>exports.renderTypeRefMD,variableName:()=>exports.variableName,variableNameChar:()=>exports.variableNameChar,yamlStringToJson:()=>exports.yamlStringToJson});var Ne,Pn;exports.Init=void 0;exports.GenerateClient=void 0;exports.InteractiveInit=void 0;var On=se(()=>{$n();Ke();_e();xn();wn();ke();Le();Ne=process.cwd(),Pn=()=>{let n;try{Ae("esbuild-register");}catch(i){throw i}let o=W__default.default.join(Ne,"openapi.sync.js"),l=W__default.default.join(Ne,"openapi.sync.ts"),e=W__default.default.join(Ne,"openapi.sync.json"),s=[o,l,e];try{for(let i of s)ie__default.default.existsSync(i)&&(n=Ae(i),Object.keys(n).length===1&&n.default&&(n=n.default));}catch(i){}typeof n=="function"&&(n=n());let t=n;if(!t)throw new Error("No config found");return t},exports.Init=n=>te(null,null,function*(){let o=Pn(),l=Object.keys(o.api),e=n&&"refetchInterval"in n&&!isNaN(n==null?void 0:n.refetchInterval)?n.refetchInterval:o.refetchInterval;He();for(let s=0;s<l.length;s+=1){let t=l[s],i=o.api[t];yield Ze(i,t,o,e);}}),exports.GenerateClient=n=>te(null,null,function*(){let o=Pn(),l=n.apiName?[n.apiName]:Object.keys(o.api);for(let s of l)if(!o.api[s])throw new Error(`API "${s}" not found in configuration. Available APIs: ${Object.keys(o.api).join(", ")}`);He();for(let s of l){let t=o.api[s];yield Ze(t,s,o);}let e=(o==null?void 0:o.folder)||"api";for(let s of l){let t=yn(s);if(t.length===0){continue}`${t.length}${s}`;let i=oe(oe(oe(oe(ve(oe({enabled:true},o.clientGeneration||{}),{type:n.type}),n.outputDir&&{outputDir:n.outputDir}),n.baseURL&&{baseURL:n.baseURL}),n.tags&&{tags:n.tags}),n.endpoints&&{endpoints:n.endpoints});yield In(t,o,i,s,W__default.default.join(Ne,e));}}),exports.InteractiveInit=()=>te(null,null,function*(){let{interactiveInit:n}=yield Promise.resolve().then(()=>(vn(),En));yield n();});});On();exports.getNestedValue=Gn;
|