openapi-sync 2.1.12 → 2.1.13
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-6GQNHE6A.mjs +1 -0
- package/dist/chunk-ALDCDVEN.mjs +10 -0
- package/dist/helpers.d.mts +14 -0
- package/dist/helpers.d.ts +14 -0
- package/dist/helpers.js +10 -0
- package/dist/helpers.mjs +1 -0
- package/dist/index.d.mts +3 -17
- package/dist/index.d.ts +3 -17
- package/dist/index.js +2 -2
- package/dist/index.mjs +36 -45
- package/dist/regex.d.mts +4 -0
- package/dist/regex.d.ts +4 -0
- package/dist/regex.js +1 -0
- package/dist/regex.mjs +1 -0
- package/package.json +12 -4
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 @@
|
|
|
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};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import{d as f}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!1;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;f.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};
|
|
@@ -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,10 @@
|
|
|
1
|
+
"use strict";var $=Object.create;var p=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var j=(e,n)=>{for(var t in n)p(e,t,{get:n[t],enumerable:!0})},u=(e,n,t,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of d(n))!b.call(e,r)&&r!==t&&p(e,r,{get:()=>n[r],enumerable:!(i=h(n,r))||i.enumerable});return e};var N=(e,n,t)=>(t=e!=null?$(x(e)):{},u(n||!e||!e.__esModule?p(t,"default",{value:e,enumerable:!0}):t,e)),S=e=>u(p({},"__esModule",{value:!0}),e);var k={};j(k,{JSONStringify:()=>g,capitalize:()=>f,getEndpointDetails:()=>E,getNestedValue:()=>T,isJson:()=>z,isYamlString:()=>m,renderTypeRefMD:()=>J,yamlStringToJson:()=>A});module.exports=S(k);var y=/[A-Za-z0-9_$]/;var c=N(require("js-yaml")),z=e=>["object"].includes(typeof e)&&!(e instanceof Blob),m=e=>{try{return c.load(e),!0}catch(n){let t=n;if(t instanceof c.YAMLException)return!1;throw t}},A=e=>{if(m(e)){let n=c.load(e),t=JSON.stringify(n,null,2);return JSON.parse(t)}},f=e=>e.substring(0,1).toUpperCase()+e.substring(1),E=(e,n)=>{let t=e.split("/"),i=`${f(n)}`,r=[];return t.forEach(o=>{if(o[0]==="{"&&o[o.length-1]==="}"){let s=o.replace(/{/,"").replace(/}/,"");r.push(s),o=`$${s}`}else if(o[0]==="<"&&o[o.length-1]===">"){let s=o.replace(/</,"").replace(/>/,"");r.push(s),o=`$${s}`}else if(o[0]===":"){let s=o.replace(/:/,"");r.push(s),o=`$${s}`}let l="";o.split("").forEach(s=>{let a=s;y.test(s)||(a="/"),l+=a}),l.split("/").forEach(s=>{i+=f(s)})}),{name:i,variables:r,pathParts:t}},g=(e,n=1)=>{let t="{",i=Object.keys(e);for(let r=0;r<i.length;r++){let o=i[r],l=e[o];if(t+=`
|
|
2
|
+
`+" ".repeat(n)+o+": ",Array.isArray(l)){t+="[";for(let s=0;s<l.length;s++){let a=l[s];typeof a=="object"&&a!==null?t+=g(a,n+1):t+=typeof a=="string"?`"${a}"`:a,s<l.length-1&&(t+=", ")}t+="]"}else typeof l=="object"&&l!==null?t+=""+g(l,n+1):t+=l.split(`
|
|
3
|
+
`).filter(s=>s.trim()!=="").join(`
|
|
4
|
+
${" ".repeat(n)}`);r<i.length-1&&(t+=", ")}return t+=`
|
|
5
|
+
${" ".repeat(n-1)}}`,t},J=(e,n=1)=>`
|
|
6
|
+
\`\`\`typescript
|
|
7
|
+
${" ".repeat(n)} ${e.split(`
|
|
8
|
+
`).filter(t=>t.trim()!=="").join(`
|
|
9
|
+
${" ".repeat(n)} `)}
|
|
10
|
+
\`\`\``;function T(e,n){return n.split(".").reduce((i,r)=>i&&i[r]!==void 0?i[r]:void 0,e)}0&&(module.exports={JSONStringify,capitalize,getEndpointDetails,getNestedValue,isJson,isYamlString,renderTypeRefMD,yamlStringToJson});
|
package/dist/helpers.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b,c,d,e,f,g,h}from"./chunk-ALDCDVEN.mjs";import"./chunk-6GQNHE6A.mjs";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};
|
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
|
@@ -7,7 +7,7 @@ ${" ".repeat(i-1)}}`,e},ee=(n,i=1)=>`
|
|
|
7
7
|
${" ".repeat(i)} ${n.split(`
|
|
8
8
|
`).filter(e=>e.trim()!=="").join(`
|
|
9
9
|
${" ".repeat(i)} `)}
|
|
10
|
-
\`\`\``;function Tt(n,i){return i.split(".").reduce((j,O)=>j&&j[O]!==void 0?j[O]:void 0,n)}var at=q(require("lodash.isequal")),Ie=q(require("lodash.get")),it=q(require("axios")),lt=q(require("axios-retry")),pe=require("@redocly/openapi-core");var tt=q(require("path")),ie=q(require("fs")),le=tt.default.join(__dirname,"../","../db.json");ie.default.existsSync(le)||ie.default.writeFileSync(le,"{}");var ce={};try{ce=require(le)}catch(n){ce={}}var te=ce||{},rt=n=>{ie.default.writeFileSync(le,JSON.stringify(n))},st=(n,i)=>{te[n]=i,rt(te)},nt=n=>te[n],ot=()=>{te={},rt(te)};var pt=require("curl-generator");var re=process.cwd(),Oe={},mt=it.default.create({timeout:6e4});(0,lt.default)(mt,{retries:20,retryCondition:n=>n.code==="ECONNABORTED"||n.message.includes("Network Error"),retryDelay:n=>n*1e3});var dt=(n,i,e,j)=>ae(null,null,function*(){var Ae,Ee,Te,Se,we,Ne;let O=yield mt.get(n),x=yield(0,pe.createConfig)({extends:["minimal"]}),E=JSON.stringify($e(O.data)?O.data:fe(O.data)),c=yield(0,pe.bundleFromString)({source:E,config:x}),C=F.default.join((e==null?void 0:e.folder)||"",i),f=c.bundle.parsed,B={},de=s=>{var r,I;if((r=e==null?void 0:e.folderSplit)!=null&&r.customFolder){let $=e.folderSplit.customFolder(s);if(
|
|
10
|
+
\`\`\``;function Tt(n,i){return i.split(".").reduce((j,O)=>j&&j[O]!==void 0?j[O]:void 0,n)}var at=q(require("lodash.isequal")),Ie=q(require("lodash.get")),it=q(require("axios")),lt=q(require("axios-retry")),pe=require("@redocly/openapi-core");var tt=q(require("path")),ie=q(require("fs")),le=tt.default.join(__dirname,"../","../db.json");ie.default.existsSync(le)||ie.default.writeFileSync(le,"{}");var ce={};try{ce=require(le)}catch(n){ce={}}var te=ce||{},rt=n=>{ie.default.writeFileSync(le,JSON.stringify(n))},st=(n,i)=>{te[n]=i,rt(te)},nt=n=>te[n],ot=()=>{te={},rt(te)};var pt=require("curl-generator");var re=process.cwd(),Oe={},mt=it.default.create({timeout:6e4});(0,lt.default)(mt,{retries:20,retryCondition:n=>n.code==="ECONNABORTED"||n.message.includes("Network Error"),retryDelay:n=>n*1e3});var dt=(n,i,e,j)=>ae(null,null,function*(){var Ae,Ee,Te,Se,we,Ne;let O=yield mt.get(n),x=yield(0,pe.createConfig)({extends:["minimal"]}),E=JSON.stringify($e(O.data)?O.data:fe(O.data)),c=yield(0,pe.bundleFromString)({source:E,config:x}),C=F.default.join((e==null?void 0:e.folder)||"",i),f=c.bundle.parsed,B={},de=s=>{var r,I;if((r=e==null?void 0:e.folderSplit)!=null&&r.customFolder){let $=e.folderSplit.customFolder(s);if(console.log("customFolder",$),$)return $}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"},je=typeof(e==null?void 0:e.server)=="string"?e==null?void 0:e.server:((Ee=(Ae=f==null?void 0:f.servers)==null?void 0:Ae[(e==null?void 0:e.server)||0])==null?void 0:Ee.url)||"",L=typeof((Se=(Te=e==null?void 0:e.types)==null?void 0:Te.name)==null?void 0:Se.prefix)=="string"?e==null?void 0:e.types.name.prefix:"I",$t=typeof((Ne=(we=e==null?void 0:e.endpoints)==null?void 0:we.name)==null?void 0:Ne.prefix)=="string"?e==null?void 0:e.endpoints.name.prefix:"",Ce=(s,r)=>{var $,o;let I=V(s);if((o=($=e==null?void 0:e.types)==null?void 0:$.name)!=null&&o.format){let p=e==null?void 0:e.types.name.format("shared",{name:s},I);if(p)return`${L}${p}`}return`${L}${I}`},U=(s,r,I,$,o,p=0)=>{let h="",a="",l="";if(r){if(r.$ref)if(r.$ref[0]==="#"){let m=(r.$ref||"").split("/");m.shift(),[...m].pop();let w=(0,Ie.default)(s,m,null);if(w){w!=null&&w.name&&(h=w.name),a=m[m.length-1];let N=Ce(a);N.includes(".")&&(N=N.split(".").map((z,Y)=>Y===0?z:`["${z}"]`).join("")),l+=`${o!=null&&o.noSharedImport?"":"Shared."}${N}`}}else l+="";else if(r.anyOf)l+=`(${r.anyOf.map(m=>U(s,m,"",$,o)).filter(m=>!!m).join("|")})`;else if(r.oneOf)l+=`(${r.oneOf.map(m=>U(s,m,"",$,o)).filter(m=>!!m).join("|")})`;else if(r.allOf)l+=`(${r.allOf.map(m=>U(s,m,"",$,o)).filter(m=>!!m).join("&")})`;else if(r.items)l+=`${U(s,r.items,"",!1,o)}[]`;else if(r.properties){let m=Object.keys(r.properties),b=r.required||[],S="";m.forEach(w=>{var X,z,Y,Q,se,D;let N="";!((z=(X=e==null?void 0:e.types)==null?void 0:X.doc)!=null&&z.disable)&&((Q=(Y=r.properties)==null?void 0:Y[w])!=null&&Q.description)&&(N=" * "+((se=r.properties)==null?void 0:se[w].description.split(`
|
|
11
11
|
`).filter(ne=>ne.trim()!=="").join(`
|
|
12
12
|
*${" ".repeat(1)}`))),S+=(N?`/**
|
|
13
13
|
${N}
|
|
@@ -53,4 +53,4 @@ ${(0,pt.CurlGenerator)({url:je+s,method:o.toUpperCase(),headers:M,body:R})}${J}
|
|
|
53
53
|
${r.types}`:r.types;yield P.default.promises.writeFile($,o)}}}if(ue.length>0){let s=F.default.join(re,C,"endpoints.ts");yield P.default.promises.mkdir(F.default.dirname(s),{recursive:!0}),yield P.default.promises.writeFile(s,ue)}if(Object.values(G).length>0){let s=F.default.join(re,C,e!=null&&e.folderSplit?"":"types","shared.ts");yield P.default.promises.mkdir(F.default.dirname(s),{recursive:!0}),yield P.default.promises.writeFile(s,Object.values(G).join(`
|
|
54
54
|
`))}if(H.length>0){let s=F.default.join(re,C,"types","index.ts");yield P.default.promises.mkdir(F.default.dirname(s),{recursive:!0}),yield P.default.promises.writeFile(s,`${Object.values(G).length>0?`import * as Shared from "./shared";
|
|
55
55
|
|
|
56
|
-
`:""}${H}`)}}),ut=dt;var me=q(require("path")),yt=q(require("fs"));var be=process.cwd(),St=n=>ae(null,null,function*(){let i;try{require("esbuild-register")}catch(f){throw f}let e=me.default.join(be,"openapi.sync.js"),j=me.default.join(be,"openapi.sync.ts"),O=me.default.join(be,"openapi.sync.json"),x=[e,j,O];try{for(let f of x)yt.default.existsSync(f)&&(i=require(f),Object.keys(i).length===1&&i.default&&(i=i.default))}catch(f){}typeof i=="function"&&(i=i());let E=i;if(!E)throw new Error("No config found");let c=Object.keys(E.api),C=n&&"refetchInterval"in n&&!isNaN(n==null?void 0:n.refetchInterval)?n.refetchInterval:E.refetchInterval;ot();for(let f=0;f<c.length;f+=1){let B=c[f],de=E.api[B];ut(de,B,E,C)}});0&&(module.exports={Init,JSONStringify,capitalize,getEndpointDetails,getNestedValue,isJson,isYamlString,renderTypeRefMD,variableName,variableNameChar,yamlStringToJson});
|
|
56
|
+
`:""}${H}`)}}),ut=dt;var me=q(require("path")),yt=q(require("fs"));var be=process.cwd(),St=n=>ae(null,null,function*(){let i;try{require("esbuild-register")}catch(f){throw f}let e=me.default.join(be,"openapi.sync.js"),j=me.default.join(be,"openapi.sync.ts"),O=me.default.join(be,"openapi.sync.json"),x=[e,j,O];try{for(let f of x)yt.default.existsSync(f)&&(i=require(f),Object.keys(i).length===1&&i.default&&(i=i.default))}catch(f){console.log(f)}typeof i=="function"&&(i=i());let E=i;if(!E)throw new Error("No config found");let c=Object.keys(E.api),C=n&&"refetchInterval"in n&&!isNaN(n==null?void 0:n.refetchInterval)?n.refetchInterval:E.refetchInterval;ot();for(let f=0;f<c.length;f+=1){let B=c[f],de=E.api[B];ut(de,B,E,C)}});0&&(module.exports={Init,JSONStringify,capitalize,getEndpointDetails,getNestedValue,isJson,isYamlString,renderTypeRefMD,variableName,variableNameChar,yamlStringToJson});
|
package/dist/index.mjs
CHANGED
|
@@ -1,56 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
${
|
|
5
|
-
${" ".repeat(m-1)}}`,e},oe=(a,m=1)=>`
|
|
6
|
-
\`\`\`typescript
|
|
7
|
-
${" ".repeat(m)} ${a.split(`
|
|
8
|
-
`).filter(e=>e.trim()!=="").join(`
|
|
9
|
-
${" ".repeat(m)} `)}
|
|
10
|
-
\`\`\``;function jt(a,m){return m.split(".").reduce((x,A)=>x&&x[A]!==void 0?x[A]:void 0,a)}import mt from"lodash.isequal";import et from"lodash.get";import dt from"axios";import ut from"axios-retry";import{bundleFromString as yt,createConfig as $t}from"@redocly/openapi-core";import pt from"path";import pe from"fs";var ae=pt.join(__dirname,"../","../db.json");pe.existsSync(ae)||pe.writeFileSync(ae,"{}");var me={};try{me=D(ae)}catch(a){me={}}var ee=me||{},Xe=a=>{pe.writeFileSync(ae,JSON.stringify(a))},De=(a,m)=>{ee[a]=m,Xe(ee)},_e=a=>ee[a],ge=()=>{ee={},Xe(ee)};import{CurlGenerator as ft}from"curl-generator";var te=process.cwd(),de={},tt=dt.create({timeout:6e4});ut(tt,{retries:20,retryCondition:a=>a.code==="ECONNABORTED"||a.message.includes("Network Error"),retryDelay:a=>a*1e3});var rt=(a,m,e,x)=>ne(null,null,function*(){var ce,Oe,Ie,be,je,Ce;let A=yield tt.get(a),j=yield $t({extends:["minimal"]}),E=JSON.stringify(Qe(A.data)?A.data:Ze(A.data)),c=yield yt({source:E,config:j}),b=F.join((e==null?void 0:e.folder)||"",m),f=c.bundle.parsed,q={},ie=s=>{var r,O;if((r=e==null?void 0:e.folderSplit)!=null&&r.customFolder){let $=e.folderSplit.customFolder(s);if($)return $}return(O=e==null?void 0:e.folderSplit)!=null&&O.byTags&&s.tags&&s.tags.length>0?s.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},$e=typeof(e==null?void 0:e.server)=="string"?e==null?void 0:e.server:((Oe=(ce=f==null?void 0:f.servers)==null?void 0:ce[(e==null?void 0:e.server)||0])==null?void 0:Oe.url)||"",U=typeof((be=(Ie=e==null?void 0:e.types)==null?void 0:Ie.name)==null?void 0:be.prefix)=="string"?e==null?void 0:e.types.name.prefix:"I",nt=typeof((Ce=(je=e==null?void 0:e.endpoints)==null?void 0:je.name)==null?void 0:Ce.prefix)=="string"?e==null?void 0:e.endpoints.name.prefix:"",fe=(s,r)=>{var $,n;let O=W(s);if((n=($=e==null?void 0:e.types)==null?void 0:$.name)!=null&&n.format){let l=e==null?void 0:e.types.name.format("shared",{name:s},O);if(l)return`${U}${l}`}return`${U}${O}`},M=(s,r,O,$,n,l=0)=>{let h="",o="",i="";if(r){if(r.$ref)if(r.$ref[0]==="#"){let p=(r.$ref||"").split("/");p.shift(),[...p].pop();let w=et(s,p,null);if(w){w!=null&&w.name&&(h=w.name),o=p[p.length-1];let N=fe(o);N.includes(".")&&(N=N.split(".").map((L,V)=>V===0?L:`["${L}"]`).join("")),i+=`${n!=null&&n.noSharedImport?"":"Shared."}${N}`}}else i+="";else if(r.anyOf)i+=`(${r.anyOf.map(p=>M(s,p,"",$,n)).filter(p=>!!p).join("|")})`;else if(r.oneOf)i+=`(${r.oneOf.map(p=>M(s,p,"",$,n)).filter(p=>!!p).join("|")})`;else if(r.allOf)i+=`(${r.allOf.map(p=>M(s,p,"",$,n)).filter(p=>!!p).join("&")})`;else if(r.items)i+=`${M(s,r.items,"",!1,n)}[]`;else if(r.properties){let p=Object.keys(r.properties),I=r.required||[],S="";p.forEach(w=>{var Z,L,V,G,re,H;let N="";!((L=(Z=e==null?void 0:e.types)==null?void 0:Z.doc)!=null&&L.disable)&&((G=(V=r.properties)==null?void 0:V[w])!=null&&G.description)&&(N=" * "+((re=r.properties)==null?void 0:re[w].description.split(`
|
|
11
|
-
`).filter(se=>se.trim()!=="").join(`
|
|
12
|
-
*${" ".repeat(1)}`))),S+=(N?`/**
|
|
13
|
-
${N}
|
|
1
|
+
import{a as Qe,b as ft,c as ze,d as X,e as Ye,f as pe,g as re,h as Ot}from"./chunk-ALDCDVEN.mjs";import{a as H,b as te,c as $t,d as ht}from"./chunk-6GQNHE6A.mjs";import v from"fs";import T from"path";import pt from"lodash.isequal";import _e from"lodash.get";import it from"axios";import lt from"axios-retry";import{bundleFromString as dt,createConfig as mt}from"@redocly/openapi-core";import ot from"path";import ie from"fs";var se=ot.join(__dirname,"../","../db.json");ie.existsSync(se)||ie.writeFileSync(se,"{}");var le={};try{le=H(se)}catch(I){le={}}var Z=le||{},He=I=>{ie.writeFileSync(se,JSON.stringify(I))},Xe=(I,b)=>{Z[I]=b,He(Z)},Ze=I=>Z[I],De=()=>{Z={},He(Z)};import{CurlGenerator as ut}from"curl-generator";var D=process.cwd(),de={},ge=it.create({timeout:6e4});lt(ge,{retries:20,retryCondition:I=>I.code==="ECONNABORTED"||I.message.includes("Network Error"),retryDelay:I=>I*1e3});var et=(I,b,e,B)=>te(null,null,function*(){var fe,Oe,Ie,je,be,Ce;let W=yield ge.get(I),ne=yield mt({extends:["minimal"]}),M=JSON.stringify(Qe(W.data)?W.data:ze(W.data)),_=yield dt({source:M,config:ne}),K=T.join((e==null?void 0:e.folder)||"",b),h=_.bundle.parsed,R={},ae=s=>{var r,$;if((r=e==null?void 0:e.folderSplit)!=null&&r.customFolder){let u=e.folderSplit.customFolder(s);if(console.log("customFolder",u),u)return u}return($=e==null?void 0:e.folderSplit)!=null&&$.byTags&&s.tags&&s.tags.length>0?s.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},ye=typeof(e==null?void 0:e.server)=="string"?e==null?void 0:e.server:((Oe=(fe=h==null?void 0:h.servers)==null?void 0:fe[(e==null?void 0:e.server)||0])==null?void 0:Oe.url)||"",q=typeof((je=(Ie=e==null?void 0:e.types)==null?void 0:Ie.name)==null?void 0:je.prefix)=="string"?e==null?void 0:e.types.name.prefix:"I",rt=typeof((Ce=(be=e==null?void 0:e.endpoints)==null?void 0:be.name)==null?void 0:Ce.prefix)=="string"?e==null?void 0:e.endpoints.name.prefix:"",$e=(s,r)=>{var u,n;let $=X(s);if((n=(u=e==null?void 0:e.types)==null?void 0:u.name)!=null&&n.format){let p=e==null?void 0:e.types.name.format("shared",{name:s},$);if(p)return`${q}${p}`}return`${q}${$}`},F=(s,r,$,u,n,p=0)=>{let y="",a="",o="";if(r){if(r.$ref)if(r.$ref[0]==="#"){let i=(r.$ref||"").split("/");i.shift(),[...i].pop();let c=_e(s,i,null);if(c){c!=null&&c.name&&(y=c.name),a=i[i.length-1];let x=$e(a);x.includes(".")&&(x=x.split(".").map((P,J)=>J===0?P:`["${P}"]`).join("")),o+=`${n!=null&&n.noSharedImport?"":"Shared."}${x}`}}else o+="";else if(r.anyOf)o+=`(${r.anyOf.map(i=>F(s,i,"",u,n)).filter(i=>!!i).join("|")})`;else if(r.oneOf)o+=`(${r.oneOf.map(i=>F(s,i,"",u,n)).filter(i=>!!i).join("|")})`;else if(r.allOf)o+=`(${r.allOf.map(i=>F(s,i,"",u,n)).filter(i=>!!i).join("&")})`;else if(r.items)o+=`${F(s,r.items,"",!1,n)}[]`;else if(r.properties){let i=Object.keys(r.properties),f=r.required||[],C="";i.forEach(c=>{var Q,P,J,V,g,z;let x="";!((P=(Q=e==null?void 0:e.types)==null?void 0:Q.doc)!=null&&P.disable)&&((V=(J=r.properties)==null?void 0:J[c])!=null&&V.description)&&(x=" * "+((g=r.properties)==null?void 0:g[c].description.split(`
|
|
2
|
+
`).filter(ee=>ee.trim()!=="").join(`
|
|
3
|
+
*${" ".repeat(1)}`))),C+=(x?`/**
|
|
4
|
+
${x}
|
|
14
5
|
*/
|
|
15
|
-
`:"")+`${
|
|
16
|
-
${" ".repeat(
|
|
17
|
-
`:""}`:""},
|
|
18
|
-
`);
|
|
6
|
+
`:"")+`${F(s,(z=r.properties)==null?void 0:z[c],c,f.includes(c),n,p+1)}`}),C.length>0?o+=`{
|
|
7
|
+
${" ".repeat(p)}${C}${" ".repeat(p)}}`:o+="{[k: string]: any}"}else if(r.enum&&r.enum.length>0)r.enum.length>1&&(o+="("),r.enum.map(i=>JSON.stringify(i)).filter(i=>!!i).forEach((i,f)=>{o+=`${f===0?"":"|"}${i}`}),r.enum.length>1&&(o+=")");else if(r.type){let i=f=>{let C="";if(typeof f=="string")["string","integer","number","array","boolean","null"].includes(f)?["integer","number"].includes(f)?C+="number":f==="array"?C+="any[]":C+=f:f==="object"&&(r.additionalProperties?C+=`{[k: string]: ${F(s,r.additionalProperties,"",!0,n)||"any"}}`:C+="{[k: string]: any}");else if(Array.isArray(f)){let c=f.map(x=>i(x));c.filter(x=>x!==""),c.length>1&&(C+="("+c.join("|")+")")}else C+="any";return C};o=i(r.type)}}else o="string";let d=y||$;n!=null&&n.useComponentName&&!d&&(d=a);let j=d?` "${d}"${u?"":"?"}: `:"",t=r!=null&&r.nullable?" | null":"";return o.length>0?`${j}${o}${t}${d?`;
|
|
8
|
+
`:""}`:""},U=(s,r)=>{let $="",u="",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),u=p[p.length-1],n+=U(s,a))}else n+="";else if(r.anyOf)n+=U(s,r.anyOf[0]);else if(r.oneOf)n+=U(s,r.oneOf[0]);else if(r.allOf)n+=`{${r.allOf.map(p=>`...(${U(s,p)})`).join(",")}}`;else if(r.items)n+=`[${U(s,r.items)}]`;else if(r.properties){let a=Object.keys(r.properties).map(o=>{var d;return` "${o}": ${U(s,(d=r.properties)==null?void 0:d[o])}`}).join(`,
|
|
9
|
+
`);a.length>0?n+=`{
|
|
10
|
+
${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=y=>{let a="";if(typeof y=="string")["string","integer","number","array","boolean","null"].includes(y)?["integer","number"].includes(y)?a+="123":y==="array"?a+="[]":y==="boolean"?a+="true":y==="null"?a+="null":a+=`"${y}"`:y==="object"&&(a+="{}");else if(Array.isArray(y)){let o=y.map(d=>p(d));o.filter(d=>d!==""),o.length>1&&(a+=o.join("|"))}else a+="any";return a};n=p(r.type)}}else n="string";return n};B&&!isNaN(B)&&B>0&&(process.env.NODE_ENV&&["production","prod","test","staging"].includes(process.env.NODE_ENV)||(de[b]&&clearTimeout(de[b]),de[b]=setTimeout(()=>et(I,b,e,B),B)));let st=Ze(b);if(pt(st,h))return;Xe(b,h);let oe="",G="",L={};h.components&&Object.keys(h.components).forEach(s=>{if(["schemas","responses","parameters","examples","requestBodies","headers","links","callbacks"].includes(s)){let r=h.components[s],$={},u={};Object.keys(r).forEach(p=>{var o;let y=(o=r[p])!=null&&o.schema?r[p].schema:r[p],a=`${F(h,y,"",!0,{noSharedImport:!0,useComponentName:["parameters"].includes(s)})}`;if(a){let d=p.split("."),j=$,t=u;for(let i=0;i<d.length;i++){let f=d[i];i<d.length-1?(f in j||(j[f]={},t[f]={}),j=j[f],t=t[f]):(j[f]=a,t[f]=y)}}}),Object.keys($).forEach(p=>{var d,j,t,i;let y=$e(p),a=$[p],o="";!((j=(d=e==null?void 0:e.types)==null?void 0:d.doc)!=null&&j.disable)&&p in r&&((t=r[p])!=null&&t.description)&&(o=" * "+r[p].description.split(`
|
|
12
|
+
`).filter(f=>f.trim()!=="").join(`
|
|
13
|
+
*${" ".repeat(1)}`)),L[p]=((i=L[p])!=null?i:"")+(o?`/**
|
|
19
14
|
${o}
|
|
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 l=h=>{let o="";if(typeof h=="string")["string","integer","number","array","boolean","null"].includes(h)?["integer","number"].includes(h)?o+="123":h==="array"?o+="[]":h==="boolean"?o+="true":h==="null"?o+="null":o+=`"${h}"`:h==="object"&&(o+="{}");else if(Array.isArray(h)){let i=h.map(u=>l(u));i.filter(u=>u!==""),i.length>1&&(o+=i.join("|"))}else o+="any";return o};n=l(r.type)}}else n="string";return n};x&&!isNaN(x)&&x>0&&(process.env.NODE_ENV&&["production","prod","test","staging"].includes(process.env.NODE_ENV)||(de[m]&&clearTimeout(de[m]),de[m]=setTimeout(()=>rt(a,m,e,x),x)));let ot=_e(m);if(mt(ot,f))return;De(m,f);let le="",Q="",Y={};f.components&&Object.keys(f.components).forEach(s=>{if(["schemas","responses","parameters","examples","requestBodies","headers","links","callbacks"].includes(s)){let r=f.components[s],O={},$={};Object.keys(r).forEach(l=>{var i;let h=(i=r[l])!=null&&i.schema?r[l].schema:r[l],o=`${M(f,h,"",!0,{noSharedImport:!0,useComponentName:["parameters"].includes(s)})}`;if(o){let u=l.split("."),T=O,t=$;for(let p=0;p<u.length;p++){let I=u[p];p<u.length-1?(I in T||(T[I]={},t[I]={}),T=T[I],t=t[I]):(T[I]=o,t[I]=h)}}}),Object.keys(O).forEach(l=>{var u,T,t,p;let h=fe(l),o=O[l],i="";!((T=(u=e==null?void 0:e.types)==null?void 0:u.doc)!=null&&T.disable)&&l in r&&((t=r[l])!=null&&t.description)&&(i=" * "+r[l].description.split(`
|
|
21
|
-
`).filter(I=>I.trim()!=="").join(`
|
|
22
|
-
*${" ".repeat(1)}`)),Y[l]=((p=Y[l])!=null?p:"")+(i?`/**
|
|
23
|
-
${i}
|
|
24
15
|
*/
|
|
25
|
-
`:"")+"export type "+
|
|
26
|
-
`})}});let he=s=>{let r="";if(s.content){let
|
|
27
|
-
${
|
|
28
|
-
`;e!=null&&e.folderSplit?
|
|
29
|
-
`;e!=null&&e.folderSplit?
|
|
30
|
-
`;e!=null&&e.folderSplit?
|
|
31
|
-
- Scopes: [\`${
|
|
32
|
-
- ${
|
|
33
|
-
`),
|
|
34
|
-
--cert client-certificate.crt --key client-private-key.key --cacert ca-certificate.crt`:
|
|
16
|
+
`:"")+"export type "+y+" = "+(typeof a=="string"?a:pe(a))+`;
|
|
17
|
+
`})}});let he=s=>{let r="";if(s.content){let $=Object.keys(s.content);$[0]&&s.content[$[0]].schema&&(r+=`${F(h,s.content[$[0]].schema,"")}`)}return r},nt=s=>{var r,$,u,n,p;if(($=(r=e==null?void 0:e.endpoints)==null?void 0:r.value)!=null&&$.replaceWords&&Array.isArray(e==null?void 0:e.endpoints.value.replaceWords)){let y=s;return(p=(n=(u=e==null?void 0:e.endpoints)==null?void 0:u.value)==null?void 0:n.replaceWords)==null||p.forEach((a,o)=>{let d=new RegExp(a.replace,"g");y=y.replace(d,a.with||"")}),y}else return s},at=(s,r,$=[])=>{var p,y;let u=(p=e==null?void 0:e.endpoints)==null?void 0:p.exclude,n=(y=e==null?void 0:e.endpoints)==null?void 0:y.include;if(n){let a=n.tags&&n.tags.length>0?$.some(d=>n.tags.includes(d)):!0,o=n.endpoints&&n.endpoints.length>0?n.endpoints.some(d=>{let j=!d.method||d.method.toLowerCase()===r.toLowerCase();return d.path?s===d.path&&j:d.regex?new RegExp(d.regex).test(s)&&j:!1}):!0;if(!a||!o)return!0}return!!(u&&(u.tags&&u.tags.length>0&&$.some(o=>u.tags.includes(o))||u.endpoints&&u.endpoints.length>0&&u.endpoints.some(o=>{let d=!o.method||o.method.toLowerCase()===r.toLowerCase();return o.path?s===o.path&&d:o.regex?new RegExp(o.regex).test(s)&&d:!1})))};if(Object.keys(h.paths||{}).forEach(s=>{let r=h.paths[s];Object.keys(r).forEach(u=>{var ee,ce,xe,Ae,Ee,Te,we,Re,Se,Ne,ve,Fe,qe,Pe,ke,Be,Me,Ue,Je,Ke,Le,Ve,We,Ge;let n=u,p=Ye(s,n),y=((ee=r[n])==null?void 0:ee.tags)||[];if(at(s,n,y))return;let a=r[n],o=ae({method:n,path:s,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId,tags:y,parameters:a==null?void 0:a.parameters,requestBody:a==null?void 0:a.requestBody,responses:a==null?void 0:a.responses});R[o]||(R[o]={endpoints:"",types:""});let d=((xe=(ce=e==null?void 0:e.endpoints)==null?void 0:ce.value)!=null&&xe.includeServer?ye:"")+p.pathParts.map(m=>(m[0]==="{"&&m[m.length-1]==="}"?m=`\${${m.replace(/{/,"").replace(/}/,"")}}`:m[0]==="<"&&m[m.length-1]===">"?m=`\${${m.replace(/</,"").replace(/>/,"")}}`:m[0]===":"&&(m=`\${${m.replace(/:/,"")}}`),m)).join("/"),j=`"${d}"`;p.variables.length>0&&(j=`(${p.variables.map(l=>`${l}:string`).join(",")})=> \`${d}\``),j=nt(j);let t=r[n],i="";if(t!=null&&t.parameters&&((t==null?void 0:t.parameters).forEach((l,A)=>{(l.$ref||l.in==="query"&&l.name)&&(i+=`${F(h,l.$ref?l:l.schema,l.name||"",l.required)}`)}),i)){i=`{
|
|
18
|
+
${i}}`;let l=`${p.name}Query`;if((Ee=(Ae=e==null?void 0:e.types)==null?void 0:Ae.name)!=null&&Ee.useOperationId&&(t!=null&&t.operationId)&&(l=`${t.operationId}Query`),l=X(`${q}${l}`),(we=(Te=e==null?void 0:e.types)==null?void 0:Te.name)!=null&&we.format){let S=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},l);S&&(l=`${q}${S}`)}let A=`export type ${l} = ${i};
|
|
19
|
+
`;e!=null&&e.folderSplit?R[o].types+=A:G+=A}let f=t==null?void 0:t.requestBody,C="";if(f&&(C=he(f),C)){let m=`${p.name}DTO`;if((Se=(Re=e==null?void 0:e.types)==null?void 0:Re.name)!=null&&Se.useOperationId&&(t!=null&&t.operationId)&&(m=`${t.operationId}DTO`),m=X(`${q}${m}`),(ve=(Ne=e==null?void 0:e.types)==null?void 0:Ne.name)!=null&&ve.format){let A=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},m);A&&(m=`${q}${A}`)}let l=`export type ${m} = ${C};
|
|
20
|
+
`;e!=null&&e.folderSplit?R[o].types+=l:G+=l}let c={},x="";if(t!=null&&t.responses){let m=t==null?void 0:t.responses;Object.keys(m).forEach(A=>{var S,N,E,w;if(x=he(m[A]),c[A]=x,x){let O=`${p.name}${A}Response`;if((N=(S=e==null?void 0:e.types)==null?void 0:S.name)!=null&&N.useOperationId&&(t!=null&&t.operationId)&&(O=`${t.operationId}${A}Response`),O=X(`${q}${O}`),(w=(E=e==null?void 0:e.types)==null?void 0:E.name)!=null&&w.format){let Y=e==null?void 0:e.types.name.format("endpoint",{code:A,type:"response",method:n,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},O);Y&&(O=`${q}${Y}`)}let k=`export type ${O} = ${x};
|
|
21
|
+
`;e!=null&&e.folderSplit?R[o].types+=k:G+=k}})}let Q=m=>!m||!m.length?"":m.map(l=>Object.entries(l).map(([S,N])=>{let E=S,w="";return Array.isArray(N)&&N.length&&(w=`
|
|
22
|
+
- Scopes: [\`${N.join("`, `")}\`]`,E=`**${E}**`),`
|
|
23
|
+
- ${E}${w}`}).join("")).join(`
|
|
24
|
+
`),P=t!=null&&t.security?Q(t.security):"",J="";if(!((qe=(Fe=e==null?void 0:e.endpoints)==null?void 0:Fe.doc)!=null&&qe.disable)){let m="";if((ke=(Pe=e==null?void 0:e.endpoints)==null?void 0:Pe.doc)!=null&&ke.showCurl){let l={},A="",S="";(Be=t.requestBody)!=null&&Be.content&&Object.keys(t.requestBody.content).forEach(w=>{let O=t.requestBody.content[w].schema;if(O){Array.isArray(l["Content-type"])?l["Content-type"].push(w):l["Content-type"]=[w];let k=U(h,O);k&&(A=k)}}),t!=null&&t.security&&t.security.forEach(E=>{Object.keys(E).forEach(w=>{var k,Y;let O=(Y=(k=h.components)==null?void 0:k.securitySchemes)==null?void 0:Y[w];O&&(O.type==="mutualTLS"?S+=`
|
|
25
|
+
--cert client-certificate.crt --key client-private-key.key --cacert ca-certificate.crt`:O.type==="apiKey"?l[(O==null?void 0:O.name)||"X-API-KEY"]="{API_KEY_VALUE}":l.Authorization=`${(O==null?void 0:O.scheme)==="basic"?"Basic":"Bearer"} {${(O==null?void 0:O.scheme)==="basic"?"VALUE":"TOKEN"}}`)})});let N={};Object.keys(l).forEach(E=>{Array.isArray(l[E])?N[E]=l[E].join("; "):N[E]=l[E]}),m=`
|
|
35
26
|
\`\`\`bash
|
|
36
|
-
${
|
|
37
|
-
\`\`\``}
|
|
27
|
+
${ut({url:ye+s,method:n.toUpperCase(),headers:N,body:A})}${S}
|
|
28
|
+
\`\`\``}J=`/**${t!=null&&t.description?`
|
|
38
29
|
* ${t==null?void 0:t.description} `:""}
|
|
39
30
|
* **Method**: \`${n.toUpperCase()}\`
|
|
40
31
|
* **Summary**: ${(t==null?void 0:t.summary)||""}
|
|
41
32
|
* **Tags**: [${((Me=t==null?void 0:t.tags)==null?void 0:Me.join(", "))||""}]
|
|
42
|
-
* **OperationId**: ${(t==null?void 0:t.operationId)||""} ${
|
|
43
|
-
* **Query**: ${
|
|
44
|
-
* **DTO**: ${
|
|
45
|
-
* **Response**: ${Object.entries(
|
|
46
|
-
- **${
|
|
47
|
-
* **Security**: ${
|
|
48
|
-
`:""}${
|
|
33
|
+
* **OperationId**: ${(t==null?void 0:t.operationId)||""} ${i?`
|
|
34
|
+
* **Query**: ${re(i)} `:""}${C?`
|
|
35
|
+
* **DTO**: ${re(C)} `:""}${x?`
|
|
36
|
+
* **Response**: ${Object.entries(c).map(([l,A])=>`
|
|
37
|
+
- **${l}**: ${re(A,2)} `).join("")}`:""}${P?`
|
|
38
|
+
* **Security**: ${P}
|
|
39
|
+
`:""}${m}
|
|
49
40
|
*/
|
|
50
|
-
`}let
|
|
51
|
-
`;e!=null&&e.folderSplit?
|
|
41
|
+
`}let V=(Je=(Ue=e==null?void 0:e.endpoints)==null?void 0:Ue.name)!=null&&Je.useOperationId&&((Ke=t==null?void 0:t.operationId)==null?void 0:Ke.length)>0?t.operationId:`${p.name}`;if((Ve=(Le=e==null?void 0:e.endpoints)==null?void 0:Le.name)!=null&&Ve.format){let m=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},V);m&&(V=m)}let g={method:`"${n}"`,operationId:`"${t==null?void 0:t.operationId}"`,url:j,tags:(t==null?void 0:t.tags)||[]},z=`${J}export const ${rt}${V} = ${((Ge=(We=e==null?void 0:e.endpoints)==null?void 0:We.value)==null?void 0:Ge.type)==="object"?pe(g):j};
|
|
42
|
+
`;e!=null&&e.folderSplit?R[o].endpoints+=z:oe+=z})}),e!=null&&e.folderSplit){for(let[s,r]of Object.entries(R))if(r.endpoints||r.types){let $=T.join(K,s);if(r.endpoints){let u=T.join(D,$,"endpoints.ts");yield v.promises.mkdir(T.dirname(u),{recursive:!0}),yield v.promises.writeFile(u,r.endpoints)}if(r.types){let u=T.join(D,$,"types.ts");yield v.promises.mkdir(T.dirname(u),{recursive:!0});let n=Object.values(L).length>0?`import * as Shared from "../shared";
|
|
52
43
|
|
|
53
|
-
${r.types}`:r.types;yield
|
|
54
|
-
`))}if(
|
|
44
|
+
${r.types}`:r.types;yield v.promises.writeFile(u,n)}}}if(oe.length>0){let s=T.join(D,K,"endpoints.ts");yield v.promises.mkdir(T.dirname(s),{recursive:!0}),yield v.promises.writeFile(s,oe)}if(Object.values(L).length>0){let s=T.join(D,K,e!=null&&e.folderSplit?"":"types","shared.ts");yield v.promises.mkdir(T.dirname(s),{recursive:!0}),yield v.promises.writeFile(s,Object.values(L).join(`
|
|
45
|
+
`))}if(G.length>0){let s=T.join(D,K,"types","index.ts");yield v.promises.mkdir(T.dirname(s),{recursive:!0}),yield v.promises.writeFile(s,`${Object.values(L).length>0?`import * as Shared from "./shared";
|
|
55
46
|
|
|
56
|
-
`:""}${
|
|
47
|
+
`:""}${G}`)}}),tt=et;import me from"path";import yt from"fs";var ue=process.cwd(),Jt=I=>te(null,null,function*(){let b;try{H("esbuild-register")}catch(h){throw h}let e=me.join(ue,"openapi.sync.js"),B=me.join(ue,"openapi.sync.ts"),W=me.join(ue,"openapi.sync.json"),ne=[e,B,W];try{for(let h of ne)yt.existsSync(h)&&(b=H(h),Object.keys(b).length===1&&b.default&&(b=b.default))}catch(h){console.log(h)}typeof b=="function"&&(b=b());let M=b;if(!M)throw new Error("No config found");let _=Object.keys(M.api),K=I&&"refetchInterval"in I&&!isNaN(I==null?void 0:I.refetchInterval)?I.refetchInterval:M.refetchInterval;De();for(let h=0;h<_.length;h+=1){let R=_[h],ae=M.api[R];tt(ae,R,M,K)}});export{Jt as Init,pe as JSONStringify,X as capitalize,Ye as getEndpointDetails,Ot as getNestedValue,Qe as isJson,ft as isYamlString,re as renderTypeRefMD,$t as variableName,ht as variableNameChar,ze as yamlStringToJson};
|
package/dist/regex.d.mts
ADDED
package/dist/regex.d.ts
ADDED
package/dist/regex.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var t=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var Z=Object.prototype.hasOwnProperty;var _=(e,a)=>{for(var o in a)t(e,o,{get:a[o],enumerable:!0})},b=(e,a,o,$)=>{if(a&&typeof a=="object"||typeof a=="function")for(let r of A(a))!Z.call(e,r)&&r!==o&&t(e,r,{get:()=>a[r],enumerable:!($=z(a,r))||$.enumerable});return e};var c=e=>b(t({},"__esModule",{value:!0}),e);var m={};_(m,{variableName:()=>i,variableNameChar:()=>l});module.exports=c(m);var i=/^[A-Za-z_$][A-Za-z0-9_$]*$/,l=/[A-Za-z0-9_$]/;0&&(module.exports={variableName,variableNameChar});
|
package/dist/regex.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as a,d as b}from"./chunk-6GQNHE6A.mjs";export{a as variableName,b as variableNameChar};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openapi-sync",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.13",
|
|
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",
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"node",
|
|
19
19
|
"codegen",
|
|
20
20
|
"generation",
|
|
21
|
-
"generator"
|
|
21
|
+
"generator",
|
|
22
|
+
"generate types"
|
|
22
23
|
],
|
|
23
24
|
"files": [
|
|
24
25
|
"bin",
|
|
@@ -39,16 +40,23 @@
|
|
|
39
40
|
"scripts": {
|
|
40
41
|
"build-tsc": "rm -rf dist && tsc",
|
|
41
42
|
"build": "rm -rf dist && tsup",
|
|
42
|
-
"publish-package": "npm run build && npm publish"
|
|
43
|
+
"publish-package": "npm run build && npm publish",
|
|
44
|
+
"test": "jest",
|
|
45
|
+
"test:watch": "jest --watch",
|
|
46
|
+
"test:coverage": "jest --coverage",
|
|
47
|
+
"test:ci": "jest --ci --coverage --watchAll=false"
|
|
43
48
|
},
|
|
44
49
|
"author": "P-Technologies",
|
|
45
50
|
"license": "ISC",
|
|
46
51
|
"devDependencies": {
|
|
52
|
+
"@types/jest": "^30.0.0",
|
|
47
53
|
"@types/js-yaml": "^4.0.9",
|
|
48
54
|
"@types/lodash": "^4.17.7",
|
|
49
55
|
"@types/lodash.get": "^4.4.9",
|
|
50
56
|
"@types/lodash.isequal": "^4.5.8",
|
|
51
57
|
"@types/node": "^22.1.0",
|
|
58
|
+
"jest": "^30.2.0",
|
|
59
|
+
"ts-jest": "^29.4.4",
|
|
52
60
|
"typescript": "^5.5.4"
|
|
53
61
|
},
|
|
54
62
|
"dependencies": {
|
|
@@ -63,4 +71,4 @@
|
|
|
63
71
|
"tsup": "^8.5.0",
|
|
64
72
|
"yargs": "^17.7.2"
|
|
65
73
|
}
|
|
66
|
-
}
|
|
74
|
+
}
|