ts-openapi-codegen 1.0.0-beta.2 → 1.0.0-beta.4

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.
Files changed (103) hide show
  1. package/dist/cli/generate/runGenerateOpenApi.d.ts.map +1 -1
  2. package/dist/cli/generate/runGenerateOpenApi.js +48 -32
  3. package/dist/cli/index.js +5 -1
  4. package/dist/cli/utils.d.ts +0 -1
  5. package/dist/cli/utils.d.ts.map +1 -1
  6. package/dist/cli/utils.js +0 -56
  7. package/dist/common/Enums.d.ts +10 -0
  8. package/dist/common/Enums.d.ts.map +1 -0
  9. package/dist/common/Enums.js +14 -0
  10. package/dist/common/Logger.d.ts +33 -0
  11. package/dist/common/Logger.d.ts.map +1 -0
  12. package/dist/common/Logger.js +117 -0
  13. package/dist/common/Options.d.ts +4 -4
  14. package/dist/common/Options.d.ts.map +1 -1
  15. package/dist/common/Utils.d.ts +2 -1
  16. package/dist/common/Utils.d.ts.map +1 -1
  17. package/dist/common/Utils.js +54 -0
  18. package/dist/common/VersionedSchema/MultiOptionsMigrationPlan.d.ts.map +1 -1
  19. package/dist/common/VersionedSchema/MultiOptionsMigrationPlan.js +1 -3
  20. package/dist/common/VersionedSchema/Types.d.ts +1 -1
  21. package/dist/common/VersionedSchema/Types.d.ts.map +1 -1
  22. package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.d.ts +9 -0
  23. package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.d.ts.map +1 -0
  24. package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.js +44 -0
  25. package/dist/common/VersionedSchema/Utils/generateKeyMappingForInvalidKeys.d.ts +2 -0
  26. package/dist/common/VersionedSchema/Utils/generateKeyMappingForInvalidKeys.d.ts.map +1 -0
  27. package/dist/common/VersionedSchema/Utils/generateKeyMappingForInvalidKeys.js +27 -0
  28. package/dist/common/VersionedSchema/Utils/getErrorFieldsFromValidation.d.ts +6 -0
  29. package/dist/common/VersionedSchema/Utils/getErrorFieldsFromValidation.d.ts.map +1 -0
  30. package/dist/common/VersionedSchema/Utils/getErrorFieldsFromValidation.js +7 -0
  31. package/dist/common/VersionedSchema/Utils/getUniqueKeysFromSchemas.d.ts +8 -0
  32. package/dist/common/VersionedSchema/Utils/getUniqueKeysFromSchemas.d.ts.map +1 -0
  33. package/dist/common/VersionedSchema/Utils/getUniqueKeysFromSchemas.js +17 -0
  34. package/dist/common/VersionedSchema/Utils/getUniqueObjectKeys.js +2 -2
  35. package/dist/common/VersionedSchema/Utils/joiHandlers.d.ts +3 -3
  36. package/dist/common/VersionedSchema/Utils/joiHandlers.d.ts.map +1 -1
  37. package/dist/common/VersionedSchema/Utils/joiHandlers.js +24 -17
  38. package/dist/common/VersionedSchema/Utils/{migrateToLatestVersion.d.ts → migrateDataToLatestSchemaVersion.d.ts} +5 -5
  39. package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.d.ts.map +1 -0
  40. package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.js +43 -0
  41. package/dist/common/VersionedSchema/Utils/replaceInvalidKeysWithMappedNames.d.ts +2 -0
  42. package/dist/common/VersionedSchema/Utils/replaceInvalidKeysWithMappedNames.d.ts.map +1 -0
  43. package/dist/common/VersionedSchema/Utils/replaceInvalidKeysWithMappedNames.js +18 -0
  44. package/dist/common/VersionedSchema/Utils/traverseObjectStructure.d.ts +3 -0
  45. package/dist/common/VersionedSchema/Utils/traverseObjectStructure.d.ts.map +1 -0
  46. package/dist/common/VersionedSchema/Utils/{traverseGeneric.js → traverseObjectStructure.js} +6 -4
  47. package/dist/common/VersionedSchema/Utils/validateAndSuggestKeyCorrections.d.ts +8 -0
  48. package/dist/common/VersionedSchema/Utils/validateAndSuggestKeyCorrections.d.ts.map +1 -0
  49. package/dist/common/VersionedSchema/Utils/validateAndSuggestKeyCorrections.js +44 -0
  50. package/dist/common/__tests__/__mock__/mockJoiSchema.d.ts +19 -0
  51. package/dist/common/__tests__/__mock__/mockJoiSchema.d.ts.map +1 -0
  52. package/dist/common/__tests__/__mock__/mockJoiSchema.js +14 -0
  53. package/dist/common/__tests__/convertArrayToObject.test.d.ts +2 -0
  54. package/dist/common/__tests__/convertArrayToObject.test.d.ts.map +1 -0
  55. package/dist/common/__tests__/convertArrayToObject.test.js +227 -0
  56. package/dist/common/__tests__/determineBestMatchingSchemaVersion.test.d.ts +2 -0
  57. package/dist/common/__tests__/determineBestMatchingSchemaVersion.test.d.ts.map +1 -0
  58. package/dist/common/__tests__/determineBestMatchingSchemaVersion.test.js +38 -0
  59. package/dist/common/__tests__/generateKeyMappingForInvalidKeys.test.d.ts +2 -0
  60. package/dist/common/__tests__/generateKeyMappingForInvalidKeys.test.d.ts.map +1 -0
  61. package/dist/common/__tests__/generateKeyMappingForInvalidKeys.test.js +22 -0
  62. package/dist/common/__tests__/getUniqueKeysFromSchemas.test.d.ts +2 -0
  63. package/dist/common/__tests__/getUniqueKeysFromSchemas.test.d.ts.map +1 -0
  64. package/dist/common/__tests__/getUniqueKeysFromSchemas.test.js +20 -0
  65. package/dist/common/__tests__/getUniqueObjectKeys.test.d.ts +2 -0
  66. package/dist/common/__tests__/getUniqueObjectKeys.test.d.ts.map +1 -0
  67. package/dist/common/__tests__/getUniqueObjectKeys.test.js +24 -0
  68. package/dist/common/__tests__/migrationForMultiOptions.test.js +84 -63
  69. package/dist/common/__tests__/migrationForOptions.test.js +27 -46
  70. package/dist/common/__tests__/replaceInvalidKeysWithMappedNames.test.d.ts +2 -0
  71. package/dist/common/__tests__/replaceInvalidKeysWithMappedNames.test.d.ts.map +1 -0
  72. package/dist/common/__tests__/replaceInvalidKeysWithMappedNames.test.js +25 -0
  73. package/dist/common/__tests__/validateAndSuggestKeyCorrections.test.d.ts +2 -0
  74. package/dist/common/__tests__/validateAndSuggestKeyCorrections.test.d.ts.map +1 -0
  75. package/dist/common/__tests__/validateAndSuggestKeyCorrections.test.js +25 -0
  76. package/dist/common/defaultOptions.d.ts.map +1 -1
  77. package/dist/common/defaultOptions.js +22 -2
  78. package/dist/core/index.d.ts +2 -2
  79. package/dist/core/index.d.ts.map +1 -1
  80. package/dist/core/index.js +41 -19
  81. package/dist/core/utils/precompileTemplates.js +9 -2
  82. package/dist/core/utils/prepareOptions.d.ts +2 -2
  83. package/dist/core/utils/prepareOptions.d.ts.map +1 -1
  84. package/dist/core/utils/writeClient.d.ts +4 -0
  85. package/dist/core/utils/writeClient.d.ts.map +1 -1
  86. package/dist/core/utils/writeClient.js +13 -0
  87. package/package.json +5 -2
  88. package/dist/common/VersionedSchema/Utils/getUniqueAllShemasKeys.d.ts +0 -8
  89. package/dist/common/VersionedSchema/Utils/getUniqueAllShemasKeys.d.ts.map +0 -1
  90. package/dist/common/VersionedSchema/Utils/getUniqueAllShemasKeys.js +0 -15
  91. package/dist/common/VersionedSchema/Utils/guessVersion.d.ts +0 -3
  92. package/dist/common/VersionedSchema/Utils/guessVersion.d.ts.map +0 -1
  93. package/dist/common/VersionedSchema/Utils/guessVersion.js +0 -16
  94. package/dist/common/VersionedSchema/Utils/migrateToLatestVersion.d.ts.map +0 -1
  95. package/dist/common/VersionedSchema/Utils/migrateToLatestVersion.js +0 -33
  96. package/dist/common/VersionedSchema/Utils/traverseGeneric.d.ts +0 -3
  97. package/dist/common/VersionedSchema/Utils/traverseGeneric.d.ts.map +0 -1
  98. package/dist/common/VersionedSchema/Utils/validateUnknownKeys.d.ts +0 -2
  99. package/dist/common/VersionedSchema/Utils/validateUnknownKeys.d.ts.map +0 -1
  100. package/dist/common/VersionedSchema/Utils/validateUnknownKeys.js +0 -32
  101. package/dist/common/__tests__/guessVersion.test.d.ts +0 -2
  102. package/dist/common/__tests__/guessVersion.test.d.ts.map +0 -1
  103. package/dist/common/__tests__/guessVersion.test.js +0 -26
