openapi-sync 2.1.16 → 2.1.17
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/dist/index.d.mts +17 -3
- package/dist/index.d.ts +17 -3
- package/dist/index.mjs +44 -35
- package/package.json +1 -1
- package/dist/chunk-6GQNHE6A.mjs +0 -1
- package/dist/chunk-ALDCDVEN.mjs +0 -10
- package/dist/helpers.d.mts +0 -14
- package/dist/helpers.d.ts +0 -14
- package/dist/helpers.js +0 -10
- package/dist/helpers.mjs +0 -1
- package/dist/regex.d.mts +0 -4
- package/dist/regex.d.ts +0 -4
- package/dist/regex.js +0 -1
- package/dist/regex.mjs +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { Method } from 'axios';
|
|
2
|
-
export { JSONStringify, capitalize, getEndpointDetails, getNestedValue, isJson, isYamlString, renderTypeRefMD, yamlStringToJson } from './helpers.mjs';
|
|
3
|
-
export { variableName, variableNameChar } from './regex.mjs';
|
|
4
2
|
|
|
5
3
|
type IOpenApiSpec = Record<"openapi", string> & Record<string, any>;
|
|
6
4
|
type IOpenApSchemaSpec = {
|
|
@@ -151,8 +149,24 @@ type IOpenApiSecuritySchemes = {
|
|
|
151
149
|
};
|
|
152
150
|
};
|
|
153
151
|
|
|
152
|
+
declare const isJson: (value: any) => boolean;
|
|
153
|
+
declare const isYamlString: (fileContent: string) => boolean;
|
|
154
|
+
declare const yamlStringToJson: (fileContent: string) => any;
|
|
155
|
+
declare const capitalize: (text: string) => string;
|
|
156
|
+
declare const getEndpointDetails: (path: string, method: string) => {
|
|
157
|
+
name: string;
|
|
158
|
+
variables: string[];
|
|
159
|
+
pathParts: string[];
|
|
160
|
+
};
|
|
161
|
+
declare const JSONStringify: (obj: Record<string, any>, indent?: number) => string;
|
|
162
|
+
declare const renderTypeRefMD: (typeRef: string, indent?: number) => string;
|
|
163
|
+
declare function getNestedValue<T>(obj: object, path: string): T | undefined;
|
|
164
|
+
|
|
165
|
+
declare const variableName: RegExp;
|
|
166
|
+
declare const variableNameChar: RegExp;
|
|
167
|
+
|
|
154
168
|
declare const Init: (options?: {
|
|
155
169
|
refetchInterval?: number;
|
|
156
170
|
}) => Promise<void>;
|
|
157
171
|
|
|
158
|
-
export { type IConfig, 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 };
|
|
172
|
+
export { type IConfig, 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, getEndpointDetails, getNestedValue, isJson, isYamlString, renderTypeRefMD, variableName, variableNameChar, yamlStringToJson };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { Method } from 'axios';
|
|
2
|
-
export { JSONStringify, capitalize, getEndpointDetails, getNestedValue, isJson, isYamlString, renderTypeRefMD, yamlStringToJson } from './helpers.js';
|
|
3
|
-
export { variableName, variableNameChar } from './regex.js';
|
|
4
2
|
|
|
5
3
|
type IOpenApiSpec = Record<"openapi", string> & Record<string, any>;
|
|
6
4
|
type IOpenApSchemaSpec = {
|
|
@@ -151,8 +149,24 @@ type IOpenApiSecuritySchemes = {
|
|
|
151
149
|
};
|
|
152
150
|
};
|
|
153
151
|
|
|
152
|
+
declare const isJson: (value: any) => boolean;
|
|
153
|
+
declare const isYamlString: (fileContent: string) => boolean;
|
|
154
|
+
declare const yamlStringToJson: (fileContent: string) => any;
|
|
155
|
+
declare const capitalize: (text: string) => string;
|
|
156
|
+
declare const getEndpointDetails: (path: string, method: string) => {
|
|
157
|
+
name: string;
|
|
158
|
+
variables: string[];
|
|
159
|
+
pathParts: string[];
|
|
160
|
+
};
|
|
161
|
+
declare const JSONStringify: (obj: Record<string, any>, indent?: number) => string;
|
|
162
|
+
declare const renderTypeRefMD: (typeRef: string, indent?: number) => string;
|
|
163
|
+
declare function getNestedValue<T>(obj: object, path: string): T | undefined;
|
|
164
|
+
|
|
165
|
+
declare const variableName: RegExp;
|
|
166
|
+
declare const variableNameChar: RegExp;
|
|
167
|
+
|
|
154
168
|
declare const Init: (options?: {
|
|
155
169
|
refetchInterval?: number;
|
|
156
170
|
}) => Promise<void>;
|
|
157
171
|
|
|
158
|
-
export { type IConfig, 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 };
|
|
172
|
+
export { type IConfig, 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, getEndpointDetails, getNestedValue, isJson, isYamlString, renderTypeRefMD, variableName, variableNameChar, yamlStringToJson };
|
package/dist/index.mjs
CHANGED
|
@@ -1,47 +1,56 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
${A}
|
|
1
|
+
import M from'fs';import F from'path';import*as g from'js-yaml';import pt from'lodash.isequal';import _e from'lodash.get';import lt from'axios';import mt from'axios-retry';import dt from'@apidevtools/swagger-parser';import {CurlGenerator}from'curl-generator';var D=(o=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(o,{get:(m,e)=>(typeof require!="undefined"?require:m)[e]}):o)(function(o){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+o+'" is not supported')});var ne=(o,m,e)=>new Promise((C,A)=>{var b=O=>{try{h(e.next(O));}catch(R){A(R);}},u=O=>{try{h(e.throw(O));}catch(R){A(R);}},h=O=>O.done?C(O.value):Promise.resolve(O.value).then(b,u);h((e=e.apply(o,m)).next());});var ft=/^[A-Za-z_$][A-Za-z0-9_$]*$/,We=/[A-Za-z0-9_$]/;var Ye=o=>["object"].includes(typeof o)&&!(o instanceof Blob),ot=o=>{try{return g.load(o),!0}catch(m){let e=m;if(e instanceof g.YAMLException)return false;throw e}},Ge=o=>{if(ot(o)){let m=g.load(o),e=JSON.stringify(m,null,2);return JSON.parse(e)}},V=o=>o.substring(0,1).toUpperCase()+o.substring(1),Qe=(o,m)=>{let e=o.split("/"),C=`${V(m)}`,A=[];return e.forEach(b=>{if(b[0]==="{"&&b[b.length-1]==="}"){let h=b.replace(/{/,"").replace(/}/,"");A.push(h),b=`$${h}`;}else if(b[0]==="<"&&b[b.length-1]===">"){let h=b.replace(/</,"").replace(/>/,"");A.push(h),b=`$${h}`;}else if(b[0]===":"){let h=b.replace(/:/,"");A.push(h),b=`$${h}`;}let u="";b.split("").forEach(h=>{let O=h;We.test(h)||(O="/"),u+=O;}),u.split("/").forEach(h=>{C+=V(h);});}),{name:C,variables:A,pathParts:e}},_=(o,m=1)=>{let e="{",C=Object.keys(o);for(let A=0;A<C.length;A++){let b=C[A],u=o[b];if(e+=`
|
|
2
|
+
`+" ".repeat(m)+b+": ",Array.isArray(u)){e+="[";for(let h=0;h<u.length;h++){let O=u[h];typeof O=="object"&&O!==null?e+=_(O,m+1):e+=typeof O=="string"?`"${O}"`:O,h<u.length-1&&(e+=", ");}e+="]";}else typeof u=="object"&&u!==null?e+=""+_(u,m+1):e+=u.split(`
|
|
3
|
+
`).filter(h=>h.trim()!=="").join(`
|
|
4
|
+
${" ".repeat(m)}`);A<C.length-1&&(e+=", ");}return e+=`
|
|
5
|
+
${" ".repeat(m-1)}}`,e},ae=(o,m=1)=>`
|
|
6
|
+
\`\`\`typescript
|
|
7
|
+
${" ".repeat(m)} ${o.split(`
|
|
8
|
+
`).filter(e=>e.trim()!=="").join(`
|
|
9
|
+
${" ".repeat(m)} `)}
|
|
10
|
+
\`\`\``;function Ot(o,m){return m.split(".").reduce((C,A)=>C&&C[A]!==void 0?C[A]:void 0,o)}var oe=F.join(__dirname,"../","../db.json");M.existsSync(oe)||M.writeFileSync(oe,"{}");var le={};try{le=D(oe);}catch(o){le={};}var ee=le||{},Ze=o=>{M.writeFileSync(oe,JSON.stringify(o));},He=(o,m)=>{ee[o]=m,Ze(ee);},Xe=o=>ee[o],De=()=>{ee={},Ze(ee);};var te=process.cwd(),me={},ge=lt.create({timeout:6e4});mt(ge,{retries:20,retryCondition:o=>o.code==="ECONNABORTED"||o.message.includes("Network Error"),retryDelay:o=>o*1e3});var et=(o,m,e,C)=>ne(null,null,function*(){var fe,he,ce,Oe,Ie,je;let A=yield ge.get(o),b=Ye(A.data)?A.data:Ge(A.data),u;try{u=yield dt.parse(b);}catch(s){let r=s instanceof Error?s.message:String(s);throw new Error(`Failed to parse OpenAPI spec for ${m}: ${r}`)}let h=F.join((e==null?void 0:e.folder)||"",m),O={},R=s=>{var r,I;if((r=e==null?void 0:e.folderSplit)!=null&&r.customFolder){let f=e.folderSplit.customFolder(s);if(console.log("customFolder",f),f)return f}return (I=e==null?void 0:e.folderSplit)!=null&&I.byTags&&s.tags&&s.tags.length>0?s.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},G=typeof(e==null?void 0:e.server)=="string"?e==null?void 0:e.server:((he=(fe=u==null?void 0:u.servers)==null?void 0:fe[(e==null?void 0:e.server)||0])==null?void 0:he.url)||"",k=typeof((Oe=(ce=e==null?void 0:e.types)==null?void 0:ce.name)==null?void 0:Oe.prefix)=="string"?e==null?void 0:e.types.name.prefix:"I",rt=typeof((je=(Ie=e==null?void 0:e.endpoints)==null?void 0:Ie.name)==null?void 0:je.prefix)=="string"?e==null?void 0:e.endpoints.name.prefix:"",ye=(s,r)=>{var f,n;let I=V(s);if((n=(f=e==null?void 0:e.types)==null?void 0:f.name)!=null&&n.format){let p=e==null?void 0:e.types.name.format("shared",{name:s},I);if(p)return `${k}${p}`}return `${k}${I}`},J=(s,r,I,f,n,p=0)=>{let c="",a="",i="";if(r){if(r.$ref)if(r.$ref[0]==="#"){let l=(r.$ref||"").split("/");l.shift(),[...l].pop();let w=_e(s,l,null);if(w){w!=null&&w.name&&(c=w.name),a=l[l.length-1];let S=ye(a);S.includes(".")&&(S=S.split(".").map((U,K)=>K===0?U:`["${U}"]`).join("")),i+=`${n!=null&&n.noSharedImport?"":"Shared."}${S}`;}}else i+="";else if(r.anyOf)i+=`(${r.anyOf.map(l=>J(s,l,"",f,n)).filter(l=>!!l).join("|")})`;else if(r.oneOf)i+=`(${r.oneOf.map(l=>J(s,l,"",f,n)).filter(l=>!!l).join("|")})`;else if(r.allOf)i+=`(${r.allOf.map(l=>J(s,l,"",f,n)).filter(l=>!!l).join("&")})`;else if(r.items)i+=`${J(s,r.items,"",false,n)}[]`;else if(r.properties){let l=Object.keys(r.properties),j=r.required||[],T="";l.forEach(w=>{var Z,U,K,Y,re,H;let S="";!((U=(Z=e==null?void 0:e.types)==null?void 0:Z.doc)!=null&&U.disable)&&((Y=(K=r.properties)==null?void 0:K[w])!=null&&Y.description)&&(S=" * "+((re=r.properties)==null?void 0:re[w].description.split(`
|
|
11
|
+
`).filter(se=>se.trim()!=="").join(`
|
|
12
|
+
*${" ".repeat(1)}`))),T+=(S?`/**
|
|
13
|
+
${S}
|
|
5
14
|
*/
|
|
6
|
-
`:"")+`${
|
|
7
|
-
${" ".repeat(p)}${
|
|
8
|
-
`:""}`:""},
|
|
15
|
+
`:"")+`${J(s,(H=r.properties)==null?void 0:H[w],w,j.includes(w),n,p+1)}`;}),T.length>0?i+=`{
|
|
16
|
+
${" ".repeat(p)}${T}${" ".repeat(p)}}`:i+="{[k: string]: any}";}else if(r.enum&&r.enum.length>0)r.enum.length>1&&(i+="("),r.enum.map(l=>JSON.stringify(l)).filter(l=>!!l).forEach((l,j)=>{i+=`${j===0?"":"|"}${l}`;}),r.enum.length>1&&(i+=")");else if(r.type){let l=j=>{let T="";if(typeof j=="string")["string","integer","number","array","boolean","null"].includes(j)?["integer","number"].includes(j)?T+="number":j==="array"?T+="any[]":T+=j:j==="object"&&(r.additionalProperties?T+=`{[k: string]: ${J(s,r.additionalProperties,"",true,n)||"any"}}`:T+="{[k: string]: any}");else if(Array.isArray(j)){let w=j.map(S=>l(S));w.filter(S=>S!==""),w.length>1&&(T+="("+w.join("|")+")");}else T+="any";return T};i=l(r.type);}}else i="string";let y=c||I;n!=null&&n.useComponentName&&!y&&(y=a);let E=y?` "${y}"${f?"":"?"}: `:"",t=r!=null&&r.nullable?" | null":"";return i.length>0?`${E}${i}${t}${y?`;
|
|
17
|
+
`:""}`:""},z=(s,r)=>{let n="";if(r){if(r.$ref)if(r.$ref[0]==="#"){let p=(r.$ref||"").split("/");p.shift();let a=_e(s,p,null);a&&(a!=null&&a.name&&(a.name),p[p.length-1],n+=z(s,a));}else n+="";else if(r.anyOf)n+=z(s,r.anyOf[0]);else if(r.oneOf)n+=z(s,r.oneOf[0]);else if(r.allOf)n+=`{${r.allOf.map(p=>`...(${z(s,p)})`).join(",")}}`;else if(r.items)n+=`[${z(s,r.items)}]`;else if(r.properties){let a=Object.keys(r.properties).map(i=>{var y;return ` "${i}": ${z(s,(y=r.properties)==null?void 0:y[i])}`}).join(`,
|
|
9
18
|
`);a.length>0?n+=`{
|
|
10
19
|
${a}
|
|
11
|
-
}`:n+="{}";}else if(r.enum&&r.enum.length>0)r.enum.length>1&&(n+=r.enum[0]);else if(r.type)if(r.example)n+=JSON.stringify(r.example);else {let p=
|
|
12
|
-
`).filter(
|
|
13
|
-
*${" ".repeat(1)}`)),
|
|
14
|
-
${
|
|
20
|
+
}`:n+="{}";}else if(r.enum&&r.enum.length>0)r.enum.length>1&&(n+=r.enum[0]);else if(r.type)if(r.example)n+=JSON.stringify(r.example);else {let p=c=>{let a="";if(typeof c=="string")["string","integer","number","array","boolean","null"].includes(c)?["integer","number"].includes(c)?a+="123":c==="array"?a+="[]":c==="boolean"?a+="true":c==="null"?a+="null":a+=`"${c}"`:c==="object"&&(a+="{}");else if(Array.isArray(c)){let i=c.map(y=>p(y));i.filter(y=>y!==""),i.length>1&&(a+=i.join("|"));}else a+="any";return a};n=p(r.type);}}else n="string";return n};C&&!isNaN(C)&&C>0&&(process.env.NODE_ENV&&["production","prod","test","staging"].includes(process.env.NODE_ENV)||(me[m]&&clearTimeout(me[m]),me[m]=setTimeout(()=>et(o,m,e,C),C)));let st=Xe(m);if(pt(st,u))return;He(m,u);let ie="",Q="",W={};u.components&&Object.keys(u.components).forEach(s=>{if(["schemas","responses","parameters","examples","requestBodies","headers","links","callbacks"].includes(s)){let r=u.components[s],I={},f={};Object.keys(r).forEach(p=>{var i;let c=(i=r[p])!=null&&i.schema?r[p].schema:r[p],a=`${J(u,c,"",true,{noSharedImport:true,useComponentName:["parameters"].includes(s)})}`;if(a){let y=p.split("."),E=I,t=f;for(let l=0;l<y.length;l++){let j=y[l];l<y.length-1?(j in E||(E[j]={},t[j]={}),E=E[j],t=t[j]):(E[j]=a,t[j]=c);}}}),Object.keys(I).forEach(p=>{var y,E,t,l;let c=ye(p),a=I[p],i="";!((E=(y=e==null?void 0:e.types)==null?void 0:y.doc)!=null&&E.disable)&&p in r&&((t=r[p])!=null&&t.description)&&(i=" * "+r[p].description.split(`
|
|
21
|
+
`).filter(j=>j.trim()!=="").join(`
|
|
22
|
+
*${" ".repeat(1)}`)),W[p]=((l=W[p])!=null?l:"")+(i?`/**
|
|
23
|
+
${i}
|
|
15
24
|
*/
|
|
16
|
-
`:"")+"export type "+
|
|
17
|
-
`;});}});let
|
|
18
|
-
${
|
|
19
|
-
`;e
|
|
20
|
-
`;e
|
|
21
|
-
`;e
|
|
22
|
-
- Scopes: [\`${
|
|
23
|
-
- ${
|
|
24
|
-
`),
|
|
25
|
-
--cert client-certificate.crt --key client-private-key.key --cacert ca-certificate.crt`:
|
|
25
|
+
`:"")+"export type "+c+" = "+(typeof a=="string"?a:_(a))+`;
|
|
26
|
+
`;});}});let $e=s=>{let r="";if(s.content){let I=Object.keys(s.content);I[0]&&s.content[I[0]].schema&&(r+=`${J(u,s.content[I[0]].schema,"")}`);}return r},nt=s=>{var r,I,f,n,p;if((I=(r=e==null?void 0:e.endpoints)==null?void 0:r.value)!=null&&I.replaceWords&&Array.isArray(e==null?void 0:e.endpoints.value.replaceWords)){let c=s;return (p=(n=(f=e==null?void 0:e.endpoints)==null?void 0:f.value)==null?void 0:n.replaceWords)==null||p.forEach((a,i)=>{let y=new RegExp(a.replace,"g");c=c.replace(y,a.with||"");}),c}else return s},at=(s,r,I=[])=>{var p,c;let f=(p=e==null?void 0:e.endpoints)==null?void 0:p.exclude,n=(c=e==null?void 0:e.endpoints)==null?void 0:c.include;if(n){let a=n.tags&&n.tags.length>0?I.some(y=>n.tags.includes(y)):true,i=n.endpoints&&n.endpoints.length>0?n.endpoints.some(y=>{let E=!y.method||y.method.toLowerCase()===r.toLowerCase();return y.path?s===y.path&&E:y.regex?new RegExp(y.regex).test(s)&&E:false}):true;if(!a||!i)return true}return !!(f&&(f.tags&&f.tags.length>0&&I.some(i=>f.tags.includes(i))||f.endpoints&&f.endpoints.length>0&&f.endpoints.some(i=>{let y=!i.method||i.method.toLowerCase()===r.toLowerCase();return i.path?s===i.path&&y:i.regex?new RegExp(i.regex).test(s)&&y:false})))};if(Object.keys(u.paths||{}).forEach(s=>{let r=u.paths[s];Object.keys(r).forEach(f=>{var se,be,xe,Ce,Ae,Ee,Te,we,Se,Ne,Re,ve,Fe,Pe,ke,qe,Be,Me,Je,Ue,Le,ze,Ke,Ve;let n=f,p=Qe(s,n),c=((se=r[n])==null?void 0:se.tags)||[];if(at(s,n,c))return;let a=r[n],i=R({method:n,path:s,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId,tags:c,parameters:a==null?void 0:a.parameters,requestBody:a==null?void 0:a.requestBody,responses:a==null?void 0:a.responses});O[i]||(O[i]={endpoints:"",types:""});let y=((xe=(be=e==null?void 0:e.endpoints)==null?void 0:be.value)!=null&&xe.includeServer?G:"")+p.pathParts.map($=>($[0]==="{"&&$[$.length-1]==="}"?$=`\${${$.replace(/{/,"").replace(/}/,"")}}`:$[0]==="<"&&$[$.length-1]===">"?$=`\${${$.replace(/</,"").replace(/>/,"")}}`:$[0]===":"&&($=`\${${$.replace(/:/,"")}}`),$)).join("/"),E=`"${y}"`;p.variables.length>0&&(E=`(${p.variables.map(d=>`${d}:string`).join(",")})=> \`${y}\``),E=nt(E);let t=r[n],l="";if(t!=null&&t.parameters&&((t==null?void 0:t.parameters).forEach((d,N)=>{(d.$ref||d.in==="query"&&d.name)&&(l+=`${J(u,d.$ref?d:d.schema,d.name||"",d.required)}`);}),l)){l=`{
|
|
27
|
+
${l}}`;let d=`${p.name}Query`;if((Ae=(Ce=e==null?void 0:e.types)==null?void 0:Ce.name)!=null&&Ae.useOperationId&&(t!=null&&t.operationId)&&(d=`${t.operationId}Query`),d=V(`${k}${d}`),(Te=(Ee=e==null?void 0:e.types)==null?void 0:Ee.name)!=null&&Te.format){let q=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"query",method:n,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},d);q&&(d=`${k}${q}`);}let N=`export type ${d} = ${l};
|
|
28
|
+
`;e!=null&&e.folderSplit?O[i].types+=N:Q+=N;}let j=t==null?void 0:t.requestBody,T="";if(j&&(T=$e(j),T)){let $=`${p.name}DTO`;if((Se=(we=e==null?void 0:e.types)==null?void 0:we.name)!=null&&Se.useOperationId&&(t!=null&&t.operationId)&&($=`${t.operationId}DTO`),$=V(`${k}${$}`),(Re=(Ne=e==null?void 0:e.types)==null?void 0:Ne.name)!=null&&Re.format){let N=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"dto",method:n,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},$);N&&($=`${k}${N}`);}let d=`export type ${$} = ${T};
|
|
29
|
+
`;e!=null&&e.folderSplit?O[i].types+=d:Q+=d;}let w={},S="";if(t!=null&&t.responses){let $=t==null?void 0:t.responses;Object.keys($).forEach(N=>{var q,B,v,P;if(S=$e($[N]),w[N]=S,S){let x=`${p.name}${N}Response`;if((B=(q=e==null?void 0:e.types)==null?void 0:q.name)!=null&&B.useOperationId&&(t!=null&&t.operationId)&&(x=`${t.operationId}${N}Response`),x=V(`${k}${x}`),(P=(v=e==null?void 0:e.types)==null?void 0:v.name)!=null&&P.format){let X=e==null?void 0:e.types.name.format("endpoint",{code:N,type:"response",method:n,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},x);X&&(x=`${k}${X}`);}let L=`export type ${x} = ${S};
|
|
30
|
+
`;e!=null&&e.folderSplit?O[i].types+=L:Q+=L;}});}let Z=$=>!$||!$.length?"":$.map(d=>Object.entries(d).map(([q,B])=>{let v=q,P="";return Array.isArray(B)&&B.length&&(P=`
|
|
31
|
+
- Scopes: [\`${B.join("`, `")}\`]`,v=`**${v}**`),`
|
|
32
|
+
- ${v}${P}`}).join("")).join(`
|
|
33
|
+
`),U=t!=null&&t.security?Z(t.security):"",K="";if(!((Fe=(ve=e==null?void 0:e.endpoints)==null?void 0:ve.doc)!=null&&Fe.disable)){let $="";if((ke=(Pe=e==null?void 0:e.endpoints)==null?void 0:Pe.doc)!=null&&ke.showCurl){let d={},N="",q="";(qe=t.requestBody)!=null&&qe.content&&Object.keys(t.requestBody.content).forEach(P=>{let x=t.requestBody.content[P].schema;if(x){Array.isArray(d["Content-type"])?d["Content-type"].push(P):d["Content-type"]=[P];let L=z(u,x);L&&(N=L);}}),t!=null&&t.security&&t.security.forEach(v=>{Object.keys(v).forEach(P=>{var L,X;let x=(X=(L=u.components)==null?void 0:L.securitySchemes)==null?void 0:X[P];x&&(x.type==="mutualTLS"?q+=`
|
|
34
|
+
--cert client-certificate.crt --key client-private-key.key --cacert ca-certificate.crt`:x.type==="apiKey"?d[(x==null?void 0:x.name)||"X-API-KEY"]="{API_KEY_VALUE}":d.Authorization=`${(x==null?void 0:x.scheme)==="basic"?"Basic":"Bearer"} {${(x==null?void 0:x.scheme)==="basic"?"VALUE":"TOKEN"}}`);});});let B={};Object.keys(d).forEach(v=>{Array.isArray(d[v])?B[v]=d[v].join("; "):B[v]=d[v];}),$=`
|
|
26
35
|
\`\`\`bash
|
|
27
|
-
${CurlGenerator({url:G+s,method:n.toUpperCase(),headers:
|
|
36
|
+
${CurlGenerator({url:G+s,method:n.toUpperCase(),headers:B,body:N})}${q}
|
|
28
37
|
\`\`\``;}K=`/**${t!=null&&t.description?`
|
|
29
38
|
* ${t==null?void 0:t.description} `:""}
|
|
30
39
|
* **Method**: \`${n.toUpperCase()}\`
|
|
31
40
|
* **Summary**: ${(t==null?void 0:t.summary)||""}
|
|
32
|
-
* **Tags**: [${((
|
|
33
|
-
* **OperationId**: ${(t==null?void 0:t.operationId)||""} ${
|
|
34
|
-
* **Query**: ${
|
|
35
|
-
* **DTO**: ${
|
|
36
|
-
* **Response**: ${Object.entries(
|
|
37
|
-
- **${
|
|
38
|
-
* **Security**: ${
|
|
39
|
-
`:""}${
|
|
41
|
+
* **Tags**: [${((Be=t==null?void 0:t.tags)==null?void 0:Be.join(", "))||""}]
|
|
42
|
+
* **OperationId**: ${(t==null?void 0:t.operationId)||""} ${l?`
|
|
43
|
+
* **Query**: ${ae(l)} `:""}${T?`
|
|
44
|
+
* **DTO**: ${ae(T)} `:""}${S?`
|
|
45
|
+
* **Response**: ${Object.entries(w).map(([d,N])=>`
|
|
46
|
+
- **${d}**: ${ae(N,2)} `).join("")}`:""}${U?`
|
|
47
|
+
* **Security**: ${U}
|
|
48
|
+
`:""}${$}
|
|
40
49
|
*/
|
|
41
|
-
`;}let
|
|
42
|
-
`;e
|
|
50
|
+
`;}let Y=(Je=(Me=e==null?void 0:e.endpoints)==null?void 0:Me.name)!=null&&Je.useOperationId&&((Ue=t==null?void 0:t.operationId)==null?void 0:Ue.length)>0?t.operationId:`${p.name}`;if((ze=(Le=e==null?void 0:e.endpoints)==null?void 0:Le.name)!=null&&ze.format){let $=e==null?void 0:e.endpoints.name.format({method:n,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},Y);$&&(Y=$);}let re={method:`"${n}"`,operationId:`"${t==null?void 0:t.operationId}"`,url:E,tags:(t==null?void 0:t.tags)||[]},H=`${K}export const ${rt}${Y} = ${((Ve=(Ke=e==null?void 0:e.endpoints)==null?void 0:Ke.value)==null?void 0:Ve.type)==="object"?_(re):E};
|
|
51
|
+
`;e!=null&&e.folderSplit?O[i].endpoints+=H:ie+=H;});}),e!=null&&e.folderSplit){for(let[s,r]of Object.entries(O))if(r.endpoints||r.types){let I=F.join(h,s);if(r.endpoints){let f=F.join(te,I,"endpoints.ts");yield M.promises.mkdir(F.dirname(f),{recursive:true}),yield M.promises.writeFile(f,r.endpoints);}if(r.types){let f=F.join(te,I,"types.ts");yield M.promises.mkdir(F.dirname(f),{recursive:true});let n=Object.values(W).length>0?`import * as Shared from "../shared";
|
|
43
52
|
|
|
44
|
-
${r.types}`:r.types;yield
|
|
45
|
-
`));}if(Q.length>0){let s=
|
|
53
|
+
${r.types}`:r.types;yield M.promises.writeFile(f,n);}}}if(ie.length>0){let s=F.join(te,h,"endpoints.ts");yield M.promises.mkdir(F.dirname(s),{recursive:true}),yield M.promises.writeFile(s,ie);}if(Object.values(W).length>0){let s=F.join(te,h,e!=null&&e.folderSplit?"":"types","shared.ts");yield M.promises.mkdir(F.dirname(s),{recursive:true}),yield M.promises.writeFile(s,Object.values(W).join(`
|
|
54
|
+
`));}if(Q.length>0){let s=F.join(te,h,"types","index.ts");yield M.promises.mkdir(F.dirname(s),{recursive:true}),yield M.promises.writeFile(s,`${Object.values(W).length>0?`import * as Shared from "./shared";
|
|
46
55
|
|
|
47
|
-
`:""}${Q}`);}}),
|
|
56
|
+
`:""}${Q}`);}}),tt=et;var ue=process.cwd(),zt=o=>ne(null,null,function*(){let m;try{D("esbuild-register");}catch(R){throw R}let e=F.join(ue,"openapi.sync.js"),C=F.join(ue,"openapi.sync.ts"),A=F.join(ue,"openapi.sync.json"),b=[e,C,A];try{for(let R of b)M.existsSync(R)&&(m=D(R),Object.keys(m).length===1&&m.default&&(m=m.default));}catch(R){console.log(R);}typeof m=="function"&&(m=m());let u=m;if(!u)throw new Error("No config found");let h=Object.keys(u.api),O=o&&"refetchInterval"in o&&!isNaN(o==null?void 0:o.refetchInterval)?o.refetchInterval:u.refetchInterval;De();for(let R=0;R<h.length;R+=1){let G=h[R],k=u.api[G];tt(k,G,u,O);}});export{zt as Init,_ as JSONStringify,V as capitalize,Qe as getEndpointDetails,Ot as getNestedValue,Ye as isJson,ot as isYamlString,ae as renderTypeRefMD,ft as variableName,We as variableNameChar,Ge as yamlStringToJson};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openapi-sync",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.17",
|
|
4
4
|
"description": "A developer-friendly tool designed to keep your API up-to-date by leveraging OpenAPI schemas. It automates the generation of endpoint URIs and type definitions, including shared types, directly from your OpenAPI specification.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
package/dist/chunk-6GQNHE6A.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var b=(e=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(e,{get:(o,r)=>(typeof require!="undefined"?require:o)[r]}):e)(function(e){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var c=(e,o,r)=>new Promise((A,z)=>{var Z=a=>{try{t(r.next(a));}catch($){z($);}},_=a=>{try{t(r.throw(a));}catch($){z($);}},t=a=>a.done?A(a.value):Promise.resolve(a.value).then(Z,_);t((r=r.apply(e,o)).next());});var l=/^[A-Za-z_$][A-Za-z0-9_$]*$/,m=/[A-Za-z0-9_$]/;export{b as a,c as b,l as c,m as d};
|
package/dist/chunk-ALDCDVEN.mjs
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import {d as d$1}from'./chunk-6GQNHE6A.mjs';import*as a from'js-yaml';var d=n=>["object"].includes(typeof n)&&!(n instanceof Blob),u=n=>{try{return a.load(n),!0}catch(s){let e=s;if(e instanceof a.YAMLException)return false;throw e}},h=n=>{if(u(n)){let s=a.load(n),e=JSON.stringify(s,null,2);return JSON.parse(e)}},p=n=>n.substring(0,1).toUpperCase()+n.substring(1),m=(n,s)=>{let e=n.split("/"),i=`${p(s)}`,o=[];return e.forEach(r=>{if(r[0]==="{"&&r[r.length-1]==="}"){let t=r.replace(/{/,"").replace(/}/,"");o.push(t),r=`$${t}`;}else if(r[0]==="<"&&r[r.length-1]===">"){let t=r.replace(/</,"").replace(/>/,"");o.push(t),r=`$${t}`;}else if(r[0]===":"){let t=r.replace(/:/,"");o.push(t),r=`$${t}`;}let l="";r.split("").forEach(t=>{let c=t;d$1.test(t)||(c="/"),l+=c;}),l.split("/").forEach(t=>{i+=p(t);});}),{name:i,variables:o,pathParts:e}},g=(n,s=1)=>{let e="{",i=Object.keys(n);for(let o=0;o<i.length;o++){let r=i[o],l=n[r];if(e+=`
|
|
2
|
-
`+" ".repeat(s)+r+": ",Array.isArray(l)){e+="[";for(let t=0;t<l.length;t++){let c=l[t];typeof c=="object"&&c!==null?e+=g(c,s+1):e+=typeof c=="string"?`"${c}"`:c,t<l.length-1&&(e+=", ");}e+="]";}else typeof l=="object"&&l!==null?e+=""+g(l,s+1):e+=l.split(`
|
|
3
|
-
`).filter(t=>t.trim()!=="").join(`
|
|
4
|
-
${" ".repeat(s)}`);o<i.length-1&&(e+=", ");}return e+=`
|
|
5
|
-
${" ".repeat(s-1)}}`,e},$=(n,s=1)=>`
|
|
6
|
-
\`\`\`typescript
|
|
7
|
-
${" ".repeat(s)} ${n.split(`
|
|
8
|
-
`).filter(e=>e.trim()!=="").join(`
|
|
9
|
-
${" ".repeat(s)} `)}
|
|
10
|
-
\`\`\``;function j(n,s){return s.split(".").reduce((i,o)=>i&&i[o]!==void 0?i[o]:void 0,n)}export{d as a,u as b,h as c,p as d,m as e,g as f,$ as g,j as h};
|
package/dist/helpers.d.mts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
declare const isJson: (value: any) => boolean;
|
|
2
|
-
declare const isYamlString: (fileContent: string) => boolean;
|
|
3
|
-
declare const yamlStringToJson: (fileContent: string) => any;
|
|
4
|
-
declare const capitalize: (text: string) => string;
|
|
5
|
-
declare const getEndpointDetails: (path: string, method: string) => {
|
|
6
|
-
name: string;
|
|
7
|
-
variables: string[];
|
|
8
|
-
pathParts: string[];
|
|
9
|
-
};
|
|
10
|
-
declare const JSONStringify: (obj: Record<string, any>, indent?: number) => string;
|
|
11
|
-
declare const renderTypeRefMD: (typeRef: string, indent?: number) => string;
|
|
12
|
-
declare function getNestedValue<T>(obj: object, path: string): T | undefined;
|
|
13
|
-
|
|
14
|
-
export { JSONStringify, capitalize, getEndpointDetails, getNestedValue, isJson, isYamlString, renderTypeRefMD, yamlStringToJson };
|
package/dist/helpers.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
declare const isJson: (value: any) => boolean;
|
|
2
|
-
declare const isYamlString: (fileContent: string) => boolean;
|
|
3
|
-
declare const yamlStringToJson: (fileContent: string) => any;
|
|
4
|
-
declare const capitalize: (text: string) => string;
|
|
5
|
-
declare const getEndpointDetails: (path: string, method: string) => {
|
|
6
|
-
name: string;
|
|
7
|
-
variables: string[];
|
|
8
|
-
pathParts: string[];
|
|
9
|
-
};
|
|
10
|
-
declare const JSONStringify: (obj: Record<string, any>, indent?: number) => string;
|
|
11
|
-
declare const renderTypeRefMD: (typeRef: string, indent?: number) => string;
|
|
12
|
-
declare function getNestedValue<T>(obj: object, path: string): T | undefined;
|
|
13
|
-
|
|
14
|
-
export { JSONStringify, capitalize, getEndpointDetails, getNestedValue, isJson, isYamlString, renderTypeRefMD, yamlStringToJson };
|
package/dist/helpers.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
'use strict';var c=require('js-yaml');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 c__namespace=/*#__PURE__*/_interopNamespace(c);var p=/[A-Za-z0-9_$]/;var $=n=>["object"].includes(typeof n)&&!(n instanceof Blob),u=n=>{try{return c__namespace.load(n),!0}catch(s){let e=s;if(e instanceof c__namespace.YAMLException)return false;throw e}},h=n=>{if(u(n)){let s=c__namespace.load(n),e=JSON.stringify(s,null,2);return JSON.parse(e)}},f=n=>n.substring(0,1).toUpperCase()+n.substring(1),d=(n,s)=>{let e=n.split("/"),i=`${f(s)}`,o=[];return e.forEach(r=>{if(r[0]==="{"&&r[r.length-1]==="}"){let t=r.replace(/{/,"").replace(/}/,"");o.push(t),r=`$${t}`;}else if(r[0]==="<"&&r[r.length-1]===">"){let t=r.replace(/</,"").replace(/>/,"");o.push(t),r=`$${t}`;}else if(r[0]===":"){let t=r.replace(/:/,"");o.push(t),r=`$${t}`;}let l="";r.split("").forEach(t=>{let a=t;p.test(t)||(a="/"),l+=a;}),l.split("/").forEach(t=>{i+=f(t);});}),{name:i,variables:o,pathParts:e}},g=(n,s=1)=>{let e="{",i=Object.keys(n);for(let o=0;o<i.length;o++){let r=i[o],l=n[r];if(e+=`
|
|
2
|
-
`+" ".repeat(s)+r+": ",Array.isArray(l)){e+="[";for(let t=0;t<l.length;t++){let a=l[t];typeof a=="object"&&a!==null?e+=g(a,s+1):e+=typeof a=="string"?`"${a}"`:a,t<l.length-1&&(e+=", ");}e+="]";}else typeof l=="object"&&l!==null?e+=""+g(l,s+1):e+=l.split(`
|
|
3
|
-
`).filter(t=>t.trim()!=="").join(`
|
|
4
|
-
${" ".repeat(s)}`);o<i.length-1&&(e+=", ");}return e+=`
|
|
5
|
-
${" ".repeat(s-1)}}`,e},x=(n,s=1)=>`
|
|
6
|
-
\`\`\`typescript
|
|
7
|
-
${" ".repeat(s)} ${n.split(`
|
|
8
|
-
`).filter(e=>e.trim()!=="").join(`
|
|
9
|
-
${" ".repeat(s)} `)}
|
|
10
|
-
\`\`\``;function b(n,s){return s.split(".").reduce((i,o)=>i&&i[o]!==void 0?i[o]:void 0,n)}exports.JSONStringify=g;exports.capitalize=f;exports.getEndpointDetails=d;exports.getNestedValue=b;exports.isJson=$;exports.isYamlString=u;exports.renderTypeRefMD=x;exports.yamlStringToJson=h;
|
package/dist/helpers.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export{f as JSONStringify,d as capitalize,e as getEndpointDetails,h as getNestedValue,a as isJson,b as isYamlString,g as renderTypeRefMD,c as yamlStringToJson}from'./chunk-ALDCDVEN.mjs';import'./chunk-6GQNHE6A.mjs';
|
package/dist/regex.d.mts
DELETED
package/dist/regex.d.ts
DELETED
package/dist/regex.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
'use strict';var a=/^[A-Za-z_$][A-Za-z0-9_$]*$/,e=/[A-Za-z0-9_$]/;exports.variableName=a;exports.variableNameChar=e;
|
package/dist/regex.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export{c as variableName,d as variableNameChar}from'./chunk-6GQNHE6A.mjs';
|