openapi-sync 2.1.12 → 2.1.14
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 +30 -25
- package/bin/cli.js +1 -0
- package/dist/chunk-RSLDWPYW.mjs +11 -0
- package/dist/chunk-RSLDWPYW.mjs.map +1 -0
- package/dist/chunk-UYNJZXTD.mjs +2 -0
- package/dist/chunk-UYNJZXTD.mjs.map +1 -0
- package/dist/helpers.d.mts +14 -0
- package/dist/helpers.d.ts +14 -0
- package/dist/helpers.js +11 -0
- package/dist/helpers.js.map +1 -0
- package/dist/helpers.mjs +2 -0
- package/dist/helpers.mjs.map +1 -0
- package/dist/index.d.mts +3 -17
- package/dist/index.d.ts +3 -17
- package/dist/index.js +46 -45
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +38 -46
- package/dist/index.mjs.map +1 -0
- package/dist/regex.d.mts +4 -0
- package/dist/regex.d.ts +4 -0
- package/dist/regex.js +2 -0
- package/dist/regex.js.map +1 -0
- package/dist/regex.mjs +2 -0
- package/dist/regex.mjs.map +1 -0
- package/package.json +18 -5
package/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
[](https://www.npmjs.com/package/openapi-sync)
|
|
2
2
|
[](https://github.com/akintomiwa-fisayo/openapi-sync/blob/main/LICENSE)
|
|
3
|
+
[](https://github.com/akintomiwa-fisayo/openapi-sync)
|
|
3
4
|
|
|
4
5
|
**OpenAPI Sync** is a powerful developer tool that automates the synchronization of your API documentation with your codebase using OpenAPI (formerly Swagger) specifications. It generates TypeScript types, endpoint definitions, and comprehensive documentation from your OpenAPI schema, ensuring your API documentation stays up-to-date with your code.
|
|
5
6
|
|
|
@@ -436,15 +437,12 @@ OpenAPI Sync generates a structured output in your specified folder:
|
|
|
436
437
|
```
|
|
437
438
|
src/api/
|
|
438
439
|
├── petstore/
|
|
439
|
-
│ ├── endpoints.ts
|
|
440
|
-
│ └── types
|
|
441
|
-
|
|
442
|
-
│
|
|
443
|
-
└──
|
|
444
|
-
|
|
445
|
-
└── types/
|
|
446
|
-
├── index.ts
|
|
447
|
-
└── shared.ts
|
|
440
|
+
│ ├── endpoints.ts # Endpoint URLs and metadata
|
|
441
|
+
│ └── types.ts # Endpoint-specific types
|
|
442
|
+
├── auth-api/
|
|
443
|
+
│ ├── endpoints.ts # Endpoint URLs and metadata
|
|
444
|
+
│ └── types.ts # Endpoint-specific types
|
|
445
|
+
└── shared.ts # Shared component types
|
|
448
446
|
```
|
|
449
447
|
|
|
450
448
|
### Folder Splitting Structure
|
|
@@ -456,26 +454,21 @@ src/api/
|
|
|
456
454
|
├── petstore/
|
|
457
455
|
│ ├── admin/ # Endpoints with "admin" tag
|
|
458
456
|
│ │ ├── endpoints.ts
|
|
459
|
-
│ │ └── types
|
|
460
|
-
│ │ ├── index.ts
|
|
461
|
-
│ │ └── shared.ts
|
|
457
|
+
│ │ └── types.ts
|
|
462
458
|
│ ├── public/ # Endpoints with "public" tag
|
|
463
459
|
│ │ ├── endpoints.ts
|
|
464
|
-
│ │ └── types
|
|
465
|
-
│ │ ├── index.ts
|
|
466
|
-
│ │ └── shared.ts
|
|
460
|
+
│ │ └── types.ts
|
|
467
461
|
│ └── user/ # Endpoints with "user" tag
|
|
468
462
|
│ ├── endpoints.ts
|
|
469
|
-
│ └── types
|
|
470
|
-
|
|
471
|
-
│
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
└── types/
|
|
463
|
+
│ └── types.ts
|
|
464
|
+
│── auth-api/
|
|
465
|
+
│ ├── v1/ # Custom folder logic
|
|
466
|
+
│ │ ├── endpoints.ts
|
|
467
|
+
│ │ └── types.ts
|
|
468
|
+
│ └── v2/
|
|
469
|
+
│ ├── endpoints.ts
|
|
470
|
+
│ └── types.ts
|
|
471
|
+
└── shared.ts # Shared component types
|
|
479
472
|
```
|
|
480
473
|
|
|
481
474
|
### Generated Endpoints
|
|
@@ -1186,9 +1179,21 @@ The tool maintains state in `db.json` to track changes:
|
|
|
1186
1179
|
|
|
1187
1180
|
### Previous Versions
|
|
1188
1181
|
|
|
1182
|
+
- v2.1.13: Fix dts type fixes and Clean up tsup build config and introduction of unit testing
|
|
1183
|
+
- v2.1.12: Add automatic sync support for function-based config, improved handling of missing OpenAPI urls
|
|
1184
|
+
- v2.1.11: Folder splitting configuration for organized code generation
|
|
1185
|
+
- v2.1.10: OperationId-based naming for types and endpoints, enhanced filtering and tag support
|
|
1189
1186
|
- v2.1.9: Enhanced JSONStringify function improvements
|
|
1190
1187
|
- v2.1.8: File extension corrections and path handling
|
|
1191
1188
|
- v2.1.7: Endpoint tags support in API documentation
|
|
1189
|
+
- v2.1.6: Improved handling of nullable fields in generated types
|
|
1190
|
+
- v2.1.5: Fixed bug with recursive schema references
|
|
1191
|
+
- v2.1.4: Enhanced error messages on invalid config
|
|
1192
|
+
- v2.1.3: Add more informative debugging logs
|
|
1193
|
+
- v2.1.2: Support enum descriptions in output
|
|
1194
|
+
- v2.1.1: Update dependencies, minor TypeScript type fixes
|
|
1195
|
+
- v2.1.0: Initial v2 major release with new sync engine
|
|
1196
|
+
- v2.0.0: Major refactor and breaking changes for v2
|
|
1192
1197
|
|
|
1193
1198
|
## License
|
|
1194
1199
|
|
package/bin/cli.js
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {d as d$1}from'./chunk-UYNJZXTD.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};//# sourceMappingURL=chunk-RSLDWPYW.mjs.map
|
|
11
|
+
//# sourceMappingURL=chunk-RSLDWPYW.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../helpers.ts"],"names":["isJson","value","isYamlString","fileContent","en","yamlStringToJson","content","jsonString","capitalize","text","getEndpointDetails","path","method","pathParts","name","variables","part","s","partVal","char","variableNameChar","val","JSONStringify","obj","indent","result","keys","i","key","j","item","line","renderTypeRefMD","typeRef","getNestedValue","currentObj"],"mappings":"s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AAA,CAE9CC,CAAAA,EAAUxB,EACP,KAAA,CAAM;AAAA,CAAI,CAAA,CACV,OAAQ8B,CAAAA,EAAiBA,CAAAA,CAAK,MAAK,GAAM,EAAE,EAC3C,IAAA,CAAK;AAAA,EAAK,MAAA,CAAO,MAAA,CAAOP,CAAM,CAAC,EAAE,CAAA,CAGlCG,CAAAA,CAAID,CAAAA,CAAK,MAAA,CAAS,CAAA,GACpBD,CAAAA,EAAU,IAAA,EAEd,CAEA,OAAAA,CAAAA,EAAU;AAAA,EAAK,MAAA,CAAO,MAAA,CAAOD,CAAAA,CAAS,CAAC,CAAC,CAAA,CAAA,CAAA,CACjCC,CACT,CAAA,CAEaO,CAAAA,CAAkB,CAACC,CAAAA,CAAiBT,CAAAA,CAAS,CAAA,GACjD;AAAA;AAAA,EAAuB,KAAK,MAAA,CAAOA,CAAM,CAAC,CAAA,EAAA,EAAKS,EACnD,KAAA,CAAM;AAAA,CAAI,CAAA,CACV,OAAQF,CAAAA,EAASA,CAAAA,CAAK,MAAK,GAAM,EAAE,EACnC,IAAA,CAAK;AAAA,EAAK,IAAA,CAAK,MAAA,CAAOP,CAAM,CAAC,IAAI,CAAC;AAAA,MAAA,EAGhC,SAASU,CAAAA,CAAkBX,CAAAA,CAAaZ,CAAAA,CAA6B,CAK1E,OAHaA,CAAAA,CAAK,KAAA,CAAM,GAAG,CAAA,CAGf,MAAA,CAAO,CAACwB,EAAiBP,CAAAA,GAG5BO,CAAAA,EAAcA,CAAAA,CAAWP,CAAG,CAAA,GAAM,MAAA,CACrCO,EAAWP,CAAG,CAAA,CACd,MAAA,CACHL,CAAG,CACR","file":"chunk-RSLDWPYW.mjs","sourcesContent":["import { variableNameChar } from \"./regex\";\nimport * as yaml from \"js-yaml\";\n\nexport const isJson = (value: any) => {\n return [\"object\"].includes(typeof value) && !(value instanceof Blob);\n};\n\nexport const isYamlString = (fileContent: string) => {\n try {\n yaml.load(fileContent);\n return true;\n } catch (en) {\n const e = en as any;\n if (e instanceof yaml.YAMLException) {\n return false;\n } else {\n throw e;\n }\n }\n};\n\nexport const yamlStringToJson = (fileContent: string) => {\n if (isYamlString(fileContent)) {\n const content = yaml.load(fileContent);\n\n const jsonString = JSON.stringify(content, null, 2);\n const json = JSON.parse(jsonString);\n return json;\n }\n};\n\nexport const capitalize = (text: string) => {\n const capitalizedWord =\n text.substring(0, 1).toUpperCase() + text.substring(1);\n return capitalizedWord;\n};\n\nexport const getEndpointDetails = (path: string, method: string) => {\n const pathParts = path.split(\"/\");\n let name = `${capitalize(method)}`;\n const variables: string[] = [];\n pathParts.forEach((part) => {\n // check if part is a variable\n //api/{userId}\n if (part[0] === \"{\" && part[part.length - 1] === \"}\") {\n const s = part.replace(/{/, \"\").replace(/}/, \"\");\n variables.push(s);\n part = `$${s}`;\n }\n\n //api/<userId>\n else if (part[0] === \"<\" && part[part.length - 1] === \">\") {\n const s = part.replace(/</, \"\").replace(/>/, \"\");\n variables.push(s);\n part = `$${s}`;\n }\n\n //api/:userId\n else if (part[0] === \":\") {\n const s = part.replace(/:/, \"\");\n variables.push(s);\n part = `$${s}`;\n }\n\n // parse to variable name\n let partVal = \"\";\n part.split(\"\").forEach((char) => {\n let c = char;\n if (!variableNameChar.test(char)) c = \"/\";\n partVal += c;\n });\n\n partVal.split(\"/\").forEach((val) => {\n name += capitalize(val);\n });\n });\n\n return { name, variables, pathParts };\n};\n\nexport const JSONStringify = (obj: Record<string, any>, indent = 1) => {\n let result = \"{\";\n const keys = Object.keys(obj);\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const value = obj[key];\n\n result += \"\\n\" + \" \".repeat(indent) + key + \": \";\n\n if (Array.isArray(value)) {\n result += \"[\";\n for (let j = 0; j < value.length; j++) {\n const item = value[j];\n if (typeof item === \"object\" && item !== null) {\n result += JSONStringify(item, indent + 1);\n } else {\n result += typeof item === \"string\" ? `\"${item}\"` : item;\n }\n if (j < value.length - 1) {\n result += \", \";\n }\n }\n result += \"]\";\n } else if (typeof value === \"object\" && value !== null) {\n result += \"\" + JSONStringify(value, indent + 1);\n } else {\n result += value\n .split(\"\\n\")\n .filter((line: string) => line.trim() !== \"\")\n .join(`\\n${\" \".repeat(indent)}`);\n }\n\n if (i < keys.length - 1) {\n result += \", \";\n }\n }\n\n result += `\\n${\" \".repeat(indent - 1)}}`;\n return result;\n};\n\nexport const renderTypeRefMD = (typeRef: string, indent = 1) => {\n return `\\n\\`\\`\\`typescript\\n${\" \".repeat(indent)} ${typeRef\n .split(\"\\n\")\n .filter((line) => line.trim() !== \"\")\n .join(`\\n${\" \".repeat(indent)} `)}\\n\\`\\`\\``;\n};\n\nexport function getNestedValue<T>(obj: object, path: string): T | undefined {\n // Split the path string into an array of keys\n const keys = path.split(\".\");\n\n // Use the reduce method to navigate the object\n return keys.reduce((currentObj: any, key: string) => {\n // If the current object is not null or undefined,\n // return the value of the next key. Otherwise, return undefined.\n return currentObj && currentObj[key] !== undefined\n ? currentObj[key]\n : undefined;\n }, obj) as T | undefined;\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
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};//# sourceMappingURL=chunk-UYNJZXTD.mjs.map
|
|
2
|
+
//# sourceMappingURL=chunk-UYNJZXTD.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../regex.ts"],"names":["variableName","variableNameChar"],"mappings":"+eAAO,IAAMA,CAAAA,CAAe,6BACfC,CAAAA,CAAmB","file":"chunk-UYNJZXTD.mjs","sourcesContent":["export const variableName = /^[A-Za-z_$][A-Za-z0-9_$]*$/;\nexport const variableNameChar = /[A-Za-z0-9_$]/;\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
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 };
|
|
@@ -0,0 +1,14 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
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;//# sourceMappingURL=helpers.js.map
|
|
11
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../regex.ts","../helpers.ts"],"names":["variableNameChar","isJson","value","isYamlString","fileContent","c","en","yamlStringToJson","content","jsonString","capitalize","text","getEndpointDetails","path","method","pathParts","name","variables","part","s","partVal","char","val","JSONStringify","obj","indent","result","keys","i","key","j","item","line","renderTypeRefMD","typeRef","getNestedValue","currentObj"],"mappings":"4YACO,IAAMA,CAAAA,CAAmB,eAAA,CCEzB,IAAMC,CAAAA,CAAUC,CAAAA,EACd,CAAC,QAAQ,CAAA,CAAE,QAAA,CAAS,OAAOA,CAAK,CAAA,EAAK,EAAEA,CAAAA,YAAiB,IAAA,CAAA,CAGpDC,CAAAA,CAAgBC,CAAAA,EAAwB,CACnD,GAAI,CACF,OAAKC,YAAA,CAAA,IAAA,CAAKD,CAAW,CAAA,CACd,CAAA,CACT,CAAA,MAASE,EAAI,CACX,IAAM,CAAA,CAAIA,CAAAA,CACV,GAAI,CAAA,YAAkBD,YAAA,CAAA,aAAA,CACpB,OAAO,MAAA,CAEP,MAAM,CAEV,CACF,CAAA,CAEaE,CAAAA,CAAoBH,CAAAA,EAAwB,CACvD,GAAID,CAAAA,CAAaC,CAAW,CAAA,CAAG,CAC7B,IAAMI,CAAAA,CAAeH,Y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AK,MAAA,CAAOA,CAAM,CAAC,CAAA,EAAA,EAAKS,EACnD,KAAA,CAAM;AAAA,CAAI,CAAA,CACV,OAAQF,CAAAA,EAASA,CAAAA,CAAK,MAAK,GAAM,EAAE,EACnC,IAAA,CAAK;AAAA,EAAK,IAAA,CAAK,MAAA,CAAOP,CAAM,CAAC,IAAI,CAAC;AAAA,MAAA,EAGhC,SAASU,CAAAA,CAAkBX,CAAAA,CAAaX,CAAAA,CAA6B,CAK1E,OAHaA,CAAAA,CAAK,KAAA,CAAM,GAAG,CAAA,CAGf,MAAA,CAAO,CAACuB,EAAiBP,CAAAA,GAG5BO,CAAAA,EAAcA,CAAAA,CAAWP,CAAG,CAAA,GAAM,MAAA,CACrCO,EAAWP,CAAG,CAAA,CACd,MAAA,CACHL,CAAG,CACR","file":"helpers.js","sourcesContent":["export const variableName = /^[A-Za-z_$][A-Za-z0-9_$]*$/;\nexport const variableNameChar = /[A-Za-z0-9_$]/;\n","import { variableNameChar } from \"./regex\";\nimport * as yaml from \"js-yaml\";\n\nexport const isJson = (value: any) => {\n return [\"object\"].includes(typeof value) && !(value instanceof Blob);\n};\n\nexport const isYamlString = (fileContent: string) => {\n try {\n yaml.load(fileContent);\n return true;\n } catch (en) {\n const e = en as any;\n if (e instanceof yaml.YAMLException) {\n return false;\n } else {\n throw e;\n }\n }\n};\n\nexport const yamlStringToJson = (fileContent: string) => {\n if (isYamlString(fileContent)) {\n const content = yaml.load(fileContent);\n\n const jsonString = JSON.stringify(content, null, 2);\n const json = JSON.parse(jsonString);\n return json;\n }\n};\n\nexport const capitalize = (text: string) => {\n const capitalizedWord =\n text.substring(0, 1).toUpperCase() + text.substring(1);\n return capitalizedWord;\n};\n\nexport const getEndpointDetails = (path: string, method: string) => {\n const pathParts = path.split(\"/\");\n let name = `${capitalize(method)}`;\n const variables: string[] = [];\n pathParts.forEach((part) => {\n // check if part is a variable\n //api/{userId}\n if (part[0] === \"{\" && part[part.length - 1] === \"}\") {\n const s = part.replace(/{/, \"\").replace(/}/, \"\");\n variables.push(s);\n part = `$${s}`;\n }\n\n //api/<userId>\n else if (part[0] === \"<\" && part[part.length - 1] === \">\") {\n const s = part.replace(/</, \"\").replace(/>/, \"\");\n variables.push(s);\n part = `$${s}`;\n }\n\n //api/:userId\n else if (part[0] === \":\") {\n const s = part.replace(/:/, \"\");\n variables.push(s);\n part = `$${s}`;\n }\n\n // parse to variable name\n let partVal = \"\";\n part.split(\"\").forEach((char) => {\n let c = char;\n if (!variableNameChar.test(char)) c = \"/\";\n partVal += c;\n });\n\n partVal.split(\"/\").forEach((val) => {\n name += capitalize(val);\n });\n });\n\n return { name, variables, pathParts };\n};\n\nexport const JSONStringify = (obj: Record<string, any>, indent = 1) => {\n let result = \"{\";\n const keys = Object.keys(obj);\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const value = obj[key];\n\n result += \"\\n\" + \" \".repeat(indent) + key + \": \";\n\n if (Array.isArray(value)) {\n result += \"[\";\n for (let j = 0; j < value.length; j++) {\n const item = value[j];\n if (typeof item === \"object\" && item !== null) {\n result += JSONStringify(item, indent + 1);\n } else {\n result += typeof item === \"string\" ? `\"${item}\"` : item;\n }\n if (j < value.length - 1) {\n result += \", \";\n }\n }\n result += \"]\";\n } else if (typeof value === \"object\" && value !== null) {\n result += \"\" + JSONStringify(value, indent + 1);\n } else {\n result += value\n .split(\"\\n\")\n .filter((line: string) => line.trim() !== \"\")\n .join(`\\n${\" \".repeat(indent)}`);\n }\n\n if (i < keys.length - 1) {\n result += \", \";\n }\n }\n\n result += `\\n${\" \".repeat(indent - 1)}}`;\n return result;\n};\n\nexport const renderTypeRefMD = (typeRef: string, indent = 1) => {\n return `\\n\\`\\`\\`typescript\\n${\" \".repeat(indent)} ${typeRef\n .split(\"\\n\")\n .filter((line) => line.trim() !== \"\")\n .join(`\\n${\" \".repeat(indent)} `)}\\n\\`\\`\\``;\n};\n\nexport function getNestedValue<T>(obj: object, path: string): T | undefined {\n // Split the path string into an array of keys\n const keys = path.split(\".\");\n\n // Use the reduce method to navigate the object\n return keys.reduce((currentObj: any, key: string) => {\n // If the current object is not null or undefined,\n // return the value of the next key. Otherwise, return undefined.\n return currentObj && currentObj[key] !== undefined\n ? currentObj[key]\n : undefined;\n }, obj) as T | undefined;\n}\n"]}
|
package/dist/helpers.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
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-RSLDWPYW.mjs';import'./chunk-UYNJZXTD.mjs';//# sourceMappingURL=helpers.mjs.map
|
|
2
|
+
//# sourceMappingURL=helpers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"helpers.mjs"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
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';
|
|
2
4
|
|
|
3
5
|
type IOpenApiSpec = Record<"openapi", string> & Record<string, any>;
|
|
4
6
|
type IOpenApSchemaSpec = {
|
|
@@ -149,24 +151,8 @@ type IOpenApiSecuritySchemes = {
|
|
|
149
151
|
};
|
|
150
152
|
};
|
|
151
153
|
|
|
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
|
-
|
|
168
154
|
declare const Init: (options?: {
|
|
169
155
|
refetchInterval?: number;
|
|
170
156
|
}) => Promise<void>;
|
|
171
157
|
|
|
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
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
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';
|
|
2
4
|
|
|
3
5
|
type IOpenApiSpec = Record<"openapi", string> & Record<string, any>;
|
|
4
6
|
type IOpenApSchemaSpec = {
|
|
@@ -149,24 +151,8 @@ type IOpenApiSecuritySchemes = {
|
|
|
149
151
|
};
|
|
150
152
|
};
|
|
151
153
|
|
|
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
|
-
|
|
168
154
|
declare const Init: (options?: {
|
|
169
155
|
refetchInterval?: number;
|
|
170
156
|
}) => Promise<void>;
|
|
171
157
|
|
|
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
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,56 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
`+" ".repeat(
|
|
3
|
-
`).filter(
|
|
4
|
-
${" ".repeat(
|
|
5
|
-
${" ".repeat(
|
|
1
|
+
'use strict';var M=require('fs'),F=require('path'),g=require('js-yaml'),pt=require('lodash.isequal'),_e=require('lodash.get'),lt=require('axios'),mt=require('axios-retry'),dt=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 M__default=/*#__PURE__*/_interopDefault(M);var F__default=/*#__PURE__*/_interopDefault(F);var g__namespace=/*#__PURE__*/_interopNamespace(g);var pt__default=/*#__PURE__*/_interopDefault(pt);var _e__default=/*#__PURE__*/_interopDefault(_e);var lt__default=/*#__PURE__*/_interopDefault(lt);var mt__default=/*#__PURE__*/_interopDefault(mt);var dt__default=/*#__PURE__*/_interopDefault(dt);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__namespace.load(o),!0}catch(m){let e=m;if(e instanceof g__namespace.YAMLException)return false;throw e}},Ge=o=>{if(ot(o)){let m=g__namespace.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
6
|
\`\`\`typescript
|
|
7
|
-
${" ".repeat(
|
|
7
|
+
${" ".repeat(m)} ${o.split(`
|
|
8
8
|
`).filter(e=>e.trim()!=="").join(`
|
|
9
|
-
${" ".repeat(
|
|
10
|
-
\`\`\``;function
|
|
11
|
-
`).filter(
|
|
12
|
-
*${" ".repeat(1)}`))),
|
|
13
|
-
${
|
|
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__default.default.join(__dirname,"../","../db.json");M__default.default.existsSync(oe)||M__default.default.writeFileSync(oe,"{}");var le={};try{le=D(oe);}catch(o){le={};}var ee=le||{},Ze=o=>{M__default.default.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__default.default.create({timeout:6e4});mt__default.default(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__default.default.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__default.default.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__default.default(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}
|
|
14
14
|
*/
|
|
15
|
-
`:"")+`${
|
|
16
|
-
${" ".repeat(p)}${
|
|
17
|
-
`:""}`:""},
|
|
18
|
-
`);a.length>0?
|
|
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__default.default(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(`,
|
|
18
|
+
`);a.length>0?n+=`{
|
|
19
19
|
${a}
|
|
20
|
-
}`:
|
|
21
|
-
`).filter(
|
|
22
|
-
*${" ".repeat(1)}`)),
|
|
23
|
-
${
|
|
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__default.default(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}
|
|
24
24
|
*/
|
|
25
|
-
`:"")+"export type "+
|
|
26
|
-
|
|
27
|
-
${
|
|
28
|
-
`;e!=null&&e.folderSplit?
|
|
29
|
-
`;e!=null&&e.folderSplit?
|
|
30
|
-
`;e!=null&&e.folderSplit?
|
|
31
|
-
- Scopes: [\`${
|
|
32
|
-
- ${v}${
|
|
33
|
-
`),
|
|
34
|
-
--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];}),$=`
|
|
35
35
|
\`\`\`bash
|
|
36
|
-
${
|
|
37
|
-
|
|
36
|
+
${curlGenerator.CurlGenerator({url:G+s,method:n.toUpperCase(),headers:B,body:N})}${q}
|
|
37
|
+
\`\`\``;}K=`/**${t!=null&&t.description?`
|
|
38
38
|
* ${t==null?void 0:t.description} `:""}
|
|
39
|
-
* **Method**: \`${
|
|
39
|
+
* **Method**: \`${n.toUpperCase()}\`
|
|
40
40
|
* **Summary**: ${(t==null?void 0:t.summary)||""}
|
|
41
|
-
* **Tags**: [${((
|
|
42
|
-
* **OperationId**: ${(t==null?void 0:t.operationId)||""} ${
|
|
43
|
-
* **Query**: ${
|
|
44
|
-
* **DTO**: ${
|
|
45
|
-
* **Response**: ${Object.entries(w).map(([d,
|
|
46
|
-
- **${d}**: ${
|
|
47
|
-
* **Security**: ${
|
|
48
|
-
`:""}${
|
|
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
|
+
`:""}${$}
|
|
49
49
|
*/
|
|
50
|
-
|
|
51
|
-
`;e!=null&&e.folderSplit?
|
|
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__default.default.join(h,s);if(r.endpoints){let f=F__default.default.join(te,I,"endpoints.ts");yield M__default.default.promises.mkdir(F__default.default.dirname(f),{recursive:true}),yield M__default.default.promises.writeFile(f,r.endpoints);}if(r.types){let f=F__default.default.join(te,I,"types.ts");yield M__default.default.promises.mkdir(F__default.default.dirname(f),{recursive:true});let n=Object.values(W).length>0?`import * as Shared from "../shared";
|
|
52
52
|
|
|
53
|
-
${r.types}`:r.types;yield
|
|
54
|
-
`))}if(
|
|
53
|
+
${r.types}`:r.types;yield M__default.default.promises.writeFile(f,n);}}}if(ie.length>0){let s=F__default.default.join(te,h,"endpoints.ts");yield M__default.default.promises.mkdir(F__default.default.dirname(s),{recursive:true}),yield M__default.default.promises.writeFile(s,ie);}if(Object.values(W).length>0){let s=F__default.default.join(te,h,e!=null&&e.folderSplit?"":"types","shared.ts");yield M__default.default.promises.mkdir(F__default.default.dirname(s),{recursive:true}),yield M__default.default.promises.writeFile(s,Object.values(W).join(`
|
|
54
|
+
`));}if(Q.length>0){let s=F__default.default.join(te,h,"types","index.ts");yield M__default.default.promises.mkdir(F__default.default.dirname(s),{recursive:true}),yield M__default.default.promises.writeFile(s,`${Object.values(W).length>0?`import * as Shared from "./shared";
|
|
55
55
|
|
|
56
|
-
`:""}${
|
|
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__default.default.join(ue,"openapi.sync.js"),C=F__default.default.join(ue,"openapi.sync.ts"),A=F__default.default.join(ue,"openapi.sync.json"),b=[e,C,A];try{for(let R of b)M__default.default.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);}});exports.Init=zt;exports.JSONStringify=_;exports.capitalize=V;exports.getEndpointDetails=Qe;exports.getNestedValue=Ot;exports.isJson=Ye;exports.isYamlString=ot;exports.renderTypeRefMD=ae;exports.variableName=ft;exports.variableNameChar=We;exports.yamlStringToJson=Ge;//# sourceMappingURL=index.js.map
|
|
57
|
+
//# sourceMappingURL=index.js.map
|