openapi-sync 3.0.2 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -1343
- package/dist/index.d.mts +43 -1
- package/dist/index.d.ts +43 -1
- package/dist/index.js +72 -54
- package/dist/index.mjs +72 -54
- package/package.json +12 -13
- package/db.json +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -16,6 +16,19 @@ type IOpenApSchemaSpec = {
|
|
|
16
16
|
anyOf?: IOpenApSchemaSpec[];
|
|
17
17
|
oneOf?: IOpenApSchemaSpec[];
|
|
18
18
|
allOf?: IOpenApSchemaSpec[];
|
|
19
|
+
minLength?: number;
|
|
20
|
+
maxLength?: number;
|
|
21
|
+
minimum?: number;
|
|
22
|
+
maximum?: number;
|
|
23
|
+
exclusiveMinimum?: boolean;
|
|
24
|
+
exclusiveMaximum?: boolean;
|
|
25
|
+
pattern?: string;
|
|
26
|
+
multipleOf?: number;
|
|
27
|
+
minItems?: number;
|
|
28
|
+
maxItems?: number;
|
|
29
|
+
uniqueItems?: boolean;
|
|
30
|
+
minProperties?: number;
|
|
31
|
+
maxProperties?: number;
|
|
19
32
|
};
|
|
20
33
|
type IOpenApiParameterSpec = {
|
|
21
34
|
$ref?: string;
|
|
@@ -94,6 +107,33 @@ type IConfigCustomCode = {
|
|
|
94
107
|
/** Add helpful instructions in markers (default: true) */
|
|
95
108
|
includeInstructions?: boolean;
|
|
96
109
|
};
|
|
110
|
+
type IConfigValidations = {
|
|
111
|
+
/** Disable validation schema generation (default: false) */
|
|
112
|
+
disable?: boolean;
|
|
113
|
+
/** Validation library to use */
|
|
114
|
+
library?: "zod" | "yup" | "joi";
|
|
115
|
+
/** Specify which types to generate validations for */
|
|
116
|
+
generate?: {
|
|
117
|
+
/** Generate validation for query parameters (default: true) */
|
|
118
|
+
query?: boolean;
|
|
119
|
+
/** Generate validation for request bodies/DTOs (default: true) */
|
|
120
|
+
dto?: boolean;
|
|
121
|
+
};
|
|
122
|
+
/** Naming configuration for validation schemas */
|
|
123
|
+
name?: {
|
|
124
|
+
prefix?: string;
|
|
125
|
+
useOperationId?: boolean;
|
|
126
|
+
suffix?: string;
|
|
127
|
+
format?: (data: {
|
|
128
|
+
type?: "dto" | "query";
|
|
129
|
+
code?: string;
|
|
130
|
+
method?: Method;
|
|
131
|
+
path?: string;
|
|
132
|
+
summary?: string;
|
|
133
|
+
operationId?: string;
|
|
134
|
+
}, defaultName: string) => string | null | undefined;
|
|
135
|
+
};
|
|
136
|
+
};
|
|
97
137
|
type IConfig = {
|
|
98
138
|
refetchInterval?: number;
|
|
99
139
|
folder?: string;
|
|
@@ -103,6 +143,8 @@ type IConfig = {
|
|
|
103
143
|
folderSplit?: IConfigFolderSplit;
|
|
104
144
|
/** Configuration for preserving custom code between regenerations */
|
|
105
145
|
customCode?: IConfigCustomCode;
|
|
146
|
+
/** Configuration for validation schema generation */
|
|
147
|
+
validations?: IConfigValidations;
|
|
106
148
|
/** Configuration for excluding endpoints from code generation */
|
|
107
149
|
types?: {
|
|
108
150
|
name?: {
|
|
@@ -212,4 +254,4 @@ declare const Init: (options?: {
|
|
|
212
254
|
refetchInterval?: number;
|
|
213
255
|
}) => Promise<void>;
|
|
214
256
|
|
|
215
|
-
export { type ExtractedCustomCode, type IConfig, type IConfigCustomCode, type IConfigDoc, type IConfigExclude, type IConfigFolderSplit, type IConfigInclude, type IConfigReplaceWord, type IOpenApSchemaSpec, type IOpenApiMediaTypeSpec, type IOpenApiParameterSpec, type IOpenApiRequestBodySpec, type IOpenApiResponseSpec, type IOpenApiSecuritySchemes, type IOpenApiSpec, Init, JSONStringify, capitalize, createCustomCodeMarker, extractCustomCode, getEndpointDetails, getNestedValue, isJson, isYamlString, mergeCustomCode, renderTypeRefMD, variableName, variableNameChar, yamlStringToJson };
|
|
257
|
+
export { type ExtractedCustomCode, type IConfig, type IConfigCustomCode, type IConfigDoc, type IConfigExclude, type IConfigFolderSplit, type IConfigInclude, type IConfigReplaceWord, type IConfigValidations, type IOpenApSchemaSpec, type IOpenApiMediaTypeSpec, type IOpenApiParameterSpec, type IOpenApiRequestBodySpec, type IOpenApiResponseSpec, type IOpenApiSecuritySchemes, type IOpenApiSpec, Init, JSONStringify, capitalize, createCustomCodeMarker, extractCustomCode, getEndpointDetails, getNestedValue, isJson, isYamlString, mergeCustomCode, renderTypeRefMD, variableName, variableNameChar, yamlStringToJson };
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,19 @@ type IOpenApSchemaSpec = {
|
|
|
16
16
|
anyOf?: IOpenApSchemaSpec[];
|
|
17
17
|
oneOf?: IOpenApSchemaSpec[];
|
|
18
18
|
allOf?: IOpenApSchemaSpec[];
|
|
19
|
+
minLength?: number;
|
|
20
|
+
maxLength?: number;
|
|
21
|
+
minimum?: number;
|
|
22
|
+
maximum?: number;
|
|
23
|
+
exclusiveMinimum?: boolean;
|
|
24
|
+
exclusiveMaximum?: boolean;
|
|
25
|
+
pattern?: string;
|
|
26
|
+
multipleOf?: number;
|
|
27
|
+
minItems?: number;
|
|
28
|
+
maxItems?: number;
|
|
29
|
+
uniqueItems?: boolean;
|
|
30
|
+
minProperties?: number;
|
|
31
|
+
maxProperties?: number;
|
|
19
32
|
};
|
|
20
33
|
type IOpenApiParameterSpec = {
|
|
21
34
|
$ref?: string;
|
|
@@ -94,6 +107,33 @@ type IConfigCustomCode = {
|
|
|
94
107
|
/** Add helpful instructions in markers (default: true) */
|
|
95
108
|
includeInstructions?: boolean;
|
|
96
109
|
};
|
|
110
|
+
type IConfigValidations = {
|
|
111
|
+
/** Disable validation schema generation (default: false) */
|
|
112
|
+
disable?: boolean;
|
|
113
|
+
/** Validation library to use */
|
|
114
|
+
library?: "zod" | "yup" | "joi";
|
|
115
|
+
/** Specify which types to generate validations for */
|
|
116
|
+
generate?: {
|
|
117
|
+
/** Generate validation for query parameters (default: true) */
|
|
118
|
+
query?: boolean;
|
|
119
|
+
/** Generate validation for request bodies/DTOs (default: true) */
|
|
120
|
+
dto?: boolean;
|
|
121
|
+
};
|
|
122
|
+
/** Naming configuration for validation schemas */
|
|
123
|
+
name?: {
|
|
124
|
+
prefix?: string;
|
|
125
|
+
useOperationId?: boolean;
|
|
126
|
+
suffix?: string;
|
|
127
|
+
format?: (data: {
|
|
128
|
+
type?: "dto" | "query";
|
|
129
|
+
code?: string;
|
|
130
|
+
method?: Method;
|
|
131
|
+
path?: string;
|
|
132
|
+
summary?: string;
|
|
133
|
+
operationId?: string;
|
|
134
|
+
}, defaultName: string) => string | null | undefined;
|
|
135
|
+
};
|
|
136
|
+
};
|
|
97
137
|
type IConfig = {
|
|
98
138
|
refetchInterval?: number;
|
|
99
139
|
folder?: string;
|
|
@@ -103,6 +143,8 @@ type IConfig = {
|
|
|
103
143
|
folderSplit?: IConfigFolderSplit;
|
|
104
144
|
/** Configuration for preserving custom code between regenerations */
|
|
105
145
|
customCode?: IConfigCustomCode;
|
|
146
|
+
/** Configuration for validation schema generation */
|
|
147
|
+
validations?: IConfigValidations;
|
|
106
148
|
/** Configuration for excluding endpoints from code generation */
|
|
107
149
|
types?: {
|
|
108
150
|
name?: {
|
|
@@ -212,4 +254,4 @@ declare const Init: (options?: {
|
|
|
212
254
|
refetchInterval?: number;
|
|
213
255
|
}) => Promise<void>;
|
|
214
256
|
|
|
215
|
-
export { type ExtractedCustomCode, type IConfig, type IConfigCustomCode, type IConfigDoc, type IConfigExclude, type IConfigFolderSplit, type IConfigInclude, type IConfigReplaceWord, type IOpenApSchemaSpec, type IOpenApiMediaTypeSpec, type IOpenApiParameterSpec, type IOpenApiRequestBodySpec, type IOpenApiResponseSpec, type IOpenApiSecuritySchemes, type IOpenApiSpec, Init, JSONStringify, capitalize, createCustomCodeMarker, extractCustomCode, getEndpointDetails, getNestedValue, isJson, isYamlString, mergeCustomCode, renderTypeRefMD, variableName, variableNameChar, yamlStringToJson };
|
|
257
|
+
export { type ExtractedCustomCode, type IConfig, type IConfigCustomCode, type IConfigDoc, type IConfigExclude, type IConfigFolderSplit, type IConfigInclude, type IConfigReplaceWord, type IConfigValidations, type IOpenApSchemaSpec, type IOpenApiMediaTypeSpec, type IOpenApiParameterSpec, type IOpenApiRequestBodySpec, type IOpenApiResponseSpec, type IOpenApiSecuritySchemes, type IOpenApiSpec, Init, JSONStringify, capitalize, createCustomCodeMarker, extractCustomCode, getEndpointDetails, getNestedValue, isJson, isYamlString, mergeCustomCode, renderTypeRefMD, variableName, variableNameChar, yamlStringToJson };
|
package/dist/index.js
CHANGED
|
@@ -1,66 +1,84 @@
|
|
|
1
|
-
'use strict';var
|
|
2
|
-
`+" ".repeat(
|
|
3
|
-
`).filter(
|
|
4
|
-
${" ".repeat(
|
|
5
|
-
${" ".repeat(
|
|
1
|
+
'use strict';var U=require('fs'),M=require('path'),ae=require('js-yaml'),Kt=require('lodash.isequal'),xe=require('lodash.get'),Wt=require('axios'),Dt=require('axios-retry'),Qt=require('@apidevtools/swagger-parser'),curlGenerator=require('curl-generator');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 U__default=/*#__PURE__*/_interopDefault(U);var M__default=/*#__PURE__*/_interopDefault(M);var ae__namespace=/*#__PURE__*/_interopNamespace(ae);var Kt__default=/*#__PURE__*/_interopDefault(Kt);var xe__default=/*#__PURE__*/_interopDefault(xe);var Wt__default=/*#__PURE__*/_interopDefault(Wt);var Dt__default=/*#__PURE__*/_interopDefault(Dt);var Qt__default=/*#__PURE__*/_interopDefault(Qt);var re=(u=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(u,{get:(d,e)=>(typeof require!="undefined"?require:d)[e]}):u)(function(u){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+u+'" is not supported')});var ne=(u,d,e)=>new Promise((j,b)=>{var v=O=>{try{y(e.next(O));}catch(E){b(E);}},m=O=>{try{y(e.throw(O));}catch(E){b(E);}},y=O=>O.done?j(O.value):Promise.resolve(O.value).then(v,m);y((e=e.apply(u,d)).next());});var Xt=/^[A-Za-z_$][A-Za-z0-9_$]*$/,Et=/[A-Za-z0-9_$]/;var ct=u=>["object"].includes(typeof u)&&!(u instanceof Blob),Gt=u=>{try{return ae__namespace.load(u),!0}catch(d){let e=d;if(e instanceof ae__namespace.YAMLException)return false;throw e}},Tt=u=>{if(Gt(u)){let d=ae__namespace.load(u),e=JSON.stringify(d,null,2);return JSON.parse(e)}},K=u=>u.substring(0,1).toUpperCase()+u.substring(1),St=(u,d)=>{let e=u.split("/"),j=`${K(d)}`,b=[];return e.forEach(v=>{if(v[0]==="{"&&v[v.length-1]==="}"){let y=v.replace(/{/,"").replace(/}/,"");b.push(y),v=`$${y}`;}else if(v[0]==="<"&&v[v.length-1]===">"){let y=v.replace(/</,"").replace(/>/,"");b.push(y),v=`$${y}`;}else if(v[0]===":"){let y=v.replace(/:/,"");b.push(y),v=`$${y}`;}let m="";v.split("").forEach(y=>{let O=y;Et.test(y)||(O="/"),m+=O;}),m.split("/").forEach(y=>{j+=K(y);});}),{name:j,variables:b,pathParts:e}},se=(u,d=1)=>{let e="{",j=Object.keys(u);for(let b=0;b<j.length;b++){let v=j[b],m=u[v];if(e+=`
|
|
2
|
+
`+" ".repeat(d)+v+": ",Array.isArray(m)){e+="[";for(let y=0;y<m.length;y++){let O=m[y];typeof O=="object"&&O!==null?e+=se(O,d+1):e+=typeof O=="string"?`"${O}"`:O,y<m.length-1&&(e+=", ");}e+="]";}else typeof m=="object"&&m!==null?e+=""+se(m,d+1):e+=m.split(`
|
|
3
|
+
`).filter(y=>y.trim()!=="").join(`
|
|
4
|
+
${" ".repeat(d)}`);b<j.length-1&&(e+=", ");}return e+=`
|
|
5
|
+
${" ".repeat(d-1)}}`,e},ue=(u,d=1)=>`
|
|
6
6
|
\`\`\`typescript
|
|
7
|
-
${" ".repeat(
|
|
7
|
+
${" ".repeat(d)} ${u.split(`
|
|
8
8
|
`).filter(e=>e.trim()!=="").join(`
|
|
9
|
-
${" ".repeat(
|
|
10
|
-
\`\`\``;function
|
|
11
|
-
`,
|
|
12
|
-
`).filter(
|
|
9
|
+
${" ".repeat(d)} `)}
|
|
10
|
+
\`\`\``;function er(u,d){return d.split(".").reduce((j,b)=>j&&j[b]!==void 0?j[b]:void 0,u)}var Ut=(u,d="CUSTOM CODE")=>{let e=`// \u{1F512} ${d} START`,j=`// \u{1F512} ${d} END`,b={beforeGenerated:"",afterGenerated:""},v=0,m=[];for(;v<u.length;){let y=u.indexOf(e,v);if(y===-1)break;let O=u.indexOf(j,y);if(O===-1)break;let E=O+j.length,P=u.substring(E,E+100),B=P.match(/^\s*\n\s*(\/\/ =+)/);if(B){let ie=P.indexOf(`
|
|
11
|
+
`,B.index+1);ie!==-1?E+=ie+1:E+=B[0].length;}let _=y,L=u.substring(Math.max(0,y-200),y).lastIndexOf("// ==========");L!==-1&&(_=Math.max(0,y-200)+L);let V=u.substring(_,E);m.push({start:_,end:E,content:V}),v=E;}return m.length>0&&(u.substring(0,m[0].start).split(`
|
|
12
|
+
`).filter(E=>{let P=E.trim();return P.length>0&&!P.startsWith("//")}).join("").length===0?(b.beforeGenerated=m[0].content,m.length>1&&(b.afterGenerated=m[1].content)):(b.afterGenerated=m[0].content,m.length>1&&!b.beforeGenerated&&(b.beforeGenerated=m[1].content))),b},At=(u,d="CUSTOM CODE",e=true)=>{let j=e?`// ${u==="top"?"Add your custom code below this line":"Add your custom code above this line"}
|
|
13
13
|
// This section will be preserved during regeneration
|
|
14
14
|
`:"";return `// ${"=".repeat(60)}
|
|
15
|
-
// \u{1F512} ${
|
|
16
|
-
${
|
|
15
|
+
// \u{1F512} ${d} START
|
|
16
|
+
${j}// ${"=".repeat(60)}
|
|
17
17
|
|
|
18
|
-
// \u{1F512} ${
|
|
19
|
-
// ${"=".repeat(60)}`},
|
|
20
|
-
`)};var
|
|
21
|
-
`).filter(
|
|
22
|
-
*${" ".repeat(1)}`))),
|
|
23
|
-
${
|
|
18
|
+
// \u{1F512} ${d} END
|
|
19
|
+
// ${"=".repeat(60)}`},wt=(u,d,e={})=>{let{position:j="bottom",markerText:b="CUSTOM CODE",includeInstructions:v=true}=e,m={beforeGenerated:"",afterGenerated:""};d&&(m=Ut(d,b)),!m.beforeGenerated&&!m.afterGenerated&&((j==="top"||j==="both")&&(m.beforeGenerated=At("top",b,v)),(j==="bottom"||j==="both")&&(m.afterGenerated=At("bottom",b,v)));let y=[];return m.beforeGenerated&&(y.push(m.beforeGenerated),y.push("")),y.push(u),m.afterGenerated&&(y.push(""),y.push(m.afterGenerated)),y.join(`
|
|
20
|
+
`)};var me=M__default.default.join(__dirname,"../","../db.json");U__default.default.existsSync(me)||U__default.default.writeFileSync(me,"{}");var $e={};try{$e=re(me);}catch(u){$e={};}var oe=$e||{},zt=u=>{U__default.default.writeFileSync(me,JSON.stringify(u));},Nt=(u,d)=>{oe[u]=d,zt(oe);},kt=u=>oe[u],Rt=()=>{oe={},zt(oe);};var Y=process.cwd(),Oe={},Jt=Wt__default.default.create({timeout:6e4});Dt__default.default(Jt,{retries:20,retryCondition:u=>u.code==="ECONNABORTED"||u.message.includes("Network Error"),retryDelay:u=>u*1e3});var Z=(u,d,e)=>ne(null,null,function*(){var m,y,O,E;if(!(((m=e==null?void 0:e.customCode)==null?void 0:m.enabled)!==false)){yield U__default.default.promises.writeFile(u,d);return}let b=null;try{b=yield U__default.default.promises.readFile(u,"utf-8");}catch(P){}let v=wt(d,b,{position:((y=e==null?void 0:e.customCode)==null?void 0:y.position)||"bottom",markerText:(O=e==null?void 0:e.customCode)==null?void 0:O.markerText,includeInstructions:(E=e==null?void 0:e.customCode)==null?void 0:E.includeInstructions});yield U__default.default.promises.writeFile(u,v);}),Mt=(u,d,e,j)=>ne(null,null,function*(){var je,ve,Ce,Ee,Ae,ce,Te,Se,we,ze;let b=yield Jt.get(u),v=ct(b.data)?b.data:Tt(b.data),m;try{m=yield Qt__default.default.parse(v);}catch(t){let r=t instanceof Error?t.message:String(t);throw new Error(`Failed to parse OpenAPI spec for ${d}: ${r}`)}let y=M__default.default.join((e==null?void 0:e.folder)||"",d),O={},E=t=>{var r,f;if((r=e==null?void 0:e.folderSplit)!=null&&r.customFolder){let l=e.folderSplit.customFolder(t);if(l)return l}return (f=e==null?void 0:e.folderSplit)!=null&&f.byTags&&t.tags&&t.tags.length>0?t.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},P=typeof(e==null?void 0:e.server)=="string"?e==null?void 0:e.server:((ve=(je=m==null?void 0:m.servers)==null?void 0:je[(e==null?void 0:e.server)||0])==null?void 0:ve.url)||"",B=typeof((Ee=(Ce=e==null?void 0:e.types)==null?void 0:Ce.name)==null?void 0:Ee.prefix)=="string"?e==null?void 0:e.types.name.prefix:"I",_=typeof((ce=(Ae=e==null?void 0:e.endpoints)==null?void 0:Ae.name)==null?void 0:ce.prefix)=="string"?e==null?void 0:e.endpoints.name.prefix:"",de=(t,r)=>{var l,a;let f=K(t);if((a=(l=e==null?void 0:e.types)==null?void 0:l.name)!=null&&a.format){let o=e==null?void 0:e.types.name.format("shared",{name:t},f);if(o)return `${B}${o}`}return `${B}${f}`},L=(t,r,f,l,a,o=0)=>{let s="",p="",i="";if(r)if(r.$ref)if(r.$ref[0]==="#"){let $=(r.$ref||"").split("/");$.shift(),[...$].pop();let k=xe__default.default(t,$,null);if(k){k!=null&&k.name&&(s=k.name),p=$[$.length-1];let R=de(p);R.includes(".")&&(R=R.split(".").map((W,Q)=>Q===0?W:`["${W}"]`).join("")),i+=`${a!=null&&a.noSharedImport?"":"Shared."}${R}`;}}else i+="";else if(r.anyOf)i+=`(${r.anyOf.map($=>L(t,$,"",l,a)).filter($=>!!$).join("|")})`;else if(r.oneOf)i+=`(${r.oneOf.map($=>L(t,$,"",l,a)).filter($=>!!$).join("|")})`;else if(r.allOf)i+=`(${r.allOf.map($=>L(t,$,"",l,a)).filter($=>!!$).join("&")})`;else if(r.items)i+=`${L(t,r.items,"",false,a)}[]`;else if(r.properties){let $=Object.keys(r.properties),C=r.required||[],N="";$.forEach(k=>{var ee,W,Q,X,le,te;let R="";!((W=(ee=e==null?void 0:e.types)==null?void 0:ee.doc)!=null&&W.disable)&&((X=(Q=r.properties)==null?void 0:Q[k])!=null&&X.description)&&(R=" * "+((le=r.properties)==null?void 0:le[k].description.split(`
|
|
21
|
+
`).filter(pe=>pe.trim()!=="").join(`
|
|
22
|
+
*${" ".repeat(1)}`))),N+=(R?`/**
|
|
23
|
+
${R}
|
|
24
24
|
*/
|
|
25
|
-
`:"")+`${
|
|
26
|
-
${" ".repeat(
|
|
27
|
-
`:""}`:""},
|
|
28
|
-
`);
|
|
29
|
-
${
|
|
30
|
-
}`:a+="{}";}else if(r.enum&&r.enum.length>0)r.enum.length>1&&(a+=r.enum[0]);else if(r.type)if(r.example)a+=JSON.stringify(r.example);else {let
|
|
31
|
-
`).filter(
|
|
32
|
-
*${" ".repeat(1)}`)),
|
|
33
|
-
${
|
|
25
|
+
`:"")+`${L(t,(te=r.properties)==null?void 0:te[k],k,C.includes(k),a,o+1)}`;}),N.length>0?i+=`{
|
|
26
|
+
${" ".repeat(o)}${N}${" ".repeat(o)}}`:i+="{[k: string]: any}";}else if(r.enum&&r.enum.length>0)r.enum.length>1&&(i+="("),r.enum.map($=>JSON.stringify($)).filter($=>!!$).forEach(($,C)=>{i+=`${C===0?"":"|"}${$}`;}),r.enum.length>1&&(i+=")");else if(r.type){let $=C=>{let N="";if(typeof C=="string")["string","integer","number","array","boolean","null"].includes(C)?["integer","number"].includes(C)?N+="number":C==="array"?N+="any[]":N+=C:C==="object"&&(r.additionalProperties?N+=`{[k: string]: ${L(t,r.additionalProperties,"",true,a)||"any"}}`:N+="{[k: string]: any}");else if(Array.isArray(C)){let k=C.map(R=>$(R));k.filter(R=>R!==""),k.length>1&&(N+="("+k.join("|")+")");}else N+="any";return N};i=$(r.type);}else i+="any";else i="string";let h=s||f;a!=null&&a.useComponentName&&!h&&(h=p);let z=h?` "${h}"${l?"":"?"}: `:"",n=r!=null&&r.nullable?" | null":"";return i.length>0?`${z}${i}${n}${h?`;
|
|
27
|
+
`:""}`:""},V=(t,r)=>{let a="";if(r)if(r.$ref)if(r.$ref[0]==="#"){let o=(r.$ref||"").split("/");o.shift();let p=xe__default.default(t,o,null);p&&(p!=null&&p.name&&(p.name),o[o.length-1],a+=V(t,p));}else a+="";else if(r.anyOf)a+=V(t,r.anyOf[0]);else if(r.oneOf)a+=V(t,r.oneOf[0]);else if(r.allOf)a+=`{${r.allOf.map(o=>`...(${V(t,o)})`).join(",")}}`;else if(r.items)a+=`[${V(t,r.items)}]`;else if(r.properties){let p=Object.keys(r.properties).map(i=>{var h;return ` "${i}": ${V(t,(h=r.properties)==null?void 0:h[i])}`}).join(`,
|
|
28
|
+
`);p.length>0?a+=`{
|
|
29
|
+
${p}
|
|
30
|
+
}`:a+="{}";}else if(r.enum&&r.enum.length>0)r.enum.length>1&&(a+=r.enum[0]);else if(r.type)if(r.example)a+=JSON.stringify(r.example);else {let o=s=>{let p="";if(typeof s=="string")["string","integer","number","array","boolean","null"].includes(s)?["integer","number"].includes(s)?p+="123":s==="array"?p+="[]":s==="boolean"?p+="true":s==="null"?p+="null":p+=`"${s}"`:s==="object"&&(p+="{}");else if(Array.isArray(s)){let i=s.map(h=>o(h));i.filter(h=>h!==""),i.length>1&&(p+=i.join("|"));}else p+="any";return p};a=o(r.type);}else a+="any";else a="string";return a};j&&!isNaN(j)&&j>0&&(process.env.NODE_ENV&&["production","prod","test","staging"].includes(process.env.NODE_ENV)||(Oe[d]&&clearTimeout(Oe[d]),Oe[d]=setTimeout(()=>Mt(u,d,e,j),j)));let ie=kt(d);if(Kt__default.default(ie,m))return;Nt(d,m);let ye="",g="",H={};m.components&&Object.keys(m.components).forEach(t=>{if(["schemas","responses","parameters","examples","requestBodies","headers","links","callbacks"].includes(t)){let r=m.components[t],f={},l={};Object.keys(r).forEach(o=>{var i;let s=(i=r[o])!=null&&i.schema?r[o].schema:r[o],p=`${L(m,s,"",true,{noSharedImport:true,useComponentName:["parameters"].includes(t)})}`;if(p){let h=o.split("."),z=f,n=l;for(let $=0;$<h.length;$++){let C=h[$];$<h.length-1?(C in z||(z[C]={},n[C]={}),z=z[C],n=n[C]):(z[C]=p,n[C]=s);}}}),Object.keys(f).forEach(o=>{var h,z,n,$;let s=de(o),p=f[o],i="";!((z=(h=e==null?void 0:e.types)==null?void 0:h.doc)!=null&&z.disable)&&o in r&&((n=r[o])!=null&&n.description)&&(i=" * "+r[o].description.split(`
|
|
31
|
+
`).filter(C=>C.trim()!=="").join(`
|
|
32
|
+
*${" ".repeat(1)}`)),H[o]=(($=H[o])!=null?$:"")+(i?`/**
|
|
33
|
+
${i}
|
|
34
34
|
*/
|
|
35
|
-
`:"")+"export type "+
|
|
36
|
-
`;});}});let
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
`),
|
|
44
|
-
|
|
35
|
+
`:"")+"export type "+s+" = "+(typeof p=="string"?p:se(p))+`;
|
|
36
|
+
`;});}});let be=t=>{let r="";if(t.content){let f=Object.keys(t.content);f[0]&&t.content[f[0]].schema&&(r+=`${L(m,t.content[f[0]].schema,"")}`);}return r},G=(t,r,f=0)=>{if(!t)return r==="joi"?"Joi.any()":r==="yup"?"yup.mixed()":"z.any()";if(t.$ref){if(t.$ref[0]==="#"){let l=t.$ref.split("/");l.shift();let a=l.join("."),o=xe__default.default(m,a);if(o)return G(o,r,f)}return r==="joi"?"Joi.any()":r==="yup"?"yup.mixed()":"z.any()"}if(t.anyOf||t.oneOf){let l=t.anyOf||t.oneOf;if(l.every(o=>o.enum!==void 0&&Array.isArray(o.enum))){let o=[],s=false;if(l.forEach(p=>{p.enum&&p.enum.forEach(i=>{i===null?s=true:o.includes(i)||o.push(i);});}),o.length>0){let p=o.map(i=>JSON.stringify(i)).join(", ");if(r==="zod"){let i=`z.enum([${p}])`;return s&&(i+=".nullable()"),i}else if(r==="yup"){let i=`yup.mixed().oneOf([${p}])`;return s&&(i+=".nullable()"),i}else return s?`Joi.valid(${p}, null)`:`Joi.valid(${p})`}else if(s)return r==="zod"?"z.null()":r==="yup"?"yup.mixed().nullable()":"Joi.valid(null)"}return r==="zod"?`z.union([${l.map(p=>G(p,r,f+1)).join(", ")}])`:r==="yup"?`yup.mixed().oneOf([${l.map(p=>G(p,r,f+1)).join(", ")}])`:`Joi.alternatives().try(${l.map(s=>G(s,r,f+1)).join(", ")})`}if(t.allOf)if(r==="zod"){let l=t.allOf.map(o=>G(o,r,f+1)),a=l[0];for(let o=1;o<l.length;o++)a=`${a}.merge(${l[o]})`;return a}else return G(t.allOf[0],r,f+1);if(t.items){let l=G(t.items,r,f+1);if(r==="zod"){let a=`z.array(${l})`;return t.minItems!==void 0&&(a+=`.min(${t.minItems})`),t.maxItems!==void 0&&(a+=`.max(${t.maxItems})`),a}else if(r==="yup"){let a=`yup.array().of(${l})`;return t.minItems!==void 0&&(a+=`.min(${t.minItems})`),t.maxItems!==void 0&&(a+=`.max(${t.maxItems})`),a}else {let a=`Joi.array().items(${l})`;return t.minItems!==void 0&&(a+=`.min(${t.minItems})`),t.maxItems!==void 0&&(a+=`.max(${t.maxItems})`),a}}if(t.properties){let l=t.required||[],a=" ".repeat(f+1),o=Object.entries(t.properties).map(([s,p])=>{let i=l.includes(s),h=G(p,r,f+1);return i||(h+=".optional()"),`${a}${s}: ${h}`}).join(`,
|
|
37
|
+
`);return r==="zod"?`z.object({
|
|
38
|
+
${o}
|
|
39
|
+
${" ".repeat(f)}})`:r==="yup"?`yup.object({
|
|
40
|
+
${o}
|
|
41
|
+
${" ".repeat(f)}})`:`Joi.object({
|
|
42
|
+
${o}
|
|
43
|
+
${" ".repeat(f)}})`}if(t.enum&&t.enum.length>0){let l=[],a=false;t.enum.forEach(s=>{s===null?a=true:l.includes(s)||l.push(s);});let o=l.map(s=>JSON.stringify(s)).join(", ");if(console.log("zod enum 3 here",{schema:t,enumValues:o}),r==="zod"){let s=`z.enum([${o}])`;return a&&(s+=".nullable()"),s}else if(r==="yup"){let s=`yup.mixed().oneOf([${o}])`;return a&&(s+=".nullable()"),s}else {let s=`Joi.valid(${o})`;return a&&(s+=".allow(null)"),s}}if(t.type){let a=(o=>{switch(o){case "string":if(r==="zod"){let s="z.string()";return t.format==="email"?s+=".email()":t.format==="uuid"?s+=".uuid()":t.format==="url"||t.format==="uri"?s+=".url()":t.format==="date-time"?s+=".datetime()":t.format==="date"&&(s+=".date()"),t.minLength&&(s+=`.min(${t.minLength})`),t.maxLength&&(s+=`.max(${t.maxLength})`),t.pattern&&(s+=`.regex(/${t.pattern}/)`),s}else if(r==="yup"){let s="yup.string()";return t.format==="email"?s+=".email()":(t.format==="url"||t.format==="uri")&&(s+=".url()"),t.minLength&&(s+=`.min(${t.minLength})`),t.maxLength&&(s+=`.max(${t.maxLength})`),t.pattern&&(s+=`.matches(/${t.pattern}/)`),s}else {let s="Joi.string()";return t.format==="email"?s+=".email()":t.format==="url"||t.format==="uri"?s+=".uri()":t.format==="uuid"?s+=".guid({ version: 'uuidv4' })":t.format==="date-time"&&(s+=".isoDate()"),t.minLength&&(s+=`.min(${t.minLength})`),t.maxLength&&(s+=`.max(${t.maxLength})`),t.pattern&&(s+=`.pattern(/${t.pattern}/)`),s}case "integer":case "number":if(r==="zod"){let s="z.number()";return o==="integer"&&(s+=".int()"),t.minimum!==void 0&&(t.exclusiveMinimum?s+=`.gt(${t.minimum})`:s+=`.min(${t.minimum})`),t.maximum!==void 0&&(t.exclusiveMaximum?s+=`.lt(${t.maximum})`:s+=`.max(${t.maximum})`),s}else if(r==="yup"){let s="yup.number()";return o==="integer"&&(s+=".integer()"),t.minimum!==void 0&&(s+=`.min(${t.minimum})`),t.maximum!==void 0&&(s+=`.max(${t.maximum})`),s}else {let s="Joi.number()";return o==="integer"&&(s+=".integer()"),t.minimum!==void 0&&(t.exclusiveMinimum?s+=`.greater(${t.minimum})`:s+=`.min(${t.minimum})`),t.maximum!==void 0&&(t.exclusiveMaximum?s+=`.less(${t.maximum})`:s+=`.max(${t.maximum})`),s}case "boolean":return r==="joi"?"Joi.boolean()":r==="yup"?"yup.boolean()":"z.boolean()";case "null":return r==="joi"?"Joi.any().allow(null)":r==="yup"?"yup.mixed().nullable()":"z.null()";default:return r==="joi"?"Joi.any()":r==="yup"?"yup.mixed()":"z.any()"}})(typeof t.type=="string"?t.type:t.type[0]);return t.nullable&&r!=="joi"?a+=".nullable()":t.nullable&&r==="joi"&&(a+=".allow(null)"),a}return r==="joi"?"Joi.any()":r==="yup"?"yup.mixed()":"z.any()"},Bt=t=>{var r,f,l,a,o;if((f=(r=e==null?void 0:e.endpoints)==null?void 0:r.value)!=null&&f.replaceWords&&Array.isArray(e==null?void 0:e.endpoints.value.replaceWords)){let s=t;return (o=(a=(l=e==null?void 0:e.endpoints)==null?void 0:l.value)==null?void 0:a.replaceWords)==null||o.forEach((p,i)=>{let h=new RegExp(p.replace,"g");s=s.replace(h,p.with||"");}),s}else return t},Pt=(t,r,f=[])=>{var o,s;let l=(o=e==null?void 0:e.endpoints)==null?void 0:o.exclude,a=(s=e==null?void 0:e.endpoints)==null?void 0:s.include;if(a){let p=a.tags&&a.tags.length>0?f.some(h=>a.tags.includes(h)):true,i=a.endpoints&&a.endpoints.length>0?a.endpoints.some(h=>{let z=!h.method||h.method.toLowerCase()===r.toLowerCase();return h.path?t===h.path&&z:h.regex?new RegExp(h.regex).test(t)&&z:false}):true;if(!p||!i)return true}return !!(l&&(l.tags&&l.tags.length>0&&f.some(i=>l.tags.includes(i))||l.endpoints&&l.endpoints.length>0&&l.endpoints.some(i=>{let h=!i.method||i.method.toLowerCase()===r.toLowerCase();return i.path?t===i.path&&h:i.regex?new RegExp(i.regex).test(t)&&h:false})))};if(Object.keys(m.paths||{}).forEach(t=>{let r=m.paths[t];Object.keys(r).forEach(l=>{var pe,Ne,ke,Re,Je,Me,qe,Be,Pe,Le,Fe,Ge,Ue,Ve,Ke,We,De,Qe,Ye,Ze,He,Xe,_e,ge,et,tt,rt,nt,st,at,ot,it,lt,pt,ut,mt,dt,yt,ft,$t,xt,Ot,It,ht,bt,jt,vt,Ct;let a=l,o=St(t,a),s=((pe=r[a])==null?void 0:pe.tags)||[];if(Pt(t,a,s))return;let p=r[a],i=E({method:a,path:t,summary:p==null?void 0:p.summary,operationId:p==null?void 0:p.operationId,tags:s,parameters:p==null?void 0:p.parameters,requestBody:p==null?void 0:p.requestBody,responses:p==null?void 0:p.responses});O[i]||(O[i]={endpoints:"",types:"",validation:""});let h=((ke=(Ne=e==null?void 0:e.endpoints)==null?void 0:Ne.value)!=null&&ke.includeServer?P:"")+o.pathParts.map(x=>(x[0]==="{"&&x[x.length-1]==="}"?x=`\${${x.replace(/{/,"").replace(/}/,"")}}`:x[0]==="<"&&x[x.length-1]===">"?x=`\${${x.replace(/</,"").replace(/>/,"")}}`:x[0]===":"&&(x=`\${${x.replace(/:/,"")}}`),x)).join("/"),z=`"${h}"`;o.variables.length>0&&(z=`(${o.variables.map(I=>`${I}:string`).join(",")})=> \`${h}\``),z=Bt(z);let n=r[a],$="";if(n!=null&&n.parameters&&((n==null?void 0:n.parameters).forEach((I,A)=>{(I.$ref||I.in==="query"&&I.name)&&($+=`${L(m,I.$ref?I:I.schema,I.name||"",I.required)}`);}),$)){$=`{
|
|
44
|
+
${$}}`;let I=`${o.name}Query`;if((Je=(Re=e==null?void 0:e.types)==null?void 0:Re.name)!=null&&Je.useOperationId&&(n!=null&&n.operationId)&&(I=`${n.operationId}Query`),I=K(`${B}${I}`),(qe=(Me=e==null?void 0:e.types)==null?void 0:Me.name)!=null&&qe.format){let S=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"query",method:a,path:t,summary:n==null?void 0:n.summary,operationId:n==null?void 0:n.operationId},I);S&&(I=`${B}${S}`);}let A=`export type ${I} = ${$};
|
|
45
|
+
`;e!=null&&e.folderSplit?O[i].types+=A:g+=A;}if(((Be=e==null?void 0:e.validations)==null?void 0:Be.disable)!==true&&((Le=(Pe=e==null?void 0:e.validations)==null?void 0:Pe.generate)==null?void 0:Le.query)!==false&&(n!=null&&n.parameters)){let x=((Fe=e.validations)==null?void 0:Fe.library)||"zod",A=n.parameters.filter(S=>!S.$ref&&S.in==="query"&&S.name);if(A.length>0){let S=((Ge=e==null?void 0:e.validations)==null?void 0:Ge.name)||((Ue=e==null?void 0:e.types)==null?void 0:Ue.name),J=typeof(S==null?void 0:S.prefix)=="string"?S.prefix:"I",c=typeof((Ke=(Ve=e==null?void 0:e.validations)==null?void 0:Ve.name)==null?void 0:Ke.suffix)=="string"?e.validations.name.suffix:"Schema",w=`${o.name}Query`;if(S!=null&&S.useOperationId&&(n!=null&&n.operationId)&&(w=`${n.operationId}Query`),w=K(`${J}${w}${c}`),(De=(We=e==null?void 0:e.validations)==null?void 0:We.name)!=null&&De.format){let F=e.validations.name.format({code:"",type:"query",method:a,path:t,summary:n==null?void 0:n.summary,operationId:n==null?void 0:n.operationId},w);F&&(w=`${J}${F}${c}`);}else if((Ye=(Qe=e==null?void 0:e.types)==null?void 0:Qe.name)!=null&&Ye.format){let F=e.types.name.format("endpoint",{code:"",type:"query",method:a,path:t,summary:n==null?void 0:n.summary,operationId:n==null?void 0:n.operationId},w);F&&(w=`${J}${F}${c}`);}let T=A.map(F=>{let Lt=F!=null&&F.schema?G(F.schema,x):x==="joi"?"Joi.string()":x==="yup"?"yup.string()":"z.string()",Ft=F.required?"":".optional()";return ` ${F.name}: ${Lt}${Ft}`}).join(`,
|
|
46
|
+
`),D=`export const ${w} = ${x==="joi"?"Joi.object":x==="yup"?"yup.object":"z.object"}({
|
|
47
|
+
${T}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
`;e!=null&&e.folderSplit||O[i]||(O[i]={endpoints:"",types:"",validation:""}),O[i].validation+=D;}}let C=n==null?void 0:n.requestBody,N="";if(C&&(N=be(C),N)){let x=`${o.name}DTO`;if((He=(Ze=e==null?void 0:e.types)==null?void 0:Ze.name)!=null&&He.useOperationId&&(n!=null&&n.operationId)&&(x=`${n.operationId}DTO`),x=K(`${B}${x}`),(_e=(Xe=e==null?void 0:e.types)==null?void 0:Xe.name)!=null&&_e.format){let A=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"dto",method:a,path:t,summary:n==null?void 0:n.summary,operationId:n==null?void 0:n.operationId},x);A&&(x=`${B}${A}`);}let I=`export type ${x} = ${N};
|
|
51
|
+
`;e!=null&&e.folderSplit?O[i].types+=I:g+=I;}if(((ge=e==null?void 0:e.validations)==null?void 0:ge.disable)!==true&&((tt=(et=e==null?void 0:e.validations)==null?void 0:et.generate)==null?void 0:tt.dto)!==false&&C){let x=((rt=e.validations)==null?void 0:rt.library)||"zod";if(C.content){let I=Object.keys(C.content);if(I[0]&&C.content[I[0]].schema){let A=((nt=e==null?void 0:e.validations)==null?void 0:nt.name)||((st=e==null?void 0:e.types)==null?void 0:st.name),S=typeof(A==null?void 0:A.prefix)=="string"?A.prefix:"I",J=typeof((ot=(at=e==null?void 0:e.validations)==null?void 0:at.name)==null?void 0:ot.suffix)=="string"?e.validations.name.suffix:"Schema",c=`${o.name}DTO`;if(A!=null&&A.useOperationId&&(n!=null&&n.operationId)&&(c=`${n.operationId}DTO`),c=K(`${S}${c}${J}`),(lt=(it=e==null?void 0:e.validations)==null?void 0:it.name)!=null&<.format){let q=e.validations.name.format({code:"",type:"dto",method:a,path:t,summary:n==null?void 0:n.summary,operationId:n==null?void 0:n.operationId},c);q&&(c=`${S}${q}${J}`);}else if((ut=(pt=e==null?void 0:e.types)==null?void 0:pt.name)!=null&&ut.format){let q=e.types.name.format("endpoint",{code:"",type:"dto",method:a,path:t,summary:n==null?void 0:n.summary,operationId:n==null?void 0:n.operationId},c);q&&(c=`${S}${q}${J}`);}let w=G(C.content[I[0]].schema,x),T=`export const ${c} = ${w};
|
|
52
|
+
|
|
53
|
+
`;e!=null&&e.folderSplit||O[i]||(O[i]={endpoints:"",types:"",validation:""}),O[i].validation+=T;}}}let k={},R="";if(n!=null&&n.responses){let x=n==null?void 0:n.responses;Object.keys(x).forEach(A=>{var S,J,c,w;if(R=be(x[A]),k[A]=R,R){let T=`${o.name}${A}Response`;if((J=(S=e==null?void 0:e.types)==null?void 0:S.name)!=null&&J.useOperationId&&(n!=null&&n.operationId)&&(T=`${n.operationId}${A}Response`),T=K(`${B}${T}`),(w=(c=e==null?void 0:e.types)==null?void 0:c.name)!=null&&w.format){let D=e==null?void 0:e.types.name.format("endpoint",{code:A,type:"response",method:a,path:t,summary:n==null?void 0:n.summary,operationId:n==null?void 0:n.operationId},T);D&&(T=`${B}${D}`);}let q=`export type ${T} = ${R};
|
|
54
|
+
`;e!=null&&e.folderSplit?O[i].types+=q:g+=q;}});}let ee=x=>!x||!x.length?"":x.map(I=>Object.entries(I).map(([S,J])=>{let c=S,w="";return Array.isArray(J)&&J.length&&(w=`
|
|
55
|
+
- Scopes: [\`${J.join("`, `")}\`]`,c=`**${c}**`),`
|
|
56
|
+
- ${c}${w}`}).join("")).join(`
|
|
57
|
+
`),W=n!=null&&n.security?ee(n.security):"",Q="";if(!((dt=(mt=e==null?void 0:e.endpoints)==null?void 0:mt.doc)!=null&&dt.disable)){let x="";if((ft=(yt=e==null?void 0:e.endpoints)==null?void 0:yt.doc)!=null&&ft.showCurl){let I={},A="",S="";($t=n.requestBody)!=null&&$t.content&&Object.keys(n.requestBody.content).forEach(w=>{let T=n.requestBody.content[w].schema;if(T){Array.isArray(I["Content-type"])?I["Content-type"].push(w):I["Content-type"]=[w];let q=V(m,T);q&&(A=q);}}),n!=null&&n.security&&n.security.forEach(c=>{Object.keys(c).forEach(w=>{var q,D;let T=(D=(q=m.components)==null?void 0:q.securitySchemes)==null?void 0:D[w];T&&(T.type==="mutualTLS"?S+=`
|
|
58
|
+
--cert client-certificate.crt --key client-private-key.key --cacert ca-certificate.crt`:T.type==="apiKey"?I[(T==null?void 0:T.name)||"X-API-KEY"]="{API_KEY_VALUE}":I.Authorization=`${(T==null?void 0:T.scheme)==="basic"?"Basic":"Bearer"} {${(T==null?void 0:T.scheme)==="basic"?"VALUE":"TOKEN"}}`);});});let J={};Object.keys(I).forEach(c=>{Array.isArray(I[c])?J[c]=I[c].join("; "):J[c]=I[c];}),x=`
|
|
45
59
|
\`\`\`bash
|
|
46
|
-
${curlGenerator.CurlGenerator({url:
|
|
47
|
-
\`\`\``;}
|
|
48
|
-
* ${
|
|
60
|
+
${curlGenerator.CurlGenerator({url:P+t,method:a.toUpperCase(),headers:J,body:A})}${S}
|
|
61
|
+
\`\`\``;}Q=`/**${n!=null&&n.description?`
|
|
62
|
+
* ${n==null?void 0:n.description} `:""}
|
|
49
63
|
* **Method**: \`${a.toUpperCase()}\`
|
|
50
|
-
* **Summary**: ${(
|
|
51
|
-
* **Tags**: [${((
|
|
52
|
-
* **OperationId**: ${(
|
|
53
|
-
* **Query**: ${
|
|
54
|
-
* **DTO**: ${
|
|
55
|
-
* **Response**: ${Object.entries(
|
|
56
|
-
- **${
|
|
57
|
-
* **Security**: ${
|
|
58
|
-
`:""}${
|
|
64
|
+
* **Summary**: ${(n==null?void 0:n.summary)||""}
|
|
65
|
+
* **Tags**: [${((xt=n==null?void 0:n.tags)==null?void 0:xt.join(", "))||""}]
|
|
66
|
+
* **OperationId**: ${(n==null?void 0:n.operationId)||""} ${$?`
|
|
67
|
+
* **Query**: ${ue($)} `:""}${N?`
|
|
68
|
+
* **DTO**: ${ue(N)} `:""}${R?`
|
|
69
|
+
* **Response**: ${Object.entries(k).map(([I,A])=>`
|
|
70
|
+
- **${I}**: ${ue(A,2)} `).join("")}`:""}${W?`
|
|
71
|
+
* **Security**: ${W}
|
|
72
|
+
`:""}${x}
|
|
59
73
|
*/
|
|
60
|
-
`;}let
|
|
61
|
-
`;e!=null&&e.folderSplit?
|
|
74
|
+
`;}let X=(It=(Ot=e==null?void 0:e.endpoints)==null?void 0:Ot.name)!=null&&It.useOperationId&&((ht=n==null?void 0:n.operationId)==null?void 0:ht.length)>0?n.operationId:`${o.name}`;if((jt=(bt=e==null?void 0:e.endpoints)==null?void 0:bt.name)!=null&&jt.format){let x=e==null?void 0:e.endpoints.name.format({method:a,path:t,summary:n==null?void 0:n.summary,operationId:n==null?void 0:n.operationId},X);x&&(X=x);}let le={method:`"${a}"`,operationId:`"${n==null?void 0:n.operationId}"`,url:z,tags:(n==null?void 0:n.tags)||[]},te=`${Q}export const ${_}${X} = ${((Ct=(vt=e==null?void 0:e.endpoints)==null?void 0:vt.value)==null?void 0:Ct.type)==="object"?se(le):z};
|
|
75
|
+
`;e!=null&&e.folderSplit?O[i].endpoints+=te:ye+=te;});}),e!=null&&e.folderSplit){for(let[t,r]of Object.entries(O))if(r.endpoints||r.types){let f=M__default.default.join(y,t);if(r.endpoints){let l=M__default.default.join(Y,f,"endpoints.ts");yield U__default.default.promises.mkdir(M__default.default.dirname(l),{recursive:true}),yield Z(l,r.endpoints,e);}if(r.types){let l=M__default.default.join(Y,f,"types.ts");yield U__default.default.promises.mkdir(M__default.default.dirname(l),{recursive:true});let a=Object.values(H).length>0?`import * as Shared from "../shared";
|
|
76
|
+
|
|
77
|
+
${r.types}`:r.types;yield Z(l,a,e);}if(((Te=e==null?void 0:e.validations)==null?void 0:Te.disable)!==true&&r.validation){let l=((Se=e.validations)==null?void 0:Se.library)||"zod",a=l==="joi"?'import Joi from "joi";':l==="yup"?'import * as yup from "yup";':'import { z } from "zod";',o=M__default.default.join(Y,f,"validations.ts");yield U__default.default.promises.mkdir(M__default.default.dirname(o),{recursive:true}),yield Z(o,`${a}
|
|
78
|
+
|
|
79
|
+
${r.validation}`,e);}}}if(ye.length>0){let t=M__default.default.join(Y,y,"endpoints.ts");yield U__default.default.promises.mkdir(M__default.default.dirname(t),{recursive:true}),yield Z(t,ye,e);}if(Object.values(H).length>0){let t=M__default.default.join(Y,y,e!=null&&e.folderSplit?"":"types","shared.ts");yield U__default.default.promises.mkdir(M__default.default.dirname(t),{recursive:true}),yield Z(t,Object.values(H).join(`
|
|
80
|
+
`),e);}if(g.length>0){let t=M__default.default.join(Y,y,"types","index.ts");yield U__default.default.promises.mkdir(M__default.default.dirname(t),{recursive:true}),yield Z(t,`${Object.values(H).length>0?`import * as Shared from "./shared";
|
|
62
81
|
|
|
63
|
-
${
|
|
64
|
-
`),e);}if(Z.length>0){let s=F__default.default.join(se,p,"types","index.ts");yield z__default.default.promises.mkdir(F__default.default.dirname(s),{recursive:true}),yield ne(s,`${Object.values(V).length>0?`import * as Shared from "./shared";
|
|
82
|
+
`:""}${g}`,e);}if(((we=e==null?void 0:e.validations)==null?void 0:we.disable)!==true){let t=((ze=e.validations)==null?void 0:ze.library)||"zod",r=t==="joi"?'import Joi from "joi";':t==="yup"?'import * as yup from "yup";':'import { z } from "zod";',f=Object.values(O).map(l=>l.validation).filter(l=>l.length>0).join("");if(f){let l=M__default.default.join(Y,y,"validations.ts");yield U__default.default.promises.mkdir(M__default.default.dirname(l),{recursive:true}),yield Z(l,`${r}
|
|
65
83
|
|
|
66
|
-
|
|
84
|
+
${f}`,e);}}}),qt=Mt;var he=process.cwd(),Cr=u=>ne(null,null,function*(){let d;try{re("esbuild-register");}catch(E){throw E}let e=M__default.default.join(he,"openapi.sync.js"),j=M__default.default.join(he,"openapi.sync.ts"),b=M__default.default.join(he,"openapi.sync.json"),v=[e,j,b];try{for(let E of v)U__default.default.existsSync(E)&&(d=re(E),Object.keys(d).length===1&&d.default&&(d=d.default));}catch(E){console.log(E);}typeof d=="function"&&(d=d());let m=d;if(!m)throw new Error("No config found");let y=Object.keys(m.api),O=u&&"refetchInterval"in u&&!isNaN(u==null?void 0:u.refetchInterval)?u.refetchInterval:m.refetchInterval;Rt();for(let E=0;E<y.length;E+=1){let P=y[E],B=m.api[P];qt(B,P,m,O);}});exports.Init=Cr;exports.JSONStringify=se;exports.capitalize=K;exports.createCustomCodeMarker=At;exports.extractCustomCode=Ut;exports.getEndpointDetails=St;exports.getNestedValue=er;exports.isJson=ct;exports.isYamlString=Gt;exports.mergeCustomCode=wt;exports.renderTypeRefMD=ue;exports.variableName=Xt;exports.variableNameChar=Et;exports.yamlStringToJson=Tt;
|