ts-openapi-codegen 2.0.0-beta.10 → 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.
Files changed (81) hide show
  1. package/README.md +2 -0
  2. package/README.rus.md +2 -2
  3. package/dist/cli/index.js +3 -1
  4. package/dist/common/Consts.d.ts.map +1 -1
  5. package/dist/common/Consts.js +3 -1
  6. package/dist/common/VersionedSchema/AllVersionedSchemas/AllMigrationPlans.d.ts +1 -1
  7. package/dist/common/VersionedSchema/AllVersionedSchemas/AllMigrationPlans.d.ts.map +1 -1
  8. package/dist/common/VersionedSchema/AllVersionedSchemas/AllMigrationPlans.js +14 -4
  9. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV1.d.ts +2 -2
  10. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV2.d.ts +2 -2
  11. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV3.d.ts +2 -2
  12. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV4.d.ts +42 -0
  13. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV4.d.ts.map +1 -0
  14. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV4.js +41 -0
  15. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedVersionedSchemas.d.ts +6 -4
  16. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedVersionedSchemas.d.ts.map +1 -1
  17. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedVersionedSchemas.js +7 -1
  18. package/dist/common/VersionedSchema/CommonSchemas.d.ts +12 -4
  19. package/dist/common/VersionedSchema/CommonSchemas.d.ts.map +1 -1
  20. package/dist/common/VersionedSchema/CommonSchemas.js +15 -7
  21. package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsSchemaV1.d.ts +2 -2
  22. package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsSchemaV4.d.ts +2 -2
  23. package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsSchemaV5.d.ts +2 -2
  24. package/dist/common/VersionedSchema/OptionsVersioned/OptionsSchemaV1.d.ts +2 -2
  25. package/dist/common/VersionedSchema/OptionsVersioned/OptionsSchemaV4.d.ts +2 -2
  26. package/dist/common/VersionedSchema/Utils/__mocks__/compatibilityCases.d.ts.map +1 -1
  27. package/dist/common/VersionedSchema/Utils/__mocks__/compatibilityCases.js +6 -0
  28. package/dist/common/VersionedSchema/Utils/__tests__/migrateDataToLatestSchemaVersion.test.js +19 -1
  29. package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.d.ts +4 -0
  30. package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.d.ts.map +1 -1
  31. package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.js +68 -23
  32. package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.d.ts +10 -0
  33. package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.d.ts.map +1 -1
  34. package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.js +31 -14
  35. package/dist/common/defaultOptions.d.ts.map +1 -1
  36. package/dist/common/defaultOptions.js +2 -0
  37. package/dist/common/utils/__tests__/convertArrayToObject.test.js +10 -5
  38. package/dist/common/utils/convertArrayToObject.d.ts.map +1 -1
  39. package/dist/common/utils/convertArrayToObject.js +1 -0
  40. package/dist/core/OpenApiClient.d.ts.map +1 -1
  41. package/dist/core/OpenApiClient.js +7 -1
  42. package/dist/core/WriteClient.d.ts +7 -1
  43. package/dist/core/WriteClient.d.ts.map +1 -1
  44. package/dist/core/WriteClient.js +44 -7
  45. package/dist/core/__tests__/WriteClient.test.js +2 -0
  46. package/dist/core/types/enums/EmptySchemaStrategy.enum.d.ts +6 -0
  47. package/dist/core/types/enums/EmptySchemaStrategy.enum.d.ts.map +1 -0
  48. package/dist/core/types/enums/EmptySchemaStrategy.enum.js +9 -0
  49. package/dist/core/utils/__tests__/writeClientSchemas.test.js +2 -0
  50. package/dist/core/utils/precompileTemplates.js +1 -0
  51. package/dist/core/utils/registerHandlebarHelpers.d.ts.map +1 -1
  52. package/dist/core/utils/registerHandlebarHelpers.js +25 -0
  53. package/dist/core/utils/writeClientSchemas.d.ts +4 -1
  54. package/dist/core/utils/writeClientSchemas.d.ts.map +1 -1
  55. package/dist/core/utils/writeClientSchemas.js +11 -2
  56. package/dist/templatesCompiled/client/joi/exportSchema.js +2 -2
  57. package/dist/templatesCompiled/client/joi/partials/joiSchemaInterface.d.ts +5 -3
  58. package/dist/templatesCompiled/client/joi/partials/joiSchemaInterface.d.ts.map +1 -1
  59. package/dist/templatesCompiled/client/joi/partials/joiSchemaInterface.js +36 -9
  60. package/dist/templatesCompiled/client/jsonschema/exportSchema.js +2 -2
  61. package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaInterface.d.ts +3 -1
  62. package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaInterface.d.ts.map +1 -1
  63. package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaInterface.js +43 -13
  64. package/dist/templatesCompiled/client/yup/exportSchema.js +2 -2
  65. package/dist/templatesCompiled/client/yup/partials/yupSchemaInterface.d.ts +5 -3
  66. package/dist/templatesCompiled/client/yup/partials/yupSchemaInterface.d.ts.map +1 -1
  67. package/dist/templatesCompiled/client/yup/partials/yupSchemaInterface.js +36 -9
  68. package/dist/templatesCompiled/client/zod/exportSchema.js +2 -2
  69. package/dist/templatesCompiled/client/zod/partials/zodSchemaArray.d.ts +5 -6
  70. package/dist/templatesCompiled/client/zod/partials/zodSchemaArray.d.ts.map +1 -1
  71. package/dist/templatesCompiled/client/zod/partials/zodSchemaArray.js +14 -28
  72. package/dist/templatesCompiled/client/zod/partials/zodSchemaComposition.d.ts +3 -0
  73. package/dist/templatesCompiled/client/zod/partials/zodSchemaComposition.d.ts.map +1 -1
  74. package/dist/templatesCompiled/client/zod/partials/zodSchemaComposition.js +28 -4
  75. package/dist/templatesCompiled/client/zod/partials/zodSchemaDictionary.d.ts +3 -4
  76. package/dist/templatesCompiled/client/zod/partials/zodSchemaDictionary.d.ts.map +1 -1
  77. package/dist/templatesCompiled/client/zod/partials/zodSchemaDictionary.js +9 -23
  78. package/dist/templatesCompiled/client/zod/partials/zodSchemaInterface.d.ts +4 -2
  79. package/dist/templatesCompiled/client/zod/partials/zodSchemaInterface.d.ts.map +1 -1
  80. package/dist/templatesCompiled/client/zod/partials/zodSchemaInterface.js +15 -4
  81. package/package.json +1 -1
