ts-openapi-codegen 2.0.0-beta.6 → 2.0.0-beta.7

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 (68) hide show
  1. package/README.md +0 -74
  2. package/README.rus.md +0 -73
  3. package/dist/cli/initOpenApiConfig/Types.d.ts +0 -5
  4. package/dist/cli/initOpenApiConfig/Types.d.ts.map +1 -1
  5. package/dist/common/utils/fileSystemHelpers.d.ts +0 -2
  6. package/dist/common/utils/fileSystemHelpers.d.ts.map +1 -1
  7. package/dist/common/utils/fileSystemHelpers.js +0 -9
  8. package/dist/core/Context.d.ts +22 -0
  9. package/dist/core/Context.d.ts.map +1 -1
  10. package/dist/core/Context.js +97 -0
  11. package/dist/core/api/v2/parser/getModels.d.ts.map +1 -1
  12. package/dist/core/api/v2/parser/getModels.js +1 -2
  13. package/dist/core/api/v2/parser/getType.d.ts.map +1 -1
  14. package/dist/core/api/v2/parser/getType.js +14 -8
  15. package/dist/core/api/v3/parser/getModels.d.ts.map +1 -1
  16. package/dist/core/api/v3/parser/getModels.js +1 -2
  17. package/dist/core/api/v3/parser/getType.d.ts.map +1 -1
  18. package/dist/core/api/v3/parser/getType.js +14 -8
  19. package/dist/core/utils/getOpenApiSpec.d.ts +0 -6
  20. package/dist/core/utils/getOpenApiSpec.d.ts.map +1 -1
  21. package/dist/core/utils/getOpenApiSpec.js +13 -23
  22. package/dist/core/utils/stripNamespace.js +1 -1
  23. package/package.json +1 -7
  24. package/dist/cli/initOpenApiConfig/Enums.d.ts +0 -5
  25. package/dist/cli/initOpenApiConfig/Enums.d.ts.map +0 -1
  26. package/dist/cli/initOpenApiConfig/Enums.js +0 -8
  27. package/dist/core/types/base/RefWithtype.model.d.ts +0 -11
  28. package/dist/core/types/base/RefWithtype.model.d.ts.map +0 -1
  29. package/dist/core/types/base/RefWithtype.model.js +0 -2
  30. package/dist/core/types/enums/TypeRef.enum.d.ts +0 -8
  31. package/dist/core/types/enums/TypeRef.enum.d.ts.map +0 -1
  32. package/dist/core/types/enums/TypeRef.enum.js +0 -11
  33. package/dist/core/utils/__tests__/getGatheringRefs.test.d.ts +0 -2
  34. package/dist/core/utils/__tests__/getGatheringRefs.test.d.ts.map +0 -1
  35. package/dist/core/utils/__tests__/getGatheringRefs.test.js +0 -26
  36. package/dist/core/utils/__tests__/getRefFromSchema.test.d.ts +0 -2
  37. package/dist/core/utils/__tests__/getRefFromSchema.test.d.ts.map +0 -1
  38. package/dist/core/utils/__tests__/getRefFromSchema.test.js +0 -167
  39. package/dist/core/utils/__tests__/refResolver.test.d.ts +0 -2
  40. package/dist/core/utils/__tests__/refResolver.test.d.ts.map +0 -1
  41. package/dist/core/utils/__tests__/refResolver.test.js +0 -55
  42. package/dist/core/utils/__tests__/resolveRefToImportPath.test.d.ts +0 -2
  43. package/dist/core/utils/__tests__/resolveRefToImportPath.test.d.ts.map +0 -1
  44. package/dist/core/utils/__tests__/resolveRefToImportPath.test.js +0 -449
  45. package/dist/core/utils/findCommonParent.d.ts +0 -7
  46. package/dist/core/utils/findCommonParent.d.ts.map +0 -1
  47. package/dist/core/utils/findCommonParent.js +0 -20
  48. package/dist/core/utils/getGatheringRefs.d.ts +0 -4
  49. package/dist/core/utils/getGatheringRefs.d.ts.map +0 -1
  50. package/dist/core/utils/getGatheringRefs.js +0 -68
  51. package/dist/core/utils/getRefFromSchema.d.ts +0 -3
  52. package/dist/core/utils/getRefFromSchema.d.ts.map +0 -1
  53. package/dist/core/utils/getRefFromSchema.js +0 -9
  54. package/dist/core/utils/isBoolean.d.ts +0 -2
  55. package/dist/core/utils/isBoolean.d.ts.map +0 -1
  56. package/dist/core/utils/isBoolean.js +0 -12
  57. package/dist/core/utils/isFileName.d.ts +0 -7
  58. package/dist/core/utils/isFileName.d.ts.map +0 -1
  59. package/dist/core/utils/isFileName.js +0 -30
  60. package/dist/core/utils/mapPathToTargetDirSafe.d.ts +0 -10
  61. package/dist/core/utils/mapPathToTargetDirSafe.d.ts.map +0 -1
  62. package/dist/core/utils/mapPathToTargetDirSafe.js +0 -48
  63. package/dist/core/utils/normalizeAllRefs.d.ts +0 -6
  64. package/dist/core/utils/normalizeAllRefs.d.ts.map +0 -1
  65. package/dist/core/utils/normalizeAllRefs.js +0 -35
  66. package/dist/core/utils/resolveRefToImportPath.d.ts +0 -13
  67. package/dist/core/utils/resolveRefToImportPath.d.ts.map +0 -1
  68. package/dist/core/utils/resolveRefToImportPath.js +0 -106