@@ -0,0 +1,38 @@
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 Enums_1 = require("../../common/VersionedSchema/Enums");
9
+ const determineBestMatchingSchemaVersion_1 = require("../VersionedSchema/Utils/determineBestMatchingSchemaVersion");
10
+ const mockJoiSchema_1 = require("./__mock__/mockJoiSchema");
11
+ (0, node_test_1.describe)('determineBestMatchingSchemaVersion', () => {
12
+ (0, node_test_1.test)('@unit: it should return the latest version if there is an exact match.', async () => {
13
+ const schemas = [
14
+ { schema: (0, mockJoiSchema_1.mockJoiSchema)(['name'], true), version: '1.0', type: Enums_1.EVersionedSchemaType.OPTIONS },
15
+ { schema: (0, mockJoiSchema_1.mockJoiSchema)(['name', 'age'], true), version: '2.0', type: Enums_1.EVersionedSchemaType.OPTIONS },
16
+ ];
17
+ const input = { name: 'John', age: 30 };
18
+ const result = (0, determineBestMatchingSchemaVersion_1.determineBestMatchingSchemaVersion)(input, schemas);
19
+ node_assert_1.default.deepEqual(result, {
20
+ lastVersionIndex: 1,
21
+ latestVersion: '2.0',
22
+ firstVersion: '1.0',
23
+ });
24
+ });
25
+ (0, node_test_1.test)('@unit: should return the best scheme in the absence of exact matches.', async () => {
26
+ const schemas = [
27
+ { schema: (0, mockJoiSchema_1.mockJoiSchema)(['name'], false, [{ path: 'age', type: 'string' }]), version: '1.0', type: Enums_1.EVersionedSchemaType.OPTIONS },
28
+ { schema: (0, mockJoiSchema_1.mockJoiSchema)(['name', 'age'], true), version: '2.0', type: Enums_1.EVersionedSchemaType.OPTIONS },
29
+ ];
30
+ const input = { name: 'John', age: 30 };
31
+ const result = (0, determineBestMatchingSchemaVersion_1.determineBestMatchingSchemaVersion)(input, schemas);
32
+ node_assert_1.default.deepEqual(result, {
33
+ lastVersionIndex: 1,
34
+ latestVersion: '2.0',
35
+ firstVersion: '2.0',
36
+ });
37
+ });
38
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=generateKeyMappingForInvalidKeys.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateKeyMappingForInvalidKeys.test.d.ts","sourceRoot":"","sources":["../../../src/common/__tests__/generateKeyMappingForInvalidKeys.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,22 @@
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 generateKeyMappingForInvalidKeys_1 = require("../VersionedSchema/Utils/generateKeyMappingForInvalidKeys");
9
+ (0, node_test_1.describe)('generateKeyMappingForInvalidKeys', () => {
10
+ (0, node_test_1.test)('@unit: must create a replacement card for invalid keys', async () => {
11
+ const inputKeys = ['nmae', 'title'];
12
+ const allowedKeys = new Set(['name', 'title']);
13
+ const result = (0, generateKeyMappingForInvalidKeys_1.generateKeyMappingForInvalidKeys)(inputKeys, allowedKeys);
14
+ node_assert_1.default.deepEqual(result, new Map([['nmae', 'name']]));
15
+ });
16
+ (0, node_test_1.test)('@unit: must return an empty card if all keys are valid.', async () => {
17
+ const inputKeys = ['name', 'title'];
18
+ const allowedKeys = new Set(['name', 'title']);
19
+ const result = (0, generateKeyMappingForInvalidKeys_1.generateKeyMappingForInvalidKeys)(inputKeys, allowedKeys);
20
+ node_assert_1.default.deepEqual(result, new Map());
21
+ });
22
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=getUniqueKeysFromSchemas.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getUniqueKeysFromSchemas.test.d.ts","sourceRoot":"","sources":["../../../src/common/__tests__/getUniqueKeysFromSchemas.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,20 @@
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 getUniqueKeysFromSchemas_1 = require("../VersionedSchema/Utils/getUniqueKeysFromSchemas");
9
+ const mockJoiSchema_1 = require("./__mock__/mockJoiSchema");
10
+ (0, node_test_1.describe)('getUniqueKeysFromSchemas', () => {
11
+ (0, node_test_1.test)('@unit: must return unique keys from the schema', async () => {
12
+ const schema = (0, mockJoiSchema_1.mockJoiSchema)(['name', 'age'], true);
13
+ const result = (0, getUniqueKeysFromSchemas_1.getUniqueKeysFromSchemas)([schema]);
14
+ node_assert_1.default.deepEqual(result, new Set(['name', 'age']));
15
+ });
16
+ (0, node_test_1.test)('@unit: should return an empty set for an empty list of schemas', async () => {
17
+ const result = (0, getUniqueKeysFromSchemas_1.getUniqueKeysFromSchemas)([]);
18
+ node_assert_1.default.deepEqual(result, new Set());
19
+ });
20
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=getUniqueObjectKeys.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getUniqueObjectKeys.test.d.ts","sourceRoot":"","sources":["../../../src/common/__tests__/getUniqueObjectKeys.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
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 getUniqueObjectKeys_1 = require("../VersionedSchema/Utils/getUniqueObjectKeys");
9
+ (0, node_test_1.describe)('getUniqueObjectKeys', () => {
10
+ (0, node_test_1.test)('@unit: must return unique keys from the object', async () => {
11
+ const input = { name: 'John', age: 30, nested: { id: 1 } };
12
+ const result = (0, getUniqueObjectKeys_1.getUniqueObjectKeys)(input);
13
+ node_assert_1.default.deepEqual(result, ['name', 'age', 'nested', 'id']);
14
+ });
15
+ (0, node_test_1.test)('@unit: must return unique keys from an array of objects', async () => {
16
+ const input = [{ name: 'John' }, { age: 30 }];
17
+ const result = (0, getUniqueObjectKeys_1.getUniqueObjectKeys)(input);
18
+ node_assert_1.default.deepEqual(result, ['name', 'age']);
19
+ });
20
+ (0, node_test_1.test)('@unit: must return an empty array for an empty object', async () => {
21
+ const result = (0, getUniqueObjectKeys_1.getUniqueObjectKeys)({});
22
+ node_assert_1.default.deepEqual(result, []);
23
+ });
24
+ });
@@ -3,79 +3,100 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_assert_1 = __importDefault(require("node:assert"));
6
+ const strict_1 = __importDefault(require("node:assert/strict"));
7
7
  const node_test_1 = require("node:test");
8
- const MultiOptionsMigrationPlan_1 = require("common/VersionedSchema/MultiOptionsMigrationPlan");
9
- const MultiOptionsVersionedSchemas_1 = require("common/VersionedSchema/MultiOptionsVersionedSchemas");
10
- const core_1 = require("../../core");
11
8
  const Enums_1 = require("../VersionedSchema/Enums");
12
- const migrateToLatestVersion_1 = require("../VersionedSchema/Utils/migrateToLatestVersion");
13
- (0, node_test_1.describe)('migrateToLatestVersion for Multioptions', () => {
14
- node_test_1.test.skip('@unit: should migrate Multioptions data from 1.0.0 to 2.0.0', () => {
15
- const dataMultiV1 = {
16
- input: 'source/path',
17
- output: 'generated/path',
18
- client: core_1.HttpClient.AXIOS,
19
- items: [{ input: 'item1', output: 'generated/path', }, { input: 'item2', output: 'generated/path', }],
20
- };
21
- const expectedDataMultiV3 = {
22
- input: 'source/path',
23
- httpClient: core_1.HttpClient.AXIOS,
24
- items: [{ input: 'item1' }, { input: 'item2' }],
25
- useCancelableRequest: false,
26
- };
27
- const result = (0, migrateToLatestVersion_1.migrateToLatestVersion)({
28
- rawInput: dataMultiV1,
29
- versionedSchemas: MultiOptionsVersionedSchemas_1.multiOptionsVersionedSchema,
9
+ const MultiOptionsMigrationPlan_1 = require("../VersionedSchema/MultiOptionsMigrationPlan");
10
+ const MultiOptionsVersionedSchemas_1 = require("../VersionedSchema/MultiOptionsVersionedSchemas");
11
+ const migrateDataToLatestSchemaVersion_1 = require("../VersionedSchema/Utils/migrateDataToLatestSchemaVersion");
12
+ const mockJoiSchema_1 = require("./__mock__/mockJoiSchema");
13
+ (0, node_test_1.describe)('migrationForMultiOptions', () => {
14
+ (0, node_test_1.test)('@unit: must successfully migrate MULTI_OPTIONS data to the latest version', async () => {
15
+ const input = { input: 'input/path', output: 'output/path', client: 'fetch', items: [{ input: 'path/item1' }] };
16
+ const result = (0, migrateDataToLatestSchemaVersion_1.migrateDataToLatestSchemaVersion)({
17
+ rawInput: input,
30
18
  migrationPlans: MultiOptionsMigrationPlan_1.multiOptionsMigrationPlan,
19
+ versionedSchemas: MultiOptionsVersionedSchemas_1.multiOptionsVersionedSchema,
20
+ });
21
+ strict_1.default.deepEqual(result, {
22
+ value: {
23
+ httpClient: 'fetch',
24
+ useCancelableRequest: false,
25
+ items: [
26
+ {
27
+ input: 'input/path',
28
+ output: 'output/path',
29
+ outputCore: undefined,
30
+ outputModels: undefined,
31
+ outputSchemas: undefined,
32
+ outputServices: undefined,
33
+ },
34
+ ],
35
+ },
36
+ schemaVersion: '2.0.0',
37
+ schemaType: Enums_1.EVersionedSchemaType.MULTI_OPTIONS,
31
38
  });
32
- 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
39
  });
34
- node_test_1.test.skip('@unit: should migrate Multioptions data from 1.0.1 to 2.0.0', () => {
35
- const dataMultiV2 = {
36
- input: 'source/path',
37
- output: 'generated/path',
38
- httpClient: core_1.HttpClient.FETCH,
39
- items: [{ input: 'item1' }, { input: 'item2' }],
40
- };
41
- const expectedDataMultiV3 = {
42
- httpClient: core_1.HttpClient.FETCH,
43
- items: [{ input: 'item1', output: 'generated/path', }, { input: 'item2', output: 'generated/path' }],
44
- };
45
- const result = (0, migrateToLatestVersion_1.migrateToLatestVersion)({
46
- rawInput: dataMultiV2,
47
- versionedSchemas: MultiOptionsVersionedSchemas_1.multiOptionsVersionedSchema,
40
+ (0, node_test_1.test)('@unit: should return null in case of validation error of the last MULTI_OPTIONS scheme', async () => {
41
+ const input = { input: 'input/path' };
42
+ const result = (0, migrateDataToLatestSchemaVersion_1.migrateDataToLatestSchemaVersion)({
43
+ rawInput: input,
48
44
  migrationPlans: MultiOptionsMigrationPlan_1.multiOptionsMigrationPlan,
45
+ versionedSchemas: MultiOptionsVersionedSchemas_1.multiOptionsVersionedSchema,
49
46
  });
50
- node_assert_1.default.deepEqual(result, { value: expectedDataMultiV3, schemaVersion: '2.0.0', schemaType: Enums_1.EVersionedSchemaType.MULTI_OPTIONS }, 'Should migrate Multioptions V2 data to V3 correctly');
47
+ strict_1.default.equal(result, null);
51
48
  });
52
- node_test_1.test.skip('@unit: should return null for invalid Multioptions data after migration', () => {
53
- const dataMultiV1 = {
54
- input: 'source/path',
55
- output: 'generated/path',
56
- client: 'invalid-client', // Некорректное значение
57
- items: [{ input: 'item1' }, { input: 'item2' }],
58
- };
59
- const result = (0, migrateToLatestVersion_1.migrateToLatestVersion)({
60
- rawInput: dataMultiV1,
49
+ (0, node_test_1.test)('@unit: should throw an error if the migration plan for MULTI_OPTIONS is not found.', async () => {
50
+ const input = { input: 'input/path', output: 'output/path', client: 'fetch', items: [{ input: 'path/item1' }] };
51
+ strict_1.default.throws(() => (0, migrateDataToLatestSchemaVersion_1.migrateDataToLatestSchemaVersion)({
52
+ rawInput: input,
53
+ migrationPlans: [],
61
54
  versionedSchemas: MultiOptionsVersionedSchemas_1.multiOptionsVersionedSchema,
62
- migrationPlans: MultiOptionsMigrationPlan_1.multiOptionsMigrationPlan,
63
- });
64
- node_assert_1.default.equal(result, null, 'Should return null for invalid Multioptions data');
55
+ }), /No migration plan from 1.0.0/);
65
56
  });
66
- node_test_1.test.skip('@unit: should throw error if no migration plan exists for Multioptions', () => {
67
- const dataMultiV1 = {
68
- input: 'source/path',
69
- output: 'generated/path',
70
- client: 'axios',
71
- items: [{ input: 'item1' }, { input: 'item2' }],
57
+ (0, node_test_1.test)('@unit: should throw an error on unrecognized fields in MULTI_OPTIONS', async () => {
58
+ const input = {
59
+ input: 'input/path',
60
+ output: 'output/path',
61
+ client: 'fetch',
62
+ items: [{ input: 'path/item1', name: 'Item1' }],
72
63
  };
73
- node_assert_1.default.throws(() => {
74
- (0, migrateToLatestVersion_1.migrateToLatestVersion)({
75
- rawInput: dataMultiV1,
76
- versionedSchemas: MultiOptionsVersionedSchemas_1.multiOptionsVersionedSchema,
77
- migrationPlans: [],
78
- });
79
- }, /No migration plan from 1.0.0/, 'Should throw for missing migration plan in Multioptions');
64
+ strict_1.default.throws(() => (0, migrateDataToLatestSchemaVersion_1.migrateDataToLatestSchemaVersion)({
65
+ rawInput: input,
66
+ migrationPlans: MultiOptionsMigrationPlan_1.multiOptionsMigrationPlan,
67
+ versionedSchemas: MultiOptionsVersionedSchemas_1.multiOptionsVersionedSchema,
68
+ }), /The "name" field is not recognized./);
69
+ });
70
+ (0, node_test_1.test)('@unit: must process an empty array of MULTI_OPTIONS data', async () => {
71
+ const schemas = [
72
+ {
73
+ schema: (0, mockJoiSchema_1.mockJoiSchema)(['name'], true, [], true),
74
+ version: '1.0',
75
+ type: Enums_1.EVersionedSchemaType.MULTI_OPTIONS,
76
+ },
77
+ {
78
+ schema: (0, mockJoiSchema_1.mockJoiSchema)(['name', 'options'], true, [], true),
79
+ version: '2.0',
80
+ type: Enums_1.EVersionedSchemaType.MULTI_OPTIONS,
81
+ },
82
+ ];
83
+ const migrationPlans = [
84
+ {
85
+ fromVersion: '1.0',
86
+ toVersion: '2.0',
87
+ migrate: (input) => input.map((item) => ({ ...item, options: [] })),
88
+ },
89
+ ];
90
+ const input = [];
91
+ const result = (0, migrateDataToLatestSchemaVersion_1.migrateDataToLatestSchemaVersion)({
92
+ rawInput: input,
93
+ migrationPlans,
94
+ versionedSchemas: schemas,
95
+ });
96
+ strict_1.default.deepEqual(result, {
97
+ value: [],
98
+ schemaVersion: '2.0',
99
+ schemaType: Enums_1.EVersionedSchemaType.MULTI_OPTIONS,
100
+ });
80
101
  });
81
102
  });
@@ -3,60 +3,41 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_assert_1 = __importDefault(require("node:assert"));
6
+ const strict_1 = __importDefault(require("node:assert/strict"));
7
7
  const node_test_1 = require("node:test");
8
- const OptionsMigrationPlans_1 = require("common/VersionedSchema/OptionsMigrationPlans");
9
- const OptionsVersionedSchemas_1 = require("common/VersionedSchema/OptionsVersionedSchemas");
10
- const core_1 = require("../../core");
11
8
  const Enums_1 = require("../VersionedSchema/Enums");
12
- const migrateToLatestVersion_1 = require("../VersionedSchema/Utils/migrateToLatestVersion");
13
- (0, node_test_1.describe)('migrateToLatestVersion', () => {
14
- (0, node_test_1.test)('@unit: should migrate data from 1.0.0 to 2.0.0', () => {
15
- const dataV1 = { input: 'source/path', output: 'generated/path', client: core_1.HttpClient.AXIOS };
16
- const expectedDataV3 = {
17
- input: 'source/path',
18
- output: 'generated/path',
19
- httpClient: core_1.HttpClient.AXIOS,
20
- useCancelableRequest: false,
21
- };
22
- const result = (0, migrateToLatestVersion_1.migrateToLatestVersion)({
23
- rawInput: dataV1,
24
- versionedSchemas: OptionsVersionedSchemas_1.optionsVersionedSchemas,
9
+ const OptionsMigrationPlans_1 = require("../VersionedSchema/OptionsMigrationPlans");
10
+ const OptionsVersionedSchemas_1 = require("../VersionedSchema/OptionsVersionedSchemas");
11
+ const migrateDataToLatestSchemaVersion_1 = require("../VersionedSchema/Utils/migrateDataToLatestSchemaVersion");
12
+ (0, node_test_1.describe)('migrationForOptions', () => {
13
+ (0, node_test_1.test)('@unit: must migrate data to the latest schema version', async () => {
14
+ const input = { input: "input/path", output: "output/path", client: "fetch" };
15
+ const result = (0, migrateDataToLatestSchemaVersion_1.migrateDataToLatestSchemaVersion)({
16
+ rawInput: input,
25
17
  migrationPlans: OptionsMigrationPlans_1.optionsMigrationPlans,
26
- });
27
- node_assert_1.default.deepEqual(result, { value: expectedDataV3, schemaVersion: '2.0.0', schemaType: Enums_1.EVersionedSchemaType.OPTIONS }, 'Should migrate 1.0.0 data to 2.0.0 correctly');
28
- });
29
- (0, node_test_1.test)('@unit: should migrate data from 1.0.1 to 2.0.0', () => {
30
- const dataV2 = { input: 'source/path', output: 'generated/path', httpClient: core_1.HttpClient.FETCH };
31
- const expectedDataV3 = {
32
- input: 'source/path',
33
- output: 'generated/path',
34
- httpClient: core_1.HttpClient.FETCH,
35
- };
36
- const result = (0, migrateToLatestVersion_1.migrateToLatestVersion)({
37
- rawInput: dataV2,
38
18
  versionedSchemas: OptionsVersionedSchemas_1.optionsVersionedSchemas,
39
- migrationPlans: OptionsMigrationPlans_1.optionsMigrationPlans,
40
19
  });
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');
20
+ strict_1.default.deepEqual(result, {
21
+ value: { input: 'input/path', output: 'output/path', httpClient: 'fetch', useCancelableRequest: false },
22
+ schemaVersion: '2.0.0',
23
+ schemaType: Enums_1.EVersionedSchemaType.OPTIONS,
24
+ });
42
25
  });
43
- node_test_1.test.skip('@unit: should return null for invalid data after migration', () => {
44
- const dataV1 = { input: 'source/path', output: 'generated/path', client: 'invalid-client' };
45
- const result = (0, migrateToLatestVersion_1.migrateToLatestVersion)({
46
- rawInput: dataV1,
47
- versionedSchemas: OptionsVersionedSchemas_1.optionsVersionedSchemas,
26
+ (0, node_test_1.test)('@unit: should return null if the validation error occurred for the last schema.', async () => {
27
+ const input = { input: "input/path", };
28
+ const result = (0, migrateDataToLatestSchemaVersion_1.migrateDataToLatestSchemaVersion)({
29
+ rawInput: input,
48
30
  migrationPlans: OptionsMigrationPlans_1.optionsMigrationPlans,
31
+ versionedSchemas: OptionsVersionedSchemas_1.optionsVersionedSchemas,
49
32
  });
50
- node_assert_1.default.equal(result, null, 'Should return null for invalid data');
33
+ strict_1.default.equal(result, null);
51
34
  });
52
- (0, node_test_1.test)('@unit: should throw error if no migration plan exists', () => {
53
- const dataV1 = { input: 'source/path', output: 'generated/path', client: core_1.HttpClient.AXIOS };
54
- node_assert_1.default.throws(() => {
55
- (0, migrateToLatestVersion_1.migrateToLatestVersion)({
56
- rawInput: dataV1,
57
- versionedSchemas: OptionsVersionedSchemas_1.optionsVersionedSchemas,
58
- migrationPlans: [],
59
- });
60
- }, /No migration plan from 1.0.0/, 'Should throw for missing migration plan');
35
+ (0, node_test_1.test)('@unit: It should throw an error if the migration plan is not found.', async () => {
36
+ const input = { input: "input/path", output: "output/path", client: "fetch" };
37
+ strict_1.default.throws(() => (0, migrateDataToLatestSchemaVersion_1.migrateDataToLatestSchemaVersion)({
38
+ rawInput: input,
39
+ migrationPlans: [],
40
+ versionedSchemas: OptionsVersionedSchemas_1.optionsVersionedSchemas,
41
+ }), /No migration plan from 1.0.0/);
61
42
  });
62
43
  });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=replaceInvalidKeysWithMappedNames.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replaceInvalidKeysWithMappedNames.test.d.ts","sourceRoot":"","sources":["../../../src/common/__tests__/replaceInvalidKeysWithMappedNames.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,25 @@
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 replaceInvalidKeysWithMappedNames_1 = require("../VersionedSchema/Utils/replaceInvalidKeysWithMappedNames");
9
+ (0, node_test_1.describe)('replaceInvalidKeysWithMappedNames', () => {
10
+ (0, node_test_1.test)('@unit: must replace invalid keys in the object', async () => {
11
+ const input = { nmae: 'John', title: 'Mr' };
12
+ const keyMap = new Map([['nmae', 'name']]);
13
+ const result = (0, replaceInvalidKeysWithMappedNames_1.replaceInvalidKeysWithMappedNames)(input, keyMap);
14
+ node_assert_1.default.deepEqual(result, { name: 'John', title: 'Mr' });
15
+ });
16
+ (0, node_test_1.test)('@unit: must replace invalid keys in an array of objects', async () => {
17
+ const input = [{ nmae: 'John' }, { nmae: 'Jane' }];
18
+ const keyMap = new Map([['nmae', 'name']]);
19
+ const result = (0, replaceInvalidKeysWithMappedNames_1.replaceInvalidKeysWithMappedNames)(input, keyMap);
20
+ node_assert_1.default.deepEqual(result, [{ name: 'John' }, { name: 'Jane' }]);
21
+ });
22
+ (0, node_test_1.test)('@unit: should throw an error for null or undefined', async () => {
23
+ node_assert_1.default.throws(() => (0, replaceInvalidKeysWithMappedNames_1.replaceInvalidKeysWithMappedNames)(null, new Map()), /The input data cannot be null or undefined./);
24
+ });
25
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=validateAndSuggestKeyCorrections.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateAndSuggestKeyCorrections.test.d.ts","sourceRoot":"","sources":["../../../src/common/__tests__/validateAndSuggestKeyCorrections.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,25 @@
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 validateAndSuggestKeyCorrections_1 = require("../VersionedSchema/Utils/validateAndSuggestKeyCorrections");
9
+ (0, node_test_1.describe)('validateAndSuggestKeyCorrections', () => {
10
+ (0, node_test_1.test)('@unit: should throw an error for unknown keys with a suggestion for correction', async () => {
11
+ const inputKeys = ['nmae'];
12
+ const allowedKeys = new Set(['name', 'title']);
13
+ node_assert_1.default.throws(() => (0, validateAndSuggestKeyCorrections_1.validateAndSuggestKeyCorrections)(inputKeys, allowedKeys), /The "nmae" field is not recognized. Perhaps you meant "name"./);
14
+ });
15
+ (0, node_test_1.test)('@unit: should throw an error without suggestions for keys with a large distance', async () => {
16
+ const inputKeys = ['unknown'];
17
+ const allowedKeys = new Set(['name', 'title']);
18
+ node_assert_1.default.throws(() => (0, validateAndSuggestKeyCorrections_1.validateAndSuggestKeyCorrections)(inputKeys, allowedKeys), /The "unknown" field is not recognized./);
19
+ });
20
+ (0, node_test_1.test)('@unit: should not throw an error for valid keys', async () => {
21
+ const inputKeys = ['name', 'title'];
22
+ const allowedKeys = new Set(['name', 'title']);
23
+ node_assert_1.default.doesNotThrow(() => (0, validateAndSuggestKeyCorrections_1.validateAndSuggestKeyCorrections)(inputKeys, allowedKeys));
24
+ });
25
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"defaultOptions.d.ts","sourceRoot":"","sources":["../../src/common/defaultOptions.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AAGtB,eAAO,MAAM,cAAc,uBAA8B,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().unknown(false);
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);
@@ -1,4 +1,4 @@
1
- import { MultiOptions, Options } from '../common/Options';
1
+ import { TMultiOptions, TOptions } from '../common/Options';
2
2
  export { HttpClient } from './types/Enums';
3
- export declare function generate(options: Options | Options[] | MultiOptions): Promise<void>;
3
+ export declare function generate(options: TOptions | TOptions[] | TMultiOptions): Promise<void>;
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAmB1D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAmH3C,wBAAsB,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,EAAE,GAAG,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAmCzF"}
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"}
@@ -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((op) => (0, prepareOptions_1.prepareOptions)(op));
122
- for (const option of optionsFinal) {
123
- if (option.output) {
124
- await fileSystem_1.fileSystem.rmdir(option.output);
125
- }
126
- if (option.outputCore) {
127
- await fileSystem_1.fileSystem.rmdir(option.outputCore);
128
- }
129
- if (option.outputSchemas) {
130
- await fileSystem_1.fileSystem.rmdir(option.outputSchemas);
131
- }
132
- if (option.outputModels) {
133
- await fileSystem_1.fileSystem.rmdir(option.outputModels);
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
- if (option.outputServices) {
136
- await fileSystem_1.fileSystem.rmdir(option.outputServices);
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
- const writeClient = new writeClient_1.WriteClient();
140
- for (const option of optionsFinal) {
141
- await generateFrom(option, writeClient);
162
+ catch (error) {
163
+ writeClient.logger.error(error.message);
142
164
  }
143
- await writeClient.combineAndWrite();
165
+ writeClient.logger.shutdownLogger();
144
166
  }