@@ -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
  }
@@ -1 +1 @@
1
- {"version":3,"file":"defaultOptions.d.ts","sourceRoot":"","sources":["../../src/common/defaultOptions.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AAKtB,eAAO,MAAM,cAAc,uBAuBV,CAAC"}
1
+ {"version":3,"file":"defaultOptions.d.ts","sourceRoot":"","sources":["../../src/common/defaultOptions.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AAMtB,eAAO,MAAM,cAAc,uBAwBV,CAAC"}
@@ -5,6 +5,7 @@ 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
+ const EmptySchemaStrategy_enum_1 = require("../core/types/enums/EmptySchemaStrategy.enum");
8
9
  const HttpClient_enum_1 = require("../core/types/enums/HttpClient.enum");
9
10
  const ValidationLibrary_enum_1 = require("../core/types/enums/ValidationLibrary.enum");
10
11
  exports.defaultOptions = joi_1.default.object({
@@ -25,4 +26,5 @@ exports.defaultOptions = joi_1.default.object({
25
26
  useCancelableRequest: joi_1.default.boolean().optional(),
26
27
  useSeparatedIndexes: joi_1.default.boolean().optional(),
27
28
  validationLibrary: joi_1.default.string().valid(...Object.values(ValidationLibrary_enum_1.ValidationLibrary)).optional(),
29
+ emptySchemaStrategy: joi_1.default.string().valid(...Object.values(EmptySchemaStrategy_enum_1.EmptySchemaStrategy)).optional(),
28
30
  }).unknown(false);
@@ -53,7 +53,8 @@ const convertArrayToObject_1 = require("../convertArrayToObject");
53
53
  useOptions: true,
54
54
  useSeparatedIndexes: undefined,
55
55
  useUnionTypes: undefined,
56
- validationLibrary: undefined
56
+ validationLibrary: undefined,
57
+ emptySchemaStrategy: undefined,
57
58
  };
58
59
  const result = (0, convertArrayToObject_1.convertArrayToObject)(input);
59
60
  node_assert_1.default.deepStrictEqual(result, expected);
@@ -95,7 +96,8 @@ const convertArrayToObject_1 = require("../convertArrayToObject");
95
96
  useOptions: true,
96
97
  useSeparatedIndexes: undefined,
97
98
  useUnionTypes: undefined,
98
- validationLibrary: undefined
99
+ validationLibrary: undefined,
100
+ emptySchemaStrategy: undefined,
99
101
  };
100
102
  const result = (0, convertArrayToObject_1.convertArrayToObject)(input);
101
103
  node_assert_1.default.deepStrictEqual(result, expected);
@@ -137,7 +139,8 @@ const convertArrayToObject_1 = require("../convertArrayToObject");
137
139
  useOptions: true,
138
140
  useSeparatedIndexes: undefined,
139
141
  useUnionTypes: undefined,
140
- validationLibrary: undefined
142
+ validationLibrary: undefined,
143
+ emptySchemaStrategy: undefined,
141
144
  };
142
145
  const result = (0, convertArrayToObject_1.convertArrayToObject)(input);
143
146
  node_assert_1.default.deepStrictEqual(result, expected);
@@ -179,7 +182,8 @@ const convertArrayToObject_1 = require("../convertArrayToObject");
179
182
  useOptions: undefined,
180
183
  useSeparatedIndexes: undefined,
181
184
  useUnionTypes: undefined,
182
- validationLibrary: undefined
185
+ validationLibrary: undefined,
186
+ emptySchemaStrategy: undefined,
183
187
  };
