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