ts-openapi-codegen 2.0.0-beta.9 → 2.0.0

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 (183) hide show
  1. package/README.md +88 -18
  2. package/README.rus.md +88 -21
  3. package/dist/cli/checkAndUpdateConfig/utils/validateAndMigrateConfigData.d.ts.map +1 -1
  4. package/dist/cli/checkAndUpdateConfig/utils/validateAndMigrateConfigData.js +5 -0
  5. package/dist/cli/generateOpenApiClient/generateOpenApiClient.d.ts.map +1 -1
  6. package/dist/cli/generateOpenApiClient/generateOpenApiClient.js +20 -8
  7. package/dist/cli/index.js +5 -3
  8. package/dist/cli/previewChanges/previewChanges.d.ts.map +1 -1
  9. package/dist/cli/previewChanges/previewChanges.js +116 -32
  10. package/dist/cli/previewChanges/utils/updateOutputPaths.d.ts.map +1 -1
  11. package/dist/cli/previewChanges/utils/updateOutputPaths.js +6 -0
  12. package/dist/common/Consts.d.ts.map +1 -1
  13. package/dist/common/Consts.js +4 -1
  14. package/dist/common/LoggerMessages.d.ts +1 -0
  15. package/dist/common/LoggerMessages.d.ts.map +1 -1
  16. package/dist/common/LoggerMessages.js +1 -0
  17. package/dist/common/VersionedSchema/AllVersionedSchemas/AllMigrationPlans.d.ts +1 -1
  18. package/dist/common/VersionedSchema/AllVersionedSchemas/AllMigrationPlans.d.ts.map +1 -1
  19. package/dist/common/VersionedSchema/AllVersionedSchemas/AllMigrationPlans.js +14 -4
  20. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV1.d.ts +2 -2
  21. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV2.d.ts +2 -2
  22. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV3.d.ts +2 -2
  23. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV4.d.ts +42 -0
  24. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV4.d.ts.map +1 -0
  25. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV4.js +38 -0
  26. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedVersionedSchemas.d.ts +155 -28
  27. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedVersionedSchemas.d.ts.map +1 -1
  28. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedVersionedSchemas.js +13 -17
  29. package/dist/common/VersionedSchema/CommonSchemas.d.ts +12 -4
  30. package/dist/common/VersionedSchema/CommonSchemas.d.ts.map +1 -1
  31. package/dist/common/VersionedSchema/CommonSchemas.js +15 -7
  32. package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsSchemaV1.d.ts +2 -2
  33. package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsSchemaV4.d.ts +2 -2
  34. package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsSchemaV5.d.ts +2 -2
  35. package/dist/common/VersionedSchema/OptionsVersioned/OptionsSchemaV1.d.ts +2 -2
  36. package/dist/common/VersionedSchema/OptionsVersioned/OptionsSchemaV4.d.ts +2 -2
  37. package/dist/common/VersionedSchema/Utils/__mocks__/compatibilityCases.d.ts.map +1 -1
  38. package/dist/common/VersionedSchema/Utils/__mocks__/compatibilityCases.js +19 -0
  39. package/dist/common/VersionedSchema/Utils/__tests__/allUtils.test.d.ts +2 -0
  40. package/dist/common/VersionedSchema/Utils/__tests__/allUtils.test.d.ts.map +1 -0
  41. package/dist/common/VersionedSchema/Utils/__tests__/allUtils.test.js +185 -0
  42. package/dist/common/VersionedSchema/Utils/__tests__/compareShapes.test.js +20 -3
  43. package/dist/common/VersionedSchema/Utils/__tests__/migrateDataToLatestSchemaVersion.test.js +19 -1
  44. package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.d.ts +4 -0
  45. package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.d.ts.map +1 -1
  46. package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.js +68 -23
  47. package/dist/common/VersionedSchema/Utils/getUniqueKeysFromSchemas.d.ts +1 -1
  48. package/dist/common/VersionedSchema/Utils/getUniqueKeysFromSchemas.js +1 -1
  49. package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.d.ts +10 -0
  50. package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.d.ts.map +1 -1
  51. package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.js +33 -15
  52. package/dist/common/utils/__tests__/convertArrayToObject.test.js +64 -169
  53. package/dist/common/utils/convertArrayToObject.d.ts.map +1 -1
  54. package/dist/common/utils/convertArrayToObject.js +51 -14
  55. package/dist/core/OpenApiClient.d.ts.map +1 -1
  56. package/dist/core/OpenApiClient.js +12 -1
  57. package/dist/core/WriteClient.d.ts +8 -1
  58. package/dist/core/WriteClient.d.ts.map +1 -1
  59. package/dist/core/WriteClient.js +48 -7
  60. package/dist/core/__tests__/WriteClient.test.js +2 -0
  61. package/dist/core/api/v2/parser/getType.d.ts.map +1 -1
  62. package/dist/core/api/v2/parser/getType.js +2 -1
  63. package/dist/core/api/v3/parser/getType.d.ts.map +1 -1
  64. package/dist/core/api/v3/parser/getType.js +2 -1
  65. package/dist/core/types/base/Templates.model.d.ts +1 -1
  66. package/dist/core/types/base/Templates.model.d.ts.map +1 -1
  67. package/dist/core/types/enums/EmptySchemaStrategy.enum.d.ts +6 -0
  68. package/dist/core/types/enums/EmptySchemaStrategy.enum.d.ts.map +1 -0
  69. package/dist/core/types/enums/EmptySchemaStrategy.enum.js +9 -0
  70. package/dist/core/utils/__tests__/getRelativeModelPath.test.d.ts +2 -0
  71. package/dist/core/utils/__tests__/getRelativeModelPath.test.d.ts.map +1 -0
  72. package/dist/core/utils/__tests__/getRelativeModelPath.test.js +27 -0
  73. package/dist/core/utils/__tests__/modelHelpers.test.d.ts +2 -0
  74. package/dist/core/utils/__tests__/modelHelpers.test.d.ts.map +1 -0
  75. package/dist/core/utils/__tests__/modelHelpers.test.js +151 -0
  76. package/dist/core/utils/__tests__/postProcessModelImports.test.d.ts +2 -0
  77. package/dist/core/utils/__tests__/postProcessModelImports.test.d.ts.map +1 -0
  78. package/dist/core/utils/__tests__/postProcessModelImports.test.js +67 -0
  79. package/dist/core/utils/__tests__/postProcessServiceImports.test.d.ts +2 -0
  80. package/dist/core/utils/__tests__/postProcessServiceImports.test.d.ts.map +1 -0
  81. package/dist/core/utils/__tests__/postProcessServiceImports.test.js +26 -0
  82. package/dist/core/utils/__tests__/resolveRefPath.test.d.ts +2 -0
  83. package/dist/core/utils/__tests__/resolveRefPath.test.d.ts.map +1 -0
  84. package/dist/core/utils/__tests__/resolveRefPath.test.js +22 -0
  85. package/dist/core/utils/__tests__/serviceHelpers.test.d.ts +2 -0
  86. package/dist/core/utils/__tests__/serviceHelpers.test.d.ts.map +1 -0
  87. package/dist/core/utils/__tests__/serviceHelpers.test.js +121 -0
  88. package/dist/core/utils/__tests__/writeClientExecutor.test.d.ts +2 -0
  89. package/dist/core/utils/__tests__/writeClientExecutor.test.d.ts.map +1 -0
  90. package/dist/core/utils/__tests__/writeClientExecutor.test.js +20 -0
  91. package/dist/core/utils/__tests__/writeClientSchemas.test.js +2 -0
  92. package/dist/core/utils/getOpenApiSpec.d.ts.map +1 -1
  93. package/dist/core/utils/getOpenApiSpec.js +14 -1
  94. package/dist/core/utils/getRelativeModelPath.d.ts +9 -0
  95. package/dist/core/utils/getRelativeModelPath.d.ts.map +1 -0
  96. package/dist/core/utils/getRelativeModelPath.js +37 -0
  97. package/dist/core/utils/modelHelpers.d.ts.map +1 -1
  98. package/dist/core/utils/modelHelpers.js +37 -3
  99. package/dist/core/utils/postProcessModelImports.d.ts.map +1 -1
  100. package/dist/core/utils/postProcessModelImports.js +14 -1
  101. package/dist/core/utils/postProcessServiceImports.d.ts.map +1 -1
  102. package/dist/core/utils/postProcessServiceImports.js +1 -2
  103. package/dist/core/utils/precompileTemplates.js +1 -0
  104. package/dist/core/utils/registerHandlebarHelpers.d.ts.map +1 -1
  105. package/dist/core/utils/registerHandlebarHelpers.js +25 -0
  106. package/dist/core/utils/registerHandlebarTemplates.d.ts.map +1 -1
  107. package/dist/core/utils/registerHandlebarTemplates.js +42 -41
  108. package/dist/core/utils/resolveRefPath.d.ts.map +1 -1
  109. package/dist/core/utils/resolveRefPath.js +1 -4
  110. package/dist/core/utils/writeClientExecutor.d.ts +4 -1
  111. package/dist/core/utils/writeClientExecutor.d.ts.map +1 -1
  112. package/dist/core/utils/writeClientExecutor.js +17 -2
  113. package/dist/core/utils/writeClientSchemas.d.ts +4 -1
  114. package/dist/core/utils/writeClientSchemas.d.ts.map +1 -1
  115. package/dist/core/utils/writeClientSchemas.js +11 -2
  116. package/dist/templatesCompiled/client/core/ApiError.js +1 -1
  117. package/dist/templatesCompiled/client/core/ApiResult.js +1 -1
  118. package/dist/templatesCompiled/client/core/axios/request.js +3 -3
  119. package/dist/templatesCompiled/client/core/executor/createExecutorAdapter.d.ts +2 -0
  120. package/dist/templatesCompiled/client/core/executor/createExecutorAdapter.d.ts.map +1 -1
  121. package/dist/templatesCompiled/client/core/executor/createExecutorAdapter.js +13 -8
  122. package/dist/templatesCompiled/client/core/executor/requestExecutor.js +1 -1
  123. package/dist/templatesCompiled/client/core/fetch/request.js +3 -3
  124. package/dist/templatesCompiled/client/core/functions/catchErrors.js +1 -1
  125. package/dist/templatesCompiled/client/core/interceptors/withInterceptors.js +1 -1
  126. package/dist/templatesCompiled/client/core/node/request.js +3 -3
  127. package/dist/templatesCompiled/client/core/xhr/request.js +3 -3
  128. package/dist/templatesCompiled/client/exportClient.d.ts +4 -0
  129. package/dist/templatesCompiled/client/exportClient.d.ts.map +1 -1
  130. package/dist/templatesCompiled/client/exportClient.js +51 -13
  131. package/dist/templatesCompiled/client/exportSchema.d.ts +5 -1
  132. package/dist/templatesCompiled/client/exportSchema.d.ts.map +1 -1
  133. package/dist/templatesCompiled/client/exportSchema.js +37 -7
  134. package/dist/templatesCompiled/client/exportService.d.ts +2 -0
  135. package/dist/templatesCompiled/client/exportService.d.ts.map +1 -1
  136. package/dist/templatesCompiled/client/exportService.js +70 -30
  137. package/dist/templatesCompiled/client/indexFull.d.ts +1 -0
  138. package/dist/templatesCompiled/client/indexFull.d.ts.map +1 -1
  139. package/dist/templatesCompiled/client/indexFull.js +4 -1
  140. package/dist/templatesCompiled/client/indexSimple.d.ts +1 -0
  141. package/dist/templatesCompiled/client/indexSimple.d.ts.map +1 -1
  142. package/dist/templatesCompiled/client/indexSimple.js +4 -1
  143. package/dist/templatesCompiled/client/joi/exportSchema.js +5 -5
  144. package/dist/templatesCompiled/client/joi/partials/joiSchema.js +7 -7
  145. package/dist/templatesCompiled/client/joi/partials/joiSchemaComposition.js +4 -4
  146. package/dist/templatesCompiled/client/joi/partials/joiSchemaInterface.d.ts +5 -3
  147. package/dist/templatesCompiled/client/joi/partials/joiSchemaInterface.d.ts.map +1 -1
  148. package/dist/templatesCompiled/client/joi/partials/joiSchemaInterface.js +39 -12
  149. package/dist/templatesCompiled/client/jsonschema/exportSchema.js +5 -5
  150. package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchema.js +7 -7
  151. package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaArray.js +5 -5
  152. package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaComposition.js +2 -2
  153. package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaDictionary.js +5 -5
  154. package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaInterface.d.ts +3 -1
  155. package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaInterface.d.ts.map +1 -1
  156. package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaInterface.js +45 -15
  157. package/dist/templatesCompiled/client/yup/exportSchema.js +3 -3
  158. package/dist/templatesCompiled/client/yup/partials/yupSchema.js +7 -7
  159. package/dist/templatesCompiled/client/yup/partials/yupSchemaComposition.js +4 -4
  160. package/dist/templatesCompiled/client/yup/partials/yupSchemaInterface.d.ts +5 -3
  161. package/dist/templatesCompiled/client/yup/partials/yupSchemaInterface.d.ts.map +1 -1
  162. package/dist/templatesCompiled/client/yup/partials/yupSchemaInterface.js +39 -12
  163. package/dist/templatesCompiled/client/zod/exportSchema.js +3 -3
  164. package/dist/templatesCompiled/client/zod/partials/zodSchema.js +7 -7
  165. package/dist/templatesCompiled/client/zod/partials/zodSchemaArray.d.ts +5 -6
  166. package/dist/templatesCompiled/client/zod/partials/zodSchemaArray.d.ts.map +1 -1
  167. package/dist/templatesCompiled/client/zod/partials/zodSchemaArray.js +14 -28
  168. package/dist/templatesCompiled/client/zod/partials/zodSchemaComposition.d.ts +3 -0
  169. package/dist/templatesCompiled/client/zod/partials/zodSchemaComposition.d.ts.map +1 -1
  170. package/dist/templatesCompiled/client/zod/partials/zodSchemaComposition.js +32 -8
  171. package/dist/templatesCompiled/client/zod/partials/zodSchemaDictionary.d.ts +3 -4
  172. package/dist/templatesCompiled/client/zod/partials/zodSchemaDictionary.d.ts.map +1 -1
  173. package/dist/templatesCompiled/client/zod/partials/zodSchemaDictionary.js +9 -23
  174. package/dist/templatesCompiled/client/zod/partials/zodSchemaInterface.d.ts +4 -2
  175. package/dist/templatesCompiled/client/zod/partials/zodSchemaInterface.d.ts.map +1 -1
  176. package/dist/templatesCompiled/client/zod/partials/zodSchemaInterface.js +18 -7
  177. package/package.json +2 -2
  178. package/dist/common/defaultOptions.d.ts +0 -3
  179. package/dist/common/defaultOptions.d.ts.map +0 -1
  180. package/dist/common/defaultOptions.js +0 -28
  181. package/dist/core/utils/advancedDeduplicatePath.d.ts +0 -5
  182. package/dist/core/utils/advancedDeduplicatePath.d.ts.map +0 -1
  183. package/dist/core/utils/advancedDeduplicatePath.js +0 -29