184
188
  const result = (0, convertArrayToObject_1.convertArrayToObject)(input);
185
189
  node_assert_1.default.deepStrictEqual(result, expected);
@@ -221,7 +225,8 @@ const convertArrayToObject_1 = require("../convertArrayToObject");
221
225
  useOptions: undefined,
222
226
  useSeparatedIndexes: undefined,
223
227
  useUnionTypes: undefined,
224
- validationLibrary: undefined
228
+ validationLibrary: undefined,
229
+ emptySchemaStrategy: undefined,
225
230
  };
226
231
  const result = (0, convertArrayToObject_1.convertArrayToObject)(input);
227
232
  node_assert_1.default.deepStrictEqual(result, expected);
@@ -1 +1 @@
1
- {"version":3,"file":"convertArrayToObject.d.ts","sourceRoot":"","sources":["../../../src/common/utils/convertArrayToObject.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CA2DxH"}
1
+ {"version":3,"file":"convertArrayToObject.d.ts","sourceRoot":"","sources":["../../../src/common/utils/convertArrayToObject.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CA4DxH"}
@@ -40,6 +40,7 @@ function convertArrayToObject(optionsArr) {
40
40
  'sortByRequired',
41
41
  'useSeparatedIndexes',
42
42
  'validationLibrary',
43
+ 'emptySchemaStrategy',
43
44
  ];
44
45
  const extractedFields = fieldsToExtract.reduce((acc, field) => ({
45
46
  ...acc,
@@ -1 +1 @@
1
- {"version":3,"file":"OpenApiClient.d.ts","sourceRoot":"","sources":["../../src/core/OpenApiClient.ts"],"names":[],"mappings":"AAGA,OAAO,EAAgB,WAAW,EAAsB,MAAM,uBAAuB,CAAC;AAetF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,qBAAa,aAAa;IACtB,OAAO,CAAC,YAAY,CAA4B;IAEhD,IAAW,WAAW,gBAKrB;IAED,OAAO,CAAC,gBAAgB;IAmDxB,OAAO,CAAC,gBAAgB;YA0BV,sBAAsB;YAUtB,oBAAoB;YAmCpB,cAAc;IAkFtB,QAAQ,CAAC,UAAU,EAAE,WAAW;CAWzC"}
1
+ {"version":3,"file":"OpenApiClient.d.ts","sourceRoot":"","sources":["../../src/core/OpenApiClient.ts"],"names":[],"mappings":"AAGA,OAAO,EAAgB,WAAW,EAAsB,MAAM,uBAAuB,CAAC;AAgBtF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,qBAAa,aAAa;IACtB,OAAO,CAAC,YAAY,CAA4B;IAEhD,IAAW,WAAW,gBAKrB;IAED,OAAO,CAAC,gBAAgB;IAqDxB,OAAO,CAAC,gBAAgB;YA2BV,sBAAsB;YAUtB,oBAAoB;YAmCpB,cAAc;IAqFtB,QAAQ,CAAC,UAAU,EAAE,WAAW;CAWzC"}
@@ -9,6 +9,7 @@ const pathHelpers_1 = require("../common/utils/pathHelpers");
9
9
  const Parser_1 = require("./api/v2/Parser");
10
10
  const Parser_2 = require("./api/v3/Parser");
11
11
  const Context_1 = require("./Context");
12
+ const EmptySchemaStrategy_enum_1 = require("./types/enums/EmptySchemaStrategy.enum");
12
13
  const ValidationLibrary_enum_1 = require("./types/enums/ValidationLibrary.enum");
13
14
  const getOpenApiSpec_1 = require("./utils/getOpenApiSpec");
14
15
  const getOpenApiVersion_1 = require("./utils/getOpenApiVersion");
@@ -44,6 +45,7 @@ class OpenApiClient {
44
45
  sortByRequired: rawOptions.sortByRequired,
45
46
  useSeparatedIndexes: rawOptions.useSeparatedIndexes,
46
47
  validationLibrary: rawOptions.validationLibrary,
48
+ emptySchemaStrategy: rawOptions.emptySchemaStrategy,
47
49
  }));
48
50
  }
49
51
  else {
@@ -71,6 +73,7 @@ class OpenApiClient {
71
73
  sortByRequired: rawOptions.sortByRequired,
72
74
  useSeparatedIndexes: rawOptions.useSeparatedIndexes,
73
75
  validationLibrary: rawOptions.validationLibrary,
76
+ emptySchemaStrategy: rawOptions.emptySchemaStrategy,
74
77
  },
75
78
  ];
76
79
  }
@@ -98,6 +101,7 @@ class OpenApiClient {
98
101
  sortByRequired: item.sortByRequired ?? Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.sortByRequired,
99
102
  useSeparatedIndexes: item.useSeparatedIndexes ?? Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.useSeparatedIndexes,
100
103
  validationLibrary: item.validationLibrary ?? Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.validationLibrary,
104
+ emptySchemaStrategy: item.emptySchemaStrategy ?? Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.emptySchemaStrategy,
101
105
  };
102
106
  }
