ts-openapi-codegen 1.0.0-beta.3 → 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.
- package/dist/cli/generate/runGenerateOpenApi.js +3 -3
- package/dist/common/VersionedSchema/Types.d.ts +1 -1
- package/dist/common/VersionedSchema/Types.d.ts.map +1 -1
- package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.d.ts +9 -0
- package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.d.ts.map +1 -0
- package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.js +44 -0
- package/dist/common/VersionedSchema/Utils/generateKeyMappingForInvalidKeys.d.ts +2 -0
- package/dist/common/VersionedSchema/Utils/generateKeyMappingForInvalidKeys.d.ts.map +1 -0
- package/dist/common/VersionedSchema/Utils/generateKeyMappingForInvalidKeys.js +27 -0
- package/dist/common/VersionedSchema/Utils/getErrorFieldsFromValidation.d.ts +6 -0
- package/dist/common/VersionedSchema/Utils/getErrorFieldsFromValidation.d.ts.map +1 -0
- package/dist/common/VersionedSchema/Utils/getErrorFieldsFromValidation.js +7 -0
- package/dist/common/VersionedSchema/Utils/{getUniqueAllShemasKeys.d.ts → getUniqueKeysFromSchemas.d.ts} +3 -3
- package/dist/common/VersionedSchema/Utils/getUniqueKeysFromSchemas.d.ts.map +1 -0
- package/dist/common/VersionedSchema/Utils/{getUniqueAllShemasKeys.js → getUniqueKeysFromSchemas.js} +4 -4
- package/dist/common/VersionedSchema/Utils/getUniqueObjectKeys.js +2 -2
- package/dist/common/VersionedSchema/Utils/joiHandlers.d.ts +3 -3
- package/dist/common/VersionedSchema/Utils/joiHandlers.d.ts.map +1 -1
- package/dist/common/VersionedSchema/Utils/joiHandlers.js +24 -17
- package/dist/common/VersionedSchema/Utils/{migrateToLatestVersion.d.ts → migrateDataToLatestSchemaVersion.d.ts} +5 -5
- package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.d.ts.map +1 -0
- package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.js +43 -0
- package/dist/common/VersionedSchema/Utils/replaceInvalidKeysWithMappedNames.d.ts +2 -0
- package/dist/common/VersionedSchema/Utils/replaceInvalidKeysWithMappedNames.d.ts.map +1 -0
- package/dist/common/VersionedSchema/Utils/replaceInvalidKeysWithMappedNames.js +18 -0
- package/dist/common/VersionedSchema/Utils/traverseObjectStructure.d.ts +3 -0
- package/dist/common/VersionedSchema/Utils/traverseObjectStructure.d.ts.map +1 -0
- package/dist/common/VersionedSchema/Utils/{traverseGeneric.js → traverseObjectStructure.js} +6 -4
- package/dist/common/VersionedSchema/Utils/validateAndSuggestKeyCorrections.d.ts +8 -0
- package/dist/common/VersionedSchema/Utils/validateAndSuggestKeyCorrections.d.ts.map +1 -0
- package/dist/common/VersionedSchema/Utils/validateAndSuggestKeyCorrections.js +44 -0
- package/dist/common/__tests__/__mock__/mockJoiSchema.d.ts +19 -0
- package/dist/common/__tests__/__mock__/mockJoiSchema.d.ts.map +1 -0
- package/dist/common/__tests__/__mock__/mockJoiSchema.js +14 -0
- package/dist/common/__tests__/determineBestMatchingSchemaVersion.test.d.ts +2 -0
- package/dist/common/__tests__/determineBestMatchingSchemaVersion.test.d.ts.map +1 -0
- package/dist/common/__tests__/determineBestMatchingSchemaVersion.test.js +38 -0
- package/dist/common/__tests__/generateKeyMappingForInvalidKeys.test.d.ts +2 -0
- package/dist/common/__tests__/generateKeyMappingForInvalidKeys.test.d.ts.map +1 -0
- package/dist/common/__tests__/generateKeyMappingForInvalidKeys.test.js +22 -0
- package/dist/common/__tests__/getUniqueKeysFromSchemas.test.d.ts +2 -0
- package/dist/common/__tests__/getUniqueKeysFromSchemas.test.d.ts.map +1 -0
- package/dist/common/__tests__/getUniqueKeysFromSchemas.test.js +20 -0
- package/dist/common/__tests__/getUniqueObjectKeys.test.d.ts +2 -0
- package/dist/common/__tests__/getUniqueObjectKeys.test.d.ts.map +1 -0
- package/dist/common/__tests__/getUniqueObjectKeys.test.js +24 -0
- package/dist/common/__tests__/migrationForMultiOptions.test.js +85 -70
- package/dist/common/__tests__/migrationForOptions.test.js +28 -48
- package/dist/common/__tests__/replaceInvalidKeysWithMappedNames.test.d.ts +2 -0
- package/dist/common/__tests__/replaceInvalidKeysWithMappedNames.test.d.ts.map +1 -0
- package/dist/common/__tests__/replaceInvalidKeysWithMappedNames.test.js +25 -0
- package/dist/common/__tests__/validateAndSuggestKeyCorrections.test.d.ts +2 -0
- package/dist/common/__tests__/validateAndSuggestKeyCorrections.test.d.ts.map +1 -0
- package/dist/common/__tests__/validateAndSuggestKeyCorrections.test.js +25 -0
- package/package.json +1 -1
- package/dist/common/VersionedSchema/Utils/getUniqueAllShemasKeys.d.ts.map +0 -1
- package/dist/common/VersionedSchema/Utils/guessVersion.d.ts +0 -3
- package/dist/common/VersionedSchema/Utils/guessVersion.d.ts.map +0 -1
- package/dist/common/VersionedSchema/Utils/guessVersion.js +0 -16
- package/dist/common/VersionedSchema/Utils/migrateToLatestVersion.d.ts.map +0 -1
- package/dist/common/VersionedSchema/Utils/migrateToLatestVersion.js +0 -34
- package/dist/common/VersionedSchema/Utils/traverseGeneric.d.ts +0 -3
- package/dist/common/VersionedSchema/Utils/traverseGeneric.d.ts.map +0 -1
- package/dist/common/VersionedSchema/Utils/validateUnknownKeys.d.ts +0 -2
- package/dist/common/VersionedSchema/Utils/validateUnknownKeys.d.ts.map +0 -1
- package/dist/common/VersionedSchema/Utils/validateUnknownKeys.js +0 -32
- package/dist/common/__tests__/guessVersion.test.d.ts +0 -2
- package/dist/common/__tests__/guessVersion.test.d.ts.map +0 -1
- package/dist/common/__tests__/guessVersion.test.js +0 -26
|
@@ -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 @@
|
|
|
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,85 +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
|
|
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
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const expectedDataMultiV3 = {
|
|
22
|
-
httpClient: core_1.HttpClient.AXIOS,
|
|
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
|
-
],
|
|
27
|
-
useCancelableRequest: false,
|
|
28
|
-
};
|
|
29
|
-
const result = (0, migrateToLatestVersion_1.migrateToLatestVersion)({
|
|
30
|
-
rawInput: dataMultiV1,
|
|
31
|
-
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,
|
|
32
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,
|
|
33
38
|
});
|
|
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');
|
|
35
39
|
});
|
|
36
|
-
(0, node_test_1.test)('@unit: should
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
httpClient: core_1.HttpClient.FETCH,
|
|
41
|
-
items: [{ input: 'item1' }, { input: 'item2' }],
|
|
42
|
-
};
|
|
43
|
-
const expectedDataMultiV3 = {
|
|
44
|
-
httpClient: core_1.HttpClient.FETCH,
|
|
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
|
-
],
|
|
49
|
-
};
|
|
50
|
-
const result = (0, migrateToLatestVersion_1.migrateToLatestVersion)({
|
|
51
|
-
rawInput: dataMultiV2,
|
|
52
|
-
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,
|
|
53
44
|
migrationPlans: MultiOptionsMigrationPlan_1.multiOptionsMigrationPlan,
|
|
45
|
+
versionedSchemas: MultiOptionsVersionedSchemas_1.multiOptionsVersionedSchema,
|
|
54
46
|
});
|
|
55
|
-
|
|
47
|
+
strict_1.default.equal(result, null);
|
|
56
48
|
});
|
|
57
|
-
(0, node_test_1.test)('@unit: should throw error if
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
};
|
|
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');
|
|
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: [],
|
|
54
|
+
versionedSchemas: MultiOptionsVersionedSchemas_1.multiOptionsVersionedSchema,
|
|
55
|
+
}), /No migration plan from 1.0.0/);
|
|
71
56
|
});
|
|
72
|
-
(0, node_test_1.test)('@unit: should throw error
|
|
73
|
-
const
|
|
74
|
-
input: '
|
|
75
|
-
output: '
|
|
76
|
-
client: '
|
|
77
|
-
items: [{ input: 'item1'
|
|
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' }],
|
|
78
63
|
};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
+
});
|
|
86
101
|
});
|
|
87
102
|
});
|
|
@@ -3,61 +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
|
|
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
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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,
|
|
18
|
+
versionedSchemas: OptionsVersionedSchemas_1.optionsVersionedSchemas,
|
|
19
|
+
});
|
|
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,
|
|
26
24
|
});
|
|
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
25
|
});
|
|
29
|
-
(0, node_test_1.test)('@unit: should
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
output: 'generated/path',
|
|
34
|
-
httpClient: core_1.HttpClient.FETCH,
|
|
35
|
-
};
|
|
36
|
-
const result = (0, migrateToLatestVersion_1.migrateToLatestVersion)({
|
|
37
|
-
rawInput: dataV2,
|
|
38
|
-
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,
|
|
39
30
|
migrationPlans: OptionsMigrationPlans_1.optionsMigrationPlans,
|
|
31
|
+
versionedSchemas: OptionsVersionedSchemas_1.optionsVersionedSchemas,
|
|
40
32
|
});
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
(0, node_test_1.test)('@unit: should throw error if not conform any known version schema', () => {
|
|
44
|
-
const dataV1 = { input: 'source/path', output: 'generated/path', client: 'invalid-client' };
|
|
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');
|
|
33
|
+
strict_1.default.equal(result, null);
|
|
52
34
|
});
|
|
53
|
-
(0, node_test_1.test)('@unit: should throw error if
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
});
|
|
61
|
-
}, /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/);
|
|
62
42
|
});
|
|
63
43
|
});
|
|
@@ -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 @@
|
|
|
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
|
+
});
|
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.4",
|
|
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",
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"guessVersion.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/guessVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEzD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,EAAE,eAAe,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,gBAgB1G"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.guessVersion = guessVersion;
|
|
4
|
-
function guessVersion(rawInput, schemas) {
|
|
5
|
-
const matchesSchemas = schemas
|
|
6
|
-
.map((vs, idx) => {
|
|
7
|
-
const { error } = vs.schema.validate(rawInput, { allowUnknown: true });
|
|
8
|
-
return error ? null : { version: vs.version, index: idx };
|
|
9
|
-
})
|
|
10
|
-
.filter(it => it !== null);
|
|
11
|
-
if (matchesSchemas.length === 0) {
|
|
12
|
-
throw new Error('Data does not conform to any known version schema');
|
|
13
|
-
}
|
|
14
|
-
const latestVersion = matchesSchemas.reduce((a, b) => (a.index > b.index ? a : b));
|
|
15
|
-
return latestVersion;
|
|
16
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.migrateToLatestVersion = migrateToLatestVersion;
|
|
4
|
-
const getUniqueAllShemasKeys_1 = require("./getUniqueAllShemasKeys");
|
|
5
|
-
const getUniqueObjectKeys_1 = require("./getUniqueObjectKeys");
|
|
6
|
-
const guessVersion_1 = require("./guessVersion");
|
|
7
|
-
const validateUnknownKeys_1 = require("./validateUnknownKeys");
|
|
8
|
-
function migrateToLatestVersion({ rawInput, migrationPlans, versionedSchemas }) {
|
|
9
|
-
let currentData = rawInput;
|
|
10
|
-
const schemas = versionedSchemas.map(el => el.schema);
|
|
11
|
-
const allRawInputKeys = (0, getUniqueObjectKeys_1.getUniqueObjectKeys)(rawInput);
|
|
12
|
-
const allSchemasKeys = (0, getUniqueAllShemasKeys_1.getUniqueAllShemasKeys)(schemas);
|
|
13
|
-
(0, validateUnknownKeys_1.validateUnknownKeys)(allRawInputKeys, allSchemasKeys);
|
|
14
|
-
const guessed = (0, guessVersion_1.guessVersion)(rawInput, versionedSchemas);
|
|
15
|
-
for (let idx = guessed.index; idx < versionedSchemas.length - 1; idx++) {
|
|
16
|
-
const fromVersion = versionedSchemas[idx].version;
|
|
17
|
-
const migrationPlan = migrationPlans.find(p => p.fromVersion === fromVersion);
|
|
18
|
-
if (!migrationPlan) {
|
|
19
|
-
throw new Error(`No migration plan from ${fromVersion}`);
|
|
20
|
-
}
|
|
21
|
-
const migratedRaw = migrationPlan.migrate(currentData);
|
|
22
|
-
const { error } = versionedSchemas[idx + 1].schema.validate(migratedRaw, { allowUnknown: false });
|
|
23
|
-
if (error) {
|
|
24
|
-
if (error)
|
|
25
|
-
throw new Error(`Error during post-migration validation ${fromVersion}->${migrationPlan.toVersion}: ${error.message}`);
|
|
26
|
-
}
|
|
27
|
-
currentData = { ...migratedRaw };
|
|
28
|
-
}
|
|
29
|
-
const currentSchema = versionedSchemas[versionedSchemas.length - 1];
|
|
30
|
-
const { error, value } = currentSchema.schema.validate(currentData);
|
|
31
|
-
if (error)
|
|
32
|
-
return null;
|
|
33
|
-
return { value, schemaVersion: currentSchema.version, schemaType: currentSchema.type };
|
|
34
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"traverseGeneric.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/traverseGeneric.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,wBAAgB,eAAe,CAC7B,IAAI,EAAE,GAAG,EACT,QAAQ,EAAE,eAAe,EAAE,EAC3B,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,QA2BpB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validateUnknownKeys.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/validateUnknownKeys.ts"],"names":[],"mappings":"AAEA,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,QAyB/E"}
|
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
exports.validateUnknownKeys = validateUnknownKeys;
|
|
7
|
-
const leven_1 = __importDefault(require("leven"));
|
|
8
|
-
function validateUnknownKeys(rawInputKeys, allowed) {
|
|
9
|
-
const errors = [];
|
|
10
|
-
for (const key of rawInputKeys) {
|
|
11
|
-
if (!allowed.has(key)) {
|
|
12
|
-
let bestMatch = null;
|
|
13
|
-
let bestDistance = Infinity;
|
|
14
|
-
for (const candidate of allowed) {
|
|
15
|
-
const d = (0, leven_1.default)(key, candidate);
|
|
16
|
-
if (d < bestDistance) {
|
|
17
|
-
bestDistance = d;
|
|
18
|
-
bestMatch = candidate;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
if (bestMatch && bestDistance <= 3) {
|
|
22
|
-
errors.push(`The "${key}" field is not recognized. Perhaps you meant "${bestMatch}".`);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
errors.push(`The "${key}" field is not recognized.`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
if (errors.length) {
|
|
30
|
-
throw new Error(errors.join('\n'));
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"guessVersion.test.d.ts","sourceRoot":"","sources":["../../../src/common/__tests__/guessVersion.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,26 +0,0 @@
|
|
|
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 OptionsVersionedSchemas_1 = require("common/VersionedSchema/OptionsVersionedSchemas");
|
|
9
|
-
const core_1 = require("../../core");
|
|
10
|
-
const guessVersion_1 = require("../VersionedSchema/Utils/guessVersion");
|
|
11
|
-
(0, node_test_1.describe)('guessVersion', () => {
|
|
12
|
-
(0, node_test_1.test)('@unit: should correctly identify version for 1.0.0 data', () => {
|
|
13
|
-
const dataV1 = { input: 'source/path', output: 'generated/path', client: core_1.HttpClient.AXIOS };
|
|
14
|
-
const result = (0, guessVersion_1.guessVersion)(dataV1, OptionsVersionedSchemas_1.optionsVersionedSchemas);
|
|
15
|
-
node_assert_1.default.deepEqual(result, { version: '1.0.0', index: 0 }, 'Should detect 1.0.0 schema');
|
|
16
|
-
});
|
|
17
|
-
(0, node_test_1.test)('@unit: should correctly identify version for 2.0.0 data', () => {
|
|
18
|
-
const dataV2 = { input: 'source/path', output: 'generated/path', httpClient: core_1.HttpClient.FETCH };
|
|
19
|
-
const result = (0, guessVersion_1.guessVersion)(dataV2, OptionsVersionedSchemas_1.optionsVersionedSchemas);
|
|
20
|
-
node_assert_1.default.deepEqual(result, { version: '2.0.0', index: 2 }, 'Should detect 2.0.0 schema');
|
|
21
|
-
});
|
|
22
|
-
(0, node_test_1.test)('@unit: should throw error for data matching no schemas', () => {
|
|
23
|
-
const invalidData = { input: 'source/path', output: 'generated/path', unknownField: 'value' };
|
|
24
|
-
node_assert_1.default.throws(() => (0, guessVersion_1.guessVersion)(invalidData, OptionsVersionedSchemas_1.optionsVersionedSchemas), /Data does not conform to any known version schema/, 'Should throw for invalid data');
|
|
25
|
-
});
|
|
26
|
-
});
|