ts-openapi-codegen 2.0.0-beta.11 → 2.0.0-beta.12

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/index.js CHANGED
@@ -77,7 +77,7 @@ program
77
77
  await updateNotifier.checkAndNotify();
78
78
  })
79
79
  .action(async (options) => {
80
- await (0, checkConfig_1.checkConfig)(options.openapiConfig);
80
+ await (0, checkConfig_1.checkConfig)(options);
81
81
  });
82
82
  /**
83
83
  * update - Команда для обновления конфигурационного файла
@@ -1,7 +1,7 @@
1
1
  import { SchemaMigrationPlan } from '../Types';
2
2
  /**
3
3
  * Unified migration plan that includes all migrations from all schema types.
4
- * Migrates from any old version to the latest UNIFIED_v1 schema.
4
+ * Migrates from any old version to the latest UNIFIED_OPTIONS_v1 schema.
5
5
  * Reuses existing migration plans to avoid code duplication.
6
6
  */
7
7
  export declare const allMigrationPlans: SchemaMigrationPlan<Record<string, any>, Record<string, any>>[];
@@ -22,26 +22,26 @@ function addVersionPrefixToMigrationPlans(plans, prefix) {
22
22
  }
23
23
  /**
24
24
  * Unified migration plan that includes all migrations from all schema types.
25
- * Migrates from any old version to the latest UNIFIED_v1 schema.
25
+ * Migrates from any old version to the latest UNIFIED_OPTIONS_v1 schema.
26
26
  * Reuses existing migration plans to avoid code duplication.
27
27
  */