103
107
  async cleanOutputDirectories(option) {
@@ -142,7 +146,7 @@ class OpenApiClient {
142
146
  this.writeClient.logger.shutdownLogger();
143
147
  }
144
148
  async generateSingle(item) {
145
- const { input, output, outputCore, outputServices, outputModels, outputSchemas, httpClient, useOptions, useUnionTypes, excludeCoreServiceFiles, request, interfacePrefix, enumPrefix, typePrefix, useCancelableRequest, sortByRequired, useSeparatedIndexes, validationLibrary = ValidationLibrary_enum_1.ValidationLibrary.NONE, } = item;
149
+ const { input, output, outputCore, outputServices, outputModels, outputSchemas, httpClient, useOptions, useUnionTypes, excludeCoreServiceFiles, request, interfacePrefix, enumPrefix, typePrefix, useCancelableRequest, sortByRequired, useSeparatedIndexes, validationLibrary = ValidationLibrary_enum_1.ValidationLibrary.NONE, emptySchemaStrategy = EmptySchemaStrategy_enum_1.EmptySchemaStrategy.KEEP, } = item;
146
150
  const outputPaths = (0, getOutputPaths_1.getOutputPaths)({
147
151
  output,
148
152
  outputCore,
@@ -178,6 +182,7 @@ class OpenApiClient {
178
182
  useCancelableRequest,
179
183
  useSeparatedIndexes,
180
184
  validationLibrary,
185
+ emptySchemaStrategy,
181
186
  });
182
187
  break;
183
188
  }
@@ -197,6 +202,7 @@ class OpenApiClient {
197
202
  useCancelableRequest,
198
203
  useSeparatedIndexes,
199
204
  validationLibrary,
205
+ emptySchemaStrategy,
200
206
  });
201
207
  break;
202
208
  }
