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