openapi-sync 2.1.9 → 2.1.11
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 +348 -17
- package/db.json +1 -1
- package/dist/index.d.mts +172 -0
- package/dist/index.d.ts +170 -4
- package/dist/index.js +56 -88
- package/dist/index.mjs +56 -0
- package/package.json +5 -7
- package/dist/Openapi-sync/index.d.ts +0 -3
- package/dist/Openapi-sync/index.js +0 -776
- package/dist/Openapi-sync/state.d.ts +0 -4
- package/dist/Openapi-sync/state.js +0 -37
- package/dist/helpers.d.ts +0 -12
- package/dist/helpers.js +0 -161
- package/dist/openapi.sync.sample.d.ts +0 -1
- package/dist/openapi.sync.sample.js +0 -55
- package/dist/regex.d.ts +0 -2
- package/dist/regex.js +0 -5
- package/dist/types.d.ts +0 -113
- package/dist/types.js +0 -2
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { Method } from 'axios';
|
|
2
|
+
|
|
3
|
+
type IOpenApiSpec = Record<"openapi", string> & Record<string, any>;
|
|
4
|
+
type IOpenApSchemaSpec = {
|
|
5
|
+
nullable?: boolean;
|
|
6
|
+
type: "string" | "integer" | "number" | "array" | "object" | "boolean" | "null" | any[];
|
|
7
|
+
example?: any;
|
|
8
|
+
enum?: string[];
|
|
9
|
+
format?: string;
|
|
10
|
+
items?: IOpenApSchemaSpec;
|
|
11
|
+
required?: string[];
|
|
12
|
+
description?: string;
|
|
13
|
+
$ref?: string;
|
|
14
|
+
properties?: Record<string, IOpenApSchemaSpec>;
|
|
15
|
+
additionalProperties?: IOpenApSchemaSpec;
|
|
16
|
+
anyOf?: IOpenApSchemaSpec[];
|
|
17
|
+
oneOf?: IOpenApSchemaSpec[];
|
|
18
|
+
allOf?: IOpenApSchemaSpec[];
|
|
19
|
+
};
|
|
20
|
+
type IOpenApiParameterSpec = {
|
|
21
|
+
$ref?: string;
|
|
22
|
+
name: string;
|
|
23
|
+
in: string;
|
|
24
|
+
enum?: string[];
|
|
25
|
+
description?: string;
|
|
26
|
+
required?: boolean;
|
|
27
|
+
deprecated?: boolean;
|
|
28
|
+
allowEmptyValue?: boolean;
|
|
29
|
+
style?: string;
|
|
30
|
+
explode?: boolean;
|
|
31
|
+
allowReserved?: boolean;
|
|
32
|
+
schema?: IOpenApSchemaSpec;
|
|
33
|
+
example?: any;
|
|
34
|
+
examples?: any[];
|
|
35
|
+
};
|
|
36
|
+
type IOpenApiMediaTypeSpec = {
|
|
37
|
+
schema?: IOpenApSchemaSpec;
|
|
38
|
+
example?: any;
|
|
39
|
+
examples?: any[];
|
|
40
|
+
encoding?: any;
|
|
41
|
+
};
|
|
42
|
+
type IOpenApiRequestBodySpec = {
|
|
43
|
+
description?: string;
|
|
44
|
+
required?: boolean;
|
|
45
|
+
content: Record<string, IOpenApiMediaTypeSpec>;
|
|
46
|
+
};
|
|
47
|
+
type IOpenApiResponseSpec = Record<string, IOpenApiRequestBodySpec>;
|
|
48
|
+
type IConfigReplaceWord = {
|
|
49
|
+
/** string and regular expression as a string*/
|
|
50
|
+
replace: string;
|
|
51
|
+
with: string;
|
|
52
|
+
};
|
|
53
|
+
type IConfigDoc = {
|
|
54
|
+
disable?: boolean;
|
|
55
|
+
showCurl?: boolean;
|
|
56
|
+
};
|
|
57
|
+
type IConfigExclude = {
|
|
58
|
+
/** Exclude/Include endpoints by tags */
|
|
59
|
+
tags?: string[];
|
|
60
|
+
/** Exclude/Include individual endpoints by path and method */
|
|
61
|
+
endpoints?: Array<{
|
|
62
|
+
/** Exact path match (regex will be ignore when provided)*/
|
|
63
|
+
path?: string;
|
|
64
|
+
/** Regular expression pattern for path matching */
|
|
65
|
+
regex?: string;
|
|
66
|
+
/** Don't specify method to exclude all methods */
|
|
67
|
+
method?: Method;
|
|
68
|
+
}>;
|
|
69
|
+
};
|
|
70
|
+
interface IConfigInclude extends IConfigExclude {
|
|
71
|
+
}
|
|
72
|
+
type IConfigFolderSplit = {
|
|
73
|
+
/** Split folders by tags - creates folders named after each tag */
|
|
74
|
+
byTags?: boolean;
|
|
75
|
+
/** Custom function to determine folder name for each endpoint */
|
|
76
|
+
customFolder?: (data: {
|
|
77
|
+
method: Method;
|
|
78
|
+
path: string;
|
|
79
|
+
summary?: string;
|
|
80
|
+
operationId?: string;
|
|
81
|
+
tags?: string[];
|
|
82
|
+
parameters?: IOpenApiParameterSpec[];
|
|
83
|
+
requestBody?: IOpenApiRequestBodySpec;
|
|
84
|
+
responses?: IOpenApiResponseSpec;
|
|
85
|
+
}) => string | null;
|
|
86
|
+
};
|
|
87
|
+
type IConfig = {
|
|
88
|
+
refetchInterval?: number;
|
|
89
|
+
folder?: string;
|
|
90
|
+
api: Record<string, string>;
|
|
91
|
+
server?: number | string;
|
|
92
|
+
/** Configuration for splitting generated code into folders */
|
|
93
|
+
folderSplit?: IConfigFolderSplit;
|
|
94
|
+
/** Configuration for excluding endpoints from code generation */
|
|
95
|
+
types?: {
|
|
96
|
+
name?: {
|
|
97
|
+
prefix?: string;
|
|
98
|
+
useOperationId?: boolean;
|
|
99
|
+
format?: (source: "shared" | "endpoint", data: {
|
|
100
|
+
name?: string;
|
|
101
|
+
type?: "response" | "dto" | "query";
|
|
102
|
+
code?: string;
|
|
103
|
+
method?: Method;
|
|
104
|
+
path?: string;
|
|
105
|
+
summary?: string;
|
|
106
|
+
operationId?: string;
|
|
107
|
+
}, defaultName: string) => string | null | undefined;
|
|
108
|
+
};
|
|
109
|
+
doc?: IConfigDoc;
|
|
110
|
+
};
|
|
111
|
+
endpoints?: {
|
|
112
|
+
value?: {
|
|
113
|
+
replaceWords?: IConfigReplaceWord[];
|
|
114
|
+
includeServer?: boolean;
|
|
115
|
+
type?: "string" | "object";
|
|
116
|
+
};
|
|
117
|
+
name?: {
|
|
118
|
+
format?: (data: {
|
|
119
|
+
method: Method;
|
|
120
|
+
path: string;
|
|
121
|
+
summary: string;
|
|
122
|
+
operationId: string;
|
|
123
|
+
}, defaultName: string) => string | null;
|
|
124
|
+
prefix?: string;
|
|
125
|
+
useOperationId?: boolean;
|
|
126
|
+
};
|
|
127
|
+
doc?: IConfigDoc;
|
|
128
|
+
exclude?: IConfigExclude;
|
|
129
|
+
include?: IConfigInclude;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
type IOpenApiSecuritySchemes = {
|
|
133
|
+
[key: string]: {
|
|
134
|
+
type: "http" | "apiKey" | "oauth2" | "openIdConnect" | "mutualTLS";
|
|
135
|
+
scheme?: "bearer" | "basic";
|
|
136
|
+
in?: "query" | "header" | "cookie";
|
|
137
|
+
flows?: {
|
|
138
|
+
authorizationCode: {
|
|
139
|
+
authorizationUrl: "https://example.com/auth";
|
|
140
|
+
tokenUrl: "https://example.com/token";
|
|
141
|
+
scopes: {
|
|
142
|
+
"read:data": "Grants read access";
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
bearerFormat?: "JWT";
|
|
147
|
+
openIdConnectUrl?: string;
|
|
148
|
+
name?: string;
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
declare const isJson: (value: any) => boolean;
|
|
153
|
+
declare const isYamlString: (fileContent: string) => boolean;
|
|
154
|
+
declare const yamlStringToJson: (fileContent: string) => any;
|
|
155
|
+
declare const capitalize: (text: string) => string;
|
|
156
|
+
declare const getEndpointDetails: (path: string, method: string) => {
|
|
157
|
+
name: string;
|
|
158
|
+
variables: string[];
|
|
159
|
+
pathParts: string[];
|
|
160
|
+
};
|
|
161
|
+
declare const JSONStringify: (obj: Record<string, any>, indent?: number) => string;
|
|
162
|
+
declare const renderTypeRefMD: (typeRef: string, indent?: number) => string;
|
|
163
|
+
declare function getNestedValue<T>(obj: object, path: string): T | undefined;
|
|
164
|
+
|
|
165
|
+
declare const variableName: RegExp;
|
|
166
|
+
declare const variableNameChar: RegExp;
|
|
167
|
+
|
|
168
|
+
declare const Init: (options?: {
|
|
169
|
+
refetchInterval?: number;
|
|
170
|
+
}) => Promise<void>;
|
|
171
|
+
|
|
172
|
+
export { type IConfig, type IConfigDoc, type IConfigExclude, type IConfigFolderSplit, type IConfigInclude, type IConfigReplaceWord, type IOpenApSchemaSpec, type IOpenApiMediaTypeSpec, type IOpenApiParameterSpec, type IOpenApiRequestBodySpec, type IOpenApiResponseSpec, type IOpenApiSecuritySchemes, type IOpenApiSpec, Init, JSONStringify, capitalize, getEndpointDetails, getNestedValue, isJson, isYamlString, renderTypeRefMD, variableName, variableNameChar, yamlStringToJson };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,172 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Method } from 'axios';
|
|
2
|
+
|
|
3
|
+
type IOpenApiSpec = Record<"openapi", string> & Record<string, any>;
|
|
4
|
+
type IOpenApSchemaSpec = {
|
|
5
|
+
nullable?: boolean;
|
|
6
|
+
type: "string" | "integer" | "number" | "array" | "object" | "boolean" | "null" | any[];
|
|
7
|
+
example?: any;
|
|
8
|
+
enum?: string[];
|
|
9
|
+
format?: string;
|
|
10
|
+
items?: IOpenApSchemaSpec;
|
|
11
|
+
required?: string[];
|
|
12
|
+
description?: string;
|
|
13
|
+
$ref?: string;
|
|
14
|
+
properties?: Record<string, IOpenApSchemaSpec>;
|
|
15
|
+
additionalProperties?: IOpenApSchemaSpec;
|
|
16
|
+
anyOf?: IOpenApSchemaSpec[];
|
|
17
|
+
oneOf?: IOpenApSchemaSpec[];
|
|
18
|
+
allOf?: IOpenApSchemaSpec[];
|
|
19
|
+
};
|
|
20
|
+
type IOpenApiParameterSpec = {
|
|
21
|
+
$ref?: string;
|
|
22
|
+
name: string;
|
|
23
|
+
in: string;
|
|
24
|
+
enum?: string[];
|
|
25
|
+
description?: string;
|
|
26
|
+
required?: boolean;
|
|
27
|
+
deprecated?: boolean;
|
|
28
|
+
allowEmptyValue?: boolean;
|
|
29
|
+
style?: string;
|
|
30
|
+
explode?: boolean;
|
|
31
|
+
allowReserved?: boolean;
|
|
32
|
+
schema?: IOpenApSchemaSpec;
|
|
33
|
+
example?: any;
|
|
34
|
+
examples?: any[];
|
|
35
|
+
};
|
|
36
|
+
type IOpenApiMediaTypeSpec = {
|
|
37
|
+
schema?: IOpenApSchemaSpec;
|
|
38
|
+
example?: any;
|
|
39
|
+
examples?: any[];
|
|
40
|
+
encoding?: any;
|
|
41
|
+
};
|
|
42
|
+
type IOpenApiRequestBodySpec = {
|
|
43
|
+
description?: string;
|
|
44
|
+
required?: boolean;
|
|
45
|
+
content: Record<string, IOpenApiMediaTypeSpec>;
|
|
46
|
+
};
|
|
47
|
+
type IOpenApiResponseSpec = Record<string, IOpenApiRequestBodySpec>;
|
|
48
|
+
type IConfigReplaceWord = {
|
|
49
|
+
/** string and regular expression as a string*/
|
|
50
|
+
replace: string;
|
|
51
|
+
with: string;
|
|
52
|
+
};
|
|
53
|
+
type IConfigDoc = {
|
|
54
|
+
disable?: boolean;
|
|
55
|
+
showCurl?: boolean;
|
|
56
|
+
};
|
|
57
|
+
type IConfigExclude = {
|
|
58
|
+
/** Exclude/Include endpoints by tags */
|
|
59
|
+
tags?: string[];
|
|
60
|
+
/** Exclude/Include individual endpoints by path and method */
|
|
61
|
+
endpoints?: Array<{
|
|
62
|
+
/** Exact path match (regex will be ignore when provided)*/
|
|
63
|
+
path?: string;
|
|
64
|
+
/** Regular expression pattern for path matching */
|
|
65
|
+
regex?: string;
|
|
66
|
+
/** Don't specify method to exclude all methods */
|
|
67
|
+
method?: Method;
|
|
68
|
+
}>;
|
|
69
|
+
};
|
|
70
|
+
interface IConfigInclude extends IConfigExclude {
|
|
71
|
+
}
|
|
72
|
+
type IConfigFolderSplit = {
|
|
73
|
+
/** Split folders by tags - creates folders named after each tag */
|
|
74
|
+
byTags?: boolean;
|
|
75
|
+
/** Custom function to determine folder name for each endpoint */
|
|
76
|
+
customFolder?: (data: {
|
|
77
|
+
method: Method;
|
|
78
|
+
path: string;
|
|
79
|
+
summary?: string;
|
|
80
|
+
operationId?: string;
|
|
81
|
+
tags?: string[];
|
|
82
|
+
parameters?: IOpenApiParameterSpec[];
|
|
83
|
+
requestBody?: IOpenApiRequestBodySpec;
|
|
84
|
+
responses?: IOpenApiResponseSpec;
|
|
85
|
+
}) => string | null;
|
|
86
|
+
};
|
|
87
|
+
type IConfig = {
|
|
88
|
+
refetchInterval?: number;
|
|
89
|
+
folder?: string;
|
|
90
|
+
api: Record<string, string>;
|
|
91
|
+
server?: number | string;
|
|
92
|
+
/** Configuration for splitting generated code into folders */
|
|
93
|
+
folderSplit?: IConfigFolderSplit;
|
|
94
|
+
/** Configuration for excluding endpoints from code generation */
|
|
95
|
+
types?: {
|
|
96
|
+
name?: {
|
|
97
|
+
prefix?: string;
|
|
98
|
+
useOperationId?: boolean;
|
|
99
|
+
format?: (source: "shared" | "endpoint", data: {
|
|
100
|
+
name?: string;
|
|
101
|
+
type?: "response" | "dto" | "query";
|
|
102
|
+
code?: string;
|
|
103
|
+
method?: Method;
|
|
104
|
+
path?: string;
|
|
105
|
+
summary?: string;
|
|
106
|
+
operationId?: string;
|
|
107
|
+
}, defaultName: string) => string | null | undefined;
|
|
108
|
+
};
|
|
109
|
+
doc?: IConfigDoc;
|
|
110
|
+
};
|
|
111
|
+
endpoints?: {
|
|
112
|
+
value?: {
|
|
113
|
+
replaceWords?: IConfigReplaceWord[];
|
|
114
|
+
includeServer?: boolean;
|
|
115
|
+
type?: "string" | "object";
|
|
116
|
+
};
|
|
117
|
+
name?: {
|
|
118
|
+
format?: (data: {
|
|
119
|
+
method: Method;
|
|
120
|
+
path: string;
|
|
121
|
+
summary: string;
|
|
122
|
+
operationId: string;
|
|
123
|
+
}, defaultName: string) => string | null;
|
|
124
|
+
prefix?: string;
|
|
125
|
+
useOperationId?: boolean;
|
|
126
|
+
};
|
|
127
|
+
doc?: IConfigDoc;
|
|
128
|
+
exclude?: IConfigExclude;
|
|
129
|
+
include?: IConfigInclude;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
type IOpenApiSecuritySchemes = {
|
|
133
|
+
[key: string]: {
|
|
134
|
+
type: "http" | "apiKey" | "oauth2" | "openIdConnect" | "mutualTLS";
|
|
135
|
+
scheme?: "bearer" | "basic";
|
|
136
|
+
in?: "query" | "header" | "cookie";
|
|
137
|
+
flows?: {
|
|
138
|
+
authorizationCode: {
|
|
139
|
+
authorizationUrl: "https://example.com/auth";
|
|
140
|
+
tokenUrl: "https://example.com/token";
|
|
141
|
+
scopes: {
|
|
142
|
+
"read:data": "Grants read access";
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
bearerFormat?: "JWT";
|
|
147
|
+
openIdConnectUrl?: string;
|
|
148
|
+
name?: string;
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
declare const isJson: (value: any) => boolean;
|
|
153
|
+
declare const isYamlString: (fileContent: string) => boolean;
|
|
154
|
+
declare const yamlStringToJson: (fileContent: string) => any;
|
|
155
|
+
declare const capitalize: (text: string) => string;
|
|
156
|
+
declare const getEndpointDetails: (path: string, method: string) => {
|
|
157
|
+
name: string;
|
|
158
|
+
variables: string[];
|
|
159
|
+
pathParts: string[];
|
|
160
|
+
};
|
|
161
|
+
declare const JSONStringify: (obj: Record<string, any>, indent?: number) => string;
|
|
162
|
+
declare const renderTypeRefMD: (typeRef: string, indent?: number) => string;
|
|
163
|
+
declare function getNestedValue<T>(obj: object, path: string): T | undefined;
|
|
164
|
+
|
|
165
|
+
declare const variableName: RegExp;
|
|
166
|
+
declare const variableNameChar: RegExp;
|
|
167
|
+
|
|
168
|
+
declare const Init: (options?: {
|
|
5
169
|
refetchInterval?: number;
|
|
6
170
|
}) => Promise<void>;
|
|
171
|
+
|
|
172
|
+
export { type IConfig, type IConfigDoc, type IConfigExclude, type IConfigFolderSplit, type IConfigInclude, type IConfigReplaceWord, type IOpenApSchemaSpec, type IOpenApiMediaTypeSpec, type IOpenApiParameterSpec, type IOpenApiRequestBodySpec, type IOpenApiResponseSpec, type IOpenApiSecuritySchemes, type IOpenApiSpec, Init, JSONStringify, capitalize, getEndpointDetails, getNestedValue, isJson, isYamlString, renderTypeRefMD, variableName, variableNameChar, yamlStringToJson };
|
package/dist/index.js
CHANGED
|
@@ -1,88 +1,56 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}))
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (fs_1.default.existsSync(configPath)) {
|
|
58
|
-
configJS = require(configPath);
|
|
59
|
-
if (Object.keys(configJS).length === 1 && configJS.default) {
|
|
60
|
-
configJS = configJS.default;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
catch (e) {
|
|
66
|
-
console.log(e);
|
|
67
|
-
}
|
|
68
|
-
if (typeof configJS === "function") {
|
|
69
|
-
configJS = configJS();
|
|
70
|
-
}
|
|
71
|
-
const config = configJS;
|
|
72
|
-
if (!config) {
|
|
73
|
-
throw new Error("No config found");
|
|
74
|
-
}
|
|
75
|
-
const apiNames = Object.keys(config.api);
|
|
76
|
-
const refetchInterval = options &&
|
|
77
|
-
"refetchInterval" in options &&
|
|
78
|
-
!isNaN(options === null || options === void 0 ? void 0 : options.refetchInterval)
|
|
79
|
-
? options.refetchInterval
|
|
80
|
-
: config.refetchInterval;
|
|
81
|
-
(0, state_1.resetState)();
|
|
82
|
-
for (let i = 0; i < apiNames.length; i += 1) {
|
|
83
|
-
const apiName = apiNames[i];
|
|
84
|
-
const apiUrl = config.api[apiName];
|
|
85
|
-
(0, Openapi_sync_1.default)(apiUrl, apiName, config, refetchInterval);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
exports.Init = Init;
|
|
1
|
+
"use strict";var Ot=Object.create;var ae=Object.defineProperty;var It=Object.getOwnPropertyDescriptor;var bt=Object.getOwnPropertyNames;var jt=Object.getPrototypeOf,xt=Object.prototype.hasOwnProperty;var Ct=(n,i)=>{for(var e in i)ae(n,e,{get:i[e],enumerable:!0})},ge=(n,i,e,j)=>{if(i&&typeof i=="object"||typeof i=="function")for(let O of bt(i))!xt.call(n,O)&&O!==e&&ae(n,O,{get:()=>i[O],enumerable:!(j=It(i,O))||j.enumerable});return n};var M=(n,i,e)=>(e=n!=null?Ot(jt(n)):{},ge(i||!n||!n.__esModule?ae(e,"default",{value:n,enumerable:!0}):e,n)),At=n=>ge(ae({},"__esModule",{value:!0}),n);var oe=(n,i,e)=>new Promise((j,O)=>{var C=x=>{try{c(e.next(x))}catch(h){O(h)}},E=x=>{try{c(e.throw(x))}catch(h){O(h)}},c=x=>x.done?j(x.value):Promise.resolve(x.value).then(C,E);c((e=e.apply(n,i)).next())});var wt={};Ct(wt,{Init:()=>St,JSONStringify:()=>Z,capitalize:()=>V,getEndpointDetails:()=>he,getNestedValue:()=>Tt,isJson:()=>$e,isYamlString:()=>et,renderTypeRefMD:()=>ee,variableName:()=>Et,variableNameChar:()=>ye,yamlStringToJson:()=>fe});module.exports=At(wt);var q=M(require("fs")),F=M(require("path")),Ie=M(require("lodash"));var Et=/^[A-Za-z_$][A-Za-z0-9_$]*$/,ye=/[A-Za-z0-9_$]/;var g=M(require("js-yaml")),$e=n=>["object"].includes(typeof n)&&!(n instanceof Blob),et=n=>{try{return g.load(n),!0}catch(i){let e=i;if(e instanceof g.YAMLException)return!1;throw e}},fe=n=>{if(et(n)){let i=g.load(n),e=JSON.stringify(i,null,2);return JSON.parse(e)}},V=n=>n.substring(0,1).toUpperCase()+n.substring(1),he=(n,i)=>{let e=n.split("/"),j=`${V(i)}`,O=[];return e.forEach(C=>{if(C[0]==="{"&&C[C.length-1]==="}"){let c=C.replace(/{/,"").replace(/}/,"");O.push(c),C=`$${c}`}else if(C[0]==="<"&&C[C.length-1]===">"){let c=C.replace(/</,"").replace(/>/,"");O.push(c),C=`$${c}`}else if(C[0]===":"){let c=C.replace(/:/,"");O.push(c),C=`$${c}`}let E="";C.split("").forEach(c=>{let x=c;ye.test(c)||(x="/"),E+=x}),E.split("/").forEach(c=>{j+=V(c)})}),{name:j,variables:O,pathParts:e}},Z=(n,i=1)=>{let e="{",j=Object.keys(n);for(let O=0;O<j.length;O++){let C=j[O],E=n[C];if(e+=`
|
|
2
|
+
`+" ".repeat(i)+C+": ",Array.isArray(E)){e+="[";for(let c=0;c<E.length;c++){let x=E[c];typeof x=="object"&&x!==null?e+=Z(x,i+1):e+=typeof x=="string"?`"${x}"`:x,c<E.length-1&&(e+=", ")}e+="]"}else typeof E=="object"&&E!==null?e+=""+Z(E,i+1):e+=E.split(`
|
|
3
|
+
`).filter(c=>c.trim()!=="").join(`
|
|
4
|
+
${" ".repeat(i)}`);O<j.length-1&&(e+=", ")}return e+=`
|
|
5
|
+
${" ".repeat(i-1)}}`,e},ee=(n,i=1)=>`
|
|
6
|
+
\`\`\`typescript
|
|
7
|
+
${" ".repeat(i)} ${n.split(`
|
|
8
|
+
`).filter(e=>e.trim()!=="").join(`
|
|
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 ot=require("lodash"),it=M(require("axios")),lt=M(require("axios-retry")),pe=require("@redocly/openapi-core");var tt=M(require("path")),ie=M(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],at=()=>{te={},rt(te)};var pt=require("curl-generator");var re=process.cwd(),Oe={},dt=it.default.create({timeout:6e4});(0,lt.default)(dt,{retries:20,retryCondition:n=>n.code==="ECONNABORTED"||n.message.includes("Network Error"),retryDelay:n=>n*1e3});var mt=(n,i,e,j)=>oe(null,null,function*(){var Ae,Ee,Te,Se,we,Ne;let O=yield dt.get(n),C=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:C}),x=F.default.join((e==null?void 0:e.folder)||"",i),h=c.bundle.parsed,P={},me=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=h==null?void 0:h.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:"",xe=(s,r)=>{var $,a;let I=V(s);if((a=($=e==null?void 0:e.types)==null?void 0:$.name)!=null&&a.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,$,a,p=0)=>{let f="",o="",l="";if(r){if(r.$ref)if(r.$ref[0]==="#"){let d=(r.$ref||"").split("/");d.shift(),[...d].pop();let S=d,w=Ie.default.get(s,S,null);if(w){w!=null&&w.name&&(f=w.name),o=d[d.length-1];let N=xe(o);N.includes(".")&&(N=N.split(".").map((z,Y)=>Y===0?z:`["${z}"]`).join("")),l+=`${a!=null&&a.noSharedImport?"":"Shared."}${N}`}}else l+="";else if(r.anyOf)l+=`(${r.anyOf.map(d=>U(s,d,"",$,a)).filter(d=>!!d).join("|")})`;else if(r.oneOf)l+=`(${r.oneOf.map(d=>U(s,d,"",$,a)).filter(d=>!!d).join("|")})`;else if(r.allOf)l+=`(${r.allOf.map(d=>U(s,d,"",$,a)).filter(d=>!!d).join("&")})`;else if(r.items)l+=`${U(s,r.items,"",!1,a)}[]`;else if(r.properties){let d=Object.keys(r.properties),b=r.required||[],S="";d.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
|
+
`).filter(ne=>ne.trim()!=="").join(`
|
|
12
|
+
*${" ".repeat(1)}`))),S+=(N?`/**
|
|
13
|
+
${N}
|
|
14
|
+
*/
|
|
15
|
+
`:"")+`${U(s,(D=r.properties)==null?void 0:D[w],w,b.includes(w),a,p+1)}`}),S.length>0?l+=`{
|
|
16
|
+
${" ".repeat(p)}${S}${" ".repeat(p)}}`:l+="{[k: string]: any}"}else if(r.enum&&r.enum.length>0)r.enum.length>1&&(l+="("),r.enum.map(d=>JSON.stringify(d)).filter(d=>!!d).forEach((d,b)=>{l+=`${b===0?"":"|"}${d}`}),r.enum.length>1&&(l+=")");else if(r.type){let d=b=>{let S="";if(typeof b=="string")["string","integer","number","array","boolean","null"].includes(b)?["integer","number"].includes(b)?S+="number":b==="array"?S+="any[]":S+=b:b==="object"&&(r.additionalProperties?S+=`{[k: string]: ${U(s,r.additionalProperties,"",!0,a)||"any"}}`:S+="{[k: string]: any}");else if(Array.isArray(b)){let w=b.map(N=>d(N));w.filter(N=>N!==""),w.length>1&&(S+="("+w.join("|")+")")}else S+="any";return S};l=d(r.type)}}else l="string";let u=f||I;a!=null&&a.useComponentName&&!u&&(u=o);let T=u?` "${u}"${$?"":"?"}: `:"",t=r!=null&&r.nullable?" | null":"";return l.length>0?`${T}${l}${t}${u?`;
|
|
17
|
+
`:""}`:""},W=(s,r)=>{let I="",$="",a="";if(r){if(r.$ref)if(r.$ref[0]==="#"){let p=(r.$ref||"").split("/");p.shift();let f=p,o=Ie.default.get(s,f,null);o&&(o!=null&&o.name&&(I=o.name),$=p[p.length-1],a+=W(s,o))}else a+="";else if(r.anyOf)a+=W(s,r.anyOf[0]);else if(r.oneOf)a+=W(s,r.oneOf[0]);else if(r.allOf)a+=`{${r.allOf.map(p=>`...(${W(s,p)})`).join(",")}}`;else if(r.items)a+=`[${W(s,r.items)}]`;else if(r.properties){let o=Object.keys(r.properties).map(l=>{var u;return` "${l}": ${W(s,(u=r.properties)==null?void 0:u[l])}`}).join(`,
|
|
18
|
+
`);o.length>0?a+=`{
|
|
19
|
+
${o}
|
|
20
|
+
}`:a+="{}"}else if(r.enum&&r.enum.length>0)r.enum.length>1&&(a+=r.enum[0]);else if(r.type)if(r.example)a+=JSON.stringify(r.example);else{let p=f=>{let o="";if(typeof f=="string")["string","integer","number","array","boolean","null"].includes(f)?["integer","number"].includes(f)?o+="123":f==="array"?o+="[]":f==="boolean"?o+="true":f==="null"?o+="null":o+=`"${f}"`:f==="object"&&(o+="{}");else if(Array.isArray(f)){let l=f.map(u=>p(u));l.filter(u=>u!==""),l.length>1&&(o+=l.join("|"))}else o+="any";return o};a=p(r.type)}}else a="string";return a};j&&!isNaN(j)&&j>0&&(process.env.NODE_ENV&&["production","prod","test","staging"].includes(process.env.NODE_ENV)||(Oe[i]&&clearTimeout(Oe[i]),Oe[i]=setTimeout(()=>mt(n,i,e,j),j)));let ft=nt(i);if((0,ot.isEqual)(ft,h))return;st(i,h);let ue="",H="",G={};h.components&&Object.keys(h.components).forEach(s=>{if(["schemas","responses","parameters","examples","requestBodies","headers","links","callbacks"].includes(s)){let r=h.components[s],I={},$={};Object.keys(r).forEach(p=>{var l;let f=(l=r[p])!=null&&l.schema?r[p].schema:r[p],o=`${U(h,f,"",!0,{noSharedImport:!0,useComponentName:["parameters"].includes(s)})}`;if(o){let u=p.split("."),T=I,t=$;for(let d=0;d<u.length;d++){let b=u[d];d<u.length-1?(b in T||(T[b]={},t[b]={}),T=T[b],t=t[b]):(T[b]=o,t[b]=f)}}}),Object.keys(I).forEach(p=>{var u,T,t,d;let f=xe(p),o=I[p],l="";!((T=(u=e==null?void 0:e.types)==null?void 0:u.doc)!=null&&T.disable)&&p in r&&((t=r[p])!=null&&t.description)&&(l=" * "+r[p].description.split(`
|
|
21
|
+
`).filter(b=>b.trim()!=="").join(`
|
|
22
|
+
*${" ".repeat(1)}`)),G[p]=((d=G[p])!=null?d:"")+(l?`/**
|
|
23
|
+
${l}
|
|
24
|
+
*/
|
|
25
|
+
`:"")+"export type "+f+" = "+(typeof o=="string"?o:Z(o))+`;
|
|
26
|
+
`})}});let Ce=s=>{let r="";if(s.content){let I=Object.keys(s.content);I[0]&&s.content[I[0]].schema&&(r+=`${U(h,s.content[I[0]].schema,"")}`)}return r},ht=s=>{var r,I,$,a,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 f=s;return(p=(a=($=e==null?void 0:e.endpoints)==null?void 0:$.value)==null?void 0:a.replaceWords)==null||p.forEach((o,l)=>{let u=new RegExp(o.replace,"g");f=f.replace(u,o.with||"")}),f}else return s},ct=(s,r,I=[])=>{var p,f;let $=(p=e==null?void 0:e.endpoints)==null?void 0:p.exclude,a=(f=e==null?void 0:e.endpoints)==null?void 0:f.include;if(a){let o=a.tags&&a.tags.length>0?I.some(u=>a.tags.includes(u)):!0,l=a.endpoints&&a.endpoints.length>0?a.endpoints.some(u=>{let T=!u.method||u.method.toLowerCase()===r.toLowerCase();return u.path?s===u.path&&T:u.regex?new RegExp(u.regex).test(s)&&T:!1}):!0;if(!o||!l)return!0}return!!($&&($.tags&&$.tags.length>0&&I.some(l=>$.tags.includes(l))||$.endpoints&&$.endpoints.length>0&&$.endpoints.some(l=>{let u=!l.method||l.method.toLowerCase()===r.toLowerCase();return l.path?s===l.path&&u:l.regex?new RegExp(l.regex).test(s)&&u:!1})))};if(Object.keys(h.paths||{}).forEach(s=>{let r=h.paths[s];Object.keys(r).forEach($=>{var ne,Re,ve,Fe,ke,qe,Pe,Be,Je,Me,Ue,Le,ze,Ke,Ve,We,Ye,Ge,Qe,Ze,He,Xe,De,_e;let a=$,p=he(s,a),f=((ne=r[a])==null?void 0:ne.tags)||[];if(ct(s,a,f))return;let o=r[a],l=me({method:a,path:s,summary:o==null?void 0:o.summary,operationId:o==null?void 0:o.operationId,tags:f,parameters:o==null?void 0:o.parameters,requestBody:o==null?void 0:o.requestBody,responses:o==null?void 0:o.responses});P[l]||(P[l]={endpoints:"",types:""});let u=((ve=(Re=e==null?void 0:e.endpoints)==null?void 0:Re.value)!=null&&ve.includeServer?je:"")+p.pathParts.map(y=>(y[0]==="{"&&y[y.length-1]==="}"?y=`\${${y.replace(/{/,"").replace(/}/,"")}}`:y[0]==="<"&&y[y.length-1]===">"?y=`\${${y.replace(/</,"").replace(/>/,"")}}`:y[0]===":"&&(y=`\${${y.replace(/:/,"")}}`),y)).join("/"),T=`"${u}"`;p.variables.length>0&&(T=`(${p.variables.map(m=>`${m}:string`).join(",")})=> \`${u}\``),T=ht(T);let t=r[a],d="";if(t!=null&&t.parameters&&((t==null?void 0:t.parameters).forEach((m,R)=>{(m.$ref||m.in==="query"&&m.name)&&(d+=`${U(h,m.$ref?m:m.schema,m.name||"",m.required)}`)}),d)){d=`{
|
|
27
|
+
${d}}`;let m=`${p.name}Query`;if((ke=(Fe=e==null?void 0:e.types)==null?void 0:Fe.name)!=null&&ke.useOperationId&&(t!=null&&t.operationId)&&(m=`${t.operationId}Query`),m=V(`${L}${m}`),(Pe=(qe=e==null?void 0:e.types)==null?void 0:qe.name)!=null&&Pe.format){let B=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"query",method:a,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},m);B&&(m=`${L}${B}`)}let R=`export type ${m} = ${d};
|
|
28
|
+
`;e!=null&&e.folderSplit?P[l].types+=R:H+=R}let b=t==null?void 0:t.requestBody,S="";if(b&&(S=Ce(b),S)){let y=`${p.name}DTO`;if((Je=(Be=e==null?void 0:e.types)==null?void 0:Be.name)!=null&&Je.useOperationId&&(t!=null&&t.operationId)&&(y=`${t.operationId}DTO`),y=V(`${L}${y}`),(Ue=(Me=e==null?void 0:e.types)==null?void 0:Me.name)!=null&&Ue.format){let R=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"dto",method:a,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},y);R&&(y=`${L}${R}`)}let m=`export type ${y} = ${S};
|
|
29
|
+
`;e!=null&&e.folderSplit?P[l].types+=m:H+=m}let w={},N="";if(t!=null&&t.responses){let y=t==null?void 0:t.responses;Object.keys(y).forEach(R=>{var B,J,v,k;if(N=Ce(y[R]),w[R]=N,N){let A=`${p.name}${R}Response`;if((J=(B=e==null?void 0:e.types)==null?void 0:B.name)!=null&&J.useOperationId&&(t!=null&&t.operationId)&&(A=`${t.operationId}${R}Response`),A=V(`${L}${A}`),(k=(v=e==null?void 0:e.types)==null?void 0:v.name)!=null&&k.format){let _=e==null?void 0:e.types.name.format("endpoint",{code:R,type:"response",method:a,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},A);_&&(A=`${L}${_}`)}let K=`export type ${A} = ${N};
|
|
30
|
+
`;e!=null&&e.folderSplit?P[l].types+=K:H+=K}})}let X=y=>!y||!y.length?"":y.map(m=>Object.entries(m).map(([B,J])=>{let v=B,k="";return Array.isArray(J)&&J.length&&(k=`
|
|
31
|
+
- Scopes: [\`${J.join("`, `")}\`]`,v=`**${v}**`),`
|
|
32
|
+
- ${v}${k}`}).join("")).join(`
|
|
33
|
+
`),z=t!=null&&t.security?X(t.security):"",Y="";if(!((ze=(Le=e==null?void 0:e.endpoints)==null?void 0:Le.doc)!=null&&ze.disable)){let y="";if((Ve=(Ke=e==null?void 0:e.endpoints)==null?void 0:Ke.doc)!=null&&Ve.showCurl){let m={},R="",B="";(We=t.requestBody)!=null&&We.content&&Object.keys(t.requestBody.content).forEach(k=>{let A=t.requestBody.content[k].schema;if(A){Array.isArray(m["Content-type"])?m["Content-type"].push(k):m["Content-type"]=[k];let K=W(h,A);K&&(R=K)}}),t!=null&&t.security&&t.security.forEach(v=>{Object.keys(v).forEach(k=>{var K,_;let A=(_=(K=h.components)==null?void 0:K.securitySchemes)==null?void 0:_[k];A&&(A.type==="mutualTLS"?B+=`
|
|
34
|
+
--cert client-certificate.crt --key client-private-key.key --cacert ca-certificate.crt`:A.type==="apiKey"?m[(A==null?void 0:A.name)||"X-API-KEY"]="{API_KEY_VALUE}":m.Authorization=`${(A==null?void 0:A.scheme)==="basic"?"Basic":"Bearer"} {${(A==null?void 0:A.scheme)==="basic"?"VALUE":"TOKEN"}}`)})});let J={};Object.keys(m).forEach(v=>{Array.isArray(m[v])?J[v]=m[v].join("; "):J[v]=m[v]}),y=`
|
|
35
|
+
\`\`\`bash
|
|
36
|
+
${(0,pt.CurlGenerator)({url:je+s,method:a.toUpperCase(),headers:J,body:R})}${B}
|
|
37
|
+
\`\`\``}Y=`/**${t!=null&&t.description?`
|
|
38
|
+
* ${t==null?void 0:t.description} `:""}
|
|
39
|
+
* **Method**: \`${a.toUpperCase()}\`
|
|
40
|
+
* **Summary**: ${(t==null?void 0:t.summary)||""}
|
|
41
|
+
* **Tags**: [${((Ye=t==null?void 0:t.tags)==null?void 0:Ye.join(", "))||""}]
|
|
42
|
+
* **OperationId**: ${(t==null?void 0:t.operationId)||""} ${d?`
|
|
43
|
+
* **Query**: ${ee(d)} `:""}${S?`
|
|
44
|
+
* **DTO**: ${ee(S)} `:""}${N?`
|
|
45
|
+
* **Response**: ${Object.entries(w).map(([m,R])=>`
|
|
46
|
+
- **${m}**: ${ee(R,2)} `).join("")}`:""}${z?`
|
|
47
|
+
* **Security**: ${z}
|
|
48
|
+
`:""}${y}
|
|
49
|
+
*/
|
|
50
|
+
`}let Q=(Qe=(Ge=e==null?void 0:e.endpoints)==null?void 0:Ge.name)!=null&&Qe.useOperationId&&((Ze=t==null?void 0:t.operationId)==null?void 0:Ze.length)>0?t.operationId:`${p.name}`;if((Xe=(He=e==null?void 0:e.endpoints)==null?void 0:He.name)!=null&&Xe.format){let y=e==null?void 0:e.endpoints.name.format({method:a,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},Q);y&&(Q=y)}let se={method:`"${a}"`,operationId:`"${t==null?void 0:t.operationId}"`,url:T,tags:(t==null?void 0:t.tags)||[]},D=`${Y}export const ${$t}${Q} = ${((_e=(De=e==null?void 0:e.endpoints)==null?void 0:De.value)==null?void 0:_e.type)==="object"?Z(se):T};
|
|
51
|
+
`;e!=null&&e.folderSplit?P[l].endpoints+=D:ue+=D})}),e!=null&&e.folderSplit){for(let[s,r]of Object.entries(P))if(r.endpoints||r.types){let I=F.default.join(x,s);if(r.endpoints){let $=F.default.join(re,I,"endpoints.ts");yield q.default.promises.mkdir(F.default.dirname($),{recursive:!0}),yield q.default.promises.writeFile($,r.endpoints)}if(r.types){let $=F.default.join(re,I,"types.ts");yield q.default.promises.mkdir(F.default.dirname($),{recursive:!0});let a=Object.values(G).length>0?`import * as Shared from "../shared";
|
|
52
|
+
|
|
53
|
+
${r.types}`:r.types;yield q.default.promises.writeFile($,a)}}}if(ue.length>0){let s=F.default.join(re,x,"endpoints.ts");yield q.default.promises.mkdir(F.default.dirname(s),{recursive:!0}),yield q.default.promises.writeFile(s,ue)}if(Object.values(G).length>0){let s=F.default.join(re,x,e!=null&&e.folderSplit?"":"types","shared.ts");yield q.default.promises.mkdir(F.default.dirname(s),{recursive:!0}),yield q.default.promises.writeFile(s,Object.values(G).join(`
|
|
54
|
+
`))}if(H.length>0){let s=F.default.join(re,x,"types","index.ts");yield q.default.promises.mkdir(F.default.dirname(s),{recursive:!0}),yield q.default.promises.writeFile(s,`${Object.values(G).length>0?`import * as Shared from "./shared";
|
|
55
|
+
|
|
56
|
+
`:""}${H}`)}}),ut=mt;var de=M(require("path")),yt=M(require("fs"));var be=process.cwd(),St=n=>oe(null,null,function*(){let i;try{require("esbuild-register")}catch(h){throw h}let e=de.default.join(be,"openapi.sync.js"),j=de.default.join(be,"openapi.sync.ts"),O=de.default.join(be,"openapi.sync.json"),C=[e,j,O];try{for(let h of C)yt.default.existsSync(h)&&(i=require(h),Object.keys(i).length===1&&i.default&&(i=i.default))}catch(h){console.log(h)}typeof i=="function"&&(i=i());let E=i;if(!E)throw new Error("No config found");let c=Object.keys(E.api),x=n&&"refetchInterval"in n&&!isNaN(n==null?void 0:n.refetchInterval)?n.refetchInterval:E.refetchInterval;at();for(let h=0;h<c.length;h+=1){let P=c[h],me=E.api[P];ut(me,P,E,x)}});0&&(module.exports={Init,JSONStringify,capitalize,getEndpointDetails,getNestedValue,isJson,isYamlString,renderTypeRefMD,variableName,variableNameChar,yamlStringToJson});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
var D=(o=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(o,{get:(d,e)=>(typeof require!="undefined"?require:d)[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,d,e)=>new Promise((C,A)=>{var j=b=>{try{c(e.next(b))}catch(h){A(h)}},E=b=>{try{c(e.throw(b))}catch(h){A(h)}},c=b=>b.done?C(b.value):Promise.resolve(b.value).then(j,E);c((e=e.apply(o,d)).next())});import J from"fs";import F from"path";import et from"lodash";var Ot=/^[A-Za-z_$][A-Za-z0-9_$]*$/,Ge=/[A-Za-z0-9_$]/;import*as g from"js-yaml";var Qe=o=>["object"].includes(typeof o)&&!(o instanceof Blob),lt=o=>{try{return g.load(o),!0}catch(d){let e=d;if(e instanceof g.YAMLException)return!1;throw e}},Ze=o=>{if(lt(o)){let d=g.load(o),e=JSON.stringify(d,null,2);return JSON.parse(e)}},W=o=>o.substring(0,1).toUpperCase()+o.substring(1),He=(o,d)=>{let e=o.split("/"),C=`${W(d)}`,A=[];return e.forEach(j=>{if(j[0]==="{"&&j[j.length-1]==="}"){let c=j.replace(/{/,"").replace(/}/,"");A.push(c),j=`$${c}`}else if(j[0]==="<"&&j[j.length-1]===">"){let c=j.replace(/</,"").replace(/>/,"");A.push(c),j=`$${c}`}else if(j[0]===":"){let c=j.replace(/:/,"");A.push(c),j=`$${c}`}let E="";j.split("").forEach(c=>{let b=c;Ge.test(c)||(b="/"),E+=b}),E.split("/").forEach(c=>{C+=W(c)})}),{name:C,variables:A,pathParts:e}},_=(o,d=1)=>{let e="{",C=Object.keys(o);for(let A=0;A<C.length;A++){let j=C[A],E=o[j];if(e+=`
|
|
2
|
+
`+" ".repeat(d)+j+": ",Array.isArray(E)){e+="[";for(let c=0;c<E.length;c++){let b=E[c];typeof b=="object"&&b!==null?e+=_(b,d+1):e+=typeof b=="string"?`"${b}"`:b,c<E.length-1&&(e+=", ")}e+="]"}else typeof E=="object"&&E!==null?e+=""+_(E,d+1):e+=E.split(`
|
|
3
|
+
`).filter(c=>c.trim()!=="").join(`
|
|
4
|
+
${" ".repeat(d)}`);A<C.length-1&&(e+=", ")}return e+=`
|
|
5
|
+
${" ".repeat(d-1)}}`,e},ae=(o,d=1)=>`
|
|
6
|
+
\`\`\`typescript
|
|
7
|
+
${" ".repeat(d)} ${o.split(`
|
|
8
|
+
`).filter(e=>e.trim()!=="").join(`
|
|
9
|
+
${" ".repeat(d)} `)}
|
|
10
|
+
\`\`\``;function jt(o,d){return d.split(".").reduce((C,A)=>C&&C[A]!==void 0?C[A]:void 0,o)}import{isEqual as dt}from"lodash";import mt 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 oe=pt.join(__dirname,"../","../db.json");pe.existsSync(oe)||pe.writeFileSync(oe,"{}");var de={};try{de=D(oe)}catch(o){de={}}var ee=de||{},Xe=o=>{pe.writeFileSync(oe,JSON.stringify(o))},De=(o,d)=>{ee[o]=d,Xe(ee)},_e=o=>ee[o],ge=()=>{ee={},Xe(ee)};import{CurlGenerator as ft}from"curl-generator";var te=process.cwd(),me={},tt=mt.create({timeout:6e4});ut(tt,{retries:20,retryCondition:o=>o.code==="ECONNABORTED"||o.message.includes("Network Error"),retryDelay:o=>o*1e3});var rt=(o,d,e,C)=>ne(null,null,function*(){var ce,Oe,Ie,be,je,xe;let A=yield tt.get(o),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)||"",d),h=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(console.log("customFolder",$),$)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=h==null?void 0:h.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((xe=(je=e==null?void 0:e.endpoints)==null?void 0:je.name)==null?void 0:xe.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 f="",a="",i="";if(r){if(r.$ref)if(r.$ref[0]==="#"){let p=(r.$ref||"").split("/");p.shift(),[...p].pop();let S=p,w=et.get(s,S,null);if(w){w!=null&&w.name&&(f=w.name),a=p[p.length-1];let N=fe(a);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}
|
|
14
|
+
*/
|
|
15
|
+
`:"")+`${M(s,(H=r.properties)==null?void 0:H[w],w,I.includes(w),n,l+1)}`}),S.length>0?i+=`{
|
|
16
|
+
${" ".repeat(l)}${S}${" ".repeat(l)}}`:i+="{[k: string]: any}"}else if(r.enum&&r.enum.length>0)r.enum.length>1&&(i+="("),r.enum.map(p=>JSON.stringify(p)).filter(p=>!!p).forEach((p,I)=>{i+=`${I===0?"":"|"}${p}`}),r.enum.length>1&&(i+=")");else if(r.type){let p=I=>{let S="";if(typeof I=="string")["string","integer","number","array","boolean","null"].includes(I)?["integer","number"].includes(I)?S+="number":I==="array"?S+="any[]":S+=I:I==="object"&&(r.additionalProperties?S+=`{[k: string]: ${M(s,r.additionalProperties,"",!0,n)||"any"}}`:S+="{[k: string]: any}");else if(Array.isArray(I)){let w=I.map(N=>p(N));w.filter(N=>N!==""),w.length>1&&(S+="("+w.join("|")+")")}else S+="any";return S};i=p(r.type)}}else i="string";let u=f||O;n!=null&&n.useComponentName&&!u&&(u=a);let T=u?` "${u}"${$?"":"?"}: `:"",t=r!=null&&r.nullable?" | null":"";return i.length>0?`${T}${i}${t}${u?`;
|
|
17
|
+
`:""}`:""},K=(s,r)=>{let O="",$="",n="";if(r){if(r.$ref)if(r.$ref[0]==="#"){let l=(r.$ref||"").split("/");l.shift();let f=l,a=et.get(s,f,null);a&&(a!=null&&a.name&&(O=a.name),$=l[l.length-1],n+=K(s,a))}else n+="";else if(r.anyOf)n+=K(s,r.anyOf[0]);else if(r.oneOf)n+=K(s,r.oneOf[0]);else if(r.allOf)n+=`{${r.allOf.map(l=>`...(${K(s,l)})`).join(",")}}`;else if(r.items)n+=`[${K(s,r.items)}]`;else if(r.properties){let a=Object.keys(r.properties).map(i=>{var u;return` "${i}": ${K(s,(u=r.properties)==null?void 0:u[i])}`}).join(`,
|
|
18
|
+
`);a.length>0?n+=`{
|
|
19
|
+
${a}
|
|
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=f=>{let a="";if(typeof f=="string")["string","integer","number","array","boolean","null"].includes(f)?["integer","number"].includes(f)?a+="123":f==="array"?a+="[]":f==="boolean"?a+="true":f==="null"?a+="null":a+=`"${f}"`:f==="object"&&(a+="{}");else if(Array.isArray(f)){let i=f.map(u=>l(u));i.filter(u=>u!==""),i.length>1&&(a+=i.join("|"))}else a+="any";return a};n=l(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[d]&&clearTimeout(me[d]),me[d]=setTimeout(()=>rt(o,d,e,C),C)));let at=_e(d);if(dt(at,h))return;De(d,h);let le="",Q="",Y={};h.components&&Object.keys(h.components).forEach(s=>{if(["schemas","responses","parameters","examples","requestBodies","headers","links","callbacks"].includes(s)){let r=h.components[s],O={},$={};Object.keys(r).forEach(l=>{var i;let f=(i=r[l])!=null&&i.schema?r[l].schema:r[l],a=`${M(h,f,"",!0,{noSharedImport:!0,useComponentName:["parameters"].includes(s)})}`;if(a){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]=a,t[I]=f)}}}),Object.keys(O).forEach(l=>{var u,T,t,p;let f=fe(l),a=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
|
+
*/
|
|
25
|
+
`:"")+"export type "+f+" = "+(typeof a=="string"?a:_(a))+`;
|
|
26
|
+
`})}});let he=s=>{let r="";if(s.content){let O=Object.keys(s.content);O[0]&&s.content[O[0]].schema&&(r+=`${M(h,s.content[O[0]].schema,"")}`)}return r},ot=s=>{var r,O,$,n,l;if((O=(r=e==null?void 0:e.endpoints)==null?void 0:r.value)!=null&&O.replaceWords&&Array.isArray(e==null?void 0:e.endpoints.value.replaceWords)){let f=s;return(l=(n=($=e==null?void 0:e.endpoints)==null?void 0:$.value)==null?void 0:n.replaceWords)==null||l.forEach((a,i)=>{let u=new RegExp(a.replace,"g");f=f.replace(u,a.with||"")}),f}else return s},it=(s,r,O=[])=>{var l,f;let $=(l=e==null?void 0:e.endpoints)==null?void 0:l.exclude,n=(f=e==null?void 0:e.endpoints)==null?void 0:f.include;if(n){let a=n.tags&&n.tags.length>0?O.some(u=>n.tags.includes(u)):!0,i=n.endpoints&&n.endpoints.length>0?n.endpoints.some(u=>{let T=!u.method||u.method.toLowerCase()===r.toLowerCase();return u.path?s===u.path&&T:u.regex?new RegExp(u.regex).test(s)&&T:!1}):!0;if(!a||!i)return!0}return!!($&&($.tags&&$.tags.length>0&&O.some(i=>$.tags.includes(i))||$.endpoints&&$.endpoints.length>0&&$.endpoints.some(i=>{let u=!i.method||i.method.toLowerCase()===r.toLowerCase();return i.path?s===i.path&&u:i.regex?new RegExp(i.regex).test(s)&&u:!1})))};if(Object.keys(h.paths||{}).forEach(s=>{let r=h.paths[s];Object.keys(r).forEach($=>{var se,Ce,Ae,Ee,Te,Se,we,Ne,Re,ve,Fe,ke,qe,Pe,Be,Je,Me,Ue,Le,ze,Ke,Ve,We,Ye;let n=$,l=He(s,n),f=((se=r[n])==null?void 0:se.tags)||[];if(it(s,n,f))return;let a=r[n],i=ie({method:n,path:s,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId,tags:f,parameters:a==null?void 0:a.parameters,requestBody:a==null?void 0:a.requestBody,responses:a==null?void 0:a.responses});q[i]||(q[i]={endpoints:"",types:""});let u=((Ae=(Ce=e==null?void 0:e.endpoints)==null?void 0:Ce.value)!=null&&Ae.includeServer?$e:"")+l.pathParts.map(y=>(y[0]==="{"&&y[y.length-1]==="}"?y=`\${${y.replace(/{/,"").replace(/}/,"")}}`:y[0]==="<"&&y[y.length-1]===">"?y=`\${${y.replace(/</,"").replace(/>/,"")}}`:y[0]===":"&&(y=`\${${y.replace(/:/,"")}}`),y)).join("/"),T=`"${u}"`;l.variables.length>0&&(T=`(${l.variables.map(m=>`${m}:string`).join(",")})=> \`${u}\``),T=ot(T);let t=r[n],p="";if(t!=null&&t.parameters&&((t==null?void 0:t.parameters).forEach((m,R)=>{(m.$ref||m.in==="query"&&m.name)&&(p+=`${M(h,m.$ref?m:m.schema,m.name||"",m.required)}`)}),p)){p=`{
|
|
27
|
+
${p}}`;let m=`${l.name}Query`;if((Te=(Ee=e==null?void 0:e.types)==null?void 0:Ee.name)!=null&&Te.useOperationId&&(t!=null&&t.operationId)&&(m=`${t.operationId}Query`),m=W(`${U}${m}`),(we=(Se=e==null?void 0:e.types)==null?void 0:Se.name)!=null&&we.format){let P=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},m);P&&(m=`${U}${P}`)}let R=`export type ${m} = ${p};
|
|
28
|
+
`;e!=null&&e.folderSplit?q[i].types+=R:Q+=R}let I=t==null?void 0:t.requestBody,S="";if(I&&(S=he(I),S)){let y=`${l.name}DTO`;if((Re=(Ne=e==null?void 0:e.types)==null?void 0:Ne.name)!=null&&Re.useOperationId&&(t!=null&&t.operationId)&&(y=`${t.operationId}DTO`),y=W(`${U}${y}`),(Fe=(ve=e==null?void 0:e.types)==null?void 0:ve.name)!=null&&Fe.format){let R=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},y);R&&(y=`${U}${R}`)}let m=`export type ${y} = ${S};
|
|
29
|
+
`;e!=null&&e.folderSplit?q[i].types+=m:Q+=m}let w={},N="";if(t!=null&&t.responses){let y=t==null?void 0:t.responses;Object.keys(y).forEach(R=>{var P,B,v,k;if(N=he(y[R]),w[R]=N,N){let x=`${l.name}${R}Response`;if((B=(P=e==null?void 0:e.types)==null?void 0:P.name)!=null&&B.useOperationId&&(t!=null&&t.operationId)&&(x=`${t.operationId}${R}Response`),x=W(`${U}${x}`),(k=(v=e==null?void 0:e.types)==null?void 0:v.name)!=null&&k.format){let X=e==null?void 0:e.types.name.format("endpoint",{code:R,type:"response",method:n,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},x);X&&(x=`${U}${X}`)}let z=`export type ${x} = ${N};
|
|
30
|
+
`;e!=null&&e.folderSplit?q[i].types+=z:Q+=z}})}let Z=y=>!y||!y.length?"":y.map(m=>Object.entries(m).map(([P,B])=>{let v=P,k="";return Array.isArray(B)&&B.length&&(k=`
|
|
31
|
+
- Scopes: [\`${B.join("`, `")}\`]`,v=`**${v}**`),`
|
|
32
|
+
- ${v}${k}`}).join("")).join(`
|
|
33
|
+
`),L=t!=null&&t.security?Z(t.security):"",V="";if(!((qe=(ke=e==null?void 0:e.endpoints)==null?void 0:ke.doc)!=null&&qe.disable)){let y="";if((Be=(Pe=e==null?void 0:e.endpoints)==null?void 0:Pe.doc)!=null&&Be.showCurl){let m={},R="",P="";(Je=t.requestBody)!=null&&Je.content&&Object.keys(t.requestBody.content).forEach(k=>{let x=t.requestBody.content[k].schema;if(x){Array.isArray(m["Content-type"])?m["Content-type"].push(k):m["Content-type"]=[k];let z=K(h,x);z&&(R=z)}}),t!=null&&t.security&&t.security.forEach(v=>{Object.keys(v).forEach(k=>{var z,X;let x=(X=(z=h.components)==null?void 0:z.securitySchemes)==null?void 0:X[k];x&&(x.type==="mutualTLS"?P+=`
|
|
34
|
+
--cert client-certificate.crt --key client-private-key.key --cacert ca-certificate.crt`:x.type==="apiKey"?m[(x==null?void 0:x.name)||"X-API-KEY"]="{API_KEY_VALUE}":m.Authorization=`${(x==null?void 0:x.scheme)==="basic"?"Basic":"Bearer"} {${(x==null?void 0:x.scheme)==="basic"?"VALUE":"TOKEN"}}`)})});let B={};Object.keys(m).forEach(v=>{Array.isArray(m[v])?B[v]=m[v].join("; "):B[v]=m[v]}),y=`
|
|
35
|
+
\`\`\`bash
|
|
36
|
+
${ft({url:$e+s,method:n.toUpperCase(),headers:B,body:R})}${P}
|
|
37
|
+
\`\`\``}V=`/**${t!=null&&t.description?`
|
|
38
|
+
* ${t==null?void 0:t.description} `:""}
|
|
39
|
+
* **Method**: \`${n.toUpperCase()}\`
|
|
40
|
+
* **Summary**: ${(t==null?void 0:t.summary)||""}
|
|
41
|
+
* **Tags**: [${((Me=t==null?void 0:t.tags)==null?void 0:Me.join(", "))||""}]
|
|
42
|
+
* **OperationId**: ${(t==null?void 0:t.operationId)||""} ${p?`
|
|
43
|
+
* **Query**: ${ae(p)} `:""}${S?`
|
|
44
|
+
* **DTO**: ${ae(S)} `:""}${N?`
|
|
45
|
+
* **Response**: ${Object.entries(w).map(([m,R])=>`
|
|
46
|
+
- **${m}**: ${ae(R,2)} `).join("")}`:""}${L?`
|
|
47
|
+
* **Security**: ${L}
|
|
48
|
+
`:""}${y}
|
|
49
|
+
*/
|
|
50
|
+
`}let G=(Le=(Ue=e==null?void 0:e.endpoints)==null?void 0:Ue.name)!=null&&Le.useOperationId&&((ze=t==null?void 0:t.operationId)==null?void 0:ze.length)>0?t.operationId:`${l.name}`;if((Ve=(Ke=e==null?void 0:e.endpoints)==null?void 0:Ke.name)!=null&&Ve.format){let y=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},G);y&&(G=y)}let re={method:`"${n}"`,operationId:`"${t==null?void 0:t.operationId}"`,url:T,tags:(t==null?void 0:t.tags)||[]},H=`${V}export const ${nt}${G} = ${((Ye=(We=e==null?void 0:e.endpoints)==null?void 0:We.value)==null?void 0:Ye.type)==="object"?_(re):T};
|
|
51
|
+
`;e!=null&&e.folderSplit?q[i].endpoints+=H:le+=H})}),e!=null&&e.folderSplit){for(let[s,r]of Object.entries(q))if(r.endpoints||r.types){let O=F.join(b,s);if(r.endpoints){let $=F.join(te,O,"endpoints.ts");yield J.promises.mkdir(F.dirname($),{recursive:!0}),yield J.promises.writeFile($,r.endpoints)}if(r.types){let $=F.join(te,O,"types.ts");yield J.promises.mkdir(F.dirname($),{recursive:!0});let n=Object.values(Y).length>0?`import * as Shared from "../shared";
|
|
52
|
+
|
|
53
|
+
${r.types}`:r.types;yield J.promises.writeFile($,n)}}}if(le.length>0){let s=F.join(te,b,"endpoints.ts");yield J.promises.mkdir(F.dirname(s),{recursive:!0}),yield J.promises.writeFile(s,le)}if(Object.values(Y).length>0){let s=F.join(te,b,e!=null&&e.folderSplit?"":"types","shared.ts");yield J.promises.mkdir(F.dirname(s),{recursive:!0}),yield J.promises.writeFile(s,Object.values(Y).join(`
|
|
54
|
+
`))}if(Q.length>0){let s=F.join(te,b,"types","index.ts");yield J.promises.mkdir(F.dirname(s),{recursive:!0}),yield J.promises.writeFile(s,`${Object.values(Y).length>0?`import * as Shared from "./shared";
|
|
55
|
+
|
|
56
|
+
`:""}${Q}`)}}),st=rt;import ue from"path";import ht from"fs";var ye=process.cwd(),Wt=o=>ne(null,null,function*(){let d;try{D("esbuild-register")}catch(h){throw h}let e=ue.join(ye,"openapi.sync.js"),C=ue.join(ye,"openapi.sync.ts"),A=ue.join(ye,"openapi.sync.json"),j=[e,C,A];try{for(let h of j)ht.existsSync(h)&&(d=D(h),Object.keys(d).length===1&&d.default&&(d=d.default))}catch(h){console.log(h)}typeof d=="function"&&(d=d());let E=d;if(!E)throw new Error("No config found");let c=Object.keys(E.api),b=o&&"refetchInterval"in o&&!isNaN(o==null?void 0:o.refetchInterval)?o.refetchInterval:E.refetchInterval;ge();for(let h=0;h<c.length;h+=1){let q=c[h],ie=E.api[q];st(ie,q,E,b)}});export{Wt as Init,_ as JSONStringify,W as capitalize,He as getEndpointDetails,jt as getNestedValue,Qe as isJson,lt as isYamlString,ae as renderTypeRefMD,Ot as variableName,Ge as variableNameChar,Ze as yamlStringToJson};
|