ts-openapi-codegen 1.0.0-beta.2 → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/generate/runGenerateOpenApi.d.ts.map +1 -1
- package/dist/cli/generate/runGenerateOpenApi.js +47 -31
- package/dist/cli/index.js +5 -1
- package/dist/cli/utils.d.ts +0 -1
- package/dist/cli/utils.d.ts.map +1 -1
- package/dist/cli/utils.js +0 -56
- package/dist/common/Enums.d.ts +10 -0
- package/dist/common/Enums.d.ts.map +1 -0
- package/dist/common/Enums.js +14 -0
- package/dist/common/Logger.d.ts +33 -0
- package/dist/common/Logger.d.ts.map +1 -0
- package/dist/common/Logger.js +117 -0
- package/dist/common/Options.d.ts +4 -4
- package/dist/common/Options.d.ts.map +1 -1
- package/dist/common/Utils.d.ts +2 -1
- package/dist/common/Utils.d.ts.map +1 -1
- package/dist/common/Utils.js +54 -0
- package/dist/common/VersionedSchema/MultiOptionsMigrationPlan.d.ts.map +1 -1
- package/dist/common/VersionedSchema/MultiOptionsMigrationPlan.js +1 -3
- package/dist/common/VersionedSchema/Utils/getUniqueAllShemasKeys.d.ts +2 -2
- package/dist/common/VersionedSchema/Utils/getUniqueAllShemasKeys.d.ts.map +1 -1
- package/dist/common/VersionedSchema/Utils/getUniqueAllShemasKeys.js +3 -1
- package/dist/common/VersionedSchema/Utils/migrateToLatestVersion.d.ts.map +1 -1
- package/dist/common/VersionedSchema/Utils/migrateToLatestVersion.js +2 -1
- package/dist/common/__tests__/convertArrayToObject.test.d.ts +2 -0
- package/dist/common/__tests__/convertArrayToObject.test.d.ts.map +1 -0
- package/dist/common/__tests__/convertArrayToObject.test.js +227 -0
- package/dist/common/__tests__/migrationForMultiOptions.test.js +22 -16
- package/dist/common/__tests__/migrationForOptions.test.js +8 -7
- package/dist/common/defaultOptions.d.ts.map +1 -1
- package/dist/common/defaultOptions.js +22 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +41 -19
- package/dist/core/utils/precompileTemplates.js +9 -2
- package/dist/core/utils/prepareOptions.d.ts +2 -2
- package/dist/core/utils/prepareOptions.d.ts.map +1 -1
- package/dist/core/utils/writeClient.d.ts +4 -0
- package/dist/core/utils/writeClient.d.ts.map +1 -1
- package/dist/core/utils/writeClient.js +13 -0
- package/package.json +5 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runGenerateOpenApi.d.ts","sourceRoot":"","sources":["../../../src/cli/generate/runGenerateOpenApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"runGenerateOpenApi.d.ts","sourceRoot":"","sources":["../../../src/cli/generate/runGenerateOpenApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAezC;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,YAAY,iBAsD7D"}
|
|
@@ -35,6 +35,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.runGenerateOpenApi = runGenerateOpenApi;
|
|
37
37
|
const defaultOptions_1 = require("../../common/defaultOptions");
|
|
38
|
+
const Enums_1 = require("../../common/Enums");
|
|
39
|
+
const Logger_1 = require("../../common/Logger");
|
|
38
40
|
const Utils_1 = require("../../common/Utils");
|
|
39
41
|
const MultiOptionsMigrationPlan_1 = require("../../common/VersionedSchema/MultiOptionsMigrationPlan");
|
|
40
42
|
const MultiOptionsVersionedSchemas_1 = require("../../common/VersionedSchema/MultiOptionsVersionedSchemas");
|
|
@@ -48,38 +50,52 @@ const isInstanceOfMultiOptions_1 = require("../../core/utils/isInstanceOfMultiOp
|
|
|
48
50
|
* @param options Options for starting generation.
|
|
49
51
|
*/
|
|
50
52
|
async function runGenerateOpenApi(options) {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
const logger = new Logger_1.Logger({
|
|
54
|
+
level: Enums_1.ELogLevel.INFO,
|
|
55
|
+
instanceId: 'openapi-cli',
|
|
56
|
+
logOutput: Enums_1.ELogOutput.CONSOLE,
|
|
57
|
+
});
|
|
58
|
+
try {
|
|
59
|
+
const hasMinimumRequiredOptions = !!options.input && !!options.output;
|
|
60
|
+
if (hasMinimumRequiredOptions) {
|
|
61
|
+
const { error: defaultValuesError, value } = defaultOptions_1.defaultOptions.validate(options);
|
|
62
|
+
if (defaultValuesError) {
|
|
63
|
+
await OpenAPI.generate(value);
|
|
64
|
+
process.exit(0);
|
|
65
|
+
}
|
|
57
66
|
}
|
|
67
|
+
const configData = (0, Utils_1.loadConfigIfExists)();
|
|
68
|
+
if (!configData) {
|
|
69
|
+
logger.error('The configuration file is missing');
|
|
70
|
+
}
|
|
71
|
+
const preparedOptions = (0, Utils_1.convertArrayToObject)(configData);
|
|
72
|
+
const isMultiOptions = (0, isInstanceOfMultiOptions_1.isInstanceOfMultioptions)(preparedOptions);
|
|
73
|
+
const migratedOptions = isMultiOptions
|
|
74
|
+
? (0, migrateToLatestVersion_1.migrateToLatestVersion)({
|
|
75
|
+
rawInput: preparedOptions,
|
|
76
|
+
migrationPlans: MultiOptionsMigrationPlan_1.multiOptionsMigrationPlan,
|
|
77
|
+
versionedSchemas: MultiOptionsVersionedSchemas_1.multiOptionsVersionedSchema,
|
|
78
|
+
})
|
|
79
|
+
: (0, migrateToLatestVersion_1.migrateToLatestVersion)({
|
|
80
|
+
rawInput: preparedOptions,
|
|
81
|
+
migrationPlans: OptionsMigrationPlans_1.optionsMigrationPlans,
|
|
82
|
+
versionedSchemas: OptionsVersionedSchemas_1.optionsVersionedSchemas,
|
|
83
|
+
});
|
|
84
|
+
if (!migratedOptions) {
|
|
85
|
+
logger.error("Couldn't convert the set of options to the current version");
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
const { value } = migratedOptions;
|
|
89
|
+
if (isMultiOptions) {
|
|
90
|
+
await OpenAPI.generate(value);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
await OpenAPI.generate(value);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
process.exit(0);
|
|
58
97
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
throw new Error('Error: The configuration file is missing');
|
|
62
|
-
}
|
|
63
|
-
const isMultiOptions = (0, isInstanceOfMultiOptions_1.isInstanceOfMultioptions)(configData);
|
|
64
|
-
const migratedOptions = isMultiOptions
|
|
65
|
-
? (0, migrateToLatestVersion_1.migrateToLatestVersion)({
|
|
66
|
-
rawInput: configData,
|
|
67
|
-
migrationPlans: MultiOptionsMigrationPlan_1.multiOptionsMigrationPlan,
|
|
68
|
-
versionedSchemas: MultiOptionsVersionedSchemas_1.multiOptionsVersionedSchema,
|
|
69
|
-
})
|
|
70
|
-
: (0, migrateToLatestVersion_1.migrateToLatestVersion)({
|
|
71
|
-
rawInput: configData,
|
|
72
|
-
migrationPlans: OptionsMigrationPlans_1.optionsMigrationPlans,
|
|
73
|
-
versionedSchemas: OptionsVersionedSchemas_1.optionsVersionedSchemas,
|
|
74
|
-
});
|
|
75
|
-
if (!migratedOptions) {
|
|
76
|
-
throw new Error('Error: Couldn\'t convert the set of options to the current version');
|
|
77
|
-
}
|
|
78
|
-
const { value } = migratedOptions;
|
|
79
|
-
if (isMultiOptions) {
|
|
80
|
-
await OpenAPI.generate(value);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
await OpenAPI.generate(value);
|
|
98
|
+
catch (error) {
|
|
99
|
+
logger.error(error.message);
|
|
84
100
|
}
|
|
85
101
|
}
|
package/dist/cli/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const commander_1 = require("commander");
|
|
4
|
+
const Enums_1 = require("../common/Enums");
|
|
5
|
+
const Enums_2 = require("../core/types/Enums");
|
|
4
6
|
const runGenerateOpenApi_1 = require("./generate/runGenerateOpenApi");
|
|
5
7
|
const APP_NAME = 'ts-openapi-codegen-cli';
|
|
6
8
|
const APP_VERSION = '1.0.0';
|
|
@@ -16,7 +18,7 @@ program
|
|
|
16
18
|
.option('-os, --outputServices <value>', 'Output directory for services')
|
|
17
19
|
.option('-om, --outputModels <value>', 'Output directory for models')
|
|
18
20
|
.option('-osm, --outputSchemas <value>', 'Output directory for schemas')
|
|
19
|
-
.
|
|
21
|
+
.addOption(new commander_1.Option('-c, --httpClient <value>', 'HTTP client to generate').choices([...Object.values(Enums_2.HttpClient)]).default(Enums_2.HttpClient.FETCH))
|
|
20
22
|
.option('--useOptions <value>', 'Use options instead of arguments', false)
|
|
21
23
|
.option('--useUnionTypes <value>', 'Use union types instead of enums', false)
|
|
22
24
|
.option('--exportCore <value>', 'Write core files to disk', true)
|
|
@@ -29,6 +31,8 @@ program
|
|
|
29
31
|
.option('--enumPrefix <value>', 'Prefix for enum model(default: "E")')
|
|
30
32
|
.option('--typePrefix <value>', 'Prefix for type model(default: "T")')
|
|
31
33
|
.option('--useCancelableRequest <value>', 'Use cancelled promise as returned data type in request(default: false)', false)
|
|
34
|
+
.addOption(new commander_1.Option('-l, --logLevel <level>', 'Logging level').choices([...Object.values(Enums_1.ELogLevel)]).default(Enums_1.ELogLevel.ERROR))
|
|
35
|
+
.addOption(new commander_1.Option('-t, --logTarget <target>', 'Target of logging').choices([...Object.values(Enums_1.ELogOutput)]).default(Enums_1.ELogOutput.CONSOLE))
|
|
32
36
|
.action(async (options) => {
|
|
33
37
|
await (0, runGenerateOpenApi_1.runGenerateOpenApi)(options);
|
|
34
38
|
});
|
package/dist/cli/utils.d.ts
CHANGED
package/dist/cli/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/cli/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/cli/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,GAAG,WAE/B;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,GAAG,WAOrC"}
|
package/dist/cli/utils.js
CHANGED
|
@@ -1,46 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.isNil = isNil;
|
|
40
4
|
exports.isValidJson = isValidJson;
|
|
41
|
-
exports.startGenerate = startGenerate;
|
|
42
|
-
const path_1 = __importDefault(require("path"));
|
|
43
|
-
const OpenAPI = __importStar(require("../core"));
|
|
44
5
|
/**
|
|
45
6
|
* Checks if `value` is `null` or `undefined`.
|
|
46
7
|
*
|
|
@@ -69,20 +30,3 @@ function isValidJson(value) {
|
|
|
69
30
|
return false;
|
|
70
31
|
}
|
|
71
32
|
}
|
|
72
|
-
function startGenerate(options) {
|
|
73
|
-
return OpenAPI.generate(options)
|
|
74
|
-
.then(() => {
|
|
75
|
-
console.group(`Generation from has been finished`);
|
|
76
|
-
const group = Array.isArray(options) ? options : Array.of(options);
|
|
77
|
-
group.forEach(option => {
|
|
78
|
-
console.log(`Generation from "${option.input}" was finished`);
|
|
79
|
-
console.log(`Output folder: ${path_1.default.resolve(process.cwd(), option.output)}`);
|
|
80
|
-
console.log('==================================');
|
|
81
|
-
});
|
|
82
|
-
console.groupEnd();
|
|
83
|
-
})
|
|
84
|
-
.catch((error) => {
|
|
85
|
-
console.log(error);
|
|
86
|
-
process.exit(1);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Enums.d.ts","sourceRoot":"","sources":["../../src/common/Enums.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS;IACjB,IAAI,SAAS;IACb,IAAI,SAAS;IACb,KAAK,UAAU;CAClB;AACD,oBAAY,UAAU;IAClB,OAAO,YAAY;IACnB,IAAI,SAAS;CAChB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ELogOutput = exports.ELogLevel = void 0;
|
|
4
|
+
var ELogLevel;
|
|
5
|
+
(function (ELogLevel) {
|
|
6
|
+
ELogLevel["INFO"] = "info";
|
|
7
|
+
ELogLevel["WARN"] = "warn";
|
|
8
|
+
ELogLevel["ERROR"] = "error";
|
|
9
|
+
})(ELogLevel || (exports.ELogLevel = ELogLevel = {}));
|
|
10
|
+
var ELogOutput;
|
|
11
|
+
(function (ELogOutput) {
|
|
12
|
+
ELogOutput["CONSOLE"] = "console";
|
|
13
|
+
ELogOutput["FILE"] = "file";
|
|
14
|
+
})(ELogOutput || (exports.ELogOutput = ELogOutput = {}));
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ELogLevel, ELogOutput } from './Enums';
|
|
2
|
+
interface LoggerOptions {
|
|
3
|
+
/** Instance ID (letters/numbers/hyphens/handwriting only) */
|
|
4
|
+
instanceId: string;
|
|
5
|
+
/** The initial logging level */
|
|
6
|
+
level: ELogLevel;
|
|
7
|
+
/** Where to write: 'console' or 'file' */
|
|
8
|
+
logOutput: ELogOutput;
|
|
9
|
+
/** Folder for logs (only with LogOutput='file') */
|
|
10
|
+
/** Rotation parameters (only for LogOutput='file') */
|
|
11
|
+
rotate?: {
|
|
12
|
+
/** Template for the date in the file name */
|
|
13
|
+
datePattern?: string;
|
|
14
|
+
/** The maximum file size, for example '20m' */
|
|
15
|
+
maxSize?: string;
|
|
16
|
+
/** Do not store files for longer, for example '14d' */
|
|
17
|
+
maxFiles?: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export declare class Logger {
|
|
21
|
+
private _logger;
|
|
22
|
+
private _currentLevel;
|
|
23
|
+
private _instanceId;
|
|
24
|
+
constructor(options: LoggerOptions);
|
|
25
|
+
setLevel(level: ELogLevel): void;
|
|
26
|
+
error(message: string): void;
|
|
27
|
+
warn(message: string): void;
|
|
28
|
+
info(message: string, hasSeparator?: boolean): void;
|
|
29
|
+
forceInfo(message: string): void;
|
|
30
|
+
shutdownLogger(): void;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=Logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/common/Logger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEhD,UAAU,aAAa;IACnB,6DAA6D;IAC7D,UAAU,EAAE,MAAM,CAAC;IACnB,gCAAgC;IAChC,KAAK,EAAE,SAAS,CAAC;IACjB,0CAA0C;IAC1C,SAAS,EAAE,UAAU,CAAC;IACtB,mDAAmD;IACnD,sDAAsD;IACtD,MAAM,CAAC,EAAE;QACL,6CAA6C;QAC7C,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,+CAA+C;QAC/C,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,uDAAuD;QACvD,QAAQ,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;CACL;AAED,qBAAa,MAAM;IACf,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,aAAa,CAAY;IACjC,OAAO,CAAC,WAAW,CAAS;gBAEhB,OAAO,EAAE,aAAa;IA6C3B,QAAQ,CAAC,KAAK,EAAE,SAAS;IAKzB,KAAK,CAAC,OAAO,EAAE,MAAM;IAKrB,IAAI,CAAC,OAAO,EAAE,MAAM;IAIpB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,OAAO;IAO5C,SAAS,CAAC,OAAO,EAAE,MAAM;IAOzB,cAAc,IAAI,IAAI;CAahC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.Logger = void 0;
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const winston_1 = require("winston");
|
|
42
|
+
const winston_daily_rotate_file_1 = __importDefault(require("winston-daily-rotate-file"));
|
|
43
|
+
const Enums_1 = require("./Enums");
|
|
44
|
+
class Logger {
|
|
45
|
+
_logger;
|
|
46
|
+
_currentLevel;
|
|
47
|
+
_instanceId;
|
|
48
|
+
constructor(options) {
|
|
49
|
+
const { instanceId, level, logOutput, rotate = { datePattern: 'YYYY-MM-DD', maxSize: '20m', maxFiles: '14d' } } = options;
|
|
50
|
+
this._currentLevel = level;
|
|
51
|
+
this._instanceId = instanceId;
|
|
52
|
+
const chosenTransports = [];
|
|
53
|
+
if (logOutput === Enums_1.ELogOutput.CONSOLE) {
|
|
54
|
+
chosenTransports.push(new winston_1.transports.Console({
|
|
55
|
+
format: winston_1.format.combine(winston_1.format.colorize(), winston_1.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston_1.format.printf(({ level, message, timestamp, label }) => {
|
|
56
|
+
return `[${level}] [${label}] ${timestamp}: ${message}`;
|
|
57
|
+
})),
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
const logDir = path.join(process.cwd(), '__logs__');
|
|
62
|
+
chosenTransports.push(new winston_daily_rotate_file_1.default({
|
|
63
|
+
filename: path.join(logDir, 'app-%DATE%.log'),
|
|
64
|
+
datePattern: rotate.datePattern,
|
|
65
|
+
zippedArchive: true,
|
|
66
|
+
maxSize: rotate.maxSize,
|
|
67
|
+
maxFiles: rotate.maxFiles,
|
|
68
|
+
format: winston_1.format.combine(winston_1.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston_1.format.printf(({ level, message, timestamp, label }) => {
|
|
69
|
+
return `[${level}] [${label}] ${timestamp}: ${message}`;
|
|
70
|
+
})),
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
this._logger = (0, winston_1.createLogger)({
|
|
74
|
+
level: this._currentLevel,
|
|
75
|
+
levels: { error: 0, warn: 1, info: 2 },
|
|
76
|
+
format: winston_1.format.label({ label: this._instanceId }),
|
|
77
|
+
transports: chosenTransports,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
setLevel(level) {
|
|
81
|
+
this._currentLevel = level;
|
|
82
|
+
this._logger.level = level;
|
|
83
|
+
}
|
|
84
|
+
error(message) {
|
|
85
|
+
this._logger.error(`Error: ${message}`);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
warn(message) {
|
|
89
|
+
this._logger.warn(message);
|
|
90
|
+
}
|
|
91
|
+
info(message, hasSeparator) {
|
|
92
|
+
this._logger.info(message);
|
|
93
|
+
if (hasSeparator) {
|
|
94
|
+
this._logger.info('==========================================');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
forceInfo(message) {
|
|
98
|
+
const originalLevel = this._logger.level;
|
|
99
|
+
this._logger.level = 'info';
|
|
100
|
+
this._logger.info(message);
|
|
101
|
+
this._logger.level = originalLevel;
|
|
102
|
+
}
|
|
103
|
+
shutdownLogger() {
|
|
104
|
+
if (this._logger) {
|
|
105
|
+
this._logger.close();
|
|
106
|
+
this._logger.transports.forEach(transport => {
|
|
107
|
+
if (typeof transport.close === 'function') {
|
|
108
|
+
transport.close();
|
|
109
|
+
}
|
|
110
|
+
if (typeof transport.end === 'function') {
|
|
111
|
+
transport.end();
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.Logger = Logger;
|
package/dist/common/Options.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HttpClient } from "../core/types/Enums";
|
|
2
|
-
export type
|
|
2
|
+
export type TOptions = {
|
|
3
3
|
input: string | Record<string, any>;
|
|
4
4
|
output: string;
|
|
5
5
|
outputCore?: string;
|
|
@@ -21,7 +21,7 @@ export type Options = {
|
|
|
21
21
|
typePrefix?: string;
|
|
22
22
|
useCancelableRequest?: boolean;
|
|
23
23
|
};
|
|
24
|
-
export type
|
|
25
|
-
items:
|
|
26
|
-
} & Omit<
|
|
24
|
+
export type TMultiOptions = {
|
|
25
|
+
items: TOptions[];
|
|
26
|
+
} & Omit<TOptions, 'input' | 'output'>;
|
|
27
27
|
//# sourceMappingURL=Options.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Options.d.ts","sourceRoot":"","sources":["../../src/common/Options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"Options.d.ts","sourceRoot":"","sources":["../../src/common/Options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,MAAM,MAAM,QAAQ,GAAG;IACnB,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,QAAQ,EAAE,CAAC;CACnB,GAAG,IAAI,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,CAAC,CAAC"}
|
package/dist/common/Utils.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export declare function loadConfigIfExists(): Record<string, any> | null;
|
|
1
|
+
export declare function loadConfigIfExists(): Record<string, any> | Record<string, any>[] | null;
|
|
2
|
+
export declare function convertArrayToObject(optionsArr: Record<string, any> | Record<string, any>[] | null): Record<string, any>;
|
|
2
3
|
//# sourceMappingURL=Utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../src/common/Utils.ts"],"names":[],"mappings":"AAOA,wBAAgB,kBAAkB
|
|
1
|
+
{"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../src/common/Utils.ts"],"names":[],"mappings":"AAOA,wBAAgB,kBAAkB,uDAYjC;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CA6DxH"}
|
package/dist/common/Utils.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.loadConfigIfExists = loadConfigIfExists;
|
|
7
|
+
exports.convertArrayToObject = convertArrayToObject;
|
|
7
8
|
const fs_1 = __importDefault(require("fs"));
|
|
8
9
|
const utils_1 = require("../cli/utils");
|
|
9
10
|
const pathHelpers_1 = require("../core/utils/pathHelpers");
|
|
@@ -20,3 +21,56 @@ function loadConfigIfExists() {
|
|
|
20
21
|
}
|
|
21
22
|
return configData;
|
|
22
23
|
}
|
|
24
|
+
function convertArrayToObject(optionsArr) {
|
|
25
|
+
const emptyResult = {
|
|
26
|
+
items: [],
|
|
27
|
+
exportCore: undefined,
|
|
28
|
+
exportServices: undefined,
|
|
29
|
+
exportModels: undefined,
|
|
30
|
+
exportSchemas: undefined,
|
|
31
|
+
request: undefined,
|
|
32
|
+
useOptions: undefined,
|
|
33
|
+
useCancelableRequest: undefined,
|
|
34
|
+
};
|
|
35
|
+
if (!optionsArr) {
|
|
36
|
+
return emptyResult;
|
|
37
|
+
}
|
|
38
|
+
if (Array.isArray(optionsArr)) {
|
|
39
|
+
if (optionsArr.length === 0) {
|
|
40
|
+
return emptyResult;
|
|
41
|
+
}
|
|
42
|
+
const items = optionsArr.map(item => ({
|
|
43
|
+
input: item.input,
|
|
44
|
+
output: item.output,
|
|
45
|
+
outputCore: item.outputCore,
|
|
46
|
+
outputServices: item.outputServices,
|
|
47
|
+
outputModels: item.outputModels,
|
|
48
|
+
outputSchemas: item.outputSchemas,
|
|
49
|
+
}));
|
|
50
|
+
const firstItem = optionsArr[0];
|
|
51
|
+
const fieldsToExtract = [
|
|
52
|
+
'httpClient',
|
|
53
|
+
'useOptions',
|
|
54
|
+
'useUnionTypes',
|
|
55
|
+
'exportCore',
|
|
56
|
+
'exportServices',
|
|
57
|
+
'exportModels',
|
|
58
|
+
'exportSchemas',
|
|
59
|
+
'clean',
|
|
60
|
+
'request',
|
|
61
|
+
'interfacePrefix',
|
|
62
|
+
'enumPrefix',
|
|
63
|
+
'typePrefix',
|
|
64
|
+
'useCancelableRequest',
|
|
65
|
+
];
|
|
66
|
+
const extractedFields = fieldsToExtract.reduce((acc, field) => ({
|
|
67
|
+
...acc,
|
|
68
|
+
[field]: firstItem[field],
|
|
69
|
+
}), {});
|
|
70
|
+
return {
|
|
71
|
+
...extractedFields,
|
|
72
|
+
items,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return optionsArr;
|
|
76
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiOptionsMigrationPlan.d.ts","sourceRoot":"","sources":["../../../src/common/VersionedSchema/MultiOptionsMigrationPlan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,mBAAmB,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"MultiOptionsMigrationPlan.d.ts","sourceRoot":"","sources":["../../../src/common/VersionedSchema/MultiOptionsMigrationPlan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,mBAAmB,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAyBpG,CAAC"}
|
|
@@ -8,11 +8,9 @@ exports.multiOptionsMigrationPlan = [
|
|
|
8
8
|
{
|
|
9
9
|
fromVersion: '1.0.0',
|
|
10
10
|
toVersion: '1.0.1',
|
|
11
|
-
migrate: ({
|
|
11
|
+
migrate: ({ client, ...otherProps }) => ({
|
|
12
12
|
...otherProps,
|
|
13
|
-
output,
|
|
14
13
|
httpClient: client,
|
|
15
|
-
items: items.map((el) => ({ ...el, output })),
|
|
16
14
|
}),
|
|
17
15
|
},
|
|
18
16
|
{
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Joi from "joi";
|
|
2
2
|
/**
|
|
3
3
|
* Get all the unique parameter keys of all Joi schemes in the array
|
|
4
4
|
* @param schemas array of joi schemes
|
|
5
5
|
* @returns All the unique parameter keys of all Joi schemes in the array
|
|
6
6
|
*/
|
|
7
|
-
export declare function getUniqueAllShemasKeys(schemas:
|
|
7
|
+
export declare function getUniqueAllShemasKeys(schemas: Joi.Schema[]): Set<string>;
|
|
8
8
|
//# sourceMappingURL=getUniqueAllShemasKeys.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getUniqueAllShemasKeys.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/getUniqueAllShemasKeys.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"getUniqueAllShemasKeys.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/getUniqueAllShemasKeys.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AAKtB;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,eAQ3D"}
|
|
@@ -10,6 +10,8 @@ const traverseGeneric_1 = require("./traverseGeneric");
|
|
|
10
10
|
*/
|
|
11
11
|
function getUniqueAllShemasKeys(schemas) {
|
|
12
12
|
const result = new Set();
|
|
13
|
-
|
|
13
|
+
for (const schema of schemas) {
|
|
14
|
+
(0, traverseGeneric_1.traverseGeneric)(schema, [joiHandlers_1.joiSchemaHandler, joiHandlers_1.joiDescHandler], result);
|
|
15
|
+
}
|
|
14
16
|
return result;
|
|
15
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrateToLatestVersion.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/migrateToLatestVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAMhE,KAAK,oBAAoB,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,gBAAgB,EAAE,eAAe,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;IACzD,cAAc,EAAE,mBAAmB,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;CACnF,CAAC;AAEF,KAAK,qBAAqB,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,oBAAoB,CAAC;CACpC,CAAA;AAED,wBAAgB,sBAAsB,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAE,gBAAgB,EAAE,EAAE,oBAAoB,GAAG,qBAAqB,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"migrateToLatestVersion.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/migrateToLatestVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAMhE,KAAK,oBAAoB,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,gBAAgB,EAAE,eAAe,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;IACzD,cAAc,EAAE,mBAAmB,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;CACnF,CAAC;AAEF,KAAK,qBAAqB,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,oBAAoB,CAAC;CACpC,CAAA;AAED,wBAAgB,sBAAsB,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAE,gBAAgB,EAAE,EAAE,oBAAoB,GAAG,qBAAqB,GAAG,IAAI,CAgCzI"}
|
|
@@ -7,8 +7,9 @@ const guessVersion_1 = require("./guessVersion");
|
|
|
7
7
|
const validateUnknownKeys_1 = require("./validateUnknownKeys");
|
|
8
8
|
function migrateToLatestVersion({ rawInput, migrationPlans, versionedSchemas }) {
|
|
9
9
|
let currentData = rawInput;
|
|
10
|
+
const schemas = versionedSchemas.map(el => el.schema);
|
|
10
11
|
const allRawInputKeys = (0, getUniqueObjectKeys_1.getUniqueObjectKeys)(rawInput);
|
|
11
|
-
const allSchemasKeys = (0, getUniqueAllShemasKeys_1.getUniqueAllShemasKeys)(
|
|
12
|
+
const allSchemasKeys = (0, getUniqueAllShemasKeys_1.getUniqueAllShemasKeys)(schemas);
|
|
12
13
|
(0, validateUnknownKeys_1.validateUnknownKeys)(allRawInputKeys, allSchemasKeys);
|
|
13
14
|
const guessed = (0, guessVersion_1.guessVersion)(rawInput, versionedSchemas);
|
|
14
15
|
for (let idx = guessed.index; idx < versionedSchemas.length - 1; idx++) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertArrayToObject.test.d.ts","sourceRoot":"","sources":["../../../src/common/__tests__/convertArrayToObject.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const node_test_1 = require("node:test");
|
|
8
|
+
const Utils_1 = require("common/Utils");
|
|
9
|
+
(0, node_test_1.describe)('convertArrayToObject', () => {
|
|
10
|
+
(0, node_test_1.test)('@unit: Empty array', () => {
|
|
11
|
+
const input = [];
|
|
12
|
+
const result = (0, Utils_1.convertArrayToObject)(input);
|
|
13
|
+
const expected = {
|
|
14
|
+
items: [],
|
|
15
|
+
exportCore: undefined,
|
|
16
|
+
exportServices: undefined,
|
|
17
|
+
exportModels: undefined,
|
|
18
|
+
exportSchemas: undefined,
|
|
19
|
+
request: undefined,
|
|
20
|
+
useOptions: undefined,
|
|
21
|
+
useCancelableRequest: undefined,
|
|
22
|
+
};
|
|
23
|
+
node_assert_1.default.deepStrictEqual(result, expected);
|
|
24
|
+
});
|
|
25
|
+
(0, node_test_1.test)('@unit: An array with one element', () => {
|
|
26
|
+
const input = [
|
|
27
|
+
{
|
|
28
|
+
input: 'url1',
|
|
29
|
+
output: 'res1',
|
|
30
|
+
exportCore: true,
|
|
31
|
+
request: 'req1',
|
|
32
|
+
useOptions: true,
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
const expected = {
|
|
36
|
+
httpClient: undefined,
|
|
37
|
+
useOptions: true,
|
|
38
|
+
useUnionTypes: undefined,
|
|
39
|
+
exportCore: true,
|
|
40
|
+
exportServices: undefined,
|
|
41
|
+
exportModels: undefined,
|
|
42
|
+
exportSchemas: undefined,
|
|
43
|
+
clean: undefined,
|
|
44
|
+
request: 'req1',
|
|
45
|
+
interfacePrefix: undefined,
|
|
46
|
+
enumPrefix: undefined,
|
|
47
|
+
typePrefix: undefined,
|
|
48
|
+
useCancelableRequest: undefined,
|
|
49
|
+
items: [
|
|
50
|
+
{
|
|
51
|
+
input: 'url1',
|
|
52
|
+
output: 'res1',
|
|
53
|
+
outputCore: undefined,
|
|
54
|
+
outputServices: undefined,
|
|
55
|
+
outputModels: undefined,
|
|
56
|
+
outputSchemas: undefined,
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
};
|
|
60
|
+
const result = (0, Utils_1.convertArrayToObject)(input);
|
|
61
|
+
node_assert_1.default.deepStrictEqual(result, expected);
|
|
62
|
+
});
|
|
63
|
+
(0, node_test_1.test)('@unit: Multiple elements with the same outer margins', () => {
|
|
64
|
+
const input = [
|
|
65
|
+
{ input: 'url1', output: 'res1', exportCore: true, request: 'req1', useOptions: true },
|
|
66
|
+
{ input: 'url2', output: 'res2', exportCore: true, request: 'req1', useOptions: true },
|
|
67
|
+
];
|
|
68
|
+
const expected = {
|
|
69
|
+
httpClient: undefined,
|
|
70
|
+
useOptions: true,
|
|
71
|
+
useUnionTypes: undefined,
|
|
72
|
+
exportCore: true,
|
|
73
|
+
exportServices: undefined,
|
|
74
|
+
exportModels: undefined,
|
|
75
|
+
exportSchemas: undefined,
|
|
76
|
+
clean: undefined,
|
|
77
|
+
request: 'req1',
|
|
78
|
+
interfacePrefix: undefined,
|
|
79
|
+
enumPrefix: undefined,
|
|
80
|
+
typePrefix: undefined,
|
|
81
|
+
useCancelableRequest: undefined,
|
|
82
|
+
items: [
|
|
83
|
+
{
|
|
84
|
+
input: 'url1',
|
|
85
|
+
output: 'res1',
|
|
86
|
+
outputCore: undefined,
|
|
87
|
+
outputServices: undefined,
|
|
88
|
+
outputModels: undefined,
|
|
89
|
+
outputSchemas: undefined,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
input: 'url2',
|
|
93
|
+
output: 'res2',
|
|
94
|
+
outputCore: undefined,
|
|
95
|
+
outputServices: undefined,
|
|
96
|
+
outputModels: undefined,
|
|
97
|
+
outputSchemas: undefined,
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
};
|
|
101
|
+
const result = (0, Utils_1.convertArrayToObject)(input);
|
|
102
|
+
node_assert_1.default.deepStrictEqual(result, expected);
|
|
103
|
+
});
|
|
104
|
+
(0, node_test_1.test)('@unit: Multiple elements with different external margins', () => {
|
|
105
|
+
const input = [
|
|
106
|
+
{ input: 'url1', output: 'res1', exportCore: true, request: 'req1', useOptions: true },
|
|
107
|
+
{ input: 'url2', output: 'res2', exportCore: false, request: 'req2', useOptions: false },
|
|
108
|
+
];
|
|
109
|
+
const expected = {
|
|
110
|
+
httpClient: undefined,
|
|
111
|
+
useOptions: true,
|
|
112
|
+
useUnionTypes: undefined,
|
|
113
|
+
exportCore: true,
|
|
114
|
+
exportServices: undefined,
|
|
115
|
+
exportModels: undefined,
|
|
116
|
+
exportSchemas: undefined,
|
|
117
|
+
clean: undefined,
|
|
118
|
+
request: 'req1',
|
|
119
|
+
interfacePrefix: undefined,
|
|
120
|
+
enumPrefix: undefined,
|
|
121
|
+
typePrefix: undefined,
|
|
122
|
+
useCancelableRequest: undefined,
|
|
123
|
+
items: [
|
|
124
|
+
{
|
|
125
|
+
input: 'url1',
|
|
126
|
+
output: 'res1',
|
|
127
|
+
outputCore: undefined,
|
|
128
|
+
outputServices: undefined,
|
|
129
|
+
outputModels: undefined,
|
|
130
|
+
outputSchemas: undefined,
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
input: 'url2',
|
|
134
|
+
output: 'res2',
|
|
135
|
+
outputCore: undefined,
|
|
136
|
+
outputServices: undefined,
|
|
137
|
+
outputModels: undefined,
|
|
138
|
+
outputSchemas: undefined,
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
};
|
|
142
|
+
const result = (0, Utils_1.convertArrayToObject)(input);
|
|
143
|
+
node_assert_1.default.deepStrictEqual(result, expected);
|
|
144
|
+
});
|
|
145
|
+
(0, node_test_1.test)('@unit: No optional fields', () => {
|
|
146
|
+
const input = [
|
|
147
|
+
{ input: 'url1', output: 'res1' },
|
|
148
|
+
{ input: 'url2', output: 'res2' },
|
|
149
|
+
];
|
|
150
|
+
const expected = {
|
|
151
|
+
httpClient: undefined,
|
|
152
|
+
useOptions: undefined,
|
|
153
|
+
useUnionTypes: undefined,
|
|
154
|
+
exportCore: undefined,
|
|
155
|
+
exportServices: undefined,
|
|
156
|
+
exportModels: undefined,
|
|
157
|
+
exportSchemas: undefined,
|
|
158
|
+
clean: undefined,
|
|
159
|
+
request: undefined,
|
|
160
|
+
interfacePrefix: undefined,
|
|
161
|
+
enumPrefix: undefined,
|
|
162
|
+
typePrefix: undefined,
|
|
163
|
+
useCancelableRequest: undefined,
|
|
164
|
+
items: [
|
|
165
|
+
{
|
|
166
|
+
input: 'url1',
|
|
167
|
+
output: 'res1',
|
|
168
|
+
outputCore: undefined,
|
|
169
|
+
outputServices: undefined,
|
|
170
|
+
outputModels: undefined,
|
|
171
|
+
outputSchemas: undefined,
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
input: 'url2',
|
|
175
|
+
output: 'res2',
|
|
176
|
+
outputCore: undefined,
|
|
177
|
+
outputServices: undefined,
|
|
178
|
+
outputModels: undefined,
|
|
179
|
+
outputSchemas: undefined,
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
};
|
|
183
|
+
const result = (0, Utils_1.convertArrayToObject)(input);
|
|
184
|
+
node_assert_1.default.deepStrictEqual(result, expected);
|
|
185
|
+
});
|
|
186
|
+
(0, node_test_1.test)('@unit: Mixed presence of optional fields', () => {
|
|
187
|
+
const input = [
|
|
188
|
+
{ input: 'url1', output: 'res1', exportCore: true },
|
|
189
|
+
{ input: 'url2', output: 'res2', request: 'req2' },
|
|
190
|
+
];
|
|
191
|
+
const expected = {
|
|
192
|
+
httpClient: undefined,
|
|
193
|
+
useOptions: undefined,
|
|
194
|
+
useUnionTypes: undefined,
|
|
195
|
+
exportCore: true,
|
|
196
|
+
exportServices: undefined,
|
|
197
|
+
exportModels: undefined,
|
|
198
|
+
exportSchemas: undefined,
|
|
199
|
+
clean: undefined,
|
|
200
|
+
request: undefined,
|
|
201
|
+
interfacePrefix: undefined,
|
|
202
|
+
enumPrefix: undefined,
|
|
203
|
+
typePrefix: undefined,
|
|
204
|
+
useCancelableRequest: undefined,
|
|
205
|
+
items: [
|
|
206
|
+
{
|
|
207
|
+
input: 'url1',
|
|
208
|
+
output: 'res1',
|
|
209
|
+
outputCore: undefined,
|
|
210
|
+
outputServices: undefined,
|
|
211
|
+
outputModels: undefined,
|
|
212
|
+
outputSchemas: undefined,
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
input: 'url2',
|
|
216
|
+
output: 'res2',
|
|
217
|
+
outputCore: undefined,
|
|
218
|
+
outputServices: undefined,
|
|
219
|
+
outputModels: undefined,
|
|
220
|
+
outputSchemas: undefined,
|
|
221
|
+
},
|
|
222
|
+
],
|
|
223
|
+
};
|
|
224
|
+
const result = (0, Utils_1.convertArrayToObject)(input);
|
|
225
|
+
node_assert_1.default.deepStrictEqual(result, expected);
|
|
226
|
+
});
|
|
227
|
+
});
|
|
@@ -11,17 +11,19 @@ const core_1 = require("../../core");
|
|
|
11
11
|
const Enums_1 = require("../VersionedSchema/Enums");
|
|
12
12
|
const migrateToLatestVersion_1 = require("../VersionedSchema/Utils/migrateToLatestVersion");
|
|
13
13
|
(0, node_test_1.describe)('migrateToLatestVersion for Multioptions', () => {
|
|
14
|
-
node_test_1.test
|
|
14
|
+
(0, node_test_1.test)('@unit: should migrate Multioptions data from 1.0.0 to 2.0.0', () => {
|
|
15
15
|
const dataMultiV1 = {
|
|
16
16
|
input: 'source/path',
|
|
17
17
|
output: 'generated/path',
|
|
18
18
|
client: core_1.HttpClient.AXIOS,
|
|
19
|
-
items: [{ input: '
|
|
19
|
+
items: [{ input: 'source/path' }, { input: 'source/path' }],
|
|
20
20
|
};
|
|
21
21
|
const expectedDataMultiV3 = {
|
|
22
|
-
input: 'source/path',
|
|
23
22
|
httpClient: core_1.HttpClient.AXIOS,
|
|
24
|
-
items: [
|
|
23
|
+
items: [
|
|
24
|
+
{ input: 'source/path', output: 'generated/path', outputCore: undefined, outputServices: undefined, outputModels: undefined, outputSchemas: undefined },
|
|
25
|
+
{ input: 'source/path', output: 'generated/path', outputCore: undefined, outputServices: undefined, outputModels: undefined, outputSchemas: undefined },
|
|
26
|
+
],
|
|
25
27
|
useCancelableRequest: false,
|
|
26
28
|
};
|
|
27
29
|
const result = (0, migrateToLatestVersion_1.migrateToLatestVersion)({
|
|
@@ -31,7 +33,7 @@ const migrateToLatestVersion_1 = require("../VersionedSchema/Utils/migrateToLate
|
|
|
31
33
|
});
|
|
32
34
|
node_assert_1.default.deepEqual(result, { value: expectedDataMultiV3, schemaVersion: '2.0.0', schemaType: Enums_1.EVersionedSchemaType.MULTI_OPTIONS }, 'Should migrate Multioptions V1 data to V3 correctly');
|
|
33
35
|
});
|
|
34
|
-
node_test_1.test
|
|
36
|
+
(0, node_test_1.test)('@unit: should migrate Multioptions data from 1.0.1 to 2.0.0', () => {
|
|
35
37
|
const dataMultiV2 = {
|
|
36
38
|
input: 'source/path',
|
|
37
39
|
output: 'generated/path',
|
|
@@ -40,30 +42,34 @@ const migrateToLatestVersion_1 = require("../VersionedSchema/Utils/migrateToLate
|
|
|
40
42
|
};
|
|
41
43
|
const expectedDataMultiV3 = {
|
|
42
44
|
httpClient: core_1.HttpClient.FETCH,
|
|
43
|
-
items: [
|
|
45
|
+
items: [
|
|
46
|
+
{ input: 'source/path', output: 'generated/path', outputCore: undefined, outputServices: undefined, outputModels: undefined, outputSchemas: undefined },
|
|
47
|
+
{ input: 'source/path', output: 'generated/path', outputCore: undefined, outputServices: undefined, outputModels: undefined, outputSchemas: undefined },
|
|
48
|
+
],
|
|
44
49
|
};
|
|
45
50
|
const result = (0, migrateToLatestVersion_1.migrateToLatestVersion)({
|
|
46
51
|
rawInput: dataMultiV2,
|
|
47
52
|
versionedSchemas: MultiOptionsVersionedSchemas_1.multiOptionsVersionedSchema,
|
|
48
53
|
migrationPlans: MultiOptionsMigrationPlan_1.multiOptionsMigrationPlan,
|
|
49
54
|
});
|
|
50
|
-
node_assert_1.default.deepEqual(result, { value: expectedDataMultiV3, schemaVersion: '2.0.0', schemaType: Enums_1.EVersionedSchemaType.MULTI_OPTIONS }, 'Should migrate Multioptions
|
|
55
|
+
node_assert_1.default.deepEqual(result, { value: expectedDataMultiV3, schemaVersion: '2.0.0', schemaType: Enums_1.EVersionedSchemaType.MULTI_OPTIONS }, 'Should migrate Multioptions 1.0.1 data to 2.0.0 correctly');
|
|
51
56
|
});
|
|
52
|
-
node_test_1.test
|
|
57
|
+
(0, node_test_1.test)('@unit: should throw error if not conform any known version schema', () => {
|
|
53
58
|
const dataMultiV1 = {
|
|
54
59
|
input: 'source/path',
|
|
55
60
|
output: 'generated/path',
|
|
56
|
-
client: 'invalid-client',
|
|
61
|
+
client: 'invalid-client',
|
|
57
62
|
items: [{ input: 'item1' }, { input: 'item2' }],
|
|
58
63
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
node_assert_1.default.throws(() => {
|
|
65
|
+
(0, migrateToLatestVersion_1.migrateToLatestVersion)({
|
|
66
|
+
rawInput: dataMultiV1,
|
|
67
|
+
versionedSchemas: MultiOptionsVersionedSchemas_1.multiOptionsVersionedSchema,
|
|
68
|
+
migrationPlans: MultiOptionsMigrationPlan_1.multiOptionsMigrationPlan,
|
|
69
|
+
});
|
|
70
|
+
}, /Data does not conform to any known version schema/, 'Should throw error if not conform any known version schema');
|
|
65
71
|
});
|
|
66
|
-
node_test_1.test
|
|
72
|
+
(0, node_test_1.test)('@unit: should throw error if no migration plan exists for Multioptions', () => {
|
|
67
73
|
const dataMultiV1 = {
|
|
68
74
|
input: 'source/path',
|
|
69
75
|
output: 'generated/path',
|
|
@@ -40,14 +40,15 @@ const migrateToLatestVersion_1 = require("../VersionedSchema/Utils/migrateToLate
|
|
|
40
40
|
});
|
|
41
41
|
node_assert_1.default.deepEqual(result, { value: expectedDataV3, schemaVersion: '2.0.0', schemaType: Enums_1.EVersionedSchemaType.OPTIONS }, 'Should migrate 1.0.1 data to 2.0.0 correctly');
|
|
42
42
|
});
|
|
43
|
-
node_test_1.test
|
|
43
|
+
(0, node_test_1.test)('@unit: should throw error if not conform any known version schema', () => {
|
|
44
44
|
const dataV1 = { input: 'source/path', output: 'generated/path', client: 'invalid-client' };
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
node_assert_1.default.throws(() => {
|
|
46
|
+
(0, migrateToLatestVersion_1.migrateToLatestVersion)({
|
|
47
|
+
rawInput: dataV1,
|
|
48
|
+
versionedSchemas: OptionsVersionedSchemas_1.optionsVersionedSchemas,
|
|
49
|
+
migrationPlans: OptionsMigrationPlans_1.optionsMigrationPlans,
|
|
50
|
+
});
|
|
51
|
+
}, /Data does not conform to any known version schema/, 'Should throw error if not conform any known version schema');
|
|
51
52
|
});
|
|
52
53
|
(0, node_test_1.test)('@unit: should throw error if no migration plan exists', () => {
|
|
53
54
|
const dataV1 = { input: 'source/path', output: 'generated/path', client: core_1.HttpClient.AXIOS };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultOptions.d.ts","sourceRoot":"","sources":["../../src/common/defaultOptions.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"defaultOptions.d.ts","sourceRoot":"","sources":["../../src/common/defaultOptions.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AAItB,eAAO,MAAM,cAAc,uBA0BV,CAAC"}
|
|
@@ -5,5 +5,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.defaultOptions = void 0;
|
|
7
7
|
const joi_1 = __importDefault(require("joi"));
|
|
8
|
-
|
|
9
|
-
exports.defaultOptions = joi_1.default.object(
|
|
8
|
+
const Enums_1 = require("../core/types/Enums");
|
|
9
|
+
exports.defaultOptions = joi_1.default.object({
|
|
10
|
+
input: joi_1.default.string().required(),
|
|
11
|
+
output: joi_1.default.string().required(),
|
|
12
|
+
httpClient: joi_1.default.string().valid(...Object.values(Enums_1.HttpClient)),
|
|
13
|
+
outputCore: joi_1.default.string().optional(),
|
|
14
|
+
outputServices: joi_1.default.string().optional(),
|
|
15
|
+
outputModels: joi_1.default.string().optional(),
|
|
16
|
+
outputSchemas: joi_1.default.string().optional(),
|
|
17
|
+
useOptions: joi_1.default.boolean().optional(),
|
|
18
|
+
useUnionTypes: joi_1.default.boolean().optional(),
|
|
19
|
+
exportCore: joi_1.default.boolean().optional(),
|
|
20
|
+
exportServices: joi_1.default.boolean().optional(),
|
|
21
|
+
exportModels: joi_1.default.boolean().optional(),
|
|
22
|
+
exportSchemas: joi_1.default.boolean().optional(),
|
|
23
|
+
clean: joi_1.default.boolean().optional(),
|
|
24
|
+
request: joi_1.default.string().optional(),
|
|
25
|
+
interfacePrefix: joi_1.default.string().optional(),
|
|
26
|
+
enumPrefix: joi_1.default.string().optional(),
|
|
27
|
+
typePrefix: joi_1.default.string().optional(),
|
|
28
|
+
useCancelableRequest: joi_1.default.boolean().optional(),
|
|
29
|
+
}).unknown(false);
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TMultiOptions, TOptions } from '../common/Options';
|
|
2
2
|
export { HttpClient } from './types/Enums';
|
|
3
|
-
export declare function generate(options:
|
|
3
|
+
export declare function generate(options: TOptions | TOptions[] | TMultiOptions): Promise<void>;
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAmB5D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAsH3C,wBAAsB,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,QAAQ,EAAE,GAAG,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAmD5F"}
|
package/dist/core/index.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.HttpClient = void 0;
|
|
4
7
|
exports.generate = generate;
|
|
8
|
+
/* istanbul ignore file */
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
5
10
|
const Parser_1 = require("./api/v2/Parser");
|
|
6
11
|
const Parser_2 = require("./api/v3/Parser");
|
|
7
12
|
const Context_1 = require("./Context");
|
|
@@ -59,12 +64,14 @@ async function generateFrom({ input, output, outputCore, outputServices, outputM
|
|
|
59
64
|
useUnionTypes,
|
|
60
65
|
useOptions,
|
|
61
66
|
});
|
|
67
|
+
writeClient.logger.info('Defining the version of the openapi specification (2 or 3)');
|
|
62
68
|
switch (openApiVersion) {
|
|
63
69
|
case getOpenApiVersion_1.OpenApiVersion.V2: {
|
|
64
70
|
const client = new Parser_1.Parser(context).parse(openApi);
|
|
65
71
|
const clientFinal = (0, postProcessClient_1.postProcessClient)(client);
|
|
66
72
|
if (!write)
|
|
67
73
|
break;
|
|
74
|
+
writeClient.logger.info('Write our OpenAPI client version 2 to disk.');
|
|
68
75
|
await writeClient.writeClient({
|
|
69
76
|
client: clientFinal,
|
|
70
77
|
templates,
|
|
@@ -87,6 +94,7 @@ async function generateFrom({ input, output, outputCore, outputServices, outputM
|
|
|
87
94
|
const clientFinal = (0, postProcessClient_1.postProcessClient)(client);
|
|
88
95
|
if (!write)
|
|
89
96
|
break;
|
|
97
|
+
writeClient.logger.info('Write our OpenAPI client version 3 to disk.');
|
|
90
98
|
await writeClient.writeClient({
|
|
91
99
|
client: clientFinal,
|
|
92
100
|
templates,
|
|
@@ -118,27 +126,41 @@ async function generate(options) {
|
|
|
118
126
|
else {
|
|
119
127
|
preparedOptions = Array.of(options);
|
|
120
128
|
}
|
|
121
|
-
const optionsFinal = preparedOptions.map(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
129
|
+
const optionsFinal = preparedOptions.map(op => (0, prepareOptions_1.prepareOptions)(op));
|
|
130
|
+
const writeClient = new writeClient_1.WriteClient();
|
|
131
|
+
writeClient.logger.forceInfo(`Generation has begun. Total number of specification files: ${optionsFinal.length}`);
|
|
132
|
+
try {
|
|
133
|
+
const start = process.hrtime();
|
|
134
|
+
for (const option of optionsFinal) {
|
|
135
|
+
if (option.output) {
|
|
136
|
+
await fileSystem_1.fileSystem.rmdir(option.output);
|
|
137
|
+
}
|
|
138
|
+
if (option.outputCore) {
|
|
139
|
+
await fileSystem_1.fileSystem.rmdir(option.outputCore);
|
|
140
|
+
}
|
|
141
|
+
if (option.outputSchemas) {
|
|
142
|
+
await fileSystem_1.fileSystem.rmdir(option.outputSchemas);
|
|
143
|
+
}
|
|
144
|
+
if (option.outputModels) {
|
|
145
|
+
await fileSystem_1.fileSystem.rmdir(option.outputModels);
|
|
146
|
+
}
|
|
147
|
+
if (option.outputServices) {
|
|
148
|
+
await fileSystem_1.fileSystem.rmdir(option.outputServices);
|
|
149
|
+
}
|
|
134
150
|
}
|
|
135
|
-
|
|
136
|
-
await
|
|
151
|
+
for (const option of optionsFinal) {
|
|
152
|
+
await generateFrom(option, writeClient);
|
|
153
|
+
writeClient.logger.info(`Generation from "${option.input}" was finished`);
|
|
154
|
+
writeClient.logger.info(`Output folder: ${path_1.default.resolve(process.cwd(), option.output)}`, true);
|
|
137
155
|
}
|
|
156
|
+
await writeClient.combineAndWrite();
|
|
157
|
+
writeClient.logger.forceInfo("Generation from has been finished");
|
|
158
|
+
const [seconds, nanoseconds] = process.hrtime(start);
|
|
159
|
+
const durationInMs = seconds + nanoseconds / 1e6;
|
|
160
|
+
writeClient.logger.forceInfo(`Lead time: ${durationInMs.toFixed(2)} sec`);
|
|
138
161
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
await generateFrom(option, writeClient);
|
|
162
|
+
catch (error) {
|
|
163
|
+
writeClient.logger.error(error.message);
|
|
142
164
|
}
|
|
143
|
-
|
|
165
|
+
writeClient.logger.shutdownLogger();
|
|
144
166
|
}
|
|
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const fs_1 = __importDefault(require("fs"));
|
|
7
7
|
const handlebars_1 = __importDefault(require("handlebars"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const Enums_1 = require("../../common/Enums");
|
|
10
|
+
const Logger_1 = require("../../common/Logger");
|
|
9
11
|
const templatesDir = path_1.default.resolve(__dirname, '../../templates');
|
|
10
12
|
const compiledDir = path_1.default.resolve(__dirname, '../../templatesCompiled');
|
|
11
13
|
const header = `// This is an automatically generated file for the hbs template.
|
|
@@ -19,6 +21,11 @@ export default `;
|
|
|
19
21
|
* Фунукция для пре-компеляции шаблонов (hbs) перед дальнейшим использованием
|
|
20
22
|
*/
|
|
21
23
|
const precompileTemplates = () => {
|
|
24
|
+
const logger = new Logger_1.Logger({
|
|
25
|
+
instanceId: 'templates',
|
|
26
|
+
level: Enums_1.ELogLevel.INFO,
|
|
27
|
+
logOutput: Enums_1.ELogOutput.CONSOLE,
|
|
28
|
+
});
|
|
22
29
|
try {
|
|
23
30
|
if (!fs_1.default.existsSync(compiledDir)) {
|
|
24
31
|
fs_1.default.mkdirSync(compiledDir, { recursive: true });
|
|
@@ -64,10 +71,10 @@ const precompileTemplates = () => {
|
|
|
64
71
|
});
|
|
65
72
|
};
|
|
66
73
|
walk(templatesDir);
|
|
67
|
-
|
|
74
|
+
logger.info('The templates have been successfully precompiled and saved!');
|
|
68
75
|
}
|
|
69
76
|
catch (error) {
|
|
70
|
-
|
|
77
|
+
logger.error(`Error during pre-compilation of templates: ${error.message}`);
|
|
71
78
|
}
|
|
72
79
|
};
|
|
73
80
|
precompileTemplates();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TOptions } from "../../common/Options";
|
|
2
2
|
/**
|
|
3
3
|
* Preparation the configuration
|
|
4
4
|
* @param options
|
|
5
5
|
* @returns
|
|
6
6
|
*/
|
|
7
|
-
export declare function prepareOptions(options:
|
|
7
|
+
export declare function prepareOptions(options: TOptions): TOptions;
|
|
8
8
|
//# sourceMappingURL=prepareOptions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareOptions.d.ts","sourceRoot":"","sources":["../../../src/core/utils/prepareOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"prepareOptions.d.ts","sourceRoot":"","sources":["../../../src/core/utils/prepareOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAI/C;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,QAAQ,GAAG,QAAQ,CAsB1D"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Logger } from '../../common/Logger';
|
|
1
2
|
import { HttpClient } from '../types/Enums';
|
|
2
3
|
import { IOutput } from '../types/Models';
|
|
3
4
|
import type { Client } from '../types/shared/Client.model';
|
|
@@ -57,6 +58,8 @@ export interface IWriteClientIndex {
|
|
|
57
58
|
*/
|
|
58
59
|
export declare class WriteClient {
|
|
59
60
|
private options;
|
|
61
|
+
private _logger;
|
|
62
|
+
constructor();
|
|
60
63
|
/**
|
|
61
64
|
* Write our OpenAPI client, using the given templates at the given output
|
|
62
65
|
* @param client Client object with all the models, services, etc.
|
|
@@ -80,6 +83,7 @@ export declare class WriteClient {
|
|
|
80
83
|
*/
|
|
81
84
|
writeClientIndex(options: IWriteClientIndex): Promise<void>;
|
|
82
85
|
combineAndWrite(): Promise<void>;
|
|
86
|
+
get logger(): Logger;
|
|
83
87
|
}
|
|
84
88
|
export {};
|
|
85
89
|
//# sourceMappingURL=writeClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeClient.d.ts","sourceRoot":"","sources":["../../../src/core/utils/writeClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"writeClient.d.ts","sourceRoot":"","sources":["../../../src/core/utils/writeClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAG3D,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAoCzD;;;;;;;;;;;;;;GAcG;AACH,UAAU,YAAY;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,SAAS,CAAC;IACrB,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,UAAU,CAAC;IACvB,UAAU,EAAE,OAAO,CAAC;IACpB,aAAa,EAAE,OAAO,CAAC;IACvB,UAAU,EAAE,OAAO,CAAC;IACpB,cAAc,EAAE,OAAO,CAAC;IACxB,YAAY,EAAE,OAAO,CAAC;IACtB,aAAa,EAAE,OAAO,CAAC;IACvB,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAClC;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,iBAAiB;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,SAAS,CAAC;IACrB,WAAW,EAAE,OAAO,CAAC;IACrB,aAAa,EAAE,OAAO,CAAC;IACvB,UAAU,EAAE,OAAO,CAAC;IACpB,cAAc,EAAE,OAAO,CAAC;IACxB,YAAY,EAAE,OAAO,CAAC;IACtB,aAAa,EAAE,OAAO,CAAC;CAC1B;AAED;;GAEG;AACH,qBAAa,WAAW;IACpB,OAAO,CAAC,OAAO,CAA+C;IAC9D,OAAO,CAAC,OAAO,CAAS;;IAUxB;;;;;;;;;;;;;;;OAeG;IACG,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IA+DvD;;;OAGG;IACG,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAU3D,eAAe;IAuFrB,IAAW,MAAM,WAEhB;CACJ"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WriteClient = void 0;
|
|
4
|
+
const Enums_1 = require("../../common/Enums");
|
|
5
|
+
const Logger_1 = require("../../common/Logger");
|
|
4
6
|
const pathHelpers_1 = require("../utils/pathHelpers");
|
|
5
7
|
const fileSystem_1 = require("./fileSystem");
|
|
6
8
|
const unique_1 = require("./unique");
|
|
@@ -40,6 +42,14 @@ function prepareAlias(models) {
|
|
|
40
42
|
*/
|
|
41
43
|
class WriteClient {
|
|
42
44
|
options = new Map();
|
|
45
|
+
_logger;
|
|
46
|
+
constructor() {
|
|
47
|
+
this._logger = new Logger_1.Logger({
|
|
48
|
+
level: Enums_1.ELogLevel.ERROR,
|
|
49
|
+
instanceId: 'client',
|
|
50
|
+
logOutput: Enums_1.ELogOutput.CONSOLE,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
43
53
|
/**
|
|
44
54
|
* Write our OpenAPI client, using the given templates at the given output
|
|
45
55
|
* @param client Client object with all the models, services, etc.
|
|
@@ -210,5 +220,8 @@ class WriteClient {
|
|
|
210
220
|
await (0, writeClientIndex_1.writeClientIndex)(value);
|
|
211
221
|
}
|
|
212
222
|
}
|
|
223
|
+
get logger() {
|
|
224
|
+
return this._logger;
|
|
225
|
+
}
|
|
213
226
|
}
|
|
214
227
|
exports.WriteClient = WriteClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-openapi-codegen",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.3",
|
|
4
4
|
"description": "Library that generates Typescript clients based on the OpenAPI specification. It bases on openapi-typescript-codegen",
|
|
5
5
|
"author": "Alexey Zverev",
|
|
6
6
|
"homepage": "https://github.com/ozonophore/openapi-codegen.git",
|
|
@@ -68,7 +68,9 @@
|
|
|
68
68
|
"json-schema-ref-parser": "9.0.7",
|
|
69
69
|
"leven": "^4.0.0",
|
|
70
70
|
"mkdirp": "1.0.4",
|
|
71
|
-
"rimraf": "3.0.2"
|
|
71
|
+
"rimraf": "3.0.2",
|
|
72
|
+
"winston": "^3.17.0",
|
|
73
|
+
"winston-daily-rotate-file": "^5.0.0"
|
|
72
74
|
},
|
|
73
75
|
"devDependencies": {
|
|
74
76
|
"@babel/cli": "7.14.8",
|
|
@@ -86,6 +88,7 @@
|
|
|
86
88
|
"@types/node-fetch": "2.5.12",
|
|
87
89
|
"@types/prettier": "3.0.0",
|
|
88
90
|
"@types/qs": "6.9.7",
|
|
91
|
+
"@types/winston": "^2.4.4",
|
|
89
92
|
"@typescript-eslint/eslint-plugin": "^8.34.1",
|
|
90
93
|
"@typescript-eslint/parser": "^8.34.1",
|
|
91
94
|
"abort-controller": "^3.0.0",
|