@@ -1,10 +0,0 @@
1
- /**
2
- * Safely muppit the path from SourceDir → targetDir
3
- * Works even if the file is outside SourceDir, but in a common parent
4
- * @param filePath
5
- * @param sourceDir
6
- * @param targetDir
7
- * @returns
8
- */
9
- export declare function mapPathToTargetDirSafe(filePath: string, sourceDir: string, targetDir: string): string;
10
- //# sourceMappingURL=mapPathToTargetDirSafe.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mapPathToTargetDirSafe.d.ts","sourceRoot":"","sources":["../../../src/core/utils/mapPathToTargetDirSafe.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CA0CrG"}
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapPathToTargetDirSafe = mapPathToTargetDirSafe;
4
- const pathHelpers_1 = require("../../common/utils/pathHelpers");
5
- const findCommonParent_1 = require("./findCommonParent");
6
- const getRelativeModelPath_1 = require("./getRelativeModelPath");
7
- /**
8
- * Safely muppit the path from SourceDir → targetDir
9
- * Works even if the file is outside SourceDir, but in a common parent
10
- * @param filePath
11
- * @param sourceDir
12
- * @param targetDir
13
- * @returns
14
- */
15
- function mapPathToTargetDirSafe(filePath, sourceDir, targetDir) {
16
- const pathSep = '/';
17
- const absFile = (0, pathHelpers_1.resolveHelper)(filePath);
18
- const absSource = (0, pathHelpers_1.resolveHelper)(sourceDir);
19
- const absTarget = (0, pathHelpers_1.resolveHelper)(targetDir);
20
- const sourceWithSep = absSource.endsWith(pathSep) ? absSource : absSource + pathSep;
21
- // 1. The file inside SourceDir → mapim as usual
22
- if (absFile.startsWith(sourceWithSep)) {
23
- const rel = (0, pathHelpers_1.relativeHelper)(absSource, absFile);
24
- return (0, pathHelpers_1.resolveHelper)(absTarget, rel);
25
- }
26
- // 2. The file is outside SourceDir, but in a common parent
27
- const commonParent = (0, findCommonParent_1.findCommonParent)(absSource, absFile);
28
- if (commonParent) {
29
- // Path from commonParent → file
30
- const fileRelToCommon = (0, pathHelpers_1.relativeHelper)(commonParent, absFile);
31
- // Path from targetDir → commonParent
32
- const targetToCommon = (0, pathHelpers_1.relativeHelper)(absTarget, commonParent);
33
- if (targetToCommon.includes('..')) {
34
- // targetDir is higher than commonParent → we can't map
35
- if (filePath) {
36
- const relativePath = (0, pathHelpers_1.relativeHelper)(absSource, absFile);
37
- return (0, getRelativeModelPath_1.getRelativeModelPath)(targetDir, relativePath);
38
- }
39
- return filePath;
40
- }
41
- // Collecting: targetDir → commonParent → file
42
- const pathFromTargetToCommon = (0, pathHelpers_1.relativeHelper)(absTarget, commonParent);
43
- const pathFromCommonToFile = fileRelToCommon;
44
- return (0, pathHelpers_1.resolveHelper)(absTarget, pathFromTargetToCommon, pathFromCommonToFile);
45
- }
46
- // 3. There is no common parent → return as is
47
- return filePath;
48
- }
@@ -1,6 +0,0 @@
1
- import type { Context } from '../Context';
2
- /**
3
- * Deep traversal and normalization of all $ref in an object
4
- */
5
- export declare function normalizeAllRefs<T extends Record<string, any>>(obj: T, context: Context, parentFilePath: string): T;
6
- //# sourceMappingURL=normalizeAllRefs.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"normalizeAllRefs.d.ts","sourceRoot":"","sources":["../../../src/core/utils/normalizeAllRefs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAG1C;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC1D,GAAG,EAAE,CAAC,EACN,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,MAAM,GACvB,CAAC,CA6BH"}
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeAllRefs = normalizeAllRefs;
4
- const normalizeRef_1 = require("./normalizeRef");
5
- /**
6
- * Deep traversal and normalization of all $ref in an object
7
- */
8
- function normalizeAllRefs(obj, context, parentFilePath) {
9
- if (!obj || typeof obj !== 'object' || Array.isArray(obj)) {
10
- return obj;
11
- }
12
- // If this object is a $ref holder
13
- if (obj.$ref && typeof obj.$ref === 'string') {
14
- const normalizedRef = (0, normalizeRef_1.normalizeRef)(obj.$ref, parentFilePath);
15
- return {
16
- ...obj,
17
- $ref: normalizedRef
18
- };
19
- }
20
- const result = Array.isArray(obj) ? [] : { ...obj };
21
- for (const [key, value] of Object.entries(obj)) {
22
- if (value && typeof value === 'object') {
23
- // For nested objects, use the same parent file path
24
- // The normalization will handle the $ref resolution correctly
25
- result[key] = normalizeAllRefs(value, context, parentFilePath);
26
- }
27
- else if (Array.isArray(value)) {
28
- result[key] = value.map((item) => (item && typeof item === 'object' ? normalizeAllRefs(item, context, parentFilePath) : item));
29
- }
30
- else {
31
- result[key] = value;
32
- }
33
- }
34
- return result;
35
- }
@@ -1,13 +0,0 @@
1
- interface IParams {
2
- mainSpecPath: string;
3
- parentFilePath: string;
4
- refValuePath: string;
5
- outputModelsPath: string;
6
- }
7
- /**
8
- * Resolves $ref reference to import path for generated code.
9
- * Handles HTTP URLs, local fragments, external file fragments, external files, and absolute paths.
10
- */
11
- export declare function resolveRefToImportPath({ mainSpecPath, parentFilePath, refValuePath, outputModelsPath }: IParams): string;
12
- export {};
13
- //# sourceMappingURL=resolveRefToImportPath.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolveRefToImportPath.d.ts","sourceRoot":"","sources":["../../../src/core/utils/resolveRefToImportPath.ts"],"names":[],"mappings":"AAQA,UAAU,OAAO;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;CAC5B;AAoED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,gBAAgB,EAAE,EAAE,OAAO,UA4C/G"}
@@ -1,106 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveRefToImportPath = resolveRefToImportPath;
4
- const path_1 = require("path");
5
- const fileSystemHelpers_1 = require("../../common/utils/fileSystemHelpers");
6
- const pathHelpers_1 = require("../../common/utils/pathHelpers");
7
- const mapPathToTargetDirSafe_1 = require("./mapPathToTargetDirSafe");
8
- const parseRef_1 = require("./parseRef");
9
- const stripNamespace_1 = require("./stripNamespace");
10
- /**
11
- * Resolves model path and returns relative path or fallback name.
12
- * Returns fallback if the path is outside outputModelsPath, otherwise returns relative path.
13
- */
14
- function resolveModelPath(absModelPath, absOutputModelsPath, fallbackName) {
15
- if (!absModelPath.startsWith(absOutputModelsPath + '/') && absModelPath !== absOutputModelsPath) {
16
- return `./${fallbackName}`;
17
- }
18
- return (0, pathHelpers_1.relativeHelper)(absOutputModelsPath, absModelPath);
19
- }
20
- /**
21
- * Resolves fragment reference (LOCAL_FRAGMENT or EXTERNAL_FILE_FRAGMENT).
22
- * Both types use the same logic: resolve model path based on parent file location.
23
- */
24
- function resolveFragmentRef(modelName, parentFilePath, mainSpecPath, sourceRoot, outputModelsPath, absOutputModelsPath) {
25
- const cleanParentForLocal = (0, stripNamespace_1.stripNamespace)(parentFilePath || mainSpecPath);
26
- const parentDirInSource = (0, pathHelpers_1.dirNameHelper)(cleanParentForLocal);
27
- const parentDirInOutput = (0, mapPathToTargetDirSafe_1.mapPathToTargetDirSafe)(parentDirInSource, sourceRoot, outputModelsPath);
28
- const modelFilePathInOutput = (0, pathHelpers_1.resolveHelper)(parentDirInOutput, modelName);
29
- const absModelPath = (0, pathHelpers_1.resolveHelper)(modelFilePathInOutput);
30
- return resolveModelPath(absModelPath, absOutputModelsPath, modelName);
31
- }
32
- /**
33
- * Resolves external file or absolute path reference.
34
- * Maps the target file path to output directory and returns relative path or fallback.
35
- */
36
- function resolveExternalFileOrAbsolutePath(targetFileAbs, sourceRoot, outputModelsPath, absOutputModelsPath) {
37
- const targetPathInOutput = (0, mapPathToTargetDirSafe_1.mapPathToTargetDirSafe)(targetFileAbs, sourceRoot, outputModelsPath);
38
- const absTargetPath = (0, pathHelpers_1.resolveHelper)(targetPathInOutput);
39
- const fallbackName = (0, stripNamespace_1.stripNamespace)((0, path_1.basename)(targetFileAbs));
40
- return resolveModelPath(absTargetPath, absOutputModelsPath, fallbackName);
41
- }
42
- /**
43
- * Prepares parent directory for resolving relative references.
44
- * Handles both file and directory paths.
45
- */
46
- function prepareParentDirForResolve(parentFilePath, mainSpecPath, sourceRoot) {
47
- const parentParsed = parentFilePath ? (0, parseRef_1.parseRef)(parentFilePath) : null;
48
- const parentRaw = parentParsed?.filePath ? parentParsed.filePath : '';
49
- const parentClean = (0, stripNamespace_1.stripNamespace)(parentRaw);
50
- let parentDirForResolve = fileSystemHelpers_1.fileSystemHelpers.isPathToFile(sourceRoot) ? (0, pathHelpers_1.dirNameHelper)(sourceRoot) : sourceRoot;
51
- if (parentClean) {
52
- parentDirForResolve = fileSystemHelpers_1.fileSystemHelpers.isPathToFile(parentRaw) ? (0, pathHelpers_1.dirNameHelper)(parentClean) : parentClean;
53
- }
54
- return parentDirForResolve.endsWith('/') ? parentDirForResolve : parentDirForResolve + '/';
55
- }
56
- /**
57
- * Removes parent basename prefix from reference value if present.
58
- * This handles cases where refValuePath starts with parent directory name.
59
- */
60
- function removeParentBasenamePrefix(refValueClean, parentDirForResolveWithSep) {
61
- const baseNameParent = (0, path_1.basename)(parentDirForResolveWithSep);
62
- const baseNameParentWithSep = baseNameParent.endsWith('/') ? baseNameParent : baseNameParent + '/';
63
- return refValueClean.startsWith(baseNameParentWithSep) ? refValueClean.replace(baseNameParentWithSep, '') : refValueClean;
64
- }
65
- /**
66
- * Resolves $ref reference to import path for generated code.
67
- * Handles HTTP URLs, local fragments, external file fragments, external files, and absolute paths.
68
- */
69
- function resolveRefToImportPath({ mainSpecPath, parentFilePath, refValuePath, outputModelsPath }) {
70
- const absOutputModelsPath = (0, pathHelpers_1.resolveHelper)(outputModelsPath);
71
- const sourceRoot = fileSystemHelpers_1.fileSystemHelpers.isDirectory(mainSpecPath) ? mainSpecPath : (0, pathHelpers_1.dirNameHelper)(mainSpecPath);
72
- const parsed = (0, parseRef_1.parseRef)(refValuePath);
73
- // HTTP URLs are returned as-is
74
- if (parsed.type === parseRef_1.RefType.HTTP_URL) {
75
- return refValuePath;
76
- }
77
- // LOCAL_FRAGMENT: reference to component in the same file (e.g., #/components/schemas/User)
78
- if (parsed.type === parseRef_1.RefType.LOCAL_FRAGMENT) {
79
- const modelName = (0, stripNamespace_1.stripNamespace)(refValuePath);
80
- return resolveFragmentRef(modelName, parentFilePath, mainSpecPath, sourceRoot, outputModelsPath, absOutputModelsPath);
81
- }
82
- // EXTERNAL_FILE_FRAGMENT: reference to component in external file (e.g., ./file.yaml#/components/schemas/User)
83
- if (parsed.type === parseRef_1.RefType.EXTERNAL_FILE_FRAGMENT) {
84
- const refFileRaw = parsed?.fragment ? parsed.fragment : '';
85
- const modelName = (0, stripNamespace_1.stripNamespace)(refFileRaw || '') || '';
86
- return resolveFragmentRef(modelName, parentFilePath, mainSpecPath, sourceRoot, outputModelsPath, absOutputModelsPath);
87
- }
88
- // Prepare parent directory for resolving relative references
89
- // This is used for both EXTERNAL_FILE and ABSOLUTE_PATH (default case)
90
- const parentDirForResolveWithSep = prepareParentDirForResolve(parentFilePath, mainSpecPath, sourceRoot);
91
- const refValueClean = (0, stripNamespace_1.stripNamespace)(refValuePath || '') || refValuePath;
92
- const currentRefValue = removeParentBasenamePrefix(refValueClean, parentDirForResolveWithSep);
93
- // EXTERNAL_FILE: reference to external file (e.g., ./file.yaml)
94
- if (parsed.type === parseRef_1.RefType.EXTERNAL_FILE) {
95
- const targetFileAbs = (0, pathHelpers_1.joinHelper)(parentDirForResolveWithSep, currentRefValue);
96
- // ВАЖНО: проверка self-reference
97
- if (parentFilePath && fileSystemHelpers_1.fileSystemHelpers.isSameFilePath(targetFileAbs, parentFilePath)) {
98
- const modelName = (0, stripNamespace_1.stripNamespace)(parentFilePath);
99
- return resolveFragmentRef(modelName, parentFilePath, mainSpecPath, sourceRoot, outputModelsPath, absOutputModelsPath);
100
- }
101
- return resolveExternalFileOrAbsolutePath(targetFileAbs, sourceRoot, outputModelsPath, absOutputModelsPath);
102
- }
103
- // ABSOLUTE_PATH (default case): absolute path reference
104
- const targetFileAbs = fileSystemHelpers_1.fileSystemHelpers.isPathToFile(refValueClean) ? (0, pathHelpers_1.joinHelper)(parentDirForResolveWithSep, refValueClean) : (0, pathHelpers_1.resolveHelper)(parentDirForResolveWithSep, refValueClean);
105
- return resolveExternalFileOrAbsolutePath(targetFileAbs, sourceRoot, outputModelsPath, absOutputModelsPath);
106
- }