@@ -1,9 +1,11 @@
1
1
  import { Logger } from '../common/Logger';
2
2
  import { OutputPaths } from './types/base/OutputPaths.model';
3
3
  import { Templates } from './types/base/Templates.model';
4
+ import { EmptySchemaStrategy } from './types/enums/EmptySchemaStrategy.enum';
4
5
  import { HttpClient } from './types/enums/HttpClient.enum';
5
6
  import { ValidationLibrary } from './types/enums/ValidationLibrary.enum';
6
7
  import type { Client } from './types/shared/Client.model';
8
+ import type { Model } from './types/shared/Model.model';
7
9
  import { writeClientCore } from './utils/writeClientCore';
8
10
  import { writeClientCoreIndex } from './utils/writeClientCoreIndex';
9
11
  import { writeClientExecutor } from './utils/writeClientExecutor';
@@ -40,8 +42,11 @@ type TWriteClientProps = {
40
42
  useCancelableRequest?: boolean;
41
43
  useSeparatedIndexes?: boolean;
42
44
  validationLibrary?: ValidationLibrary;
45
+ emptySchemaStrategy: EmptySchemaStrategy;
46
+ };
47
+ type TAPIClientGeneratorConfig = Omit<TWriteClientProps, 'httpClient' | 'useOptions' | 'request' | 'useCancelableRequest' | 'useSeparatedIndexes'> & {
48
+ schemaModels: Model[];
43
49
  };
44
- type TAPIClientGeneratorConfig = Omit<TWriteClientProps, 'httpClient' | 'useOptions' | 'request' | 'useCancelableRequest' | 'useSeparatedIndexes'>;
45
50
  /**
46
51
  * The client which is writing all items and keep the parameters to write index file
47
52
  */
