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
|
@@ -1,776 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const fs_1 = __importDefault(require("fs"));
|
|
16
|
-
const path_1 = __importDefault(require("path"));
|
|
17
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
18
|
-
const helpers_1 = require("../helpers");
|
|
19
|
-
const lodash_2 = require("lodash");
|
|
20
|
-
const axios_1 = __importDefault(require("axios"));
|
|
21
|
-
const axios_retry_1 = __importDefault(require("axios-retry"));
|
|
22
|
-
const openapi_core_1 = require("@redocly/openapi-core");
|
|
23
|
-
const state_1 = require("./state");
|
|
24
|
-
const curl_generator_1 = require("curl-generator");
|
|
25
|
-
const rootUsingCwd = process.cwd();
|
|
26
|
-
let fetchTimeout = {};
|
|
27
|
-
// Create an Axios instance
|
|
28
|
-
const apiClient = axios_1.default.create({
|
|
29
|
-
timeout: 60000, // Timeout after 1min
|
|
30
|
-
});
|
|
31
|
-
// Configure axios-retry
|
|
32
|
-
(0, axios_retry_1.default)(apiClient, {
|
|
33
|
-
retries: 20, // Number of retry attempts
|
|
34
|
-
retryCondition: (error) => {
|
|
35
|
-
// Retry on network error
|
|
36
|
-
return (error.code === "ECONNABORTED" || error.message.includes("Network Error"));
|
|
37
|
-
},
|
|
38
|
-
retryDelay: (retryCount) => {
|
|
39
|
-
return retryCount * 1000; // Exponential back-off: 1s, 2s, 3s, etc.
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
const OpenapiSync = (apiUrl, apiName, config, refetchInterval) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
-
var _a, _b, _c, _d, _e, _f;
|
|
44
|
-
const specResponse = yield apiClient.get(apiUrl);
|
|
45
|
-
const redoclyConfig = yield (0, openapi_core_1.createConfig)({
|
|
46
|
-
extends: ["minimal"],
|
|
47
|
-
});
|
|
48
|
-
const source = JSON.stringify((0, helpers_1.isJson)(specResponse.data)
|
|
49
|
-
? specResponse.data
|
|
50
|
-
: (0, helpers_1.yamlStringToJson)(specResponse.data));
|
|
51
|
-
const lintResults = yield (0, openapi_core_1.bundleFromString)({
|
|
52
|
-
source,
|
|
53
|
-
config: redoclyConfig,
|
|
54
|
-
});
|
|
55
|
-
const folderPath = path_1.default.join((config === null || config === void 0 ? void 0 : config.folder) || "", apiName);
|
|
56
|
-
const spec = lintResults.bundle.parsed;
|
|
57
|
-
const serverUrl = typeof (config === null || config === void 0 ? void 0 : config.server) === "string"
|
|
58
|
-
? config === null || config === void 0 ? void 0 : config.server
|
|
59
|
-
: ((_b = (_a = spec === null || spec === void 0 ? void 0 : spec.servers) === null || _a === void 0 ? void 0 : _a[(config === null || config === void 0 ? void 0 : config.server) || 0]) === null || _b === void 0 ? void 0 : _b.url) || "";
|
|
60
|
-
const typePrefix = typeof ((_d = (_c = config === null || config === void 0 ? void 0 : config.types) === null || _c === void 0 ? void 0 : _c.name) === null || _d === void 0 ? void 0 : _d.prefix) === "string"
|
|
61
|
-
? config === null || config === void 0 ? void 0 : config.types.name.prefix
|
|
62
|
-
: "I";
|
|
63
|
-
const endpointPrefix = typeof ((_f = (_e = config === null || config === void 0 ? void 0 : config.endpoints) === null || _e === void 0 ? void 0 : _e.name) === null || _f === void 0 ? void 0 : _f.prefix) === "string"
|
|
64
|
-
? config === null || config === void 0 ? void 0 : config.endpoints.name.prefix
|
|
65
|
-
: "";
|
|
66
|
-
const getSharedComponentName = (componentName, componentType) => {
|
|
67
|
-
var _a, _b;
|
|
68
|
-
const defaultName = (0, helpers_1.capitalize)(componentName);
|
|
69
|
-
if ((_b = (_a = config === null || config === void 0 ? void 0 : config.types) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.format) {
|
|
70
|
-
const formattedName = config === null || config === void 0 ? void 0 : config.types.name.format("shared", {
|
|
71
|
-
name: componentName,
|
|
72
|
-
}, defaultName);
|
|
73
|
-
if (formattedName)
|
|
74
|
-
return `${typePrefix}${formattedName}`;
|
|
75
|
-
}
|
|
76
|
-
return `${typePrefix}${defaultName}`;
|
|
77
|
-
};
|
|
78
|
-
const parseSchemaToType = (apiDoc, schema, name, isRequired, options, indentLevel = 0) => {
|
|
79
|
-
let overrideName = "";
|
|
80
|
-
let componentName = "";
|
|
81
|
-
let type = "";
|
|
82
|
-
if (schema) {
|
|
83
|
-
if (schema.$ref) {
|
|
84
|
-
if (schema.$ref[0] === "#") {
|
|
85
|
-
let pathToComponentParts = (schema.$ref || "").split("/");
|
|
86
|
-
pathToComponentParts.shift();
|
|
87
|
-
const partsClone = [...pathToComponentParts];
|
|
88
|
-
partsClone.pop();
|
|
89
|
-
const pathToComponent = pathToComponentParts;
|
|
90
|
-
const component = lodash_1.default.get(apiDoc, pathToComponent, null);
|
|
91
|
-
if (component) {
|
|
92
|
-
if (component === null || component === void 0 ? void 0 : component.name) {
|
|
93
|
-
overrideName = component.name;
|
|
94
|
-
}
|
|
95
|
-
componentName =
|
|
96
|
-
pathToComponentParts[pathToComponentParts.length - 1];
|
|
97
|
-
let name = getSharedComponentName(componentName);
|
|
98
|
-
if (name.includes(".")) {
|
|
99
|
-
const nameParts = name.split(".");
|
|
100
|
-
name = nameParts
|
|
101
|
-
.map((part, i) => {
|
|
102
|
-
if (i === 0) {
|
|
103
|
-
return part;
|
|
104
|
-
}
|
|
105
|
-
return `["${part}"]`;
|
|
106
|
-
})
|
|
107
|
-
.join("");
|
|
108
|
-
}
|
|
109
|
-
// Reference component via import instead of parsing
|
|
110
|
-
type += `${(options === null || options === void 0 ? void 0 : options.noSharedImport) ? "" : "Shared."}${name}`;
|
|
111
|
-
// type += `${parseSchemaToType(apiDoc, component, "", isRequired)}`;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
type += "";
|
|
116
|
-
//TODO $ref is a uri - use axios to fetch doc
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
else if (schema.anyOf) {
|
|
120
|
-
type += `(${schema.anyOf
|
|
121
|
-
.map((v) => parseSchemaToType(apiDoc, v, "", isRequired, options))
|
|
122
|
-
.filter((v) => !!v)
|
|
123
|
-
.join("|")})`;
|
|
124
|
-
}
|
|
125
|
-
else if (schema.oneOf) {
|
|
126
|
-
type += `(${schema.oneOf
|
|
127
|
-
.map((v) => parseSchemaToType(apiDoc, v, "", isRequired, options))
|
|
128
|
-
.filter((v) => !!v)
|
|
129
|
-
.join("|")})`;
|
|
130
|
-
}
|
|
131
|
-
else if (schema.allOf) {
|
|
132
|
-
type += `(${schema.allOf
|
|
133
|
-
.map((v) => parseSchemaToType(apiDoc, v, "", isRequired, options))
|
|
134
|
-
.filter((v) => !!v)
|
|
135
|
-
.join("&")})`;
|
|
136
|
-
}
|
|
137
|
-
else if (schema.items) {
|
|
138
|
-
type += `${parseSchemaToType(apiDoc, schema.items, "", false, options)}[]`;
|
|
139
|
-
}
|
|
140
|
-
else if (schema.properties) {
|
|
141
|
-
//parse object key one at a time
|
|
142
|
-
const objKeys = Object.keys(schema.properties);
|
|
143
|
-
const requiredKeys = schema.required || [];
|
|
144
|
-
let typeCnt = "";
|
|
145
|
-
objKeys.forEach((key) => {
|
|
146
|
-
var _a, _b, _c, _d, _e, _f;
|
|
147
|
-
let doc = "";
|
|
148
|
-
if (!((_b = (_a = config === null || config === void 0 ? void 0 : config.types) === null || _a === void 0 ? void 0 : _a.doc) === null || _b === void 0 ? void 0 : _b.disable) &&
|
|
149
|
-
((_d = (_c = schema.properties) === null || _c === void 0 ? void 0 : _c[key]) === null || _d === void 0 ? void 0 : _d.description)) {
|
|
150
|
-
doc =
|
|
151
|
-
" * " +
|
|
152
|
-
((_e = schema.properties) === null || _e === void 0 ? void 0 : _e[key].description.split("\n").filter((line) => line.trim() !== "").join(` \n *${" ".repeat(1)}`));
|
|
153
|
-
}
|
|
154
|
-
typeCnt +=
|
|
155
|
-
(doc ? `/**\n${doc}\n */\n` : "") +
|
|
156
|
-
`${parseSchemaToType(apiDoc, (_f = schema.properties) === null || _f === void 0 ? void 0 : _f[key], key, requiredKeys.includes(key), options, indentLevel + 1)}`;
|
|
157
|
-
});
|
|
158
|
-
if (typeCnt.length > 0) {
|
|
159
|
-
type += `{\n${" ".repeat(indentLevel)}${typeCnt}${" ".repeat(indentLevel)}}`;
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
type += "{[k: string]: any}";
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
else if (schema.enum && schema.enum.length > 0) {
|
|
166
|
-
if (schema.enum.length > 1)
|
|
167
|
-
type += "(";
|
|
168
|
-
schema.enum
|
|
169
|
-
.map((v) => JSON.stringify(v))
|
|
170
|
-
.filter((v) => !!v)
|
|
171
|
-
.forEach((v, i) => {
|
|
172
|
-
type += `${i === 0 ? "" : "|"}${v}`;
|
|
173
|
-
});
|
|
174
|
-
if (schema.enum.length > 1)
|
|
175
|
-
type += ")";
|
|
176
|
-
}
|
|
177
|
-
else if (schema.type) {
|
|
178
|
-
const handleType = (_type) => {
|
|
179
|
-
let typeCnt = "";
|
|
180
|
-
if (typeof _type === "string") {
|
|
181
|
-
if ([
|
|
182
|
-
"string",
|
|
183
|
-
"integer",
|
|
184
|
-
"number",
|
|
185
|
-
"array",
|
|
186
|
-
"boolean",
|
|
187
|
-
"null",
|
|
188
|
-
].includes(_type)) {
|
|
189
|
-
if (["integer", "number"].includes(_type)) {
|
|
190
|
-
typeCnt += `number`;
|
|
191
|
-
}
|
|
192
|
-
else if (_type === "array") {
|
|
193
|
-
//Since we would have already parsed the arrays keys above "schema.items" if it exists
|
|
194
|
-
typeCnt += "any[]";
|
|
195
|
-
/* if (schema.items) {
|
|
196
|
-
typeCnt += `${parseSchemaToType(
|
|
197
|
-
apiDoc,
|
|
198
|
-
schema.items,
|
|
199
|
-
"",
|
|
200
|
-
false,
|
|
201
|
-
options
|
|
202
|
-
)}[]`;
|
|
203
|
-
} else {
|
|
204
|
-
typeCnt += "any[]";
|
|
205
|
-
} */
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
typeCnt += _type;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
else if (_type === "object") {
|
|
212
|
-
//Since we would have already parsed the object keys above "schema.properties" if it exists
|
|
213
|
-
if (schema.additionalProperties) {
|
|
214
|
-
typeCnt += `{[k: string]: ${parseSchemaToType(apiDoc, schema.additionalProperties, "", true, options) || "any"}}`;
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
typeCnt += "{[k: string]: any}";
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
else if (Array.isArray(_type)) {
|
|
222
|
-
const arrType = _type.map((v) => handleType(v));
|
|
223
|
-
arrType.filter((v) => v !== "");
|
|
224
|
-
if (arrType.length > 1)
|
|
225
|
-
typeCnt += "(" + arrType.join("|") + ")";
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
typeCnt += "any";
|
|
229
|
-
}
|
|
230
|
-
return typeCnt;
|
|
231
|
-
};
|
|
232
|
-
type = handleType(schema.type);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
else {
|
|
236
|
-
//Default type to string if no schema provided
|
|
237
|
-
type = "string";
|
|
238
|
-
}
|
|
239
|
-
let _name = overrideName || name;
|
|
240
|
-
if ((options === null || options === void 0 ? void 0 : options.useComponentName) && !_name) {
|
|
241
|
-
_name = componentName;
|
|
242
|
-
}
|
|
243
|
-
let typeName = _name ? `\t"${_name}"${isRequired ? "" : "?"}: ` : "";
|
|
244
|
-
const nullable = (schema === null || schema === void 0 ? void 0 : schema.nullable) ? " | null" : "";
|
|
245
|
-
return type.length > 0
|
|
246
|
-
? `${typeName}${type}${nullable}${_name ? ";\n" : ""}`
|
|
247
|
-
: "";
|
|
248
|
-
};
|
|
249
|
-
const getSchemaExamples = (apiDoc, schema) => {
|
|
250
|
-
let overrideName = "";
|
|
251
|
-
let componentName = "";
|
|
252
|
-
let type = "";
|
|
253
|
-
if (schema) {
|
|
254
|
-
if (schema.$ref) {
|
|
255
|
-
if (schema.$ref[0] === "#") {
|
|
256
|
-
let pathToComponentParts = (schema.$ref || "").split("/");
|
|
257
|
-
pathToComponentParts.shift();
|
|
258
|
-
const pathToComponent = pathToComponentParts;
|
|
259
|
-
const component = lodash_1.default.get(apiDoc, pathToComponent, null);
|
|
260
|
-
if (component) {
|
|
261
|
-
if (component === null || component === void 0 ? void 0 : component.name) {
|
|
262
|
-
overrideName = component.name;
|
|
263
|
-
}
|
|
264
|
-
componentName =
|
|
265
|
-
pathToComponentParts[pathToComponentParts.length - 1];
|
|
266
|
-
type += getSchemaExamples(apiDoc, component);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
else {
|
|
270
|
-
type += "";
|
|
271
|
-
//TODO $ref is a uri - use axios to fetch doc
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
else if (schema.anyOf) {
|
|
275
|
-
type += getSchemaExamples(apiDoc, schema.anyOf[0]);
|
|
276
|
-
}
|
|
277
|
-
else if (schema.oneOf) {
|
|
278
|
-
type += getSchemaExamples(apiDoc, schema.oneOf[0]);
|
|
279
|
-
}
|
|
280
|
-
else if (schema.allOf) {
|
|
281
|
-
type += `{${schema.allOf
|
|
282
|
-
.map((v) => `...(${getSchemaExamples(apiDoc, v)})`)
|
|
283
|
-
.join(",")}}`;
|
|
284
|
-
}
|
|
285
|
-
else if (schema.items) {
|
|
286
|
-
type += `[${getSchemaExamples(apiDoc, schema.items)}]`;
|
|
287
|
-
}
|
|
288
|
-
else if (schema.properties) {
|
|
289
|
-
//parse object key one at a time
|
|
290
|
-
const objKeys = Object.keys(schema.properties);
|
|
291
|
-
const arr = objKeys.map((key) => {
|
|
292
|
-
var _a;
|
|
293
|
-
return ` "${key}": ${getSchemaExamples(apiDoc, (_a = schema.properties) === null || _a === void 0 ? void 0 : _a[key])}`;
|
|
294
|
-
});
|
|
295
|
-
let typeCnt = arr.join(",\n");
|
|
296
|
-
if (typeCnt.length > 0) {
|
|
297
|
-
type += `{\n${typeCnt}\n }`;
|
|
298
|
-
}
|
|
299
|
-
else {
|
|
300
|
-
type += "{}";
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
else if (schema.enum && schema.enum.length > 0) {
|
|
304
|
-
if (schema.enum.length > 1)
|
|
305
|
-
type += schema.enum[0];
|
|
306
|
-
}
|
|
307
|
-
else if (schema.type) {
|
|
308
|
-
if (schema.example) {
|
|
309
|
-
type += JSON.stringify(schema.example);
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
const handleType = (_type) => {
|
|
313
|
-
let typeCnt = "";
|
|
314
|
-
if (typeof _type === "string") {
|
|
315
|
-
if ([
|
|
316
|
-
"string",
|
|
317
|
-
"integer",
|
|
318
|
-
"number",
|
|
319
|
-
"array",
|
|
320
|
-
"boolean",
|
|
321
|
-
"null",
|
|
322
|
-
].includes(_type)) {
|
|
323
|
-
if (["integer", "number"].includes(_type)) {
|
|
324
|
-
typeCnt += `123`;
|
|
325
|
-
}
|
|
326
|
-
else if (_type === "array") {
|
|
327
|
-
//Since we would have already parsed the arrays keys above "schema.items" if it exists
|
|
328
|
-
typeCnt += "[]";
|
|
329
|
-
}
|
|
330
|
-
else if (_type === "boolean") {
|
|
331
|
-
typeCnt += `true`;
|
|
332
|
-
}
|
|
333
|
-
else if (_type === "null") {
|
|
334
|
-
typeCnt += `null`;
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
typeCnt += `"${_type}"`;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
else if (_type === "object") {
|
|
341
|
-
//Since we would have already parsed the object keys above "schema.properties" if it exists
|
|
342
|
-
typeCnt += "{}";
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
else if (Array.isArray(_type)) {
|
|
346
|
-
const arrType = _type.map((v) => handleType(v));
|
|
347
|
-
arrType.filter((v) => v !== "");
|
|
348
|
-
if (arrType.length > 1)
|
|
349
|
-
typeCnt += arrType.join("|");
|
|
350
|
-
}
|
|
351
|
-
else {
|
|
352
|
-
typeCnt += "any";
|
|
353
|
-
}
|
|
354
|
-
return typeCnt;
|
|
355
|
-
};
|
|
356
|
-
type = handleType(schema.type);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
else {
|
|
361
|
-
//Default type to string if no schema provided
|
|
362
|
-
type = "string";
|
|
363
|
-
}
|
|
364
|
-
return type;
|
|
365
|
-
};
|
|
366
|
-
// auto update only on dev
|
|
367
|
-
if (refetchInterval && !isNaN(refetchInterval) && refetchInterval > 0) {
|
|
368
|
-
if (!(process.env.NODE_ENV &&
|
|
369
|
-
["production", "prod", "test", "staging"].includes(process.env.NODE_ENV))) {
|
|
370
|
-
// auto sync at interval
|
|
371
|
-
if (fetchTimeout[apiName])
|
|
372
|
-
clearTimeout(fetchTimeout[apiName]);
|
|
373
|
-
// set next request timeout
|
|
374
|
-
fetchTimeout[apiName] = setTimeout(() => OpenapiSync(apiUrl, apiName, config, refetchInterval), refetchInterval);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
// compare new spec with old spec, continuing only if spec it different
|
|
378
|
-
const prevSpec = (0, state_1.getState)(apiName);
|
|
379
|
-
if ((0, lodash_2.isEqual)(prevSpec, spec))
|
|
380
|
-
return;
|
|
381
|
-
(0, state_1.setState)(apiName, spec);
|
|
382
|
-
let endpointsFileContent = "";
|
|
383
|
-
let typesFileContent = "";
|
|
384
|
-
let sharedTypesFileContent = {};
|
|
385
|
-
if (spec.components) {
|
|
386
|
-
Object.keys(spec.components).forEach((key) => {
|
|
387
|
-
if ([
|
|
388
|
-
"schemas",
|
|
389
|
-
"responses",
|
|
390
|
-
"parameters",
|
|
391
|
-
"examples",
|
|
392
|
-
"requestBodies",
|
|
393
|
-
"headers",
|
|
394
|
-
"links",
|
|
395
|
-
"callbacks",
|
|
396
|
-
].includes(key)) {
|
|
397
|
-
// Create components (shared) types
|
|
398
|
-
const components = spec.components[key];
|
|
399
|
-
const componentInterfaces = {};
|
|
400
|
-
const componentSchema = {};
|
|
401
|
-
const contentKeys = Object.keys(components);
|
|
402
|
-
// only need 1 schema so will us the first schema provided
|
|
403
|
-
contentKeys.forEach((contentKey) => {
|
|
404
|
-
var _a;
|
|
405
|
-
/* const schema = (() => {
|
|
406
|
-
switch (key) {
|
|
407
|
-
case "parameters":
|
|
408
|
-
return components[contentKey].schema;
|
|
409
|
-
default:
|
|
410
|
-
return components[contentKey];
|
|
411
|
-
}
|
|
412
|
-
})() as IOpenApSchemaSpec; */
|
|
413
|
-
const schema = (((_a = components[contentKey]) === null || _a === void 0 ? void 0 : _a.schema)
|
|
414
|
-
? components[contentKey].schema
|
|
415
|
-
: components[contentKey]);
|
|
416
|
-
const typeCnt = `${parseSchemaToType(spec, schema, "", true, {
|
|
417
|
-
noSharedImport: true,
|
|
418
|
-
useComponentName: ["parameters"].includes(key),
|
|
419
|
-
})}`;
|
|
420
|
-
if (typeCnt) {
|
|
421
|
-
const parts = contentKey.split(".");
|
|
422
|
-
let currentLevel = componentInterfaces;
|
|
423
|
-
let currentSchemaLevel = componentSchema;
|
|
424
|
-
// Navigate or create the nested structure
|
|
425
|
-
for (let i = 0; i < parts.length; i++) {
|
|
426
|
-
const part = parts[i];
|
|
427
|
-
if (i < parts.length - 1) {
|
|
428
|
-
// If it's not the last part, create a nested object if it doesn't exist
|
|
429
|
-
if (!(part in currentLevel)) {
|
|
430
|
-
currentLevel[part] = {}; //<== This rely on js ability to assign value to origianl object by reference, so this assignment will be reflected in componentInterfaces
|
|
431
|
-
currentSchemaLevel[part] = {}; //<== This rely on js ability to assign value to origianl object by reference, so this assignment will be reflected in componentSchema
|
|
432
|
-
}
|
|
433
|
-
currentLevel = currentLevel[part]; //<== This rely on js ability to assign value to origianl object by reference, so this assignment will be reflected in componentInterfaces
|
|
434
|
-
currentSchemaLevel = currentSchemaLevel[part]; //<== This rely on js ability to assign value to origianl object by reference, so this assignment will be reflected in componentSchema
|
|
435
|
-
}
|
|
436
|
-
else {
|
|
437
|
-
// This is the last part, assign the original schema value
|
|
438
|
-
currentLevel[part] = typeCnt; //<== This rely on js ability to assign value to origianl object by reference, so this assignment will be reflected in componentInterfaces
|
|
439
|
-
currentSchemaLevel[part] = schema; //<== This rely on js ability to assign value to origianl object by reference, so this assignment will be reflected in componentSchema
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
});
|
|
444
|
-
// Generate TypeScript interfaces for each component
|
|
445
|
-
Object.keys(componentInterfaces).forEach((key) => {
|
|
446
|
-
var _a, _b, _c, _d;
|
|
447
|
-
const name = getSharedComponentName(key);
|
|
448
|
-
const cnt = componentInterfaces[key];
|
|
449
|
-
let doc = "";
|
|
450
|
-
if (!((_b = (_a = config === null || config === void 0 ? void 0 : config.types) === null || _a === void 0 ? void 0 : _a.doc) === null || _b === void 0 ? void 0 : _b.disable) &&
|
|
451
|
-
key in components &&
|
|
452
|
-
(
|
|
453
|
-
//@ts-expect-error
|
|
454
|
-
(_c = components[key]) === null || _c === void 0 ? void 0 : _c.description)) {
|
|
455
|
-
doc =
|
|
456
|
-
" * " +
|
|
457
|
-
//@ts-expect-error
|
|
458
|
-
components[key].description
|
|
459
|
-
.split("\n")
|
|
460
|
-
.filter((line) => line.trim() !== "")
|
|
461
|
-
.join(` \n *${" ".repeat(1)}`);
|
|
462
|
-
}
|
|
463
|
-
sharedTypesFileContent[key] =
|
|
464
|
-
((_d = sharedTypesFileContent[key]) !== null && _d !== void 0 ? _d : "") +
|
|
465
|
-
(doc ? `/**\n${doc}\n */\n` : "") +
|
|
466
|
-
"export type " +
|
|
467
|
-
name +
|
|
468
|
-
" = " +
|
|
469
|
-
(typeof cnt === "string" ? cnt : (0, helpers_1.JSONStringify)(cnt)) +
|
|
470
|
-
";\n";
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
});
|
|
474
|
-
}
|
|
475
|
-
const getBodySchemaType = (requestBody) => {
|
|
476
|
-
let typeCnt = "";
|
|
477
|
-
if (requestBody.content) {
|
|
478
|
-
const contentKeys = Object.keys(requestBody.content);
|
|
479
|
-
// only need 1 schema so will us the first schema provided
|
|
480
|
-
if (contentKeys[0] && requestBody.content[contentKeys[0]].schema) {
|
|
481
|
-
typeCnt += `${parseSchemaToType(spec, requestBody.content[contentKeys[0]].schema, "")}`;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
return typeCnt;
|
|
485
|
-
};
|
|
486
|
-
const treatEndpointUrl = (endpointUrl) => {
|
|
487
|
-
var _a, _b, _c, _d, _e;
|
|
488
|
-
if (((_b = (_a = config === null || config === void 0 ? void 0 : config.endpoints) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.replaceWords) &&
|
|
489
|
-
Array.isArray(config === null || config === void 0 ? void 0 : config.endpoints.value.replaceWords)) {
|
|
490
|
-
let newEndpointUrl = endpointUrl;
|
|
491
|
-
(_e = (_d = (_c = config === null || config === void 0 ? void 0 : config.endpoints) === null || _c === void 0 ? void 0 : _c.value) === null || _d === void 0 ? void 0 : _d.replaceWords) === null || _e === void 0 ? void 0 : _e.forEach((replaceWord, indx) => {
|
|
492
|
-
const regexp = new RegExp(replaceWord.replace, "g");
|
|
493
|
-
newEndpointUrl = newEndpointUrl.replace(regexp, replaceWord.with || "");
|
|
494
|
-
});
|
|
495
|
-
return newEndpointUrl;
|
|
496
|
-
}
|
|
497
|
-
else {
|
|
498
|
-
return endpointUrl;
|
|
499
|
-
}
|
|
500
|
-
};
|
|
501
|
-
Object.keys(spec.paths || {}).forEach((endpointPath) => {
|
|
502
|
-
const endpointSpec = spec.paths[endpointPath];
|
|
503
|
-
const endpointMethods = Object.keys(endpointSpec);
|
|
504
|
-
endpointMethods.forEach((_method) => {
|
|
505
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
506
|
-
const method = _method;
|
|
507
|
-
const endpoint = (0, helpers_1.getEndpointDetails)(endpointPath, method);
|
|
508
|
-
const endpointUrlTxt = (((_b = (_a = config === null || config === void 0 ? void 0 : config.endpoints) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.includeServer) ? serverUrl : "") +
|
|
509
|
-
endpoint.pathParts
|
|
510
|
-
.map((part) => {
|
|
511
|
-
// check if part is a variable
|
|
512
|
-
if (part[0] === "{" && part[part.length - 1] === "}") {
|
|
513
|
-
const s = part.replace(/{/, "").replace(/}/, "");
|
|
514
|
-
part = `\${${s}}`;
|
|
515
|
-
}
|
|
516
|
-
//api/<userId>
|
|
517
|
-
else if (part[0] === "<" && part[part.length - 1] === ">") {
|
|
518
|
-
const s = part.replace(/</, "").replace(/>/, "");
|
|
519
|
-
part = `\${${s}}`;
|
|
520
|
-
}
|
|
521
|
-
//api/:userId
|
|
522
|
-
else if (part[0] === ":") {
|
|
523
|
-
const s = part.replace(/:/, "");
|
|
524
|
-
part = `\${${s}}`;
|
|
525
|
-
}
|
|
526
|
-
return part;
|
|
527
|
-
})
|
|
528
|
-
.join("/");
|
|
529
|
-
let endpointUrl = `"${endpointUrlTxt}"`;
|
|
530
|
-
if (endpoint.variables.length > 0) {
|
|
531
|
-
const params = endpoint.variables.map((v) => `${v}:string`).join(",");
|
|
532
|
-
endpointUrl = `(${params})=> \`${endpointUrlTxt}\``;
|
|
533
|
-
}
|
|
534
|
-
//treat endpoint url
|
|
535
|
-
endpointUrl = treatEndpointUrl(endpointUrl);
|
|
536
|
-
const eSpec = endpointSpec[method];
|
|
537
|
-
let queryTypeCnt = "";
|
|
538
|
-
if (eSpec === null || eSpec === void 0 ? void 0 : eSpec.parameters) {
|
|
539
|
-
// create query parameters types
|
|
540
|
-
const parameters = eSpec === null || eSpec === void 0 ? void 0 : eSpec.parameters;
|
|
541
|
-
parameters.forEach((param, i) => {
|
|
542
|
-
if (param.$ref || (param.in === "query" && param.name)) {
|
|
543
|
-
queryTypeCnt += `${parseSchemaToType(spec, param.$ref ? param : param.schema, param.name || "", param.required)}`;
|
|
544
|
-
}
|
|
545
|
-
});
|
|
546
|
-
if (queryTypeCnt) {
|
|
547
|
-
queryTypeCnt = `{\n${queryTypeCnt}}`;
|
|
548
|
-
let name = `${endpoint.name}Query`;
|
|
549
|
-
if ((_d = (_c = config === null || config === void 0 ? void 0 : config.types) === null || _c === void 0 ? void 0 : _c.name) === null || _d === void 0 ? void 0 : _d.format) {
|
|
550
|
-
const formattedName = config === null || config === void 0 ? void 0 : config.types.name.format("endpoint", {
|
|
551
|
-
code: "",
|
|
552
|
-
type: "query",
|
|
553
|
-
method,
|
|
554
|
-
path: endpointPath,
|
|
555
|
-
summary: eSpec === null || eSpec === void 0 ? void 0 : eSpec.summary,
|
|
556
|
-
}, name);
|
|
557
|
-
if (formattedName)
|
|
558
|
-
name = formattedName;
|
|
559
|
-
}
|
|
560
|
-
typesFileContent += `export type ${typePrefix}${name} = ${queryTypeCnt};\n`;
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
const requestBody = eSpec === null || eSpec === void 0 ? void 0 : eSpec.requestBody;
|
|
564
|
-
let dtoTypeCnt = "";
|
|
565
|
-
if (requestBody) {
|
|
566
|
-
//create requestBody types
|
|
567
|
-
dtoTypeCnt = getBodySchemaType(requestBody);
|
|
568
|
-
if (dtoTypeCnt) {
|
|
569
|
-
let name = `${endpoint.name}DTO`;
|
|
570
|
-
if ((_f = (_e = config === null || config === void 0 ? void 0 : config.types) === null || _e === void 0 ? void 0 : _e.name) === null || _f === void 0 ? void 0 : _f.format) {
|
|
571
|
-
const formattedName = config === null || config === void 0 ? void 0 : config.types.name.format("endpoint", {
|
|
572
|
-
code: "",
|
|
573
|
-
type: "dto",
|
|
574
|
-
method,
|
|
575
|
-
path: endpointPath,
|
|
576
|
-
summary: eSpec === null || eSpec === void 0 ? void 0 : eSpec.summary,
|
|
577
|
-
}, name);
|
|
578
|
-
if (formattedName)
|
|
579
|
-
name = formattedName;
|
|
580
|
-
}
|
|
581
|
-
typesFileContent += `export type ${typePrefix}${name} = ${dtoTypeCnt};\n`;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
const responseTypeObject = {};
|
|
585
|
-
let responseTypeCnt = "";
|
|
586
|
-
if (eSpec === null || eSpec === void 0 ? void 0 : eSpec.responses) {
|
|
587
|
-
// create request response types
|
|
588
|
-
const responses = eSpec === null || eSpec === void 0 ? void 0 : eSpec.responses;
|
|
589
|
-
const resCodes = Object.keys(responses);
|
|
590
|
-
resCodes.forEach((code) => {
|
|
591
|
-
var _a, _b;
|
|
592
|
-
responseTypeCnt = getBodySchemaType(responses[code]);
|
|
593
|
-
responseTypeObject[code] = responseTypeCnt;
|
|
594
|
-
if (responseTypeCnt) {
|
|
595
|
-
let name = `${endpoint.name}${code}Response`;
|
|
596
|
-
if ((_b = (_a = config === null || config === void 0 ? void 0 : config.types) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.format) {
|
|
597
|
-
const formattedName = config === null || config === void 0 ? void 0 : config.types.name.format("endpoint", {
|
|
598
|
-
code,
|
|
599
|
-
type: "response",
|
|
600
|
-
method,
|
|
601
|
-
path: endpointPath,
|
|
602
|
-
summary: eSpec === null || eSpec === void 0 ? void 0 : eSpec.summary,
|
|
603
|
-
}, name);
|
|
604
|
-
if (formattedName)
|
|
605
|
-
name = formattedName;
|
|
606
|
-
}
|
|
607
|
-
typesFileContent += `export type ${typePrefix}${name} = ${responseTypeCnt};\n`;
|
|
608
|
-
}
|
|
609
|
-
});
|
|
610
|
-
}
|
|
611
|
-
// Function to format security requirements
|
|
612
|
-
const formatSecuritySpec = (security) => {
|
|
613
|
-
if (!security || !security.length)
|
|
614
|
-
return "";
|
|
615
|
-
return security
|
|
616
|
-
.map((securityRequirement) => {
|
|
617
|
-
const requirements = Object.entries(securityRequirement)
|
|
618
|
-
.map(([scheme, scopes]) => {
|
|
619
|
-
let sch = scheme;
|
|
620
|
-
let scopeText = "";
|
|
621
|
-
if (Array.isArray(scopes) && scopes.length) {
|
|
622
|
-
scopeText = `\n - Scopes: [\`${scopes.join("`, `")}\`]`;
|
|
623
|
-
sch = `**${sch}**`;
|
|
624
|
-
}
|
|
625
|
-
return `\n - ${sch}${scopeText}`;
|
|
626
|
-
})
|
|
627
|
-
.join("");
|
|
628
|
-
return requirements;
|
|
629
|
-
})
|
|
630
|
-
.join("\n");
|
|
631
|
-
};
|
|
632
|
-
// Get formatted security specification
|
|
633
|
-
const securitySpec = (eSpec === null || eSpec === void 0 ? void 0 : eSpec.security)
|
|
634
|
-
? formatSecuritySpec(eSpec.security)
|
|
635
|
-
: "";
|
|
636
|
-
let doc = "";
|
|
637
|
-
if (!((_h = (_g = config === null || config === void 0 ? void 0 : config.endpoints) === null || _g === void 0 ? void 0 : _g.doc) === null || _h === void 0 ? void 0 : _h.disable)) {
|
|
638
|
-
let curl = "";
|
|
639
|
-
if ((_k = (_j = config === null || config === void 0 ? void 0 : config.endpoints) === null || _j === void 0 ? void 0 : _j.doc) === null || _k === void 0 ? void 0 : _k.showCurl) {
|
|
640
|
-
// console.log("cirl data", {
|
|
641
|
-
// body: eSpec?.requestBody,
|
|
642
|
-
// bodyContent:
|
|
643
|
-
// eSpec?.requestBody?.content["application/json"]?.schema
|
|
644
|
-
// ?.properties,
|
|
645
|
-
// security: eSpec?.security,
|
|
646
|
-
// });
|
|
647
|
-
const headers = {};
|
|
648
|
-
let body = "";
|
|
649
|
-
let extras = "";
|
|
650
|
-
if ((_l = eSpec.requestBody) === null || _l === void 0 ? void 0 : _l.content) {
|
|
651
|
-
const contentTypes = Object.keys(eSpec.requestBody.content);
|
|
652
|
-
contentTypes.forEach((contentType) => {
|
|
653
|
-
// console.log("requestBody content", {
|
|
654
|
-
// contentType,
|
|
655
|
-
// schema: eSpec.requestBody.content[contentType].schema,
|
|
656
|
-
// });
|
|
657
|
-
const schema = eSpec.requestBody.content[contentType].schema;
|
|
658
|
-
if (schema) {
|
|
659
|
-
if (Array.isArray(headers["Content-type"])) {
|
|
660
|
-
headers["Content-type"].push(contentType);
|
|
661
|
-
}
|
|
662
|
-
else {
|
|
663
|
-
headers["Content-type"] = [contentType];
|
|
664
|
-
}
|
|
665
|
-
const schemaType = getSchemaExamples(spec, schema);
|
|
666
|
-
if (schemaType)
|
|
667
|
-
body = schemaType;
|
|
668
|
-
}
|
|
669
|
-
});
|
|
670
|
-
}
|
|
671
|
-
if (eSpec === null || eSpec === void 0 ? void 0 : eSpec.security) {
|
|
672
|
-
eSpec.security.forEach((securityItem) => {
|
|
673
|
-
Object.keys(securityItem).forEach((security) => {
|
|
674
|
-
var _a, _b;
|
|
675
|
-
const securitySchema = (_b = (_a = spec.components) === null || _a === void 0 ? void 0 : _a.securitySchemes) === null || _b === void 0 ? void 0 : _b[security];
|
|
676
|
-
if (securitySchema) {
|
|
677
|
-
// headers["Authorization"] = securitySchema;
|
|
678
|
-
if (securitySchema.type === "mutualTLS") {
|
|
679
|
-
extras += `\n--cert client-certificate.crt \
|
|
680
|
-
--key client-private-key.key \
|
|
681
|
-
--cacert ca-certificate.crt`;
|
|
682
|
-
}
|
|
683
|
-
else if (securitySchema.type === "apiKey") {
|
|
684
|
-
headers[(securitySchema === null || securitySchema === void 0 ? void 0 : securitySchema.name) || "X-API-KEY"] = `{API_KEY_VALUE}`;
|
|
685
|
-
}
|
|
686
|
-
else {
|
|
687
|
-
headers["Authorization"] = `${(securitySchema === null || securitySchema === void 0 ? void 0 : securitySchema.scheme) === "basic" ? "Basic" : "Bearer"} {${(securitySchema === null || securitySchema === void 0 ? void 0 : securitySchema.scheme) === "basic" ? "VALUE" : "TOKEN"}}`;
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
});
|
|
691
|
-
});
|
|
692
|
-
}
|
|
693
|
-
const curlHeaders = {};
|
|
694
|
-
Object.keys(headers).forEach((header) => {
|
|
695
|
-
if (Array.isArray(headers[header])) {
|
|
696
|
-
curlHeaders[header] = headers[header].join("; ");
|
|
697
|
-
}
|
|
698
|
-
else {
|
|
699
|
-
curlHeaders[header] = headers[header];
|
|
700
|
-
}
|
|
701
|
-
});
|
|
702
|
-
// console.log("curlHeaders", { headers, curlHeaders, body });
|
|
703
|
-
curl = `\n\`\`\`bash
|
|
704
|
-
${(0, curl_generator_1.CurlGenerator)({
|
|
705
|
-
url: serverUrl + endpointPath,
|
|
706
|
-
method: method.toUpperCase(),
|
|
707
|
-
headers: curlHeaders,
|
|
708
|
-
body,
|
|
709
|
-
})}${extras}
|
|
710
|
-
\`\`\``;
|
|
711
|
-
}
|
|
712
|
-
doc = `/**${(eSpec === null || eSpec === void 0 ? void 0 : eSpec.description) ? `\n* ${eSpec === null || eSpec === void 0 ? void 0 : eSpec.description} ` : ""}
|
|
713
|
-
* **Method**: \`${method.toUpperCase()}\`
|
|
714
|
-
* **Summary**: ${(eSpec === null || eSpec === void 0 ? void 0 : eSpec.summary) || ""}
|
|
715
|
-
* **Tags**: [${((_m = eSpec === null || eSpec === void 0 ? void 0 : eSpec.tags) === null || _m === void 0 ? void 0 : _m.join(", ")) || ""}]
|
|
716
|
-
* **OperationId**: ${(eSpec === null || eSpec === void 0 ? void 0 : eSpec.operationId) || ""} ${queryTypeCnt
|
|
717
|
-
? `\n * **Query**: ${(0, helpers_1.renderTypeRefMD)(queryTypeCnt)} `
|
|
718
|
-
: ""}${dtoTypeCnt ? `\n * **DTO**: ${(0, helpers_1.renderTypeRefMD)(dtoTypeCnt)} ` : ""}${responseTypeCnt
|
|
719
|
-
? `\n * **Response**: ${Object.entries(responseTypeObject)
|
|
720
|
-
.map(([code, type]) => `\n - **${code}**: ${(0, helpers_1.renderTypeRefMD)(type, 2)} `)
|
|
721
|
-
.join("")}`
|
|
722
|
-
: ""}${securitySpec ? `\n * **Security**: ${securitySpec}\n` : ""}${curl}
|
|
723
|
-
*/\n`;
|
|
724
|
-
}
|
|
725
|
-
let name = ((_p = (_o = config === null || config === void 0 ? void 0 : config.endpoints) === null || _o === void 0 ? void 0 : _o.name) === null || _p === void 0 ? void 0 : _p.useOperationId) &&
|
|
726
|
-
((_q = eSpec === null || eSpec === void 0 ? void 0 : eSpec.operationId) === null || _q === void 0 ? void 0 : _q.length) > 0
|
|
727
|
-
? eSpec.operationId
|
|
728
|
-
: `${endpoint.name}`;
|
|
729
|
-
if ((_s = (_r = config === null || config === void 0 ? void 0 : config.endpoints) === null || _r === void 0 ? void 0 : _r.name) === null || _s === void 0 ? void 0 : _s.format) {
|
|
730
|
-
const formattedName = config === null || config === void 0 ? void 0 : config.endpoints.name.format({
|
|
731
|
-
method,
|
|
732
|
-
path: endpointPath,
|
|
733
|
-
summary: eSpec === null || eSpec === void 0 ? void 0 : eSpec.summary,
|
|
734
|
-
operationId: eSpec === null || eSpec === void 0 ? void 0 : eSpec.operationId,
|
|
735
|
-
}, name);
|
|
736
|
-
if (formattedName)
|
|
737
|
-
name = formattedName;
|
|
738
|
-
}
|
|
739
|
-
const content = {
|
|
740
|
-
method: `"${method}"`,
|
|
741
|
-
operationId: `"${eSpec === null || eSpec === void 0 ? void 0 : eSpec.operationId}"`,
|
|
742
|
-
url: endpointUrl,
|
|
743
|
-
tags: (eSpec === null || eSpec === void 0 ? void 0 : eSpec.tags) || [],
|
|
744
|
-
};
|
|
745
|
-
// Add the endpoint url
|
|
746
|
-
endpointsFileContent += `${doc}export const ${endpointPrefix}${name} = ${((_u = (_t = config === null || config === void 0 ? void 0 : config.endpoints) === null || _t === void 0 ? void 0 : _t.value) === null || _u === void 0 ? void 0 : _u.type) === "object"
|
|
747
|
-
? (0, helpers_1.JSONStringify)(content)
|
|
748
|
-
: endpointUrl};
|
|
749
|
-
`;
|
|
750
|
-
});
|
|
751
|
-
});
|
|
752
|
-
// Create the necessary directories
|
|
753
|
-
const endpointsFilePath = path_1.default.join(rootUsingCwd, folderPath, "endpoints.ts");
|
|
754
|
-
yield fs_1.default.promises.mkdir(path_1.default.dirname(endpointsFilePath), { recursive: true });
|
|
755
|
-
// Create the file asynchronously
|
|
756
|
-
yield fs_1.default.promises.writeFile(endpointsFilePath, endpointsFileContent);
|
|
757
|
-
if (Object.values(sharedTypesFileContent).length > 0) {
|
|
758
|
-
// Create the necessary directories
|
|
759
|
-
const sharedTypesFilePath = path_1.default.join(rootUsingCwd, folderPath, "types", "shared.ts");
|
|
760
|
-
yield fs_1.default.promises.mkdir(path_1.default.dirname(sharedTypesFilePath), {
|
|
761
|
-
recursive: true,
|
|
762
|
-
});
|
|
763
|
-
// Create the file asynchronously
|
|
764
|
-
yield fs_1.default.promises.writeFile(sharedTypesFilePath, Object.values(sharedTypesFileContent).join("\n"));
|
|
765
|
-
}
|
|
766
|
-
if (typesFileContent.length > 0) {
|
|
767
|
-
// Create the necessary directories
|
|
768
|
-
const typesFilePath = path_1.default.join(rootUsingCwd, folderPath, "types", "index.ts");
|
|
769
|
-
yield fs_1.default.promises.mkdir(path_1.default.dirname(typesFilePath), { recursive: true });
|
|
770
|
-
// Create the file asynchronously
|
|
771
|
-
yield fs_1.default.promises.writeFile(typesFilePath, `${Object.values(sharedTypesFileContent).length > 0
|
|
772
|
-
? `import * as Shared from "./shared";\n\n`
|
|
773
|
-
: ""}${typesFileContent}`);
|
|
774
|
-
}
|
|
775
|
-
});
|
|
776
|
-
exports.default = OpenapiSync;
|