@@ -17,7 +17,20 @@ async function getOpenApiSpec(context, input) {
17
17
  throw new Error(`OpenAPI spec not found: ${absoluteInput}`);
18
18
  }
19
19
  const parser = new swagger_parser_1.default();
20
- const resolved = await parser.resolve(absoluteInput);
20
+ const previousCwd = process.cwd();
21
+ const inputDir = (0, pathHelpers_1.dirNameHelper)(absoluteInput);
22
+ if (previousCwd !== inputDir) {
23
+ process.chdir(inputDir);
24
+ }
25
+ let resolved;
26
+ try {
27
+ resolved = await parser.resolve(absoluteInput);
28
+ }
29
+ finally {
30
+ if (process.cwd() !== previousCwd) {
31
+ process.chdir(previousCwd);
32
+ }
33
+ }
21
34
  context.addRefs(resolved);
22
35
  // Получить основную схему
23
36
  const raw = resolved.get(absoluteInput);
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The function calculates the relative path to the model.
3
+ * Removes the transition to the directory with a level above.
4
+ * @param folderPath Root folder.
5
+ * @param relativeModelPath Relative path to the model.
6
+ * @returns Correct relative model path.
7
+ */
8
+ export declare function getRelativeModelPath(folderPath: string | undefined, relativeModelPath: string): string;
9
+ //# sourceMappingURL=getRelativeModelPath.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRelativeModelPath.d.ts","sourceRoot":"","sources":["../../../src/core/utils/getRelativeModelPath.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,EAAE,iBAAiB,EAAE,MAAM,UA2B7F"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRelativeModelPath = getRelativeModelPath;
4
+ const pathHelpers_1 = require("../../common/utils/pathHelpers");
5
+ const getTypeName_1 = require("./getTypeName");
6
+ const isInsideDirectory_1 = require("./isInsideDirectory");
7
+ /**
8
+ * The function calculates the relative path to the model.
9
+ * Removes the transition to the directory with a level above.
10
+ * @param folderPath Root folder.
11
+ * @param relativeModelPath Relative path to the model.
12
+ * @returns Correct relative model path.
13
+ */
14
+ function getRelativeModelPath(folderPath, relativeModelPath) {
15
+ if (!folderPath) {
16
+ return relativeModelPath;
17
+ }
18
+ const pathSep = '/';
19
+ let mappedPaths = '';
20
+ let modelPath = relativeModelPath;
21
+ // If absolute path (filesystem or URL-like), collapse to type name only
22
+ if (modelPath.startsWith('/')) {
23
+ return (0, getTypeName_1.getTypeName)(modelPath);
24
+ }
25
+ if (modelPath.startsWith('../')) {
26
+ const pathArray = modelPath.split(pathSep).filter(Boolean);
27
+ while (pathArray[0] === '..') {
28
+ pathArray.shift();
29
+ }
30
+ modelPath = pathArray.join(pathSep);
31
+ }
32
+ const resolvedPath = (0, pathHelpers_1.resolveHelper)(folderPath, modelPath);
33
+ if ((0, isInsideDirectory_1.isInsideDirectory)(resolvedPath, folderPath)) {
34
+ mappedPaths = modelPath;
35
+ }
36
+ return mappedPaths;
37
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"modelHelpers.d.ts","sourceRoot":"","sources":["../../../src/core/utils/modelHelpers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAEzD;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,CAkBjE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,eAAe,EAAE,MAAM,GAAG,KAAK,EAAE,CA+BrF"}
1
+ {"version":3,"file":"modelHelpers.d.ts","sourceRoot":"","sources":["../../../src/core/utils/modelHelpers.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAEzD;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,CAkBjE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,eAAe,EAAE,MAAM,GAAG,KAAK,EAAE,CA4ErF"}
@@ -52,8 +52,36 @@ function setDuplicateModelAliases(models) {
52
52
  * @returns the same array of models (modified)
53
53
  */
54
54
  function resolveModelImports(models, outputModelsDir) {
55
+ const normalizeImportPath = (value) => (value.startsWith('./') ? value.slice(2) : value);
56
+ const applyAliasToModel = (model, imprt) => {
57
+ const modelPath = normalizeImportPath(model.path);
58
+ const importPath = normalizeImportPath(imprt.path);
59
+ if (modelPath === importPath && model.type === imprt.name && imprt.alias) {
60
+ model.alias = imprt.alias;
61
+ model.base = imprt.alias;
62
+ model.type = imprt.alias;
63
+ }
64
+ if (imprt.alias && model.imports?.some(item => normalizeImportPath(item.path) === importPath && item.name === imprt.name)) {
65
+ if (model.base === imprt.name) {
66
+ model.base = imprt.alias;
67
+ }
68
+ if (model.type === imprt.name) {
69
+ model.type = imprt.alias;
70
+ }
71
+ }
72
+ if (model.link) {
73
+ applyAliasToModel(model.link, imprt);
74
+ }
75
+ if (model.properties?.length) {
76
+ model.properties.forEach(child => applyAliasToModel(child, imprt));
77
+ }
78
+ if (model.enums?.length) {
79
+ model.enums.forEach(child => applyAliasToModel(child, imprt));
80
+ }
81
+ };
55
82
  models.forEach(model => {
56
- model.imports = model.imports.map(imprt => {
83
+ const importsWithSourcePath = model.imports.map(imprt => {
84
+ const sourcePath = imprt.path;
57
85
  const importModel = models.find(value => {
58
86
  const normalizedPath = !value.path.startsWith('./') ? `./${value.path}` : value.path;
59
87
  return normalizedPath === imprt.path && value.name === imprt.name;
@@ -69,16 +97,22 @@ function resolveModelImports(models, outputModelsDir) {
69
97
  importPath = `./${file}`;
70
98
  }
71
99
  else if (relativePath.startsWith('./')) {
72
- importPath = `${relativePath}${file}`;
100
+ importPath = `${relativePath}/${file}`;
73
101
  }
74
102
  else {
75
103
  importPath = `${relativePath}/${file}`;
76
104
  }
77
105
  }
78
- return Object.assign(imprt, {
106
+ const mappedImport = Object.assign(imprt, {
79
107
  alias: importAlias,
80
108
  path: importPath,
81
109
  });
110
+ return { mappedImport, sourcePath };
111
+ });
112
+ model.imports = importsWithSourcePath.map(item => item.mappedImport);
113
+ importsWithSourcePath.forEach(item => {
114
+ applyAliasToModel(model, item.mappedImport);
115
+ applyAliasToModel(model, Object.assign({}, item.mappedImport, { path: item.sourcePath }));
82
116
  });
83
117
  });
84
118
  return models;
@@ -1 +1 @@
1
- {"version":3,"file":"postProcessModelImports.d.ts","sourceRoot":"","sources":["../../../src/core/utils/postProcessModelImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAIzD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE,CAK9D"}
1
+ {"version":3,"file":"postProcessModelImports.d.ts","sourceRoot":"","sources":["../../../src/core/utils/postProcessModelImports.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAQzD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE,CAY9D"}
@@ -1,15 +1,28 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.postProcessModelImports = postProcessModelImports;
7
+ const path_1 = __importDefault(require("path"));
4
8
  const sort_1 = require("./sort");
5
9
  const unique_1 = require("./unique");
10
+ function normalizePath(value) {
11
+ return value.startsWith('./') ? value.slice(2) : value;
12
+ }
6
13
  /**
7
14
  * Set unique imports, sorted by name
8
15
  * @param model The model that is post-processed
9
16
  */
10
17
  function postProcessModelImports(model) {
18
+ const currentModelPath = normalizePath(model.path);
19
+ const currentModelDir = path_1.default.posix.dirname(currentModelPath);
11
20
  return model?.imports
12
21
  ?.filter(unique_1.unique)
13
22
  ?.sort(sort_1.sort)
14
- ?.filter(item => model.name !== item.name);
23
+ ?.filter(item => {
24
+ const importPath = normalizePath(item.path);
25
+ const resolvedFromCurrentModel = path_1.default.posix.normalize(path_1.default.posix.join(currentModelDir, importPath));
26
+ return resolvedFromCurrentModel !== currentModelPath;
27
+ });
15
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"postProcessServiceImports.d.ts","sourceRoot":"","sources":["../../../src/core/utils/postProcessServiceImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAI7D;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,EAAE,CAKpE"}
1
+ {"version":3,"file":"postProcessServiceImports.d.ts","sourceRoot":"","sources":["../../../src/core/utils/postProcessServiceImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAI7D;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,EAAE,CAIpE"}
@@ -10,6 +10,5 @@ const unique_1 = require("./unique");
10
10
  function postProcessServiceImports(service) {
11
11
  return service.imports
12
12
  .filter(unique_1.unique)
13
- .sort(sort_1.sort)
14
- .filter(item => service.name !== item.name);
13
+ .sort(sort_1.sort);
15
14
  }
@@ -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)
@@ -1 +1 @@
1
- {"version":3,"file":"registerHandlebarTemplates.d.ts","sourceRoot":"","sources":["../../../src/core/utils/registerHandlebarTemplates.ts"],"names":[],"mappings":"AA6FA,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AA2C1E,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE1D;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE;IAAE,UAAU,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,OAAO,CAAC;IAAC,aAAa,EAAE,OAAO,CAAC;IAAC,iBAAiB,CAAC,EAAE,iBAAiB,CAAA;CAAE,GAAG,SAAS,CAyK1K"}
1
+ {"version":3,"file":"registerHandlebarTemplates.d.ts","sourceRoot":"","sources":["../../../src/core/utils/registerHandlebarTemplates.ts"],"names":[],"mappings":"AA8FA,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AA2C1E,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE1D;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE;IAAE,UAAU,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,OAAO,CAAC;IAAC,aAAa,EAAE,OAAO,CAAC;IAAC,iBAAiB,CAAC,EAAE,iBAAiB,CAAA;CAAE,GAAG,SAAS,CAqK1K"}
@@ -89,6 +89,7 @@ const getResponseHeader_4 = __importDefault(require("../../templatesCompiled/cli
89
89
  const request_5 = __importDefault(require("../../templatesCompiled/client/core/xhr/request"));
90
90
  const sendRequest_4 = __importDefault(require("../../templatesCompiled/client/core/xhr/sendRequest"));
91
91
  const exportClient_1 = __importDefault(require("../../templatesCompiled/client/exportClient"));
92
+ const exportSchema_1 = __importDefault(require("../../templatesCompiled/client/exportSchema"));
92
93
  const exportModel_1 = __importDefault(require("../../templatesCompiled/client/exportModel"));
93
94
  const exportService_1 = __importDefault(require("../../templatesCompiled/client/exportService"));
94
95
  const indexFull_1 = __importDefault(require("../../templatesCompiled/client/indexFull"));
@@ -130,7 +131,7 @@ const typeReference_1 = __importDefault(require("../../templatesCompiled/client/
130
131
  const typeUnion_1 = __importDefault(require("../../templatesCompiled/client/partials/typeUnion"));
131
132
  const registerHandlebarHelpers_1 = require("./registerHandlebarHelpers");
132
133
  const ValidationLibrary_enum_1 = require("../types/enums/ValidationLibrary.enum");
133
- const exportSchema_1 = __importDefault(require("../../templatesCompiled/client/zod/exportSchema"));
134
+ const exportSchema_2 = __importDefault(require("../../templatesCompiled/client/zod/exportSchema"));
134
135
  const zodSchema_1 = __importDefault(require("../../templatesCompiled/client/zod/partials/zodSchema"));
135
136
  const zodSchemaInterface_1 = __importDefault(require("../../templatesCompiled/client/zod/partials/zodSchemaInterface"));
136
137
  const zodSchemaEnum_1 = __importDefault(require("../../templatesCompiled/client/zod/partials/zodSchemaEnum"));
@@ -139,7 +140,7 @@ const zodSchemaDictionary_1 = __importDefault(require("../../templatesCompiled/c
139
140
  const zodSchemaGeneric_1 = __importDefault(require("../../templatesCompiled/client/zod/partials/zodSchemaGeneric"));
140
141
  const zodSchemaReference_1 = __importDefault(require("../../templatesCompiled/client/zod/partials/zodSchemaReference"));
141
142
  const zodSchemaComposition_1 = __importDefault(require("../../templatesCompiled/client/zod/partials/zodSchemaComposition"));
142
- const exportSchema_2 = __importDefault(require("../../templatesCompiled/client/yup/exportSchema"));
143
+ const exportSchema_3 = __importDefault(require("../../templatesCompiled/client/yup/exportSchema"));
143
144
  const yupSchema_1 = __importDefault(require("../../templatesCompiled/client/yup/partials/yupSchema"));
144
145
  const yupSchemaInterface_1 = __importDefault(require("../../templatesCompiled/client/yup/partials/yupSchemaInterface"));
145
146
  const yupSchemaEnum_1 = __importDefault(require("../../templatesCompiled/client/yup/partials/yupSchemaEnum"));
@@ -148,7 +149,7 @@ const yupSchemaDictionary_1 = __importDefault(require("../../templatesCompiled/c
148
149
  const yupSchemaGeneric_1 = __importDefault(require("../../templatesCompiled/client/yup/partials/yupSchemaGeneric"));
149
150
  const yupSchemaReference_1 = __importDefault(require("../../templatesCompiled/client/yup/partials/yupSchemaReference"));
150
151
  const yupSchemaComposition_1 = __importDefault(require("../../templatesCompiled/client/yup/partials/yupSchemaComposition"));
151
- const exportSchema_3 = __importDefault(require("../../templatesCompiled/client/joi/exportSchema"));
152
+ const exportSchema_4 = __importDefault(require("../../templatesCompiled/client/joi/exportSchema"));
152
153
  const joiSchema_1 = __importDefault(require("../../templatesCompiled/client/joi/partials/joiSchema"));
153
154
  const joiSchemaInterface_1 = __importDefault(require("../../templatesCompiled/client/joi/partials/joiSchemaInterface"));
154
155
  const joiSchemaEnum_1 = __importDefault(require("../../templatesCompiled/client/joi/partials/joiSchemaEnum"));
@@ -157,7 +158,7 @@ const joiSchemaDictionary_1 = __importDefault(require("../../templatesCompiled/c
157
158
  const joiSchemaGeneric_1 = __importDefault(require("../../templatesCompiled/client/joi/partials/joiSchemaGeneric"));
158
159
  const joiSchemaReference_1 = __importDefault(require("../../templatesCompiled/client/joi/partials/joiSchemaReference"));
159
160
  const joiSchemaComposition_1 = __importDefault(require("../../templatesCompiled/client/joi/partials/joiSchemaComposition"));
160
- const exportSchema_4 = __importDefault(require("../../templatesCompiled/client/jsonschema/exportSchema"));
161
+ const exportSchema_5 = __importDefault(require("../../templatesCompiled/client/jsonschema/exportSchema"));
161
162
  const jsonschemaSchema_1 = __importDefault(require("../../templatesCompiled/client/jsonschema/partials/jsonschemaSchema"));
162
163
  const jsonschemaSchemaInterface_1 = __importDefault(require("../../templatesCompiled/client/jsonschema/partials/jsonschemaSchemaInterface"));
163
164
  const jsonschemaSchemaEnum_1 = __importDefault(require("../../templatesCompiled/client/jsonschema/partials/jsonschemaSchemaEnum"));
@@ -185,7 +186,7 @@ function registerHandlebarTemplates(root) {
185
186
  exports: {
186
187
  client: Handlebars.template(exportClient_1.default),
187
188
  model: Handlebars.template(exportModel_1.default),
188
- schema: undefined,
189
+ schema: Handlebars.template(exportSchema_1.default),
189
190
  service: Handlebars.template(exportService_1.default),
190
191
  },
191
192
  core: {
@@ -277,50 +278,50 @@ function registerHandlebarTemplates(root) {
277
278
  Handlebars.registerPartial('axios/request', Handlebars.template(request_1.default));
278
279
  // Register Zod partials if validationLibrary is ZOD
279
280
  if (root?.validationLibrary === ValidationLibrary_enum_1.ValidationLibrary.ZOD) {
280
- templates.exports.schema = Handlebars.template(exportSchema_1.default);
281
- Handlebars.registerPartial('zodSchema', Handlebars.template(zodSchema_1.default));
282
- Handlebars.registerPartial('zodSchemaInterface', Handlebars.template(zodSchemaInterface_1.default));
283
- Handlebars.registerPartial('zodSchemaEnum', Handlebars.template(zodSchemaEnum_1.default));
284
- Handlebars.registerPartial('zodSchemaArray', Handlebars.template(zodSchemaArray_1.default));
285
- Handlebars.registerPartial('zodSchemaDictionary', Handlebars.template(zodSchemaDictionary_1.default));
286
- Handlebars.registerPartial('zodSchemaGeneric', Handlebars.template(zodSchemaGeneric_1.default));
287
- Handlebars.registerPartial('zodSchemaReference', Handlebars.template(zodSchemaReference_1.default));
288
- Handlebars.registerPartial('zodSchemaComposition', Handlebars.template(zodSchemaComposition_1.default));
281
+ Handlebars.registerPartial('zod/exportSchema', Handlebars.template(exportSchema_2.default));
282
+ Handlebars.registerPartial('zod/zodSchema', Handlebars.template(zodSchema_1.default));
283
+ Handlebars.registerPartial('zod/zodSchemaInterface', Handlebars.template(zodSchemaInterface_1.default));
284
+ Handlebars.registerPartial('zod/zodSchemaEnum', Handlebars.template(zodSchemaEnum_1.default));
285
+ Handlebars.registerPartial('zod/zodSchemaArray', Handlebars.template(zodSchemaArray_1.default));
286
+ Handlebars.registerPartial('zod/zodSchemaDictionary', Handlebars.template(zodSchemaDictionary_1.default));
287
+ Handlebars.registerPartial('zod/zodSchemaGeneric', Handlebars.template(zodSchemaGeneric_1.default));
288
+ Handlebars.registerPartial('zod/zodSchemaReference', Handlebars.template(zodSchemaReference_1.default));
289
+ Handlebars.registerPartial('zod/zodSchemaComposition', Handlebars.template(zodSchemaComposition_1.default));
289
290
  }
290
291
  // Register Yup partials if validationLibrary is YUP
291
292
  if (root?.validationLibrary === ValidationLibrary_enum_1.ValidationLibrary.YUP) {
292
- templates.exports.schema = Handlebars.template(exportSchema_2.default);
293
- Handlebars.registerPartial('yupSchema', Handlebars.template(yupSchema_1.default));
294
- Handlebars.registerPartial('yupSchemaInterface', Handlebars.template(yupSchemaInterface_1.default));
295
- Handlebars.registerPartial('yupSchemaEnum', Handlebars.template(yupSchemaEnum_1.default));
296
- Handlebars.registerPartial('yupSchemaArray', Handlebars.template(yupSchemaArray_1.default));
297
- Handlebars.registerPartial('yupSchemaDictionary', Handlebars.template(yupSchemaDictionary_1.default));
298
- Handlebars.registerPartial('yupSchemaGeneric', Handlebars.template(yupSchemaGeneric_1.default));
299
- Handlebars.registerPartial('yupSchemaReference', Handlebars.template(yupSchemaReference_1.default));
300
- Handlebars.registerPartial('yupSchemaComposition', Handlebars.template(yupSchemaComposition_1.default));
293
+ Handlebars.registerPartial('yup/exportSchema', Handlebars.template(exportSchema_3.default));
294
+ Handlebars.registerPartial('yup/yupSchema', Handlebars.template(yupSchema_1.default));
295
+ Handlebars.registerPartial('yup/yupSchemaInterface', Handlebars.template(yupSchemaInterface_1.default));
296
+ Handlebars.registerPartial('yup/yupSchemaEnum', Handlebars.template(yupSchemaEnum_1.default));
297
+ Handlebars.registerPartial('yup/yupSchemaArray', Handlebars.template(yupSchemaArray_1.default));
298
+ Handlebars.registerPartial('yup/yupSchemaDictionary', Handlebars.template(yupSchemaDictionary_1.default));
299
+ Handlebars.registerPartial('yup/yupSchemaGeneric', Handlebars.template(yupSchemaGeneric_1.default));
300
+ Handlebars.registerPartial('yup/yupSchemaReference', Handlebars.template(yupSchemaReference_1.default));
301
+ Handlebars.registerPartial('yup/yupSchemaComposition', Handlebars.template(yupSchemaComposition_1.default));
301
302
  }
302
303
  // Register Joi partials if validationLibrary is JOI
303
304
  if (root?.validationLibrary === ValidationLibrary_enum_1.ValidationLibrary.JOI) {
304
- templates.exports.schema = Handlebars.template(exportSchema_3.default);
305
- Handlebars.registerPartial('joiSchema', Handlebars.template(joiSchema_1.default));
306
- Handlebars.registerPartial('joiSchemaInterface', Handlebars.template(joiSchemaInterface_1.default));
307
- Handlebars.registerPartial('joiSchemaEnum', Handlebars.template(joiSchemaEnum_1.default));
308
- Handlebars.registerPartial('joiSchemaArray', Handlebars.template(joiSchemaArray_1.default));
309
- Handlebars.registerPartial('joiSchemaDictionary', Handlebars.template(joiSchemaDictionary_1.default));
310
- Handlebars.registerPartial('joiSchemaGeneric', Handlebars.template(joiSchemaGeneric_1.default));
311
- Handlebars.registerPartial('joiSchemaReference', Handlebars.template(joiSchemaReference_1.default));
312
- Handlebars.registerPartial('joiSchemaComposition', Handlebars.template(joiSchemaComposition_1.default));
305
+ Handlebars.registerPartial('joi/exportSchema', Handlebars.template(exportSchema_4.default));
306
+ Handlebars.registerPartial('joi/joiSchema', Handlebars.template(joiSchema_1.default));
307
+ Handlebars.registerPartial('joi/joiSchemaInterface', Handlebars.template(joiSchemaInterface_1.default));
308
+ Handlebars.registerPartial('joi/joiSchemaEnum', Handlebars.template(joiSchemaEnum_1.default));
309
+ Handlebars.registerPartial('joi/joiSchemaArray', Handlebars.template(joiSchemaArray_1.default));
310
+ Handlebars.registerPartial('joi/joiSchemaDictionary', Handlebars.template(joiSchemaDictionary_1.default));
311
+ Handlebars.registerPartial('joi/joiSchemaGeneric', Handlebars.template(joiSchemaGeneric_1.default));
312
+ Handlebars.registerPartial('joi/joiSchemaReference', Handlebars.template(joiSchemaReference_1.default));
313
+ Handlebars.registerPartial('joi/joiSchemaComposition', Handlebars.template(joiSchemaComposition_1.default));
313
314
  }
314
315
  if (root.validationLibrary === ValidationLibrary_enum_1.ValidationLibrary.JSONSCHEMA) {
315
- templates.exports.schema = Handlebars.template(exportSchema_4.default);
316
- Handlebars.registerPartial('jsonschemaSchema', Handlebars.template(jsonschemaSchema_1.default));
317
- Handlebars.registerPartial('jsonschemaSchemaInterface', Handlebars.template(jsonschemaSchemaInterface_1.default));
318
- Handlebars.registerPartial('jsonschemaSchemaEnum', Handlebars.template(jsonschemaSchemaEnum_1.default));
319
- Handlebars.registerPartial('jsonschemaSchemaArray', Handlebars.template(jsonschemaSchemaArray_1.default));
320
- Handlebars.registerPartial('jsonschemaSchemaDictionary', Handlebars.template(jsonschemaSchemaDictionary_1.default));
321
- Handlebars.registerPartial('jsonschemaSchemaGeneric', Handlebars.template(jsonschemaSchemaGeneric_1.default));
322
- Handlebars.registerPartial('jsonschemaSchemaReference', Handlebars.template(jsonschemaSchemaReference_1.default));
323
- Handlebars.registerPartial('jsonschemaSchemaComposition', Handlebars.template(jsonschemaSchemaComposition_1.default));
316
+ Handlebars.registerPartial('jsonschema/exportSchema', Handlebars.template(exportSchema_5.default));
317
+ Handlebars.registerPartial('jsonschema/jsonschemaSchema', Handlebars.template(jsonschemaSchema_1.default));
318
+ Handlebars.registerPartial('jsonschema/jsonschemaSchemaInterface', Handlebars.template(jsonschemaSchemaInterface_1.default));
319
+ Handlebars.registerPartial('jsonschema/jsonschemaSchemaEnum', Handlebars.template(jsonschemaSchemaEnum_1.default));
320
+ Handlebars.registerPartial('jsonschema/jsonschemaSchemaArray', Handlebars.template(jsonschemaSchemaArray_1.default));
321
+ Handlebars.registerPartial('jsonschema/jsonschemaSchemaDictionary', Handlebars.template(jsonschemaSchemaDictionary_1.default));
322
+ Handlebars.registerPartial('jsonschema/jsonschemaSchemaGeneric', Handlebars.template(jsonschemaSchemaGeneric_1.default));
323
+ Handlebars.registerPartial('jsonschema/jsonschemaSchemaReference', Handlebars.template(jsonschemaSchemaReference_1.default));
324
+ Handlebars.registerPartial('jsonschema/jsonschemaSchemaComposition', Handlebars.template(jsonschemaSchemaComposition_1.default));
324
325
  }
325
326
  return templates;
326
327
  }
@@ -1 +1 @@
1
- {"version":3,"file":"resolveRefPath.d.ts","sourceRoot":"","sources":["../../../src/core/utils/resolveRefPath.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAW,MAAM,YAAY,CAAC;AAEhD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CA4BnF"}
1
+ {"version":3,"file":"resolveRefPath.d.ts","sourceRoot":"","sources":["../../../src/core/utils/resolveRefPath.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAW,MAAM,YAAY,CAAC;AAEhD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CA0BnF"}
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveRefPath = resolveRefPath;
4
4
  const pathHelpers_1 = require("../../common/utils/pathHelpers");
5
- const advancedDeduplicatePath_1 = require("./advancedDeduplicatePath");
6
5
  const parseRef_1 = require("./parseRef");
7
6
  /**
8
7
  * Resolve a parsed reference to an absolute path (when applicable).
@@ -19,9 +18,7 @@ function resolveRefPath(parsedRef, parentFilePath) {
19
18
  case parseRef_1.RefType.EXTERNAL_FILE_FRAGMENT:
20
19
  // Resolve relative to parent file directory
21
20
  if (parsedRef.filePath) {
22
- const resolvedPath = (0, pathHelpers_1.resolveHelper)(parentDir, parsedRef.filePath);
23
- // Clean any duplicate path segments
24
- return (0, advancedDeduplicatePath_1.advancedDeduplicatePath)(resolvedPath);
21
+ return (0, pathHelpers_1.resolveHelper)(parentDir, parsedRef.filePath);
25
22
  }
26
23
  return parentFilePath;
27
24
  case parseRef_1.RefType.ABSOLUTE_PATH:
@@ -4,9 +4,12 @@ import { WriteClient } from '../WriteClient';
4
4
  interface WriteClientExecutor {
5
5
  outputPath: string;
6
6
  outputCorePath: string;
7
+ request?: string;
8
+ customExecutorPath?: string;
7
9
  services: Service[];
8
10
  templates: Templates;
9
11
  }
12
+ declare function deduplicateServicesByName(services: Service[]): Service[];
10
13
  export declare function writeClientExecutor(this: WriteClient, options: WriteClientExecutor): Promise<void>;
11
- export {};
14
+ export { deduplicateServicesByName };
12
15
  //# sourceMappingURL=writeClientExecutor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"writeClientExecutor.d.ts","sourceRoot":"","sources":["../../../src/core/utils/writeClientExecutor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,UAAU,mBAAmB;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,SAAS,EAAE,SAAS,CAAC;CACxB;AAED,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAYxG"}
1
+ {"version":3,"file":"writeClientExecutor.d.ts","sourceRoot":"","sources":["../../../src/core/utils/writeClientExecutor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,UAAU,mBAAmB;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,SAAS,EAAE,SAAS,CAAC;CACxB;AAED,iBAAS,yBAAyB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CASjE;AAED,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBxG;AAED,OAAO,EAAE,yBAAyB,EAAE,CAAC"}
@@ -1,16 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.writeClientExecutor = writeClientExecutor;
4
+ exports.deduplicateServicesByName = deduplicateServicesByName;
4
5
  const fileSystemHelpers_1 = require("../../common/utils/fileSystemHelpers");
5
6
  const format_1 = require("../../common/utils/format");
6
7
  const pathHelpers_1 = require("../../common/utils/pathHelpers");
8
+ function deduplicateServicesByName(services) {
9
+ const seen = new Set();
10
+ return services.filter(service => {
11
+ if (seen.has(service.name)) {
12
+ return false;
13
+ }
14
+ seen.add(service.name);
15
+ return true;
16
+ });
17
+ }
7
18
  async function writeClientExecutor(options) {
8
- const { outputPath, outputCorePath, templates, services } = options;
19
+ const { outputPath, outputCorePath, templates, services, request, customExecutorPath } = options;
9
20
  const file = (0, pathHelpers_1.resolveHelper)(outputPath, 'createClient.ts');
21
+ const uniqueServices = deduplicateServicesByName(services);
22
+ const hasCustomRequest = !!request;
10
23
  this.logger.info(`Началась запись файла ${file}`);
11
24
  const templateResult = templates.exports.client({
12
25
  outputCore: outputCorePath,
13
- services,
26
+ useCustomRequest: hasCustomRequest,
27
+ customExecutorPath,
28
+ services: uniqueServices,
14
29
  });
15
30
  const formattedValue = await (0, format_1.format)(templateResult);
16
31
  await fileSystemHelpers_1.fileSystemHelpers.writeFile(file, formattedValue);
@@ -1,4 +1,5 @@
1
1
  import { Templates } from '../types/base/Templates.model';
2
+ import { EmptySchemaStrategy } from '../types/enums/EmptySchemaStrategy.enum';
2
3
  import { HttpClient } from '../types/enums/HttpClient.enum';
3
4
  import { ValidationLibrary } from '../types/enums/ValidationLibrary.enum';
4
5
  import type { Model } from '../types/shared/Model.model';
@@ -17,7 +18,9 @@ interface IWriteClientSchemas {
17
18
  httpClient: HttpClient;
18
19
  useUnionTypes: boolean;
19
20
  validationLibrary?: ValidationLibrary;
21
+ emptySchemaStrategy: EmptySchemaStrategy;
20
22
  }
23
+ export declare function isEmptySchemaModel(model: Model): boolean;
21
24
  /**
22
25
  * Generate Schemas using the Handlebar template and write to disk.
23
26
  * @param models Array of Models to write
@@ -26,6 +29,6 @@ interface IWriteClientSchemas {
26
29
  * @param httpClient The selected httpClient (fetch, xhr or node)
27
30
  * @param useUnionTypes Use union types instead of enums
28
31
  */
29
- export declare function writeClientSchemas(this: WriteClient, options: IWriteClientSchemas): Promise<void>;
32
+ export declare function writeClientSchemas(this: WriteClient, options: IWriteClientSchemas): Promise<Model[]>;
30
33
  export {};
31
34
  //# sourceMappingURL=writeClientSchemas.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"writeClientSchemas.d.ts","sourceRoot":"","sources":["../../../src/core/utils/writeClientSchemas.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;;;GAMG;AACH,UAAU,mBAAmB;IACzB,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,SAAS,EAAE,SAAS,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,UAAU,CAAC;IACvB,aAAa,EAAE,OAAO,CAAC;IACvB,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;CACzC;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAiCvG"}
1
+ {"version":3,"file":"writeClientSchemas.d.ts","sourceRoot":"","sources":["../../../src/core/utils/writeClientSchemas.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;;;GAMG;AACH,UAAU,mBAAmB;IACzB,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,SAAS,EAAE,SAAS,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,UAAU,CAAC;IACvB,aAAa,EAAE,OAAO,CAAC;IACvB,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,mBAAmB,EAAE,mBAAmB,CAAC;CAC5C;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAExD;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,CAwC1G"}
@@ -1,10 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isEmptySchemaModel = isEmptySchemaModel;
3
4
  exports.writeClientSchemas = writeClientSchemas;
4
5
  const fs_1 = require("fs");
5
6
  const fileSystemHelpers_1 = require("../../common/utils/fileSystemHelpers");
6
7
  const format_1 = require("../../common/utils/format");
7
8
  const pathHelpers_1 = require("../../common/utils/pathHelpers");
9
+ const EmptySchemaStrategy_enum_1 = require("../types/enums/EmptySchemaStrategy.enum");
10
+ function isEmptySchemaModel(model) {
11
+ return model.export === 'interface' && model.properties.length === 0;
12
+ }
8
13
  /**
9
14
  * Generate Schemas using the Handlebar template and write to disk.
10
15
  * @param models Array of Models to write
@@ -14,10 +19,11 @@ const pathHelpers_1 = require("../../common/utils/pathHelpers");
14
19
  * @param useUnionTypes Use union types instead of enums
15
20
  */
16
21
  async function writeClientSchemas(options) {
17
- const { models, templates, outputSchemasPath, httpClient, useUnionTypes, validationLibrary } = options;
22
+ const { models, templates, outputSchemasPath, httpClient, useUnionTypes, validationLibrary, emptySchemaStrategy } = options;
18
23
  if (templates.exports.schema) {
19
24
  this.logger.info('The recording of model validation schema files begins.');
20
- for (const model of models) {
25
+ const modelsToWrite = emptySchemaStrategy === EmptySchemaStrategy_enum_1.EmptySchemaStrategy.SKIP ? models.filter(model => !isEmptySchemaModel(model)) : models;
26
+ for (const model of modelsToWrite) {
21
27
  const modelFolderPath = model?.path;
22
28
  const dir = (0, pathHelpers_1.dirNameHelper)(modelFolderPath);
23
29
  if (dir) {
@@ -32,11 +38,14 @@ async function writeClientSchemas(options) {
32
38
  httpClient,
33
39
  useUnionTypes,
34
40
  validationLibrary,
41
+ emptySchemaStrategy,
35
42
  });
36
43
  const formattedValue = await (0, format_1.format)(templateResult);
37
44
  await fileSystemHelpers_1.fileSystemHelpers.writeFile(file, formattedValue);
38
45
  this.logger.info(`File recording completed: ${file}`);
39
46
  }
40
47
  this.logger.info('The recording of model validation schema files has been completed successfully');
48
+ return modelsToWrite;
41
49
  }
50
+ return [];
42
51
  }
@@ -14,5 +14,5 @@ exports.default = { "compiler": [8, ">= 4.3.0"], "main": function (container, de
14
14
  return undefined;
15
15
  };
16
16
  return ((stack1 = container.invokePartial(lookupProperty(partials, "header"), depth0, { "name": "header", "data": data, "helpers": helpers, "partials": partials, "decorators": container.decorators })) != null ? stack1 : "")
17
- + "\nexport class ApiError<TBody = unknown> extends Error {\n readonly status: number;\n readonly body?: TBody;\n readonly headers?: Record<string, string>;\n readonly request: RequestConfig;\n\n constructor(params: { status: number; message: string; body?: TBody; headers?: Record<string, string>; request: RequestConfig }) {\n super(params.message);\n this.name = 'ApiError';\n this.status = params.status;\n this.body = params.body;\n this.headers = params.headers;\n this.request = params.request;\n }\n}\n";
17
+ + "\nimport { RequestConfig } from './executor/requestExecutor';\n\nexport class ApiError<TBody = unknown> extends Error {\n readonly status: number;\n readonly body?: TBody;\n readonly headers?: Record<string, string>;\n readonly request: RequestConfig;\n\n constructor(params: { status: number; message: string; body?: TBody; headers?: Record<string, string>; request: RequestConfig }) {\n super(params.message);\n this.name = 'ApiError';\n this.status = params.status;\n this.body = params.body;\n this.headers = params.headers;\n this.request = params.request;\n }\n}\n";
18
18
  }, "usePartial": true, "useData": true };
@@ -14,5 +14,5 @@ exports.default = { "compiler": [8, ">= 4.3.0"], "main": function (container, de
14
14
  return undefined;
15
15
  };
16
16
  return ((stack1 = container.invokePartial(lookupProperty(partials, "header"), depth0, { "name": "header", "data": data, "helpers": helpers, "partials": partials, "decorators": container.decorators })) != null ? stack1 : "")
17
- + "\nexport type ApiResult = {\n readonly url: string;\n readonly ok: boolean;\n readonly status: number;\n readonly statusText: string;\n readonly body: any;\n}\n";
17
+ + "\nexport type ApiResult<TBody = unknown> = {\n readonly url: string;\n readonly ok: boolean;\n readonly status: number;\n readonly statusText: string;\n readonly body: TBody;\n}\n";
18
18
  }, "usePartial": true, "useData": true };
@@ -9,9 +9,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.default = { "1": function (container, depth0, helpers, partials, data) {
10
10
  return "import { CancelablePromise } from './CancelablePromise';\n";
11
11
  }, "3": function (container, depth0, helpers, partials, data) {
12
- return " export function request<T>(options: ApiRequestOptions, config: TOpenAPIConfig): CancelablePromise<T> {\n return new CancelablePromise(async(resolve, reject, onCancel) => {\n try {\n const url = getUrl(options, config);\n \n if (!onCancel.isCancelled) {\n const response = await sendRequest<T>(options, url, config, onCancel);\n const responseBody = getResponseBody(response);\n const responseHeader = getResponseHeader(response, options.responseHeader);\n const result: ApiResult = {\n url,\n ok: isSuccess(response.status),\n status: response.status,\n statusText: response.statusText,\n body: responseHeader || responseBody,\n };\n\n catchErrors(options, result);\n resolve(result.body);\n }\n } catch (error) {\n reject(error);\n }\n });\n}\n";
12
+ return " export function requestRaw<T>(options: ApiRequestOptions, config: TOpenAPIConfig): CancelablePromise<ApiResult<T>> {\n return new CancelablePromise(async(resolve, reject, onCancel) => {\n try {\n const url = getUrl(options, config);\n \n if (!onCancel.isCancelled) {\n const response = await sendRequest<T>(options, url, config, onCancel);\n const responseBody = getResponseBody(response);\n const responseHeader = getResponseHeader(response, options.responseHeader);\n const result: ApiResult<T> = {\n url,\n ok: isSuccess(response.status),\n status: response.status,\n statusText: response.statusText,\n body: (responseHeader || responseBody) as T,\n };\n\n catchErrors(options, result);\n resolve(result);\n }\n } catch (error) {\n reject(error);\n }\n });\n}\n\nexport function request<T>(options: ApiRequestOptions, config: TOpenAPIConfig): CancelablePromise<T> {\n return new CancelablePromise(async(resolve, reject, onCancel) => {\n try {\n const url = getUrl(options, config);\n \n if (!onCancel.isCancelled) {\n const response = await sendRequest<T>(options, url, config, onCancel);\n const responseBody = getResponseBody(response);\n const responseHeader = getResponseHeader(response, options.responseHeader);\n const result: ApiResult<T> = {\n url,\n ok: isSuccess(response.status),\n status: response.status,\n statusText: response.statusText,\n body: (responseHeader || responseBody) as T,\n };\n\n catchErrors(options, result);\n resolve(result.body);\n }\n } catch (error) {\n reject(error);\n }\n });\n}\n";
13
13
  }, "5": function (container, depth0, helpers, partials, data) {
14
- return "export async function request<T>(options: ApiRequestOptions, config: TOpenAPIConfig): Promise<T> {\n return new Promise(async (resolve, reject) => {\n try {\n const url = getUrl(options, config);\n const response = await sendRequest(options, url, config);\n const responseBody = getResponseBody(response);\n const responseHeader = getResponseHeader(response, options.responseHeader);\n\n const result: ApiResult = {\n url,\n ok: isSuccess(response.status),\n status: response.status,\n statusText: response.statusText,\n body: responseHeader || responseBody,\n };\n\n catchErrors(options, result);\n resolve(result.body);\n } catch (error) {\n reject(error);\n }\n });\n}\n";
14
+ return "export async function request<T>(options: ApiRequestOptions, config: TOpenAPIConfig): Promise<T> {\n const result = await requestRaw<T>(options, config);\n return result.body;\n}\n\nexport async function requestRaw<T>(options: ApiRequestOptions, config: TOpenAPIConfig): Promise<ApiResult<T>> {\n return new Promise(async (resolve, reject) => {\n try {\n const url = getUrl(options, config);\n const response = await sendRequest(options, url, config);\n const responseBody = getResponseBody(response);\n const responseHeader = getResponseHeader(response, options.responseHeader);\n\n const result: ApiResult<T> = {\n url,\n ok: isSuccess(response.status),\n status: response.status,\n statusText: response.statusText,\n body: (responseHeader || responseBody) as T,\n };\n\n catchErrors(options, result);\n resolve(result);\n } catch (error) {\n reject(error);\n }\n });\n}\n";
15
15
  }, "compiler": [8, ">= 4.3.0"], "main": function (container, depth0, helpers, partials, data) {
16
16
  var stack1, alias1 = depth0 != null ? depth0 : (container.nullContext || {}), lookupProperty = container.lookupProperty || function (parent, propertyName) {
17
17
  if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
@@ -53,5 +53,5 @@ exports.default = { "1": function (container, depth0, helpers, partials, data) {
53
53
  + "\n\n"
54
54
  + ((stack1 = container.invokePartial(lookupProperty(partials, "functions/catchErrors"), depth0, { "name": "functions/catchErrors", "data": data, "helpers": helpers, "partials": partials, "decorators": container.decorators })) != null ? stack1 : "")
55
55
  + "\n\n/**\n * Request using axios client\n * @param config The OpenAPI configuration object\n * @param options The request options from the the service\n * @returns ApiResult\n * @throws ApiError\n */\n"
56
- + ((stack1 = lookupProperty(helpers, "if").call(alias1, lookupProperty(lookupProperty(data, "root"), "useCancelableRequest"), { "name": "if", "hash": {}, "fn": container.program(3, data, 0), "inverse": container.program(5, data, 0), "data": data, "loc": { "start": { "line": 69, "column": 0 }, "end": { "line": 119, "column": 7 } } })) != null ? stack1 : "");
56
+ + ((stack1 = lookupProperty(helpers, "if").call(alias1, lookupProperty(lookupProperty(data, "root"), "useCancelableRequest"), { "name": "if", "hash": {}, "fn": container.program(3, data, 0), "inverse": container.program(5, data, 0), "data": data, "loc": { "start": { "line": 69, "column": 0 }, "end": { "line": 150, "column": 7 } } })) != null ? stack1 : "");
57
57
  }, "usePartial": true, "useData": true };
@@ -3,6 +3,8 @@ declare const _default: {
3
3
  "3": (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
4
4
  "5": (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
5
5
  "7": (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
6
+ "9": (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
7
+ "11": (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
6
8
  compiler: (string | number)[];
7
9
  main: (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
8
10
  usePartial: boolean;