28
28
  exports.allMigrationPlans = [
29
29
  // ===== OPTIONS migrations (with prefix) =====
30
30
  ...addVersionPrefixToMigrationPlans(OptionsMigrationPlans_1.optionsMigrationPlans, 'OPTIONS'),
31
31
  // Migration from OPTIONS latest version to UNIFIED v1
32
- (0, createTrivialMigration_1.createTrivialMigration)(`OPTIONS_${(0, getLatestVersionFromMigrationPlans_1.getLatestVersionFromMigrationPlans)(OptionsMigrationPlans_1.optionsMigrationPlans)}`, 'UNIFIED_v1', 'Migrate from OPTIONS to UNIFIED schema'),
32
+ (0, createTrivialMigration_1.createTrivialMigration)(`OPTIONS_${(0, getLatestVersionFromMigrationPlans_1.getLatestVersionFromMigrationPlans)(OptionsMigrationPlans_1.optionsMigrationPlans)}`, 'UNIFIED_OPTIONS_v1', 'Migrate from OPTIONS to UNIFIED schema'),
33
33
  // ===== MULTI_OPTIONS migrations (with prefix) =====
34
34
  ...addVersionPrefixToMigrationPlans(MultiOptionsMigrationPlan_1.multiOptionsMigrationPlan, 'MULTI_OPTIONS'),
35
35
  // Migration from MULTI_OPTIONS latest version to UNIFIED v1
36
- (0, createTrivialMigration_1.createTrivialMigration)(`MULTI_OPTIONS_${(0, getLatestVersionFromMigrationPlans_1.getLatestVersionFromMigrationPlans)(MultiOptionsMigrationPlan_1.multiOptionsMigrationPlan)}`, 'UNIFIED_v1', 'Migrate from MULTI_OPTIONS to UNIFIED schema'),
37
- (0, createFieldTransformationMigration_1.createFieldTransformationMigration)('UNIFIED_v1', 'UNIFIED_v2', ({ includeSchemasFiles, ...otherProps }) => {
36
+ (0, createTrivialMigration_1.createTrivialMigration)(`MULTI_OPTIONS_${(0, getLatestVersionFromMigrationPlans_1.getLatestVersionFromMigrationPlans)(MultiOptionsMigrationPlan_1.multiOptionsMigrationPlan)}`, 'UNIFIED_OPTIONS_v1', 'Migrate from MULTI_OPTIONS to UNIFIED schema'),
37
+ (0, createFieldTransformationMigration_1.createFieldTransformationMigration)('UNIFIED_OPTIONS_v1', 'UNIFIED_OPTIONS_v2', ({ includeSchemasFiles, ...otherProps }) => {
38
38
  return { ...otherProps, validationLibrary: !includeSchemasFiles ? ValidationLibrary_enum_1.ValidationLibrary.NONE : undefined };
39
39
  }, 'Transforms includeSchemasFiles to validationLibrary: if includeSchemasFiles is false, sets validationLibrary to NONE'),
40
- (0, createDefaultFieldsMigration_1.createDefaultFieldsMigration)('UNIFIED_v2', 'UNIFIED_v3', {
40
+ (0, createDefaultFieldsMigration_1.createDefaultFieldsMigration)('UNIFIED_OPTIONS_v2', 'UNIFIED_OPTIONS_v3', {
41
41
  logLevel: Enums_1.ELogLevel.ERROR,
42
42
  logTarget: Enums_1.ELogOutput.CONSOLE
43
43
  }),
44
- (0, createDefaultFieldsMigration_1.createDefaultFieldsMigration)('UNIFIED_v3', 'UNIFIED_v4', {
44
+ (0, createDefaultFieldsMigration_1.createDefaultFieldsMigration)('UNIFIED_OPTIONS_v3', 'UNIFIED_OPTIONS_v4', {
45
45
  emptySchemaStrategy: EmptySchemaStrategy_enum_1.EmptySchemaStrategy.KEEP
46
46
  })
47
47
  ];
@@ -73,3 +73,21 @@ const migrateDataToLatestSchemaVersion_1 = require("../migrateDataToLatestSchema
73
73
  node_assert_1.default.strictEqual(result?.value.httpClient, 'fetch');
74
74
  node_assert_1.default.strictEqual(result?.value.validationLibrary, ValidationLibrary_enum_1.ValidationLibrary.NONE);
75
75
  });
76
+ (0, node_test_1.default)('@unit: migrateDataToLatestSchemaVersion (all schemas: chooses old options branch before unified)', () => {
77
+ const rawInput = {
78
+ input: './spec.json',
79
+ output: './dist',
80
+ httpClient: 'fetch',
81
+ exportCore: true,
82
+ };
83
+ const result = (0, migrateDataToLatestSchemaVersion_1.migrateDataToLatestSchemaVersion)({
84
+ rawInput,
85
+ migrationPlans: AllMigrationPlans_1.allMigrationPlans,
86
+ versionedSchemas: AllVersionedSchemas_1.allVersionedSchemas,
87
+ migrationMode: Enums_1.EMigrationMode.VALIDATE_CONFIG,
88
+ });
89
+ node_assert_1.default.ok(result);
90
+ node_assert_1.default.strictEqual(result?.schemaType, Enums_2.EVersionedSchemaType.UNIFIED_OPTIONS);
91
+ node_assert_1.default.strictEqual(result?.schemaVersion, 'UNIFIED_OPTIONS_v4');
92
+ node_assert_1.default.ok(result?.guessedVersion.latestVersion.startsWith('OPTIONS_'));
93
+ });
@@ -1,4 +1,8 @@
1
1
  import { z } from 'zod';
2
2
  import { VersionedSchema, VersionMatchResult } from '../Types';
3
+ /**
4
+ * Determines the best matching schema version for input data.
5
+ * `invalid_value` issues are intentionally ignored to allow migration from older enum/value variants.
6
+ */
3
7
  export declare function determineBestMatchingSchemaVersion(inputData: Record<string, any>, versionedSchemas: VersionedSchema<z.ZodTypeAny>[]): VersionMatchResult;
4
8
  //# sourceMappingURL=determineBestMatchingSchemaVersion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"determineBestMatchingSchemaVersion.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAK/D,wBAAgB,kCAAkC,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,gBAAgB,EAAE,eAAe,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,GAAG,kBAAkB,CA4CxJ"}
1
+ {"version":3,"file":"determineBestMatchingSchemaVersion.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAiE/D;;;GAGG;AACH,wBAAgB,kCAAkC,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,gBAAgB,EAAE,eAAe,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,GAAG,kBAAkB,CAgDxJ"}
@@ -4,38 +4,83 @@ exports.determineBestMatchingSchemaVersion = determineBestMatchingSchemaVersion;
4
4
  const validateZodOptions_1 = require("../../Validation/validateZodOptions");
5
5
  const getUniqueKeysFromSchemas_1 = require("./getUniqueKeysFromSchemas");
6
6
  const getUniqueObjectKeys_1 = require("./getUniqueObjectKeys");
7
- // Determining the most appropriate schema version
7
+ /**
8
+ * Counts unknown keys using a strict schema variant.
9
+ * The strict check is used only for ranking candidates, not for final validation.
10
+ */
11
+ function getStrictUnrecognizedKeyCount(schema, inputData) {
12
+ const strictResult = (0, validateZodOptions_1.validateZodOptionsRaw)(schema.strict(), inputData);
13
+ if (strictResult.success) {
14
+ return 0;
15
+ }
16
+ return strictResult.error.issues.reduce((count, issue) => {
17
+ if (issue.code !== 'unrecognized_keys' || !('keys' in issue)) {
18
+ return count;
19
+ }
20
+ return count + issue.keys.length;
21
+ }, 0);
22
+ }
23
+ /**
24
+ * Compares two schema candidates and returns the better one.
25
+ * Priority:
26
+ * 1) fewer structural errors;
27
+ * 2) fewer strict-mode unknown keys;
28
+ * 3) more matching keys;
29
+ * 4) newer version inside the same schema family;
30
+ * 5) lower index when schema families differ.
31
+ */
32
+ function compareCandidates(best, current) {
33
+ if (current.structuralErrorCount !== best.structuralErrorCount) {
34
+ return current.structuralErrorCount < best.structuralErrorCount ? current : best;
35
+ }
36
+ if (current.strictUnrecognizedKeyCount !== best.strictUnrecognizedKeyCount) {
37
+ return current.strictUnrecognizedKeyCount < best.strictUnrecognizedKeyCount ? current : best;
38
+ }
39
+ if (current.matchingKeysCount !== best.matchingKeysCount) {
40
+ return current.matchingKeysCount > best.matchingKeysCount ? current : best;
41
+ }
42
+ if (current.type === best.type) {
43
+ return current.index > best.index ? current : best;
44
+ }
45
+ return current.index < best.index ? current : best;
46
+ }
47
+ /**
48
+ * Determines the best matching schema version for input data.
49
+ * `invalid_value` issues are intentionally ignored to allow migration from older enum/value variants.
50
+ */
8
51
  function determineBestMatchingSchemaVersion(inputData, versionedSchemas) {
9
52
  if (!versionedSchemas.length) {
10
53
  throw new Error('The list of schemes cannot be empty');
11
54
  }
12
55
  const inputKeys = (0, getUniqueObjectKeys_1.getUniqueObjectKeys)(inputData);
13
- const matchingSchemas = versionedSchemas
14
- .map(({ schema, version }, idx) => {
56
+ const schemaMatches = versionedSchemas.map(({ schema, baseSchema, version, type }, idx) => {
57
+ const schemaKeys = (0, getUniqueKeysFromSchemas_1.getUniqueKeysFromSchemas)([schema]);
58
+ const matchingKeysCount = inputKeys.filter(key => schemaKeys.has(key)).length;
59
+ const strictUnrecognizedKeyCount = getStrictUnrecognizedKeyCount(baseSchema, inputData);
15
60
  const validationResult = (0, validateZodOptions_1.validateZodOptionsRaw)(schema, inputData);
16
- const errorFields = !validationResult.success ? validationResult.error.issues.filter(err => err.code !== 'invalid_value') : [];
17
- return errorFields.length === 0 ? { version, index: idx } : null;
18
- })
19
- .filter((match) => match !== null);
20
- if (matchingSchemas.length > 0) {
21
- const latestMatch = matchingSchemas.reduce((prev, curr) => (curr.index > prev.index ? curr : prev));
61
+ const structuralErrorCount = !validationResult.success
62
+ ? validationResult.error.issues.filter(issue => issue.code !== 'invalid_value').length
63
+ : 0;
22
64
  return {
23
- lastVersionIndex: latestMatch.index,
24
- latestVersion: latestMatch.version,
25
- firstVersion: matchingSchemas[0].version,
65
+ index: idx,
66
+ version,
67
+ type,
68
+ structuralErrorCount,
69
+ strictUnrecognizedKeyCount,
70
+ matchingKeysCount,
26
71
  };
27
- }
28
- const schemaMatches = versionedSchemas.map(({ schema, version }, idx) => {
29
- const schemaKeys = (0, getUniqueKeysFromSchemas_1.getUniqueKeysFromSchemas)([schema]);
30
- const validationResult = (0, validateZodOptions_1.validateZodOptionsRaw)(schema, inputData);
31
- const errorFields = !validationResult.success ? validationResult.error.issues.filter(err => err.code !== 'invalid_value') : [];
32
- const matchingKeys = inputKeys.filter(key => schemaKeys.has(key));
33
- return { index: idx, version, errorFields, matchingKeys };
34
72
  });
35
- const bestMatch = schemaMatches.reduce((best, current) => {
36
- const isBetterMatch = current.matchingKeys.length >= best.matchingKeys.length && current.errorFields.length <= best.errorFields.length;
37
- return isBetterMatch ? current : best;
38
- }, schemaMatches[0]);
73
+ const structurallyValidMatches = schemaMatches.filter(match => match.structuralErrorCount === 0);
74
+ if (structurallyValidMatches.length > 0) {
75
+ const bestStructurallyValidMatch = structurallyValidMatches.reduce(compareCandidates);
76
+ const firstVersion = structurallyValidMatches.reduce((earliest, current) => (current.index < earliest.index ? current : earliest)).version;
77
+ return {
78
+ lastVersionIndex: bestStructurallyValidMatch.index,
79
+ latestVersion: bestStructurallyValidMatch.version,
80
+ firstVersion,
81
+ };
82
+ }
83
+ const bestMatch = schemaMatches.reduce(compareCandidates);
39
84
  return {
40
85
  lastVersionIndex: bestMatch.index,
41
86
  latestVersion: bestMatch.version,
@@ -2,18 +2,28 @@ import { z } from 'zod';
2
2
  import { EMigrationMode } from '../../Enums';
3
3
  import { EVersionedSchemaType } from '../Enums';
4
4
  import { SchemaMigrationPlan, VersionedSchema, VersionMatchResult } from '../Types';
5
+ /**
6
+ * Input arguments for migrating arbitrary config data to the latest schema version.
7
+ */
5
8
  type MigrateToLatestProps = {
6
9
  rawInput: Record<string, any>;
7
10
  migrationPlans: SchemaMigrationPlan<Record<string, any>, Record<string, any>>[];
8
11
  versionedSchemas: VersionedSchema<z.ZodTypeAny>[];
9
12
  migrationMode: EMigrationMode;
10
13
  };
14
+ /**
15
+ * Result of successful migration to the latest schema.
16
+ */
11
17
  type MigrateToLatestResult = {
12
18
  value: Record<string, any>;
13
19
  guessedVersion: VersionMatchResult;
14
20
  schemaVersion: string;
15
21
  schemaType: EVersionedSchemaType;
16
22
  };
23
+ /**
24
+ * Migrates raw input through the migration graph to the latest schema version.
25
+ * Migration path is resolved by `fromVersion -> toVersion` links from `migrationPlans`.
26
+ */
17
27
  export declare function migrateDataToLatestSchemaVersion({ rawInput, migrationPlans, versionedSchemas, migrationMode }: MigrateToLatestProps): MigrateToLatestResult | null;
18
28
  export {};
19
29
  //# sourceMappingURL=migrateDataToLatestSchemaVersion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"migrateDataToLatestSchemaVersion.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AASpF,KAAK,oBAAoB,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,cAAc,EAAE,mBAAmB,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;IAChF,gBAAgB,EAAE,eAAe,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC;IAClD,aAAa,EAAE,cAAc,CAAC;CACjC,CAAC;AAEF,KAAK,qBAAqB,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,cAAc,EAAE,kBAAkB,CAAC;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,oBAAoB,CAAC;CACpC,CAAC;AAEF,wBAAgB,gCAAgC,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAE,gBAAgB,EAAE,aAAa,EAAE,EAAE,oBAAoB,GAAG,qBAAqB,GAAG,IAAI,CAiElK"}
1
+ {"version":3,"file":"migrateDataToLatestSchemaVersion.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AASpF;;GAEG;AACH,KAAK,oBAAoB,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,cAAc,EAAE,mBAAmB,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;IAChF,gBAAgB,EAAE,eAAe,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC;IAClD,aAAa,EAAE,cAAc,CAAC;CACjC,CAAC;AAEF;;GAEG;AACH,KAAK,qBAAqB,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,cAAc,EAAE,kBAAkB,CAAC;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,oBAAoB,CAAC;CACpC,CAAC;AAEF;;;GAGG;AACH,wBAAgB,gCAAgC,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAE,gBAAgB,EAAE,aAAa,EAAE,EAAE,oBAAoB,GAAG,qBAAqB,GAAG,IAAI,CAoFlK"}
@@ -10,6 +10,10 @@ const getUniqueKeysFromSchemas_1 = require("./getUniqueKeysFromSchemas");
10
10
  const getUniqueObjectKeys_1 = require("./getUniqueObjectKeys");
11
11
  const replaceInvalidKeysWithMappedNames_1 = require("./replaceInvalidKeysWithMappedNames");
12
12
  const validateAndSuggestKeyCorrections_1 = require("./validateAndSuggestKeyCorrections");
13
+ /**
14
+ * Migrates raw input through the migration graph to the latest schema version.
15
+ * Migration path is resolved by `fromVersion -> toVersion` links from `migrationPlans`.
16
+ */
13
17
  function migrateDataToLatestSchemaVersion({ rawInput, migrationPlans, versionedSchemas, migrationMode }) {
14
18
  const schemas = versionedSchemas.map(el => el.schema);
15
19
  const allUniqueKeysFromSchemas = (0, getUniqueKeysFromSchemas_1.getUniqueKeysFromSchemas)(schemas);
@@ -20,33 +24,46 @@ function migrateDataToLatestSchemaVersion({ rawInput, migrationPlans, versionedS
20
24
  const schemaPossibleKeys = (0, getUniqueKeysFromSchemas_1.getUniqueKeysFromSchemas)([guessedValidationSchema]);
21
25
  const replacingKeysMap = (0, generateKeyMappingForInvalidKeys_1.generateKeyMappingForInvalidKeys)(allUniqueKeysFromRawInput, schemaPossibleKeys);
22
26
  let currentData = replacingKeysMap.size ? (0, replaceInvalidKeysWithMappedNames_1.replaceInvalidKeysWithMappedNames)(rawInput, replacingKeysMap) : rawInput;
23
- const actualVersionIndex = versionedSchemas.length - 1;
24
- const actualSchema = versionedSchemas[actualVersionIndex];
25
- for (let idx = guessedVersion.lastVersionIndex; idx < versionedSchemas.length - 1; idx++) {
26
- const currentVersionSchema = versionedSchemas[idx];
27
- const firstValidationResult = (0, validateZodOptions_1.validateZodOptionsRaw)(currentVersionSchema.schema, currentData);
27
+ const actualSchema = versionedSchemas[versionedSchemas.length - 1];
28
+ const schemasByVersion = new Map(versionedSchemas.map(schemaInfo => [schemaInfo.version, schemaInfo.schema]));
29
+ const migrationPlanByFromVersion = new Map(migrationPlans.map(plan => [plan.fromVersion, plan]));
30
+ let currentVersion = guessedVersion.latestVersion;
31
+ const visitedVersions = new Set([currentVersion]);
32
+ while (currentVersion !== actualSchema.version) {
33
+ const currentVersionSchema = schemasByVersion.get(currentVersion);
34
+ if (!currentVersionSchema) {
35
+ throw new Error(`No schema found for version ${currentVersion}.`);
36
+ }
37
+ const firstValidationResult = (0, validateZodOptions_1.validateZodOptionsRaw)(currentVersionSchema, currentData);
28
38
  if (!firstValidationResult.success) {
29
39
  (0, getCurrentErrorMessage_1.getCurrentErrorMessage)(firstValidationResult.error, replacingKeysMap);
30
40
  }
31
- const fromVersion = currentVersionSchema.version;
32
- const migrationPlan = migrationPlans.find(p => p.fromVersion === fromVersion);
41
+ const migrationPlan = migrationPlanByFromVersion.get(currentVersion);
33
42
  if (!migrationPlan) {
34
- const availableVersions = migrationPlans.map(p => p.fromVersion).join(', ');
35
- throw new Error(`No migration plan from ${fromVersion}. ` +
43
+ const availableVersions = Array.from(migrationPlanByFromVersion.keys()).join(', ');
44
+ throw new Error(`No migration plan from ${currentVersion}. ` +
36
45
  `Available migration plans: ${availableVersions}. ` +
37
46
  `This usually means the migration chain is incomplete.`);
38
47
  }
39
- const toVersion = versionedSchemas[idx + 1].version;
48
+ const nextVersion = migrationPlan.toVersion;
49
+ const nextSchema = schemasByVersion.get(nextVersion);
50
+ if (!nextSchema) {
51
+ throw new Error(`Migration plan from ${migrationPlan.fromVersion} points to unknown schema version ${nextVersion}.`);
52
+ }
40
53
  const migratedRaw = migrationPlan.migrate(currentData);
41
- const validationResult = (0, validateZodOptions_1.validateZodOptions)(versionedSchemas[idx + 1].schema, migratedRaw);
54
+ const validationResult = (0, validateZodOptions_1.validateZodOptions)(nextSchema, migratedRaw);
42
55
  if (!validationResult.success) {
43
- throw new Error(`Migration from ${fromVersion} to ${toVersion} failed validation. ` +
56
+ throw new Error(`Migration from ${currentVersion} to ${nextVersion} failed validation. ` +
44
57
  `Error: ${validationResult.errors.join('\n')}. ` +
45
58
  `Migration description: ${migrationPlan.description || 'No description provided'}.`);
46
59
  }
47
60
  currentData = { ...migratedRaw };
48
- const isLastIteration = idx + 1 === actualVersionIndex;
49
- if (isLastIteration && migrationMode === Enums_1.EMigrationMode.GENERATE_OPENAPI) {
61
+ currentVersion = nextVersion;
62
+ if (visitedVersions.has(currentVersion)) {
63
+ throw new Error(`Migration loop detected at version ${currentVersion}.`);
64
+ }
65
+ visitedVersions.add(currentVersion);
66
+ if (currentVersion === actualSchema.version && migrationMode === Enums_1.EMigrationMode.GENERATE_OPENAPI) {
50
67
  console.warn('Для выполнения генерации OpenApi потребовалось мигрировать схему Ваших данных на актуальную. Для обновленмя конфигурации в файле используйте команду `npm name_cli_tool update-config`');
51
68
  }
52
69
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-openapi-codegen",
3
- "version": "2.0.0-beta.11",
3
+ "version": "2.0.0-beta.12",
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",