@@ -53,6 +58,7 @@ export declare class WriteClient {
53
58
  * Write our OpenAPI client, using the given templates at the given output
54
59
  */
55
60
  writeClient(options: TWriteClientProps): Promise<void>;
61
+ private writeModelsAndFinalize;
56
62
  /**
57
63
  * Method keeps all options that is need to create index file
58
64
  * @param config
@@ -1 +1 @@
1
- {"version":3,"file":"WriteClient.d.ts","sourceRoot":"","sources":["../../src/core/WriteClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,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B,CAAC,EAAE,OAAO,CAAC;IAC9B,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,mBAAmB,EAAE,mBAAmB,CAAC;CAC5C,CAAC;AAEF,KAAK,yBAAyB,GAAG,IAAI,CAAC,iBAAiB,EAAE,YAAY,GAAG,YAAY,GAAG,SAAS,GAAG,sBAAsB,GAAG,qBAAqB,CAAC,GAAG;IACjJ,YAAY,EAAE,KAAK,EAAE,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,qBAAa,WAAW;IACpB,OAAO,CAAC,MAAM,CAAuD;IACrE,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,CAAC,EAAE,MAAM;IAU3B;;OAEG;IACG,WAAW,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;YAkH9C,sBAAsB;IA+BpC;;;OAGG;IACH,6BAA6B,CAAC,MAAM,EAAE,yBAAyB;IAUzD,eAAe;IAKf,sBAAsB;IAK5B,IAAW,MAAM,WAEhB;IAED,OAAO,CAAC,yBAAyB;IAyCjC,OAAO,CAAC,mBAAmB;YA4Db,gBAAgB;YAUhB,uBAAuB;IAMrC,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,iBAAiB;IAezB,OAAO,CAAC,uBAAuB;IAe/B,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,aAAa;IAId,eAAe,yBAAmB;IAClC,oBAAoB,8BAAwB;IAC5C,oBAAoB,8BAAwB;IAC5C,iBAAiB,2BAAqB;IACtC,sBAAsB,gCAA0B;IAChD,kBAAkB,4BAAsB;IACxC,uBAAuB,iCAA2B;IAClD,mBAAmB,6BAAuB;IAC1C,wBAAwB,kCAA4B;IACpD,sBAAsB,gCAA0B;IAChD,mBAAmB,6BAAuB;CACpD"}
@@ -39,7 +39,7 @@ class WriteClient {
39
39
  * Write our OpenAPI client, using the given templates at the given output
40
40
  */
41
41
  async writeClient(options) {
42
- const { client, templates, outputPaths, httpClient, useOptions, useUnionTypes, excludeCoreServiceFiles = false, request, useCancelableRequest = false, useSeparatedIndexes = false, validationLibrary = ValidationLibrary_enum_1.ValidationLibrary.NONE, } = options;
42
+ const { client, templates, outputPaths, httpClient, useOptions, useUnionTypes, excludeCoreServiceFiles = false, request, useCancelableRequest = false, useSeparatedIndexes = false, validationLibrary = ValidationLibrary_enum_1.ValidationLibrary.NONE, emptySchemaStrategy, } = options;
43
43
  if (!excludeCoreServiceFiles) {
44
44
  const executorPath = (0, pathHelpers_1.resolveHelper)(outputPaths.outputCore, 'executor');
45
45
  const interceptorsPath = (0, pathHelpers_1.resolveHelper)(outputPaths.outputCore, 'interceptors');
@@ -87,21 +87,56 @@ class WriteClient {
87
87
  */
88
88
  if (validationLibrary !== ValidationLibrary_enum_1.ValidationLibrary.NONE) {
89
89
  await fileSystemHelpers_1.fileSystemHelpers.mkdir(outputPaths.outputSchemas);
90
- await this.writeClientSchemas({
90
+ const schemaModels = await this.writeClientSchemas({
91
91
  models: client.models,
92
92
  templates,
93
93
  outputSchemasPath: outputPaths.outputSchemas,
94
94
  httpClient,
95
95
  useUnionTypes,
96
96
  validationLibrary,
97
+ emptySchemaStrategy,
97
98
  });
98
99
  await this.writeClientSchemasIndex({
99
- models: client.models,
100
+ models: schemaModels,
100
101
  templates,
101
102
  outputSchemasPath: outputPaths.outputSchemas,
102
103
  useSeparatedIndexes,
103
104
  });
105
+ await this.writeModelsAndFinalize({
106
+ client,
107
+ templates,
108
+ outputPaths,
109
+ httpClient,
110
+ useOptions,
111
+ useUnionTypes,
112
+ excludeCoreServiceFiles,
113
+ request,
114
+ useCancelableRequest,
115
+ useSeparatedIndexes,
116
+ validationLibrary,
117
+ emptySchemaStrategy,
118
+ schemaModels,
119
+ });
120
+ return;
104
121
  }
122
+ await this.writeModelsAndFinalize({
123
+ client,
124
+ templates,
125
+ outputPaths,
126
+ httpClient,
127
+ useOptions,
128
+ useUnionTypes,
129
+ excludeCoreServiceFiles,
130
+ request,
131
+ useCancelableRequest,
132
+ useSeparatedIndexes,
133
+ validationLibrary,
134
+ emptySchemaStrategy,
135
+ schemaModels: [],
136
+ });
137
+ }
138
+ async writeModelsAndFinalize(config) {
139
+ const { client, templates, outputPaths, httpClient, useUnionTypes, useSeparatedIndexes, excludeCoreServiceFiles, validationLibrary, emptySchemaStrategy, schemaModels } = config;
105
140
  await fileSystemHelpers_1.fileSystemHelpers.mkdir(outputPaths.outputModels);
106
141
  await this.writeClientModels({
107
142
  models: client.models,
@@ -124,6 +159,8 @@ class WriteClient {
124
159
  useUnionTypes,
125
160
  excludeCoreServiceFiles,
126
161
  validationLibrary,
162
+ emptySchemaStrategy,
163
+ schemaModels,
127
164
  });
128
165
  }
129
166
  /**
@@ -155,7 +192,7 @@ class WriteClient {
155
192
  const result = new Map();
156
193
  for (const [key, value] of this.config.entries()) {
157
194
  for (const item of value) {
158
- const { outputPaths, templates, excludeCoreServiceFiles, validationLibrary } = item;
195
+ const { outputPaths, templates, excludeCoreServiceFiles, validationLibrary, schemaModels } = item;
159
196
  const outputCore = this.getOutputPath(outputPaths?.outputCore, key, 'core');
160
197
  const outputModels = this.getOutputPath(outputPaths?.outputModels, key, 'models');
161
198
  const outputSchemas = this.getOutputPath(outputPaths?.outputSchemas, key, 'schemas');
@@ -175,7 +212,7 @@ class WriteClient {
175
212
  if (!clientIndex.models.includes(relativePathModel)) {
176
213
  clientIndex.models.push(relativePathModel);
177
214
  }
178
- if (validationLibrary !== ValidationLibrary_enum_1.ValidationLibrary.NONE) {
215
+ if (validationLibrary !== ValidationLibrary_enum_1.ValidationLibrary.NONE && schemaModels.length > 0) {
179
216
  const relativePathSchema = (0, pathHelpers_1.relativeHelper)(key, outputSchemas);
180
217
  if (!clientIndex.schemas.includes(relativePathSchema)) {
181
218
  clientIndex.schemas.push(relativePathSchema);
@@ -189,7 +226,7 @@ class WriteClient {
189
226
  const result = new Map();
190
227
  for (const [key, value] of this.config.entries()) {
191
228
  for (const item of value) {
192
- const { outputPaths, client, templates, useUnionTypes, excludeCoreServiceFiles, validationLibrary } = item;
229
+ const { outputPaths, client, templates, useUnionTypes, excludeCoreServiceFiles, validationLibrary, schemaModels } = item;
193
230
  const outputCore = this.getOutputPath(outputPaths?.outputCore, key, 'core');
194
231
  const outputModels = this.getOutputPath(outputPaths?.outputModels, key, 'models');
195
232
  const outputSchemas = this.getOutputPath(outputPaths?.outputSchemas, key, 'schemas');
@@ -225,7 +262,7 @@ class WriteClient {
225
262
  if (!clientIndex.models.some(m => this.isSameModel(m, modelFinal))) {
226
263
  clientIndex.models.push(modelFinal);
227
264
  }
228
- if (validationLibrary !== ValidationLibrary_enum_1.ValidationLibrary.NONE) {
265
+ if (validationLibrary !== ValidationLibrary_enum_1.ValidationLibrary.NONE && schemaModels.some(schemaModel => schemaModel.name === model.name && schemaModel.path === model.path)) {
229
266
  const schema = { ...modelFinal, package: relativePathSchema };
230
267
  if (!clientIndex.schemas.some(s => this.isSameShema(s, schema))) {
231
268
  clientIndex.schemas.push(schema);
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const strict_1 = __importDefault(require("node:assert/strict"));
7
7
  const node_test_1 = require("node:test");
8
8
  const fileSystemHelpers_1 = require("../../common/utils/fileSystemHelpers");
9
+ const EmptySchemaStrategy_enum_1 = require("../types/enums/EmptySchemaStrategy.enum");
9
10
  const HttpClient_enum_1 = require("../types/enums/HttpClient.enum");
10
11
  const ValidationLibrary_enum_1 = require("../types/enums/ValidationLibrary.enum");
11
12
  const getOutputPaths_1 = require("../utils/getOutputPaths");
@@ -70,6 +71,7 @@ const WriteClient_1 = require("../WriteClient");
70
71
  useUnionTypes: false,
71
72
  excludeCoreServiceFiles: false,
72
73
  validationLibrary: ValidationLibrary_enum_1.ValidationLibrary.NONE,
74
+ emptySchemaStrategy: EmptySchemaStrategy_enum_1.EmptySchemaStrategy.KEEP,
73
75
  });
74
76
  strict_1.default.ok(mkdirCalls.length > 0, 'mkdir should be called at least once');
75
77
  strict_1.default.ok(writeFileCalls.length > 0, 'writeFile should be called at least once');
@@ -0,0 +1,6 @@
1
+ export declare enum EmptySchemaStrategy {
2
+ SEMANTIC = "semantic",
3
+ SKIP = "skip",
4
+ KEEP = "keep"
5
+ }
6
+ //# sourceMappingURL=EmptySchemaStrategy.enum.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EmptySchemaStrategy.enum.d.ts","sourceRoot":"","sources":["../../../../src/core/types/enums/EmptySchemaStrategy.enum.ts"],"names":[],"mappings":"AAAA,oBAAY,mBAAmB;IAC3B,QAAQ,aAAa;IACrB,IAAI,SAAS;IACb,IAAI,SAAS;CAChB"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EmptySchemaStrategy = void 0;
4
+ var EmptySchemaStrategy;
5
+ (function (EmptySchemaStrategy) {
6
+ EmptySchemaStrategy["SEMANTIC"] = "semantic";
7
+ EmptySchemaStrategy["SKIP"] = "skip";
8
+ EmptySchemaStrategy["KEEP"] = "keep";
9
+ })(EmptySchemaStrategy || (exports.EmptySchemaStrategy = EmptySchemaStrategy = {}));
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const node_assert_1 = __importDefault(require("node:assert"));
7
7
  const node_test_1 = require("node:test");
8
8
  const fileSystemHelpers_1 = require("../../../common/utils/fileSystemHelpers");
9
+ const EmptySchemaStrategy_enum_1 = require("../../types/enums/EmptySchemaStrategy.enum");
9
10
  const HttpClient_enum_1 = require("../../types/enums/HttpClient.enum");
10
11
  const ValidationLibrary_enum_1 = require("../../types/enums/ValidationLibrary.enum");
11
12
  const WriteClient_1 = require("../../WriteClient");
@@ -47,6 +48,7 @@ const templates_1 = require("../__mocks__/templates");
47
48
  httpClient: HttpClient_enum_1.HttpClient.FETCH,
48
49
  useUnionTypes: false,
49
50
  validationLibrary: ValidationLibrary_enum_1.ValidationLibrary.NONE,
51
+ emptySchemaStrategy: EmptySchemaStrategy_enum_1.EmptySchemaStrategy.KEEP,
50
52
  });
51
53
  node_assert_1.default.ok(writeFileCalls.some(([filePath, content]) => filePath.toString().includes('MyModelSchema.ts') && content.toString().includes('schema')), 'Expected writeFile to be called with schema content for MyModelSchema.ts');
52
54
  // Restoring the original function
@@ -66,6 +66,7 @@ const precompileTemplates = () => {
66
66
  isBasicType: true,
67
67
  yupBaseSchema: true,
68
68
  joiBaseSchema: true,
69
+ zodBaseSchema: true,
69
70
  getRequiredFields: true,
70
71
  getEnumType: true,
71
72
  camelCase: true,
@@ -1 +1 @@
1
- {"version":3,"file":"registerHandlebarHelpers.d.ts","sourceRoot":"","sources":["../../../src/core/utils/registerHandlebarHelpers.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAK5D,wBAAgB,wBAAwB,CAAC,IAAI,EAAE;IAAE,UAAU,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,OAAO,CAAC;IAAC,aAAa,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAqK5H"}
1
+ {"version":3,"file":"registerHandlebarHelpers.d.ts","sourceRoot":"","sources":["../../../src/core/utils/registerHandlebarHelpers.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAK5D,wBAAgB,wBAAwB,CAAC,IAAI,EAAE;IAAE,UAAU,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,OAAO,CAAC;IAAC,aAAa,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAgM5H"}
@@ -168,6 +168,31 @@ function registerHandlebarHelpers(root) {
168
168
  return 'Joi.any()';
169
169
  }
170
170
  });
171
+ Handlebars.registerHelper('zodBaseSchema', function (base) {
172
+ if (!base)
173
+ return 'z.any()';
174
+ const baseLower = base.toLowerCase();
175
+ switch (baseLower) {
176
+ case 'string':
177
+ return 'z.string()';
178
+ case 'number':
179
+ return 'z.number()';
180
+ case 'integer':
181
+ case 'int':
182
+ return 'z.number().int()';
183
+ case 'boolean':
184
+ return 'z.boolean()';
185
+ case 'null':
186
+ return 'z.null()';
187
+ case 'uuid':
188
+ return 'z.uuid()';
189
+ case 'file':
190
+ case 'any':
191
+ return 'z.any()';
192
+ default:
193
+ return `${base}Schema`;
194
+ }
195
+ });
171
196
  Handlebars.registerHelper('getRequiredFields', function (properties) {
172
197
  const required = properties
173
198
  .filter(prop => prop.isRequired)