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.js
CHANGED
|
@@ -1,103 +1,100 @@
|
|
|
1
|
-
'use strict';var
|
|
2
|
-
`+" ".repeat(
|
|
3
|
-
`).filter(
|
|
4
|
-
${" ".repeat(
|
|
5
|
-
${" ".repeat(
|
|
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 an=Object.defineProperty,Rn=Object.defineProperties;var kn=Object.getOwnPropertyDescriptors;var rn=Object.getOwnPropertySymbols;var Un=Object.prototype.hasOwnProperty,Fn=Object.prototype.propertyIsEnumerable;var sn=(r,a,t)=>a in r?an(r,a,{enumerable:true,configurable:true,writable:true,value:t}):r[a]=t,se=(r,a)=>{for(var t in a||(a={}))Un.call(a,t)&&sn(r,t,a[t]);if(rn)for(var t of rn(a))Fn.call(a,t)&&sn(r,t,a[t]);return r},ve=(r,a)=>Rn(r,kn(a));var Ae=(r=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(r,{get:(a,t)=>(typeof require!="undefined"?require:a)[t]}):r)(function(r){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var ae=(r,a)=>()=>(r&&(a=r(r=0)),a);var on=(r,a)=>{for(var t in a)an(r,t,{get:a[t],enumerable:true});};var te=(r,a,t)=>new Promise((e,o)=>{var n=c=>{try{s(t.next(c));}catch(m){o(m);}},l=c=>{try{s(t.throw(c));}catch(m){o(m);}},s=c=>c.done?e(c.value):Promise.resolve(c.value).then(n,l);s((t=t.apply(r,a)).next());});exports.variableName=void 0;exports.variableNameChar=void 0;var Le=ae(()=>{exports.variableName=/^[A-Za-z_$][A-Za-z0-9_$]*$/,exports.variableNameChar=/[A-Za-z0-9_$]/;});function Mn(r,a){return a.split(".").reduce((e,o)=>e&&e[o]!==void 0?e[o]:void 0,r)}exports.isJson=void 0;exports.isYamlString=void 0;exports.yamlStringToJson=void 0;exports.capitalize=void 0;exports.getEndpointDetails=void 0;exports.JSONStringify=void 0;exports.renderTypeRefMD=void 0;exports.extractCustomCode=void 0;exports.createCustomCodeMarker=void 0;exports.mergeCustomCode=void 0;var ke=ae(()=>{Le();exports.isJson=r=>["object"].includes(typeof r)&&!(r instanceof Blob),exports.isYamlString=r=>{try{return Oe__namespace.load(r),!0}catch(a){let t=a;if(t instanceof Oe__namespace.YAMLException)return false;throw t}},exports.yamlStringToJson=r=>{if(exports.isYamlString(r)){let a=Oe__namespace.load(r),t=JSON.stringify(a,null,2);return JSON.parse(t)}},exports.capitalize=r=>r.substring(0,1).toUpperCase()+r.substring(1),exports.getEndpointDetails=(r,a)=>{let t=r.split("/"),e=`${exports.capitalize(a)}`,o=[];return t.forEach(n=>{if(n[0]==="{"&&n[n.length-1]==="}"){let s=n.replace(/{/,"").replace(/}/,"");o.push(s),n=`$${s}`;}else if(n[0]==="<"&&n[n.length-1]===">"){let s=n.replace(/</,"").replace(/>/,"");o.push(s),n=`$${s}`;}else if(n[0]===":"){let s=n.replace(/:/,"");o.push(s),n=`$${s}`;}let l="";n.split("").forEach(s=>{let c=s;exports.variableNameChar.test(s)||(c="/"),l+=c;}),l.split("/").forEach(s=>{e+=exports.capitalize(s);});}),{name:e,variables:o,pathParts:t}},exports.JSONStringify=(r,a=1)=>{let t="{",e=Object.keys(r);for(let o=0;o<e.length;o++){let n=e[o],l=r[n];if(t+=`
|
|
2
|
+
`+" ".repeat(a)+n+": ",Array.isArray(l)){t+="[";for(let s=0;s<l.length;s++){let c=l[s];typeof c=="object"&&c!==null?t+=exports.JSONStringify(c,a+1):t+=typeof c=="string"?`"${c}"`:c,s<l.length-1&&(t+=", ");}t+="]";}else typeof l=="object"&&l!==null?t+=""+exports.JSONStringify(l,a+1):t+=l.split(`
|
|
3
|
+
`).filter(s=>s.trim()!=="").join(`
|
|
4
|
+
${" ".repeat(a)}`);o<e.length-1&&(t+=", ");}return t+=`
|
|
5
|
+
${" ".repeat(a-1)}}`,t},exports.renderTypeRefMD=(r,a=1)=>`
|
|
6
6
|
\`\`\`typescript
|
|
7
|
-
${" ".repeat(
|
|
7
|
+
${" ".repeat(a)} ${r.split(`
|
|
8
8
|
`).filter(t=>t.trim()!=="").join(`
|
|
9
|
-
${" ".repeat(
|
|
10
|
-
\`\`\``;exports.extractCustomCode=(
|
|
11
|
-
`,
|
|
12
|
-
`).filter(
|
|
9
|
+
${" ".repeat(a)} `)}
|
|
10
|
+
\`\`\``;exports.extractCustomCode=(r,a="CUSTOM CODE")=>{let t=`// \u{1F512} ${a} START`,e=`// \u{1F512} ${a} END`,o={beforeGenerated:"",afterGenerated:""},n=0,l=[];for(;n<r.length;){let s=r.indexOf(t,n);if(s===-1)break;let c=r.indexOf(e,s);if(c===-1)break;let m=c+e.length,f=r.substring(m,m+100),v=f.match(/^\s*\n\s*(\/\/ =+)/);if(v){let G=f.indexOf(`
|
|
11
|
+
`,v.index+1);G!==-1?m+=G+1:m+=v[0].length;}let k=s,x=r.substring(Math.max(0,s-200),s).lastIndexOf("// ==========");x!==-1&&(k=Math.max(0,s-200)+x);let O=r.substring(k,m);l.push({start:k,end:m,content:O}),n=m;}return l.length>0&&(r.substring(0,l[0].start).split(`
|
|
12
|
+
`).filter(m=>{let f=m.trim();return f.length>0&&!f.startsWith("//")}).join("").length===0?(o.beforeGenerated=l[0].content,l.length>1&&(o.afterGenerated=l[1].content)):(o.afterGenerated=l[0].content,l.length>1&&!o.beforeGenerated&&(o.beforeGenerated=l[1].content))),o},exports.createCustomCodeMarker=(r,a="CUSTOM CODE",t=true)=>{let e=t?`// ${r==="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} ${a} START
|
|
16
16
|
${e}// ${"=".repeat(60)}
|
|
17
17
|
|
|
18
|
-
// \u{1F512} ${
|
|
19
|
-
// ${"=".repeat(60)}`},exports.mergeCustomCode=(
|
|
20
|
-
`)};});var
|
|
21
|
-
`).filter(
|
|
22
|
-
*${" ".repeat(1)}`))),
|
|
23
|
-
${
|
|
18
|
+
// \u{1F512} ${a} END
|
|
19
|
+
// ${"=".repeat(60)}`},exports.mergeCustomCode=(r,a,t={})=>{let{position:e="bottom",markerText:o="CUSTOM CODE",includeInstructions:n=true}=t,l={beforeGenerated:"",afterGenerated:""};a&&(l=exports.extractCustomCode(a,o)),!l.beforeGenerated&&!l.afterGenerated&&((e==="top"||e==="both")&&(l.beforeGenerated=exports.createCustomCodeMarker("top",o,n)),(e==="bottom"||e==="both")&&(l.afterGenerated=exports.createCustomCodeMarker("bottom",o,n)));let s=[];return l.beforeGenerated&&(s.push(l.beforeGenerated),s.push("")),s.push(r),l.afterGenerated&&(s.push(""),s.push(l.afterGenerated)),s.join(`
|
|
20
|
+
`)};});var Ue,Je,je,un,mn,dn,He,Ke=ae(()=>{Ue=W__default.default.join(__dirname,"../","../db.json");ie__default.default.existsSync(Ue)||ie__default.default.writeFileSync(Ue,"{}");Je={};try{Je=Ae(Ue);}catch(r){Je={};}je=Je||{},un=r=>{ie__default.default.writeFileSync(Ue,JSON.stringify(r));},mn=(r,a)=>{je[r]=a,un(je);},dn=r=>je[r],He=()=>{je={},un(je);};});var cn,yn,fn,_e=ae(()=>{cn={},yn=(r,a)=>{cn[r]=a;},fn=r=>cn[r]||[];});var fe,Ye,gn,ge,hn,Ze,$n=ae(()=>{ke();Ke();_e();fe=process.cwd(),Ye={},gn=Qn__default.default.create({timeout:6e4});Bn__default.default(gn,{retries:20,retryCondition:r=>r.code==="ECONNABORTED"||r.message.includes("Network Error"),retryDelay:r=>r*1e3});ge=(r,a,t)=>te(null,null,function*(){var l,s,c,m;if(!(((l=t==null?void 0:t.customCode)==null?void 0:l.enabled)!==false)){yield ie__default.default.promises.writeFile(r,a);return}let o=null;try{o=yield ie__default.default.promises.readFile(r,"utf-8");}catch(f){}let n=exports.mergeCustomCode(a,o,{position:((s=t==null?void 0:t.customCode)==null?void 0:s.position)||"bottom",markerText:(c=t==null?void 0:t.customCode)==null?void 0:c.markerText,includeInstructions:(m=t==null?void 0:t.customCode)==null?void 0:m.includeInstructions});yield ie__default.default.promises.writeFile(r,n);}),hn=(r,a,t,e)=>te(null,null,function*(){var pe,ne,ue,we,Ce,Re,rt,st,at,ot;let o=yield gn.get(r),n=exports.isJson(o.data)?o.data:exports.yamlStringToJson(o.data),l;try{l=yield zn__default.default.parse(n);}catch(i){let u=i instanceof Error?i.message:String(i);throw new Error(`Failed to parse OpenAPI spec for ${a}: ${u}`)}let s=W__default.default.join((t==null?void 0:t.folder)||"",a),c={},m=i=>{var u,E;if((u=t==null?void 0:t.folderSplit)!=null&&u.customFolder){let $=t.folderSplit.customFolder(i);if($)return $}return (E=t==null?void 0:t.folderSplit)!=null&&E.byTags&&i.tags&&i.tags.length>0?i.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},f=typeof(t==null?void 0:t.server)=="string"?t==null?void 0:t.server:((ne=(pe=l==null?void 0:l.servers)==null?void 0:pe[(t==null?void 0:t.server)||0])==null?void 0:ne.url)||"",v=typeof((we=(ue=t==null?void 0:t.types)==null?void 0:ue.name)==null?void 0:we.prefix)=="string"?t==null?void 0:t.types.name.prefix:"I",k=typeof((Re=(Ce=t==null?void 0:t.endpoints)==null?void 0:Ce.name)==null?void 0:Re.prefix)=="string"?t==null?void 0:t.endpoints.name.prefix:"",q=(i,u)=>{var $,y;let E=exports.capitalize(i);if((y=($=t==null?void 0:t.types)==null?void 0:$.name)!=null&&y.format){let g=t==null?void 0:t.types.name.format("shared",{name:i},E);if(g)return `${v}${g}`}return `${v}${E}`},x=(i,u,E,$,y,g=0)=>{let d="",b="",h="";if(u)if(u.$ref)if(u.$ref[0]==="#"){let P=(u.$ref||"").split("/");P.shift(),[...P].pop();let N=Ve__default.default(i,P,null);if(N){N!=null&&N.name&&(d=N.name),b=P[P.length-1];let H=q(b);H.includes(".")&&(H=H.split(".").map((de,Ie)=>Ie===0?de:`["${de}"]`).join("")),h+=`${y!=null&&y.noSharedImport?"":"Shared."}${H}`;}}else h+="";else if(u.anyOf)h+=`(${u.anyOf.map(P=>x(i,P,"",$,y)).filter(P=>!!P).join("|")})`;else if(u.oneOf)h+=`(${u.oneOf.map(P=>x(i,P,"",$,y)).filter(P=>!!P).join("|")})`;else if(u.allOf)h+=`(${u.allOf.map(P=>x(i,P,"",$,y)).filter(P=>!!P).join("&")})`;else if(u.items)h+=`${x(i,u.items,"",false,y)}[]`;else if(u.properties){let P=Object.keys(u.properties),M=u.required||[],Q="";P.forEach(N=>{var me,de,Ie,Te,Ee,ye;let H="";!((de=(me=t==null?void 0:t.types)==null?void 0:me.doc)!=null&&de.disable)&&((Te=(Ie=u.properties)==null?void 0:Ie[N])!=null&&Te.description)&&(H=" * "+((Ee=u.properties)==null?void 0:Ee[N].description.split(`
|
|
21
|
+
`).filter(Me=>Me.trim()!=="").join(`
|
|
22
|
+
*${" ".repeat(1)}`))),Q+=(H?`/**
|
|
23
|
+
${H}
|
|
24
24
|
*/
|
|
25
|
-
`:"")+`${x(
|
|
26
|
-
${" ".repeat(
|
|
27
|
-
`:""}`:""},
|
|
28
|
-
`)
|
|
29
|
-
${
|
|
30
|
-
}`:y+="{}";}else if(
|
|
31
|
-
`).filter(
|
|
32
|
-
*${" ".repeat(1)}`)),
|
|
33
|
-
${
|
|
25
|
+
`:"")+`${x(i,(ye=u.properties)==null?void 0:ye[N],N,M.includes(N),y,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),M=u.enum.filter(N=>N!==null).map(N=>JSON.stringify(N)).filter(N=>N!==void 0),Q=M.length>1||M.length>0&&P;Q&&(h+="("),M.forEach((N,H)=>{h+=`${H===0?"":"|"}${N}`;}),P&&(h+=`${M.length>0?"|":""}null`),Q&&(h+=")");}else if(u.type){let P=M=>{let Q="";if(typeof M=="string")["string","integer","number","array","boolean","null"].includes(M)?["integer","number"].includes(M)?Q+="number":M==="array"?Q+="any[]":Q+=M:M==="object"&&(u.additionalProperties?Q+=`{[k: string]: ${x(i,u.additionalProperties,"",true,y)||"any"}}`:Q+="{[k: string]: any}");else if(Array.isArray(M)){let N=M.map(H=>P(H));N.filter(H=>H!==""),N.length>1&&(Q+="("+N.join("|")+")");}else Q+="any";return Q};h=P(u.type);}else h+="any";else h="string";let A=d||E;y!=null&&y.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=(i,u)=>{let y="";if(u)if(u.$ref)if(u.$ref[0]==="#"){let g=(u.$ref||"").split("/");g.shift();let b=Ve__default.default(i,g,null);b&&(b!=null&&b.name&&(b.name),g[g.length-1],y+=O(i,b));}else y+="";else if(u.anyOf)y+=O(i,u.anyOf[0]);else if(u.oneOf)y+=O(i,u.oneOf[0]);else if(u.allOf)y+=`{${u.allOf.map(g=>`...(${O(i,g)})`).join(",")}}`;else if(u.items)y+=`[${O(i,u.items)}]`;else if(u.properties){let b=Object.keys(u.properties).map(h=>{var A;return ` "${h}": ${O(i,(A=u.properties)==null?void 0:A[h])}`}).join(`,
|
|
28
|
+
`);b.length>0?y+=`{
|
|
29
|
+
${b}
|
|
30
|
+
}`:y+="{}";}else if(u.enum&&u.enum.length>0)u.enum.length>1&&(y+=u.enum[0]);else if(u.type)if(u.example)y+=JSON.stringify(u.example);else {let g=d=>{let b="";if(typeof d=="string")["string","integer","number","array","boolean","null"].includes(d)?["integer","number"].includes(d)?b+="123":d==="array"?b+="[]":d==="boolean"?b+="true":d==="null"?b+="null":b+=`"${d}"`:d==="object"&&(b+="{}");else if(Array.isArray(d)){let h=d.map(A=>g(A));h.filter(A=>A!==""),h.length>1&&(b+=h.join("|"));}else b+="any";return b};y=g(u.type);}else y+="any";else y="string";return y};e&&!isNaN(e)&&e>0&&(process.env.NODE_ENV&&["production","prod","test","staging"].includes(process.env.NODE_ENV)||(Ye[a]&&clearTimeout(Ye[a]),Ye[a]=setTimeout(()=>hn(r,a,t,e),e)));let G=dn(a);if(Ln__default.default(G,l))return;mn(a,l);let R="",D="",T={},I=[];l.components&&Object.keys(l.components).forEach(i=>{if(["schemas","responses","parameters","examples","requestBodies","headers","links","callbacks"].includes(i)){let u=l.components[i],E={},$={};Object.keys(u).forEach(g=>{var h;let d=(h=u[g])!=null&&h.schema?u[g].schema:u[g],b=`${x(l,d,"",true,{noSharedImport:true,useComponentName:["parameters"].includes(i)})}`;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]=d);}}}),Object.keys(E).forEach(g=>{var A,J,p,V;let d=q(g),b=E[g],h="";!((J=(A=t==null?void 0:t.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 "+d+" = "+(typeof
|
|
36
|
-
`;});}});let
|
|
37
|
-
`);return
|
|
38
|
-
${
|
|
39
|
-
${" ".repeat(
|
|
40
|
-
${
|
|
41
|
-
${" ".repeat(
|
|
42
|
-
${
|
|
43
|
-
${" ".repeat(
|
|
44
|
-
${
|
|
45
|
-
`;t!=null&&t.folderSplit?c[
|
|
46
|
-
`),
|
|
47
|
-
${
|
|
35
|
+
`:"")+"export type "+d+" = "+(typeof b=="string"?b:exports.JSONStringify(b))+`;
|
|
36
|
+
`;});}});let _=i=>{let u="";if(i.content){let E=Object.keys(i.content);E[0]&&i.content[E[0]].schema&&(u+=`${x(l,i.content[E[0]].schema,"")}`);}return u},j=(i,u,E=0)=>{if(!i)return u==="joi"?"Joi.any()":u==="yup"?"yup.mixed()":"z.any()";if(i.$ref){if(i.$ref[0]==="#"){let $=i.$ref.split("/");$.shift();let y=$.join("."),g=Ve__default.default(l,y);if(g)return j(g,u,E)}return u==="joi"?"Joi.any()":u==="yup"?"yup.mixed()":"z.any()"}if(i.anyOf||i.oneOf){let $=i.anyOf||i.oneOf;if($.every(g=>g.enum!==void 0&&Array.isArray(g.enum))){let g=[],d=false;if($.forEach(b=>{b.enum&&b.enum.forEach(h=>{h===null?d=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 d&&(h+=".nullable()"),h}else if(u==="yup"){let h=`yup.mixed().oneOf([${b}])`;return d&&(h+=".nullable()"),h}else return d?`Joi.valid(${b}, null)`:`Joi.valid(${b})`}else if(d)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(d=>j(d,u,E+1)).join(", ")})`}if(i.allOf)if(u==="zod"){let $=i.allOf.map(g=>j(g,u,E+1)),y=$[0];for(let g=1;g<$.length;g++)y=`${y}.merge(${$[g]})`;return y}else return j(i.allOf[0],u,E+1);if(i.items){let $=j(i.items,u,E+1);if(u==="zod"){let y=`z.array(${$})`;return i.minItems!==void 0&&(y+=`.min(${i.minItems})`),i.maxItems!==void 0&&(y+=`.max(${i.maxItems})`),y}else if(u==="yup"){let y=`yup.array().of(${$})`;return i.minItems!==void 0&&(y+=`.min(${i.minItems})`),i.maxItems!==void 0&&(y+=`.max(${i.maxItems})`),y}else {let y=`Joi.array().items(${$})`;return i.minItems!==void 0&&(y+=`.min(${i.minItems})`),i.maxItems!==void 0&&(y+=`.max(${i.maxItems})`),y}}if(i.properties){let $=i.required||[],y=" ".repeat(E+1),g=Object.entries(i.properties).map(([d,b])=>{let h=$.includes(d),A=j(b,u,E+1);return h||(A+=".optional()"),`${y}${d}: ${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(i.enum&&i.enum.length>0){let $=[],y=false;i.enum.forEach(d=>{d===null?y=true:$.includes(d)||$.push(d);});let g=$.map(d=>JSON.stringify(d)).join(", ");if(u==="zod"){let d=`z.enum([${g}])`;return y&&(d+=".nullable()"),d}else if(u==="yup"){let d=`yup.mixed().oneOf([${g}])`;return y&&(d+=".nullable()"),d}else {let d=`Joi.valid(${g})`;return y&&(d+=".allow(null)"),d}}if(i.type){let y=(g=>{switch(g){case "string":if(u==="zod"){let d="z.string()";return i.format==="email"?d+=".email()":i.format==="uuid"?d+=".uuid()":i.format==="url"||i.format==="uri"?d+=".url()":i.format==="date-time"?d+=".datetime()":i.format==="date"&&(d+=".date()"),i.minLength&&(d+=`.min(${i.minLength})`),i.maxLength&&(d+=`.max(${i.maxLength})`),i.pattern&&(d+=`.regex(/${i.pattern}/)`),d}else if(u==="yup"){let d="yup.string()";return i.format==="email"?d+=".email()":(i.format==="url"||i.format==="uri")&&(d+=".url()"),i.minLength&&(d+=`.min(${i.minLength})`),i.maxLength&&(d+=`.max(${i.maxLength})`),i.pattern&&(d+=`.matches(/${i.pattern}/)`),d}else {let d="Joi.string()";return i.format==="email"?d+=".email()":i.format==="url"||i.format==="uri"?d+=".uri()":i.format==="uuid"?d+=".guid({ version: 'uuidv4' })":i.format==="date-time"&&(d+=".isoDate()"),i.minLength&&(d+=`.min(${i.minLength})`),i.maxLength&&(d+=`.max(${i.maxLength})`),i.pattern&&(d+=`.pattern(/${i.pattern}/)`),d}case "integer":case "number":if(u==="zod"){let d="z.number()";return g==="integer"&&(d+=".int()"),i.minimum!==void 0&&(i.exclusiveMinimum?d+=`.gt(${i.minimum})`:d+=`.min(${i.minimum})`),i.maximum!==void 0&&(i.exclusiveMaximum?d+=`.lt(${i.maximum})`:d+=`.max(${i.maximum})`),d}else if(u==="yup"){let d="yup.number()";return g==="integer"&&(d+=".integer()"),i.minimum!==void 0&&(d+=`.min(${i.minimum})`),i.maximum!==void 0&&(d+=`.max(${i.maximum})`),d}else {let d="Joi.number()";return g==="integer"&&(d+=".integer()"),i.minimum!==void 0&&(i.exclusiveMinimum?d+=`.greater(${i.minimum})`:d+=`.min(${i.minimum})`),i.maximum!==void 0&&(i.exclusiveMaximum?d+=`.less(${i.maximum})`:d+=`.max(${i.maximum})`),d}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 i.type=="string"?i.type:i.type[0]);return i.nullable&&u!=="joi"?y+=".nullable()":i.nullable&&u==="joi"&&(y+=".allow(null)"),y}return u==="joi"?"Joi.any()":u==="yup"?"yup.mixed()":"z.any()"},z=i=>{var u,E,$,y,g;if((E=(u=t==null?void 0:t.endpoints)==null?void 0:u.value)!=null&&E.replaceWords&&Array.isArray(t==null?void 0:t.endpoints.value.replaceWords)){let d=i;return (g=(y=($=t==null?void 0:t.endpoints)==null?void 0:$.value)==null?void 0:y.replaceWords)==null||g.forEach((b,h)=>{let A=new RegExp(b.replace,"g");d=d.replace(A,b.with||"");}),d}else return i},le=(i,u,E=[])=>{var g,d;let $=(g=t==null?void 0:t.endpoints)==null?void 0:g.exclude,y=(d=t==null?void 0:t.endpoints)==null?void 0:d.include;if(y){let b=y.tags&&y.tags.length>0?E.some(A=>y.tags.includes(A)):true,h=y.endpoints&&y.endpoints.length>0?y.endpoints.some(A=>{let J=!A.method||A.method.toLowerCase()===u.toLowerCase();return A.path?i===A.path&&J:A.regex?new RegExp(A.regex).test(i)&&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?i===h.path&&A:h.regex?new RegExp(h.regex).test(i)&&A:false})))};if(Object.keys(l.paths||{}).forEach(i=>{let u=l.paths[i];Object.keys(u).forEach($=>{var lt,pt,ut,mt,dt,ct,yt,ft,gt,ht,$t,bt,Ct,It,xt,wt,Tt,Et,vt,At,Ot,Pt,qt,jt,St,Rt,kt,Ut,Ft,Gt,Mt,Nt,Lt,Qt,Bt,zt,Wt,Dt,Jt,Ht,Kt,_t,Vt,Yt,Zt,Xt,en,tn,nn;let y=$,g=exports.getEndpointDetails(i,y),d=((lt=u[y])==null?void 0:lt.tags)||[];if(le(i,y,d))return;let b=u[y],h=m({method:y,path:i,summary:b==null?void 0:b.summary,operationId:b==null?void 0:b.operationId,tags:d,parameters:b==null?void 0:b.parameters,requestBody:b==null?void 0:b.requestBody,responses:b==null?void 0:b.responses});c[h]||(c[h]={endpoints:"",types:"",validation:""});let A=((ut=(pt=t==null?void 0:t.endpoints)==null?void 0:pt.value)!=null&&ut.includeServer?f:"")+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[y],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(l,w.$ref?w:w.schema,w.name||"",w.required)}`);}),V)){V=`{
|
|
44
|
+
${V}}`;let w=`${g.name}Query`;if((dt=(mt=t==null?void 0:t.types)==null?void 0:mt.name)!=null&&dt.useOperationId&&(p!=null&&p.operationId)&&(w=`${p.operationId}Query`),w=exports.capitalize(`${v}${w}`),(yt=(ct=t==null?void 0:t.types)==null?void 0:ct.name)!=null&&yt.format){let L=t==null?void 0:t.types.name.format("endpoint",{code:"",type:"query",method:y,path:i,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
|
+
`;t!=null&&t.folderSplit?c[h].types+=S:D+=S;}if(((ft=t==null?void 0:t.validations)==null?void 0:ft.disable)!==true&&((ht=(gt=t==null?void 0:t.validations)==null?void 0:gt.generate)==null?void 0:ht.query)!==false&&(p!=null&&p.parameters)){let C=(($t=t.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=t==null?void 0:t.validations)==null?void 0:bt.name)||((Ct=t==null?void 0:t.types)==null?void 0:Ct.name),K=typeof(L==null?void 0:L.prefix)=="string"?L.prefix:"I",F=typeof((xt=(It=t==null?void 0:t.validations)==null?void 0:It.name)==null?void 0:xt.suffix)=="string"?t.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=t==null?void 0:t.validations)==null?void 0:wt.name)!=null&&Tt.format){let ee=t.validations.name.format({code:"",type:"query",method:y,path:i,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId},B);ee&&(B=`${K}${ee}${F}`);}else if((vt=(Et=t==null?void 0:t.types)==null?void 0:Et.name)!=null&&vt.format){let ee=t.types.name.format("endpoint",{code:"",type:"query",method:y,path:i,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
|
+
`),ce=`export const ${B} = ${C==="joi"?"Joi.object":C==="yup"?"yup.object":"z.object"}({
|
|
47
|
+
${U}
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
`;t!=null&&t.folderSplit||c[
|
|
51
|
-
`;t!=null&&t.folderSplit?c[
|
|
50
|
+
`;t!=null&&t.folderSplit||c[h]||(c[h]={endpoints:"",types:"",validation:""}),c[h].validation+=ce;}}let M=p==null?void 0:p.requestBody,Q="",N;if(M&&(Q=_(M),Q)){let C=`${g.name}DTO`;if((Ot=(At=t==null?void 0:t.types)==null?void 0:At.name)!=null&&Ot.useOperationId&&(p!=null&&p.operationId)&&(C=`${p.operationId}DTO`),C=exports.capitalize(`${v}${C}`),(qt=(Pt=t==null?void 0:t.types)==null?void 0:Pt.name)!=null&&qt.format){let S=t==null?void 0:t.types.name.format("endpoint",{code:"",type:"dto",method:y,path:i,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId},C);S&&(C=`${v}${S}`);}N=C;let w=`export type ${C} = ${Q};
|
|
51
|
+
`;t!=null&&t.folderSplit?c[h].types+=w:D+=w;}if(((jt=t==null?void 0:t.validations)==null?void 0:jt.disable)!==true&&((Rt=(St=t==null?void 0:t.validations)==null?void 0:St.generate)==null?void 0:Rt.dto)!==false&&M){let C=((kt=t.validations)==null?void 0:kt.library)||"zod";if(M.content){let w=Object.keys(M.content);if(w[0]&&M.content[w[0]].schema){let S=((Ut=t==null?void 0:t.validations)==null?void 0:Ut.name)||((Ft=t==null?void 0:t.types)==null?void 0:Ft.name),L=typeof(S==null?void 0:S.prefix)=="string"?S.prefix:"I",K=typeof((Mt=(Gt=t==null?void 0:t.validations)==null?void 0:Gt.name)==null?void 0:Mt.suffix)=="string"?t.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=(Nt=t==null?void 0:t.validations)==null?void 0:Nt.name)!=null&&Lt.format){let X=t.validations.name.format({code:"",type:"dto",method:y,path:i,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId},F);X&&(F=`${L}${X}${K}`);}else if((Bt=(Qt=t==null?void 0:t.types)==null?void 0:Qt.name)!=null&&Bt.format){let X=t.types.name.format("endpoint",{code:"",type:"dto",method:y,path:i,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId},F);X&&(F=`${L}${X}${K}`);}let B=j(M.content[w[0]].schema,C),U=`export const ${F} = ${B};
|
|
52
52
|
|
|
53
|
-
`;t!=null&&t.folderSplit||c[
|
|
54
|
-
`;t!=null&&t.folderSplit?c[
|
|
55
|
-
- Scopes: [\`${K.join("`, `")}\`]`,
|
|
56
|
-
- ${
|
|
57
|
-
`),
|
|
58
|
-
--cert client-certificate.crt --key client-private-key.key --cacert ca-certificate.crt`:
|
|
53
|
+
`;t!=null&&t.folderSplit||c[h]||(c[h]={endpoints:"",types:"",validation:""}),c[h].validation+=U;}}}let H={},me="",de="";if(p!=null&&p.responses){let C=p==null?void 0:p.responses;Object.keys(C).forEach(S=>{var L,K,F,B;if(me=_(C[S]),H[S]=me,me){let U=`${g.name}${S}Response`;if((K=(L=t==null?void 0:t.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=t==null?void 0:t.types)==null?void 0:F.name)!=null&&B.format){let ee=t==null?void 0:t.types.name.format("endpoint",{code:S,type:"response",method:y,path:i,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId},U);ee&&(U=`${v}${ee}`);}let X=`export type ${U} = ${me};
|
|
54
|
+
`;t!=null&&t.folderSplit?c[h].types+=X:D+=X,H[S]=U;let ce=parseInt(S);ce>=200&&ce<300&&(de=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=t==null?void 0:t.endpoints)==null?void 0:zt.doc)!=null&&Wt.disable)){let C="";if((Jt=(Dt=t==null?void 0:t.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(l,U);X&&(S=X);}}),p!=null&&p.security&&p.security.forEach(F=>{Object.keys(F).forEach(B=>{var X,ce;let U=(ce=(X=l.components)==null?void 0:X.securitySchemes)==null?void 0:ce[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
|
-
* ${
|
|
60
|
+
${curlGenerator.CurlGenerator({url:f+i,method:y.toUpperCase(),headers:K,body:S})}${L}
|
|
61
|
+
\`\`\``;}Ee=`/**${p!=null&&p.description?`
|
|
62
|
+
* ${p==null?void 0:p.description} `:""}
|
|
63
63
|
* **Method**: \`${y.toUpperCase()}\`
|
|
64
|
-
* **Summary**: ${(
|
|
65
|
-
* **Tags**: [${((Kt=
|
|
66
|
-
* **OperationId**: ${(
|
|
67
|
-
* **Query**: ${exports.renderTypeRefMD(
|
|
68
|
-
* **DTO**: ${exports.renderTypeRefMD(Q)} `:""}${
|
|
69
|
-
* **Response**: ${Object.entries(
|
|
70
|
-
- **${
|
|
71
|
-
* **Security**: ${
|
|
72
|
-
`:""}${
|
|
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)} `:""}${me?`
|
|
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
|
-
`;t!=null&&t.folderSplit?c[
|
|
74
|
+
`;}let ye=(Vt=(_t=t==null?void 0:t.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=t==null?void 0:t.endpoints)==null?void 0:Zt.name)!=null&&Xt.format){let C=t==null?void 0:t.endpoints.name.format({method:y,path:i,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId},ye);C&&(ye=C);}let Me={method:`"${y}"`,operationId:`"${p==null?void 0:p.operationId}"`,url:J,tags:(p==null?void 0:p.tags)||[]},it=`${Ee}export const ${k}${ye} = ${((tn=(en=t==null?void 0:t.endpoints)==null?void 0:en.value)==null?void 0:tn.type)==="object"?exports.JSONStringify(Me):J};
|
|
75
|
+
`;t!=null&&t.folderSplit?c[h].endpoints+=it:R+=it;let qn={name:`${k}${ye}`,method:y,path:i,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId,tags:d,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:M?{type:Q,required:M.required}:void 0,responses:H?Object.entries(H).reduce((C,[w,S])=>(C[w]={type:S},C),{}):void 0,queryType:P,dtoType:N,responseType:de||void 0};I.push(qn);});}),t!=null&&t.folderSplit){for(let[i,u]of Object.entries(c))if(u.endpoints||u.types){let E=W__default.default.join(s,i);if(u.endpoints){let $=W__default.default.join(fe,E,"endpoints.ts");yield ie__default.default.promises.mkdir(W__default.default.dirname($),{recursive:true}),yield ge($,u.endpoints,t);}if(u.types){let $=W__default.default.join(fe,E,"types.ts");yield ie__default.default.promises.mkdir(W__default.default.dirname($),{recursive:true});let y=Object.values(T).length>0?`import * as Shared from "../shared";
|
|
76
76
|
|
|
77
|
-
${
|
|
77
|
+
${u.types}`:u.types;yield ge($,y,t);}if(((rt=t==null?void 0:t.validations)==null?void 0:rt.disable)!==true&&u.validation){let $=((st=t.validations)==null?void 0:st.library)||"zod",y=$==="joi"?'import Joi from "joi";':$==="yup"?'import * as yup from "yup";':'import { z } from "zod";',g=W__default.default.join(fe,E,"validations.ts");yield ie__default.default.promises.mkdir(W__default.default.dirname(g),{recursive:true}),yield ge(g,`${y}
|
|
78
78
|
|
|
79
|
-
${
|
|
80
|
-
`),t);}if(
|
|
79
|
+
${u.validation}`,t);}}}if(R.length>0){let i=W__default.default.join(fe,s,"endpoints.ts");yield ie__default.default.promises.mkdir(W__default.default.dirname(i),{recursive:true}),yield ge(i,R,t);}if(Object.values(T).length>0){let i=W__default.default.join(fe,s,t!=null&&t.folderSplit?"":"types","shared.ts");yield ie__default.default.promises.mkdir(W__default.default.dirname(i),{recursive:true}),yield ge(i,Object.values(T).join(`
|
|
80
|
+
`),t);}if(D.length>0){let i=W__default.default.join(fe,s,"types","index.ts");yield ie__default.default.promises.mkdir(W__default.default.dirname(i),{recursive:true}),yield ge(i,`${Object.values(T).length>0?`import * as Shared from "./shared";
|
|
81
81
|
|
|
82
|
-
`:""}${
|
|
82
|
+
`:""}${D}`,t);}if(((at=t==null?void 0:t.validations)==null?void 0:at.disable)!==true&&!(t!=null&&t.folderSplit)){let i=((ot=t.validations)==null?void 0:ot.library)||"zod",u=i==="joi"?'import Joi from "joi";':i==="yup"?'import * as yup from "yup";':'import { z } from "zod";',E=Object.values(c).map($=>$.validation).filter($=>$.length>0).join("");if(E){let $=W__default.default.join(fe,s,"validations.ts");yield ie__default.default.promises.mkdir(W__default.default.dirname($),{recursive:true}),yield ge($,`${u}
|
|
83
83
|
|
|
84
|
-
${
|
|
84
|
+
${E}`,t);}}yn(a,I);}),Ze=hn;});var bn,Xe,he,et,tt,nt,Cn=ae(()=>{bn=(r,a)=>{let t=r;return a.tags&&a.tags.length>0&&(t=t.filter(e=>!e.tags||e.tags.length===0?false:e.tags.some(o=>a.tags.includes(o)))),a.endpoints&&a.endpoints.length>0&&(t=t.filter(e=>a.endpoints.includes(e.name))),t},Xe=(r,a,t=false)=>{var s,c;let e=a.baseURL||"";a.auth;let n=`// Generated Fetch API Client
|
|
85
85
|
`;n+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
86
86
|
|
|
87
87
|
`,n+=`import type {
|
|
88
|
-
`;let
|
|
88
|
+
`;let l=new Set;return r.forEach(m=>{m.queryType&&l.add(m.queryType),m.dtoType&&l.add(m.dtoType),m.responseType&&l.add(m.responseType);}),l.forEach(m=>{n+=` ${m},
|
|
89
89
|
`;}),n+=`} from '../types';
|
|
90
90
|
|
|
91
91
|
`,n+=`import {
|
|
92
|
-
`,
|
|
92
|
+
`,r.forEach(m=>{n+=` ${m.name} as ${m.name}_endpoint,
|
|
93
93
|
`;}),n+=`} from '../endpoints';
|
|
94
94
|
|
|
95
95
|
`,n+=`export interface ApiConfig {
|
|
96
96
|
`,n+=` baseURL?: string;
|
|
97
|
-
`,
|
|
98
|
-
`,n+=` token?: string;
|
|
99
|
-
`,n+=` };
|
|
100
|
-
`),n+=` headers?: Record<string, string>;
|
|
97
|
+
`,n+=` headers?: Record<string, string>;
|
|
101
98
|
`,n+=`}
|
|
102
99
|
|
|
103
100
|
`,n+=`let globalConfig: ApiConfig = {
|
|
@@ -108,7 +105,7 @@ ${T}`,t);}}cn(o,C);}),Ke=gn;});var $n,He,ce,_e,Ve,Ye,bn=se(()=>{$n=(s,o)=>{let t
|
|
|
108
105
|
`,n+=` globalConfig = { ...globalConfig, ...config };
|
|
109
106
|
`,n+=`};
|
|
110
107
|
|
|
111
|
-
`,(a
|
|
108
|
+
`,(s=a.errorHandling)!=null&&s.generateErrorClasses&&(n+=`export class ApiError extends Error {
|
|
112
109
|
`,n+=` constructor(
|
|
113
110
|
`,n+=` message: string,
|
|
114
111
|
`,n+=` public statusCode: number,
|
|
@@ -129,19 +126,12 @@ ${T}`,t);}}cn(o,C);}),Ke=gn;});var $n,He,ce,_e,Ve,Ye,bn=se(()=>{$n=(s,o)=>{let t
|
|
|
129
126
|
`,n+=` ...(options.headers as Record<string, string>),
|
|
130
127
|
`,n+=` };
|
|
131
128
|
|
|
132
|
-
`,
|
|
133
|
-
`,n+=" headers['Authorization'] = `Bearer ${globalConfig.auth.token}`;\n",n+=` }
|
|
134
|
-
|
|
135
|
-
`):(r==null?void 0:r.type)==="apiKey"&&r.in==="header"&&(n+=` if (globalConfig.auth?.token) {
|
|
136
|
-
`,n+=` headers['${r.name||"X-API-Key"}'] = globalConfig.auth.token;
|
|
137
|
-
`,n+=` }
|
|
138
|
-
|
|
139
|
-
`),n+=" const response = await fetch(`${globalConfig.baseURL}${url}`, {\n",n+=` ...options,
|
|
129
|
+
`,n+=" const response = await fetch(`${globalConfig.baseURL}${url}`, {\n",n+=` ...options,
|
|
140
130
|
`,n+=` headers,
|
|
141
131
|
`,n+=` });
|
|
142
132
|
|
|
143
133
|
`,n+=` if (!response.ok) {
|
|
144
|
-
`,(c=
|
|
134
|
+
`,(c=a.errorHandling)!=null&&c.generateErrorClasses?(n+=` const errorData = await response.json().catch(() => ({}));
|
|
145
135
|
`,n+=` throw new ApiError(
|
|
146
136
|
`,n+=` errorData.message || response.statusText,
|
|
147
137
|
`,n+=` response.status,
|
|
@@ -152,64 +142,61 @@ ${T}`,t);}}cn(o,C);}),Ke=gn;});var $n,He,ce,_e,Ve,Ye,bn=se(()=>{$n=(s,o)=>{let t
|
|
|
152
142
|
`,n+=` return response.json();
|
|
153
143
|
`,n+=`}
|
|
154
144
|
|
|
155
|
-
`,
|
|
156
|
-
`,
|
|
157
|
-
`),n+=` * @method ${
|
|
158
|
-
`,n+=` * @path ${
|
|
159
|
-
`,
|
|
145
|
+
`,r.forEach(m=>{var D,T;let f=m.name,v=((D=m.parameters)==null?void 0:D.filter(I=>I.in==="path"))||[],k=((T=m.parameters)==null?void 0:T.filter(I=>I.in==="query"))||[],q=v.length>0,x=k.length>0,O=!!m.requestBody,G=m.responseType||"any";if(n+=`/**
|
|
146
|
+
`,m.summary&&(n+=` * ${m.summary}
|
|
147
|
+
`),n+=` * @method ${m.method.toUpperCase()}
|
|
148
|
+
`,n+=` * @path ${m.path}
|
|
149
|
+
`,m.tags&&m.tags.length>0&&(n+=` * @tags ${m.tags.join(", ")}
|
|
160
150
|
`),n+=` */
|
|
161
|
-
`,n+=`export async function ${
|
|
162
|
-
`,
|
|
163
|
-
`,
|
|
151
|
+
`,n+=`export async function ${f}(`,(q||x||O)&&(n+=`params: {
|
|
152
|
+
`,q&&(n+=` 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?"":"?";n+=` ${I.name}${z}: ${j};
|
|
164
154
|
`;}),n+=` };
|
|
165
|
-
`),x&&(n+=` query: ${
|
|
166
|
-
`),
|
|
155
|
+
`),x&&(n+=` query: ${m.queryType||"Record<string, any>"};
|
|
156
|
+
`),O&&(n+=` data: ${m.dtoType||"any"};
|
|
167
157
|
`),n+=`}
|
|
168
|
-
`),n+=`): Promise<${
|
|
169
|
-
`,
|
|
170
|
-
`;}let
|
|
171
|
-
`,
|
|
172
|
-
`:(n+=` if (query.${
|
|
173
|
-
`,n+=` queryParams.append('${
|
|
158
|
+
`),n+=`): Promise<${G}> {
|
|
159
|
+
`,q||x||O){let I=[];q&&I.push("url"),x&&I.push("query"),O&&I.push("data"),n+=` const { ${I.join(", ")} } = params;
|
|
160
|
+
`;}let R;if(q){let I=v.map(_=>`url.${_.name}`).join(", ");R=`${m.name}_endpoint(${I})`;}else R=`${m.name}_endpoint`;x?(n+=` const queryParams = new URLSearchParams();
|
|
161
|
+
`,k.forEach(I=>{I.required?n+=` queryParams.append('${I.name}', String(query.${I.name}));
|
|
162
|
+
`:(n+=` if (query.${I.name} !== undefined) {
|
|
163
|
+
`,n+=` queryParams.append('${I.name}', String(query.${I.name}));
|
|
174
164
|
`,n+=` }
|
|
175
|
-
`);}),n+=` const _url = \`\${${
|
|
176
|
-
`):n+=` const _url = ${
|
|
177
|
-
`,n+=` return fetchAPI<${
|
|
178
|
-
`,n+=` method: '${
|
|
179
|
-
`,
|
|
165
|
+
`);}),n+=` const _url = \`\${${R}}?\${queryParams.toString()}\`;
|
|
166
|
+
`):n+=` const _url = ${R};
|
|
167
|
+
`,n+=` return fetchAPI<${G}>(_url, {
|
|
168
|
+
`,n+=` method: '${m.method.toUpperCase()}',
|
|
169
|
+
`,O&&(n+=` body: JSON.stringify(data),
|
|
180
170
|
`),n+=` });
|
|
181
171
|
`,n+=`}
|
|
182
172
|
|
|
183
173
|
`;}),t&&(n+=`// Export all functions as a default object
|
|
184
174
|
`,n+=`const apiClient = {
|
|
185
175
|
`,n+=` setApiConfig,
|
|
186
|
-
`,
|
|
176
|
+
`,r.forEach(m=>{n+=` ${m.name},
|
|
187
177
|
`;}),n+=`};
|
|
188
178
|
|
|
189
179
|
`,n+=`export default apiClient;
|
|
190
|
-
`),n},
|
|
180
|
+
`),n},he=(r,a,t=false)=>{var s,c;let e=a.baseURL||"";a.auth;let n=`// Generated Axios API Client
|
|
191
181
|
`;n+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
192
182
|
|
|
193
183
|
`,n+=`import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
194
184
|
|
|
195
185
|
`,n+=`import type {
|
|
196
|
-
`;let
|
|
186
|
+
`;let l=new Set;return r.forEach(m=>{m.queryType&&l.add(m.queryType),m.dtoType&&l.add(m.dtoType),m.responseType&&l.add(m.responseType);}),l.forEach(m=>{n+=` ${m},
|
|
197
187
|
`;}),n+=`} from '../types';
|
|
198
188
|
|
|
199
189
|
`,n+=`import {
|
|
200
|
-
`,
|
|
190
|
+
`,r.forEach(m=>{n+=` ${m.name},
|
|
201
191
|
`;}),n+=`} from '../endpoints';
|
|
202
192
|
|
|
203
193
|
`,n+=`export interface ApiConfig {
|
|
204
194
|
`,n+=` baseURL?: string;
|
|
205
|
-
`,
|
|
206
|
-
`,n+=` token?: string;
|
|
207
|
-
`,n+=` };
|
|
208
|
-
`),n+=` headers?: Record<string, string>;
|
|
195
|
+
`,n+=` headers?: Record<string, string>;
|
|
209
196
|
`,n+=` timeout?: number;
|
|
210
197
|
`,n+=`}
|
|
211
198
|
|
|
212
|
-
`,(a
|
|
199
|
+
`,(s=a.errorHandling)!=null&&s.generateErrorClasses&&(n+=`export class ApiError extends Error {
|
|
213
200
|
`,n+=` constructor(
|
|
214
201
|
`,n+=` message: string,
|
|
215
202
|
`,n+=` public statusCode: number,
|
|
@@ -233,23 +220,11 @@ ${T}`,t);}}cn(o,C);}),Ke=gn;});var $n,He,ce,_e,Ve,Ye,bn=se(()=>{$n=(s,o)=>{let t
|
|
|
233
220
|
`,n+=` },
|
|
234
221
|
`,n+=` });
|
|
235
222
|
|
|
236
|
-
`,
|
|
237
|
-
`,n+=` this.client.interceptors.request.use((config) => {
|
|
238
|
-
`,r.type==="bearer"?(n+=` const token = this.getAuthToken();
|
|
239
|
-
`,n+=` if (token) {
|
|
240
|
-
`,n+=" config.headers.Authorization = `Bearer ${token}`;\n",n+=` }
|
|
241
|
-
`):r.type==="apiKey"&&r.in==="header"&&(n+=` const token = this.getAuthToken();
|
|
242
|
-
`,n+=` if (token) {
|
|
243
|
-
`,n+=` config.headers['${r.name||"X-API-Key"}'] = token;
|
|
244
|
-
`,n+=` }
|
|
245
|
-
`),n+=` return config;
|
|
246
|
-
`,n+=` });
|
|
247
|
-
|
|
248
|
-
`),n+=` // Response interceptor for error handling
|
|
223
|
+
`,n+=` // Response interceptor for error handling
|
|
249
224
|
`,n+=` this.client.interceptors.response.use(
|
|
250
225
|
`,n+=` (response) => response,
|
|
251
226
|
`,n+=` (error) => {
|
|
252
|
-
`,(c=
|
|
227
|
+
`,(c=a.errorHandling)!=null&&c.generateErrorClasses?(n+=` const message = error.response?.data?.message || error.message;
|
|
253
228
|
`,n+=` const statusCode = error.response?.status || 500;
|
|
254
229
|
`,n+=` throw new ApiError(message, statusCode, error.response?.data);
|
|
255
230
|
`):n+=` return Promise.reject(error);
|
|
@@ -257,41 +232,31 @@ ${T}`,t);}}cn(o,C);}),Ke=gn;});var $n,He,ce,_e,Ve,Ye,bn=se(()=>{$n=(s,o)=>{let t
|
|
|
257
232
|
`,n+=` );
|
|
258
233
|
`,n+=` }
|
|
259
234
|
|
|
260
|
-
`,
|
|
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>) {
|
|
235
|
+
`,n+=` updateConfig(config: Partial<ApiConfig>) {
|
|
271
236
|
`,n+=` Object.assign(this.client.defaults, config);
|
|
272
237
|
`,n+=` }
|
|
273
238
|
|
|
274
|
-
`,
|
|
275
|
-
`,
|
|
276
|
-
`),n+=` * @method ${
|
|
277
|
-
`,n+=` * @path ${
|
|
278
|
-
`,
|
|
239
|
+
`,r.forEach(m=>{var R,D;let f=m.name,v=((R=m.parameters)==null?void 0:R.filter(T=>T.in==="path"))||[],k=((D=m.parameters)==null?void 0:D.filter(T=>T.in==="query"))||[],q=v.length>0,x=k.length>0,O=!!m.requestBody,G=m.responseType||"any";if(n+=` /**
|
|
240
|
+
`,m.summary&&(n+=` * ${m.summary}
|
|
241
|
+
`),n+=` * @method ${m.method.toUpperCase()}
|
|
242
|
+
`,n+=` * @path ${m.path}
|
|
243
|
+
`,m.tags&&m.tags.length>0&&(n+=` * @tags ${m.tags.join(", ")}
|
|
279
244
|
`),n+=` */
|
|
280
|
-
`,n+=` async ${
|
|
281
|
-
`,
|
|
282
|
-
`,
|
|
245
|
+
`,n+=` async ${f}(`,(q||x||O)&&(n+=`params: {
|
|
246
|
+
`,q&&(n+=` 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?"":"?";n+=` ${T.name}${j}: ${_};
|
|
283
248
|
`;}),n+=` };
|
|
284
|
-
`),x&&(n+=` query: ${
|
|
285
|
-
`),
|
|
286
|
-
`),n+=" }"),n+=`): Promise<${
|
|
287
|
-
`,
|
|
288
|
-
`;}if(
|
|
289
|
-
`;}else n+=` const _url = ${
|
|
249
|
+
`),x&&(n+=` query: ${m.queryType||"Record<string, any>"};
|
|
250
|
+
`),O&&(n+=` data: ${m.dtoType||"any"};
|
|
251
|
+
`),n+=" }"),n+=`): Promise<${G}> {
|
|
252
|
+
`,q||x||O){let T=[];q&&T.push("url"),x&&T.push("query"),O&&T.push("data"),n+=` const { ${T.join(", ")} } = params;
|
|
253
|
+
`;}if(q){let T=v.map(I=>`url.${I.name}`).join(", ");n+=` const _url = ${m.name}(${T});
|
|
254
|
+
`;}else n+=` const _url = ${m.name};
|
|
290
255
|
`;n+=` const config: AxiosRequestConfig = {};
|
|
291
256
|
`,x&&(n+=` config.params = { ...query };
|
|
292
|
-
`),n+=` const response = await this.client.${
|
|
257
|
+
`),n+=` const response = await this.client.${m.method.toLowerCase()}<${G}>(
|
|
293
258
|
`,n+=` _url,
|
|
294
|
-
`,
|
|
259
|
+
`,O?n+=` data,
|
|
295
260
|
config
|
|
296
261
|
`:n+=` config
|
|
297
262
|
`,n+=` );
|
|
@@ -303,73 +268,107 @@ ${T}`,t);}}cn(o,C);}),Ke=gn;});var $n,He,ce,_e,Ve,Ye,bn=se(()=>{$n=(s,o)=>{let t
|
|
|
303
268
|
`,t?n+=`export default ApiClient;
|
|
304
269
|
`:(n+=`export const apiClient = new ApiClient();
|
|
305
270
|
`,n+=`export default apiClient;
|
|
306
|
-
`),n},
|
|
307
|
-
`;
|
|
271
|
+
`),n},et=(r,a)=>{var c,m;let t=((c=a.reactQuery)==null?void 0:c.version)||5,e=((m=a.reactQuery)==null?void 0:m.mutations)!==false,o=!!(a.reactQuery&&a.reactQuery.infiniteQueries&&!a.reactQuery.infiniteQueries.disable),n=`// Generated React Query Hooks
|
|
272
|
+
`;n+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
308
273
|
|
|
309
|
-
`;let
|
|
274
|
+
`;let l=e&&r.some(f=>["POST","PUT","PATCH","DELETE"].includes(f.method.toUpperCase()));if(t===5){let f=l?`import { useQuery, useMutation, UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
310
275
|
`:`import { useQuery, UseQueryOptions } from '@tanstack/react-query';
|
|
311
|
-
|
|
276
|
+
`;o&&(f=f.replace("@tanstack/react-query';\\n",`@tanstack/react-query';
|
|
277
|
+
import { useInfiniteQuery, UseInfiniteQueryOptions } from '@tanstack/react-query';
|
|
278
|
+
`)),n+=f;}else {let f=l?`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
|
+
`;o&&(f=f.replace("react-query';\\n",`react-query';
|
|
281
|
+
import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query';
|
|
282
|
+
`)),n+=f;}n+=`
|
|
283
|
+
`,n+=`import apiClient from './client';
|
|
284
|
+
`,n+=`import type {
|
|
285
|
+
`;let s=new Set;return r.forEach(f=>{f.queryType&&s.add(f.queryType),f.dtoType&&s.add(f.dtoType),f.responseType&&s.add(f.responseType);}),s.forEach(f=>{n+=` ${f},
|
|
286
|
+
`;}),n+=`} from '../types';
|
|
287
|
+
|
|
288
|
+
`,r.forEach(f=>{var I,_;let v=f.method.toUpperCase(),k=v==="GET",q=["POST","PUT","PATCH","DELETE"].includes(v),x=((I=f.parameters)==null?void 0:I.filter(j=>j.in==="path"))||[],O=((_=f.parameters)==null?void 0:_.filter(j=>j.in==="query"))||[],G=x.length>0,R=O.length>0,D=!!f.requestBody,T=f.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"))&&o,pe=`use${f.name.charAt(0).toUpperCase()+f.name.slice(1)}`;if(n+=`/**
|
|
289
|
+
`,f.summary&&(n+=` * ${f.summary}
|
|
290
|
+
`),n+=` * @method ${v}
|
|
291
|
+
`,n+=` * @path ${f.path}
|
|
292
|
+
`,f.tags&&f.tags.length>0&&(n+=` * @tags ${f.tags.join(", ")}
|
|
293
|
+
`),n+=` */
|
|
294
|
+
`,G||R?(n+=`export function ${pe}(
|
|
295
|
+
`,n+=` params: {
|
|
296
|
+
`,G&&(n+=` 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?"":"?";n+=` ${ne.name}${Ce}: ${we};
|
|
298
|
+
`;}),n+=` };
|
|
299
|
+
`),R&&(n+=` query: ${f.queryType||"Record<string, any>"};
|
|
300
|
+
`),n+=` },
|
|
301
|
+
`,n+=` options?: Omit<UseQueryOptions<${T}>, 'queryKey' | 'queryFn'>
|
|
302
|
+
`,n+=`) {
|
|
303
|
+
`,n+=` return useQuery({
|
|
304
|
+
`,n+=` queryKey: ['${f.name}', params],
|
|
305
|
+
`,n+=` queryFn: () => apiClient.${f.name}(params),
|
|
306
|
+
`,n+=` ...options,
|
|
307
|
+
`,n+=` });
|
|
308
|
+
`,n+=`}
|
|
309
|
+
|
|
310
|
+
`):(n+=`export function ${pe}(
|
|
311
|
+
`,n+=` options?: Omit<UseQueryOptions<${T}>, 'queryKey' | 'queryFn'>
|
|
312
|
+
`,n+=`) {
|
|
313
|
+
`,n+=` return useQuery({
|
|
314
|
+
`,n+=` queryKey: ['${f.name}'],
|
|
315
|
+
`,n+=` queryFn: () => apiClient.${f.name}(),
|
|
316
|
+
`,n+=` ...options,
|
|
317
|
+
`,n+=` });
|
|
318
|
+
`,n+=`}
|
|
319
|
+
|
|
320
|
+
`),le){let ne=`${pe}Infinite`;G||R?(n+=`export function ${ne}(
|
|
321
|
+
`,n+=` params: {
|
|
322
|
+
`,G&&(n+=` 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?"":"?";n+=` ${ue.name}${Re}: ${Ce};
|
|
324
|
+
`;}),n+=` };
|
|
325
|
+
`),R&&(n+=` query: ${f.queryType||"Record<string, any>"};
|
|
326
|
+
`),n+=` },
|
|
327
|
+
`,n+=` options?: Omit<UseInfiniteQueryOptions<${T}, Error, ${T}>, 'queryKey' | 'queryFn'>
|
|
328
|
+
`,n+=`) {
|
|
329
|
+
`,n+=` return useInfiniteQuery({
|
|
330
|
+
`,n+=` queryKey: ['${f.name}', params],
|
|
331
|
+
`,n+=` queryFn: ({ pageParam = 1 }) => apiClient.${f.name}({ ...params, query: { ...(params.query || {}), page: pageParam } }),
|
|
332
|
+
`,n+=` getNextPageParam: (lastPage) => lastPage?.nextPage ?? lastPage?.nextCursor ?? null,
|
|
333
|
+
`,n+=` ...options,
|
|
334
|
+
`,n+=` });
|
|
335
|
+
`,n+=`}
|
|
336
|
+
|
|
337
|
+
`):(n+=`export function ${ne}(
|
|
338
|
+
`,n+=` options?: Omit<UseInfiniteQueryOptions<${T}, Error, ${T}>, 'queryKey' | 'queryFn'>
|
|
339
|
+
`,n+=`) {
|
|
340
|
+
`,n+=` return useInfiniteQuery({
|
|
341
|
+
`,n+=` queryKey: ['${f.name}'],
|
|
342
|
+
`,n+=` queryFn: ({ pageParam = 1 }) => apiClient.${f.name}({ query: { page: pageParam } }),
|
|
343
|
+
`,n+=` getNextPageParam: (lastPage) => lastPage?.nextPage ?? lastPage?.nextCursor ?? null,
|
|
344
|
+
`,n+=` ...options,
|
|
345
|
+
`,n+=` });
|
|
346
|
+
`,n+=`}
|
|
347
|
+
|
|
348
|
+
`);}}else if(q&&e){let j=`use${f.name.charAt(0).toUpperCase()+f.name.slice(1)}`;n+=`/**
|
|
349
|
+
`,f.summary&&(n+=` * ${f.summary}
|
|
350
|
+
`),n+=` * @method ${v}
|
|
351
|
+
`,n+=` * @path ${f.path}
|
|
352
|
+
`,f.tags&&f.tags.length>0&&(n+=` * @tags ${f.tags.join(", ")}
|
|
353
|
+
`),n+=` */
|
|
354
|
+
`;let z="void";(G||R||D)&&(z=`{
|
|
355
|
+
`,G&&(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: ${f.queryType||"Record<string, any>"};
|
|
359
|
+
`),D&&(z+=` data: ${f.dtoType||"any"};
|
|
360
|
+
`),z+=" }"),n+=`export function ${j}(
|
|
361
|
+
`,n+=` options?: Omit<UseMutationOptions<${T}, Error, ${z}>, 'mutationFn'>
|
|
362
|
+
`,n+=`) {
|
|
363
|
+
`,n+=` return useMutation({
|
|
364
|
+
`,n+=" mutationFn: (",z!=="void"&&(n+=`variables: ${z}`),n+=`) => {
|
|
365
|
+
`,n+=` return apiClient.${f.name}(${z!=="void"?"variables":""});
|
|
366
|
+
`,n+=` },
|
|
367
|
+
`,n+=` ...options,
|
|
368
|
+
`,n+=` });
|
|
369
|
+
`,n+=`}
|
|
370
|
+
|
|
371
|
+
`;}}),n},tt=(r,a)=>{var l;let t=((l=a.swr)==null?void 0:l.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,226 +563,226 @@ ${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
|
-
`,t&&
|
|
566
|
+
`,t&&r.some(s=>["POST","PUT","PATCH","DELETE"].includes(s.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 n=new Set;return
|
|
570
|
+
`;let n=new Set;return r.forEach(s=>{s.queryType&&n.add(s.queryType),s.dtoType&&n.add(s.dtoType),s.responseType&&n.add(s.responseType);}),n.forEach(s=>{e+=` ${s},
|
|
572
571
|
`;}),e+=`} from '../types';
|
|
573
572
|
|
|
574
|
-
`,
|
|
575
|
-
`,
|
|
573
|
+
`,r.forEach(s=>{var R,D;let c=s.method.toUpperCase(),m=c==="GET",f=["POST","PUT","PATCH","DELETE"].includes(c),v=((R=s.parameters)==null?void 0:R.filter(T=>T.in==="path"))||[],k=((D=s.parameters)==null?void 0:D.filter(T=>T.in==="query"))||[],q=v.length>0,x=k.length>0,O=!!s.requestBody,G=s.responseType||"any";if(m){let T=`use${s.name.charAt(0).toUpperCase()+s.name.slice(1)}`;e+=`/**
|
|
574
|
+
`,s.summary&&(e+=` * ${s.summary}
|
|
576
575
|
`),e+=` * @method ${c}
|
|
577
|
-
`,e+=` * @path ${
|
|
578
|
-
`,
|
|
576
|
+
`,e+=` * @path ${s.path}
|
|
577
|
+
`,s.tags&&s.tags.length>0&&(e+=` * @tags ${s.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: ${s.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+=` ['${s.name}', params],
|
|
590
|
+
`,e+=` () => apiClient.${s.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+=` '${s.name}',
|
|
598
|
+
`,e+=` () => apiClient.${s.name}(),
|
|
600
599
|
`,e+=` config
|
|
601
600
|
`,e+=` );
|
|
602
601
|
`),e+=`}
|
|
603
602
|
|
|
604
|
-
`;}else if(
|
|
605
|
-
`,
|
|
603
|
+
`;}else if(f&&t){let T=`use${s.name.charAt(0).toUpperCase()+s.name.slice(1)}`;e+=`/**
|
|
604
|
+
`,s.summary&&(e+=` * ${s.summary}
|
|
606
605
|
`),e+=` * @method ${c}
|
|
607
|
-
`,e+=` * @path ${
|
|
608
|
-
`,
|
|
606
|
+
`,e+=` * @path ${s.path}
|
|
607
|
+
`,s.tags&&s.tags.length>0&&(e+=` * @tags ${s.tags.join(", ")}
|
|
609
608
|
`),e+=` */
|
|
610
|
-
`;let
|
|
611
|
-
`,
|
|
612
|
-
`,
|
|
613
|
-
`;}),
|
|
614
|
-
`),x&&(
|
|
615
|
-
`),
|
|
616
|
-
`),
|
|
617
|
-
`,e+=` config?: SWRMutationConfiguration<${
|
|
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: ${s.queryType||"Record<string, any>"};
|
|
614
|
+
`),O&&(I+=` data: ${s.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+=` '${s.name}',
|
|
620
|
+
`,e+=" async (_, ",I!=="void"&&(e+=`{ arg }: ${_}`),e+=`) => {
|
|
621
|
+
`,e+=` return apiClient.${s.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 n=new Set;return
|
|
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
|
-
`,
|
|
685
|
-
`;
|
|
686
|
-
`,
|
|
687
|
-
|
|
688
|
-
`,
|
|
689
|
-
`;}),
|
|
627
|
+
`;}}),e},nt=(r,a)=>{var l;let t=((l=a.rtkQuery)==null?void 0:l.apiName)||"api",e=a.baseURL||"",o=`// Generated RTK Query API Slice
|
|
628
|
+
`;o+=`// This file was auto-generated. Add custom code in the marked sections.
|
|
629
|
+
|
|
630
|
+
`,o+=`import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
|
|
631
|
+
|
|
632
|
+
`,o+=`import type {
|
|
633
|
+
`;let n=new Set;return r.forEach(s=>{s.queryType&&n.add(s.queryType),s.dtoType&&n.add(s.dtoType),s.responseType&&n.add(s.responseType);}),n.forEach(s=>{o+=` ${s},
|
|
634
|
+
`;}),o+=`} from '../types';
|
|
635
|
+
|
|
636
|
+
`,o+=`import {
|
|
637
|
+
`,r.forEach(s=>{o+=` ${s.name},
|
|
638
|
+
`;}),o+=`} from '../endpoints';
|
|
639
|
+
|
|
640
|
+
`,o+=`const ${t}Api = createApi({
|
|
641
|
+
`,o+=` reducerPath: '${t}Api',
|
|
642
|
+
`,o+=` baseQuery: fetchBaseQuery({
|
|
643
|
+
`,o+=` baseUrl: '${e}',
|
|
644
|
+
`,a.auth&&(o+=` prepareHeaders: (headers, { getState }) => {
|
|
645
|
+
`,o+=` // Get token from your auth state
|
|
646
|
+
`,o+=` // const token = (getState() as RootState).auth.token;
|
|
647
|
+
`,o+=` // if (token) {
|
|
648
|
+
`,a.auth.type==="bearer"?o+=" // headers.set('Authorization', `Bearer ${token}`);\n":a.auth.type==="apiKey"&&a.auth.in==="header"&&(o+=` // headers.set('${a.auth.name||"X-API-Key"}', token);
|
|
649
|
+
`),o+=` // }
|
|
650
|
+
`,o+=` return headers;
|
|
651
|
+
`,o+=` },
|
|
652
|
+
`),o+=` }),
|
|
653
|
+
`,o+=` tagTypes: [${[...new Set(r.flatMap(s=>s.tags||[]))].map(s=>`'${s}'`).join(", ")}],
|
|
654
|
+
`,o+=` endpoints: (builder) => ({
|
|
655
|
+
`,r.forEach((s,c)=>{var D,T;let m=s.method.toUpperCase(),f=m==="GET",v=((D=s.parameters)==null?void 0:D.filter(I=>I.in==="path"))||[],k=((T=s.parameters)==null?void 0:T.filter(I=>I.in==="query"))||[],q=v.length>0,x=k.length>0,O=!!s.requestBody,G=s.responseType||"any";o+=` ${s.name}: builder.${f?"query":"mutation"}<
|
|
656
|
+
`,o+=` ${G},
|
|
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: ${s.queryType||"Record<string, any>"};
|
|
662
|
+
`),O&&(R+=` data: ${s.dtoType||"any"};
|
|
663
|
+
`),R+=" }"),o+=` ${R}
|
|
664
|
+
`,o+=` >({
|
|
665
|
+
`,o+=" query: (",R!=="void"&&(o+="arg"),o+=`) => {
|
|
666
|
+
`,q){let I=v.map(_=>`arg.url.${_.name}`).join(", ");o+=` const url = ${s.name}(${I});
|
|
667
|
+
`;}else o+=` const url = ${s.name};
|
|
668
|
+
`;o+=` return {
|
|
669
|
+
`,o+=` url,
|
|
670
|
+
`,o+=` method: '${m}',
|
|
671
|
+
`,x&&(o+=` params: arg.query,
|
|
672
|
+
`),O&&(o+=` body: arg.data,
|
|
673
|
+
`),o+=` };
|
|
674
|
+
`,o+=` },
|
|
675
|
+
`,s.tags&&s.tags.length>0&&(f?o+=` providesTags: ['${s.tags[0]}'],
|
|
676
|
+
`:o+=` invalidatesTags: ['${s.tags[0]}'],
|
|
677
|
+
`),o+=` })${c<r.length-1?",":""}
|
|
678
|
+
`;}),o+=` }),
|
|
679
|
+
`,o+=`});
|
|
680
|
+
|
|
681
|
+
`,o+=`export default ${t}Api;
|
|
682
|
+
|
|
683
|
+
`,o};});var Dn,In,Y,Jn,Hn,xn=ae(()=>{Cn();ke();Dn=(r,a)=>{var t,e;if((t=a==null?void 0:a.folderSplit)!=null&&t.customFolder){let o=a.folderSplit.customFolder({method:r.method,path:r.path,tags:r.tags,operationId:r.operationId,summary:r.summary});if(o)return o}return (e=a==null?void 0:a.folderSplit)!=null&&e.byTags&&r.tags&&r.tags.length>0?r.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},In=(r,a,t,e,o)=>te(null,null,function*(){let n=bn(r,t);if(n.length===0)return;let l=t.type||"fetch";t.outputDir||W__default.default.join(o,e,"client");let c=!!(a!=null&&a.folderSplit&&(a.folderSplit.byTags||a.folderSplit.customFolder));if(`${l}${n.length}`,c){let f={};n.forEach(q=>{let x=Dn(q,a);f[x]||(f[x]=[]),f[x].push(q);});let v=Object.keys(f);for(let[q,x]of Object.entries(f)){let O=W__default.default.join(o,e,q);yield ie__default.default.promises.mkdir(O,{recursive:true}),`${l}${q}${x.length}`,yield Jn(x,a,t,O,l,q,true);}let k=W__default.default.join(o,e);yield Hn(k,v,l,a);return}let m=W__default.default.join(o,e);switch(yield ie__default.default.promises.mkdir(m,{recursive:true}),l){case "fetch":let f=Xe(n,t);f=f.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield Y(W__default.default.join(m,"clients.ts"),f,a);break;case "axios":let v=he(n,t,false);v=v.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield Y(W__default.default.join(m,"clients.ts"),v,a);break;case "react-query":let k=he(n,t,false);k=k.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield Y(W__default.default.join(m,"clients.ts"),k,a);let q=et(n,t);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(m,"hooks.ts"),q,a);break;case "swr":let x=he(n,t,false);x=x.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield Y(W__default.default.join(m,"clients.ts"),x,a);let O=tt(n,t);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(m,"hooks.ts"),O,a);break;case "rtk-query":let G=nt(n,t);G=G.replace("} from '../types';","} from './types';").replace("} from '../endpoints';","} from './endpoints';"),yield Y(W__default.default.join(m,"api.ts"),G,a);break;default:throw new Error(`Unknown client type: ${l}`)}}),Y=(r,a,t)=>te(null,null,function*(){var l,s,c,m;if(!(((l=t==null?void 0:t.customCode)==null?void 0:l.enabled)!==false)){yield ie__default.default.promises.writeFile(r,a);return}let o=null;try{o=yield ie__default.default.promises.readFile(r,"utf-8");}catch(f){}let n=exports.mergeCustomCode(a,o,{position:((s=t==null?void 0:t.customCode)==null?void 0:s.position)||"bottom",markerText:(c=t==null?void 0:t.customCode)==null?void 0:c.markerText,includeInstructions:(m=t==null?void 0:t.customCode)==null?void 0:m.includeInstructions});yield ie__default.default.promises.writeFile(r,n);}),Jn=(r,a,t,e,o,n,l=false)=>te(null,null,function*(){let s="",c="",m=l?"./types":"../types",f=l?"./endpoints":"../endpoints";switch(o){case "fetch":s=Xe(r,t,l),s=s.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${f}';`),yield Y(W__default.default.join(e,"client.ts"),s,a);break;case "axios":s=he(r,t,l),s=s.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${f}';`),yield Y(W__default.default.join(e,"client.ts"),s,a);break;case "react-query":if(s=he(r,t,l),s=s.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${f}';`),yield Y(W__default.default.join(e,"client.ts"),s,a),c=et(r,t),c=c.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${f}';`),l){let k=n.replace(/-/g,"_");c=c.replace("import apiClient from './client';",`import { ${k}Client as apiClient } from '../clients';`);}yield Y(W__default.default.join(e,"hooks.ts"),c,a);break;case "swr":if(s=he(r,t,l),s=s.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${f}';`),yield Y(W__default.default.join(e,"client.ts"),s,a),c=tt(r,t),c=c.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${f}';`),l){let k=n.replace(/-/g,"_");c=c.replace("import apiClient from './client';",`import { ${k}Client as apiClient } from '../clients';`);}yield Y(W__default.default.join(e,"hooks.ts"),c,a);break;case "rtk-query":let v=l?ve(se({},t),{rtkQuery:ve(se({},t.rtkQuery),{apiName:n.replace(/-/g,"_")})}):t;c=nt(r,v),c=c.replace("} from '../types';",`} from '${m}';`).replace("} from '../endpoints';",`} from '${f}';`),yield Y(W__default.default.join(e,"api.ts"),c,a);break;default:throw new Error(`Unknown client type: ${o}`)}}),Hn=(r,a,t,e)=>te(null,null,function*(){var n;if(t==="rtk-query"){let l=`// Generated RTK Query APIs
|
|
684
|
+
`;l+=`// This file was auto-generated.
|
|
685
|
+
`,l+=`// Aggregates all API slices for easy Redux store setup
|
|
686
|
+
|
|
687
|
+
`,a.forEach(s=>{let c=s.replace(/-/g,"_");l+=`import ${c}Api from './${s}/api';
|
|
688
|
+
`;}),l+=`
|
|
690
689
|
// Export all API slices
|
|
691
|
-
`,
|
|
692
|
-
`;}),
|
|
690
|
+
`,a.forEach(s=>{let c=s.replace(/-/g,"_");l+=`export { default as ${c}Api } from './${s}/api';
|
|
691
|
+
`;}),l+=`
|
|
693
692
|
/**
|
|
694
|
-
`,
|
|
695
|
-
`,
|
|
696
|
-
`,
|
|
697
|
-
`,
|
|
698
|
-
`,
|
|
699
|
-
`,
|
|
700
|
-
`,
|
|
701
|
-
`,
|
|
702
|
-
`,
|
|
703
|
-
`,
|
|
704
|
-
`,
|
|
705
|
-
`,
|
|
706
|
-
`,
|
|
707
|
-
`,
|
|
708
|
-
`,
|
|
709
|
-
`;}),
|
|
710
|
-
`,
|
|
711
|
-
`,
|
|
712
|
-
`;}),
|
|
713
|
-
`,
|
|
714
|
-
`,yield
|
|
715
|
-
`;if(
|
|
716
|
-
`,
|
|
717
|
-
|
|
718
|
-
`,t==="fetch"?
|
|
719
|
-
`;}):(
|
|
720
|
-
`;}),
|
|
693
|
+
`,l+=` * Configure Redux store with all API slices
|
|
694
|
+
`,l+=` *
|
|
695
|
+
`,l+=` * @example
|
|
696
|
+
`,l+=` * import { configureStore } from '@reduxjs/toolkit';
|
|
697
|
+
`,l+=` * import { setupApiStore } from './apis';
|
|
698
|
+
`,l+=` *
|
|
699
|
+
`,l+=` * export const store = configureStore({
|
|
700
|
+
`,l+=` * reducer: setupApiStore.reducer,
|
|
701
|
+
`,l+=` * middleware: (getDefaultMiddleware) =>
|
|
702
|
+
`,l+=` * getDefaultMiddleware().concat(setupApiStore.middleware),
|
|
703
|
+
`,l+=` * });
|
|
704
|
+
`,l+=` */
|
|
705
|
+
`,l+=`export const setupApiStore = {
|
|
706
|
+
`,l+=` reducer: {
|
|
707
|
+
`,a.forEach(s=>{let c=s.replace(/-/g,"_");l+=` [${c}Api.reducerPath]: ${c}Api.reducer,
|
|
708
|
+
`;}),l+=` },
|
|
709
|
+
`,l+=` middleware: [
|
|
710
|
+
`,a.forEach(s=>{let c=s.replace(/-/g,"_");l+=` ${c}Api.middleware,
|
|
711
|
+
`;}),l+=` ],
|
|
712
|
+
`,l+=`};
|
|
713
|
+
`,yield Y(W__default.default.join(r,"apis.ts"),l,e);return}let o=`// Generated API Clients
|
|
714
|
+
`;if(o+=`// This file was auto-generated.
|
|
715
|
+
`,o+=`// Centralized client instances and configuration
|
|
716
|
+
|
|
717
|
+
`,t==="fetch"?a.forEach(l=>{let s=l.replace(/-/g,"_");o+=`export { default as ${s}Client } from './${l}/client';
|
|
718
|
+
`;}):(a.forEach(l=>{let s=l.replace(/-/g,"_"),c=`${s.charAt(0).toUpperCase()+s.slice(1)}ApiClient`;o+=`import ${c} from './${l}/client';
|
|
719
|
+
`;}),o+=`
|
|
721
720
|
// Create client instances
|
|
722
|
-
`,
|
|
723
|
-
`;})),t==="fetch"&&(
|
|
721
|
+
`,a.forEach(l=>{let s=l.replace(/-/g,"_"),c=`${s.charAt(0).toUpperCase()+s.slice(1)}ApiClient`;o+=`export const ${s}Client = new ${c}();
|
|
722
|
+
`;})),t==="fetch"&&(o+=`
|
|
724
723
|
// Import clients for aggregation
|
|
725
|
-
`,
|
|
726
|
-
`;})),
|
|
724
|
+
`,a.forEach(l=>{let s=l.replace(/-/g,"_");o+=`import ${s}_client from './${l}/client';
|
|
725
|
+
`;})),o+=`
|
|
727
726
|
// Aggregate all client instances
|
|
728
|
-
`,
|
|
729
|
-
`,
|
|
730
|
-
`:
|
|
731
|
-
`;}),
|
|
727
|
+
`,o+=`export const clients = {
|
|
728
|
+
`,a.forEach(l=>{let s=l.replace(/-/g,"_");t==="fetch"?o+=` ${s}: ${s}_client,
|
|
729
|
+
`:o+=` ${s}: ${s}Client,
|
|
730
|
+
`;}),o+=`};
|
|
732
731
|
|
|
733
|
-
`,t==="axios"?(
|
|
732
|
+
`,t==="axios"?(o+=`
|
|
734
733
|
/**
|
|
735
|
-
`,
|
|
736
|
-
`,
|
|
737
|
-
`,
|
|
738
|
-
`,
|
|
739
|
-
`,
|
|
740
|
-
`,
|
|
741
|
-
`,
|
|
742
|
-
`,
|
|
743
|
-
`,
|
|
744
|
-
`;}),
|
|
745
|
-
|
|
746
|
-
`):t==="fetch"&&(
|
|
734
|
+
`,o+=` * Configure all API clients at once
|
|
735
|
+
`,o+=` * @param config - Configuration to apply to all clients
|
|
736
|
+
`,o+=` */
|
|
737
|
+
`,o+=`export const configureAllClients = (config: {
|
|
738
|
+
`,o+=` baseURL?: string;
|
|
739
|
+
`,o+=` headers?: Record<string, string>;
|
|
740
|
+
`,o+=` timeout?: number;
|
|
741
|
+
`,o+=`}) => {
|
|
742
|
+
`,a.forEach(l=>{let s=l.replace(/-/g,"_");o+=` ${s}Client.updateConfig(config);
|
|
743
|
+
`;}),o+=`};
|
|
744
|
+
|
|
745
|
+
`):t==="fetch"&&(o+=`
|
|
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
|
|
771
|
-
`;
|
|
772
|
-
`,
|
|
773
|
-
|
|
774
|
-
`,
|
|
775
|
-
`;}),
|
|
747
|
+
`,o+=` * Configure all API clients at once
|
|
748
|
+
`,o+=` * @param config - Configuration to apply to all clients
|
|
749
|
+
`,o+=` */
|
|
750
|
+
`,o+=`export const configureAllClients = (config: {
|
|
751
|
+
`,o+=` baseURL?: string;
|
|
752
|
+
`,o+=` headers?: Record<string, string>;
|
|
753
|
+
`,o+=` auth?: { token?: string };
|
|
754
|
+
`,o+=`}) => {
|
|
755
|
+
`,a.forEach(l=>{let s=l.replace(/-/g,"_");o+=` ${s}_client.setApiConfig(config);
|
|
756
|
+
`;}),o+=`};
|
|
757
|
+
|
|
758
|
+
`),o+=`// Example usage:
|
|
759
|
+
`,o+=`// import { configureAllClients, clients } from './clients';
|
|
760
|
+
`,o+=`//
|
|
761
|
+
`,o+=`// // Configure all clients at once
|
|
762
|
+
`,o+=`// configureAllClients({
|
|
763
|
+
`,o+=`// baseURL: 'https://api.example.com',
|
|
764
|
+
`,o+=`// timeout: 10000,
|
|
765
|
+
`,o+=`// });
|
|
766
|
+
`,o+=`//
|
|
767
|
+
`,o+=`// // Use specific client
|
|
768
|
+
`,o+=`// const data = await clients.${(n=a[0])==null?void 0:n.replace(/-/g,"_")}.someMethod(...);
|
|
769
|
+
`,yield Y(W__default.default.join(r,"clients.ts"),o,e),t==="react-query"||t==="swr"){let l=`// Generated Hooks Aggregator
|
|
770
|
+
`;l+=`// This file was auto-generated.
|
|
771
|
+
`,l+=`// Aggregates all folder-split hooks
|
|
772
|
+
|
|
773
|
+
`,a.forEach(s=>{l+=`export * from './${s}/hooks';
|
|
774
|
+
`;}),l+=`
|
|
776
775
|
// Example usage:
|
|
777
|
-
`,
|
|
778
|
-
`,yield
|
|
776
|
+
`,l+=`// import { useGetSomething } from './hooks';
|
|
777
|
+
`,yield Y(W__default.default.join(r,"hooks.ts"),l,e);}});});var wn=ae(()=>{});var En={};on(En,{interactiveInit:()=>Kn});function Kn(){return te(this,null,function*(){try{let r=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:s=>s==="url"?"text":null,name:"apiUrl",message:"Enter the OpenAPI specification URL:",validate:s=>s.startsWith("http://")||s.startsWith("https://")?!0:"Please enter a valid URL starting with http:// or https://"},{type:(s,c)=>c.apiSource==="file"?"text":null,name:"apiFile",message:"Enter the path to your OpenAPI file:",validate:s=>s.trim()!==""?!0:"Please enter a valid file path"},{type:"text",name:"apiName",message:"What would you like to name this API?",initial:"myapi",validate:s=>/^[a-zA-Z0-9_-]+$/.test(s)?!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:s=>{if(!s||s.trim()==="")return "Output folder cannot be empty";let c=W__default.default.normalize(s);if(c==="/"||c==="C:\\"||c==="\\")return "Cannot use filesystem root directory. Please use a project subfolder like './src/api'";if(W__default.default.isAbsolute(s)){let m=process.cwd();if(!s.startsWith(m))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:s=>s?"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:s=>s?"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:s=>s?"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")}}),a={refetchInterval:r.refetchInterval||void 0,folder:r.outputFolder,api:{[r.apiName]:r.apiUrl||r.apiFile}};r.enableFolderSplit&&(a.folderSplit={byTags:!0}),a.types={name:{prefix:r.typesPrefix||"",useOperationId:r.typesUseOperationId}},a.endpoints={name:{useOperationId:r.typesUseOperationId},doc:{showCurl:r.showCurlInDocs}},r.excludeEndpointsByTags&&r.excludeTags&&(a.endpoints.exclude={tags:r.excludeTags.split(",").map(s=>s.trim())}),r.generateClient&&r.clientType&&(a.clientGeneration={enabled:!0,type:r.clientType,outputDir:W__default.default.join(r.outputFolder,r.apiName,"client")},r.clientType==="react-query"?a.clientGeneration.reactQuery={version:5,mutations:!0}:r.clientType==="swr"&&(a.clientGeneration.swr={mutations:!0})),r.enableValidation&&r.validationLibrary&&(a.validations={library:r.validationLibrary}),r.enableCustomCode&&(a.customCode={enabled:!0,position:"bottom"});let t,e;r.configFormat==="json"?(e="openapi.sync.json",t=JSON.stringify(a,null,2)):r.configFormat==="typescript"?(e="openapi.sync.ts",t=`import { IConfig } from "openapi-sync";
|
|
779
778
|
|
|
780
|
-
const config: IConfig = ${JSON.stringify(
|
|
779
|
+
const config: IConfig = ${JSON.stringify(a,null,2)};
|
|
781
780
|
|
|
782
781
|
export default config;
|
|
783
|
-
`):(e="openapi.sync.js",t=`module.exports = ${JSON.stringify(
|
|
784
|
-
`);let
|
|
782
|
+
`):(e="openapi.sync.js",t=`module.exports = ${JSON.stringify(a,null,2)};
|
|
783
|
+
`);let o=W__default.default.join(process.cwd(),e);if(ie__default.default.existsSync(o)&&!(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(o,t,"utf-8"),re||`${e}`;let n=W__default.default.isAbsolute(r.outputFolder)?r.outputFolder:W__default.default.join(process.cwd(),r.outputFolder);if(!ie__default.default.existsSync(n))try{ie__default.default.mkdirSync(n,{recursive:!0}),re||`${r.outputFolder}`;}catch(s){re||`${s.message}`;}let l=W__default.default.join(process.cwd(),".gitignore");if(ie__default.default.existsSync(l)&&(ie__default.default.readFileSync(l,"utf-8").includes(r.outputFolder)||ie__default.default.appendFileSync(l,`
|
|
785
784
|
# OpenAPI Sync generated files
|
|
786
|
-
${
|
|
787
|
-
`)),
|
|
788
|
-
\u274C Error during sync:`,
|
|
789
|
-
\u274C Error during setup:`,
|
|
785
|
+
${r.outputFolder}
|
|
786
|
+
`)),re||(`${e}`,r.generateClient&&r.clientType&&(r.clientType==="axios"||r.clientType==="react-query"||r.clientType==="swr"||r.clientType),r.enableValidation&&r.validationLibrary&&(r.generateClient,`${r.validationLibrary}`)),r.runSync&&!re)try{let{Init:s,GenerateClient:c}=yield Promise.resolve().then(()=>(On(),An));yield s({refetchInterval:r.refetchInterval}),r.generateClient&&r.clientType&&(yield c({type:r.clientType,apiName:r.apiName}));}catch(s){console.error(`
|
|
787
|
+
\u274C Error during sync:`,s.message),s.stack&&process.env.DEBUG&&console.error(s.stack);}else re||(r.generateClient||r.enableValidation,r.generateClient&&r.clientType&&(r.generateClient||r.enableValidation,`${r.clientType}`));re||(`${r.outputFolder}${r.apiName}`,r.generateClient&&`${r.outputFolder}${r.apiName}`,r.generateClient&&r.clientType&&`${r.clientType}`);}catch(r){throw re||(console.error(`
|
|
788
|
+
\u274C Error during setup:`,r.message),process.exit(1)),r}})}var re,vn=ae(()=>{re=process.env.NODE_ENV==="test"||process.env.JEST_WORKER_ID!==void 0;});var An={};on(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:()=>Mn,isJson:()=>exports.isJson,isYamlString:()=>exports.isYamlString,mergeCustomCode:()=>exports.mergeCustomCode,renderTypeRefMD:()=>exports.renderTypeRefMD,variableName:()=>exports.variableName,variableNameChar:()=>exports.variableNameChar,yamlStringToJson:()=>exports.yamlStringToJson});var Ge,Pn;exports.Init=void 0;exports.GenerateClient=void 0;exports.InteractiveInit=void 0;var On=ae(()=>{$n();Ke();_e();xn();wn();ke();Le();Ge=process.cwd(),Pn=()=>{let r;try{Ae("esbuild-register");}catch(l){throw l}let a=W__default.default.join(Ge,"openapi.sync.js"),t=W__default.default.join(Ge,"openapi.sync.ts"),e=W__default.default.join(Ge,"openapi.sync.json"),o=[a,t,e];try{for(let l of o)ie__default.default.existsSync(l)&&(r=Ae(l),Object.keys(r).length===1&&r.default&&(r=r.default));}catch(l){}typeof r=="function"&&(r=r());let n=r;if(!n)throw new Error("No config found");return n},exports.Init=r=>te(null,null,function*(){let a=Pn(),t=Object.keys(a.api),e=r&&"refetchInterval"in r&&!isNaN(r==null?void 0:r.refetchInterval)?r.refetchInterval:a.refetchInterval;He();for(let o=0;o<t.length;o+=1){let n=t[o],l=a.api[n];yield Ze(l,n,a,e);}}),exports.GenerateClient=r=>te(null,null,function*(){let a=Pn(),t=r.apiName?[r.apiName]:Object.keys(a.api);for(let o of t)if(!a.api[o])throw new Error(`API "${o}" not found in configuration. Available APIs: ${Object.keys(a.api).join(", ")}`);He();for(let o of t){let n=a.api[o];yield Ze(n,o,a);}let e=(a==null?void 0:a.folder)||"api";for(let o of t){let n=fn(o);if(n.length===0){continue}`${n.length}${o}`;let l=se(se(se(se(ve(se({enabled:true},a.clientGeneration||{}),{type:r.type}),r.outputDir&&{outputDir:r.outputDir}),r.baseURL&&{baseURL:r.baseURL}),r.tags&&{tags:r.tags}),r.endpoints&&{endpoints:r.endpoints});yield In(n,a,l,o,W__default.default.join(Ge,e));}}),exports.InteractiveInit=()=>te(null,null,function*(){let{interactiveInit:r}=yield Promise.resolve().then(()=>(vn(),En));yield r();});});On();exports.getNestedValue=Mn;
|