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,449 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const node_assert_1 = require("node:assert");
4
- const node_test_1 = require("node:test");
5
- const fileSystemHelpers_1 = require("../../../common/utils/fileSystemHelpers");
6
- const Consts_1 = require("../../types/Consts");
7
- const resolveRefToImportPath_1 = require("../resolveRefToImportPath");
8
- // Normalization of paths for cross-platform
9
- const normalizePath = (p) => p.replace(Consts_1.REGEX_BACKSLASH, '/');
10
- (0, node_test_1.describe)('@unit resolveRefToImportPath — correctly resolves links to components', () => {
11
- const mainSpecPath = '/Users/user/Developer/my_app/openapi/app/openapi_spec.yaml';
12
- const outputModelsPath = '/Users/user/Developer/openapi-codegen/generated/account/models';
13
- const originalIsDirectory = fileSystemHelpers_1.fileSystemHelpers.isDirectory;
14
- const originalIsPathToFile = fileSystemHelpers_1.fileSystemHelpers.isPathToFile;
15
- (0, node_test_1.beforeEach)(() => {
16
- fileSystemHelpers_1.fileSystemHelpers.isDirectory = node_test_1.mock.fn(() => false);
17
- fileSystemHelpers_1.fileSystemHelpers.isPathToFile = node_test_1.mock.fn(() => true);
18
- });
19
- (0, node_test_1.afterEach)(() => {
20
- fileSystemHelpers_1.fileSystemHelpers.isDirectory = originalIsDirectory;
21
- fileSystemHelpers_1.fileSystemHelpers.isPathToFile = originalIsPathToFile;
22
- });
23
- (0, node_test_1.describe)('HTTP_URL', () => {
24
- (0, node_test_1.test)('http URL → returns URL as is', () => {
25
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
26
- mainSpecPath,
27
- parentFilePath: mainSpecPath,
28
- refValuePath: 'http://example.com/schema.json',
29
- outputModelsPath,
30
- });
31
- node_assert_1.strict.equal(result, 'http://example.com/schema.json');
32
- });
33
- (0, node_test_1.test)('https URL → returns URL as is', () => {
34
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
35
- mainSpecPath,
36
- parentFilePath: mainSpecPath,
37
- refValuePath: 'https://api.example.com/schemas/user.yaml',
38
- outputModelsPath,
39
- });
40
- node_assert_1.strict.equal(result, 'https://api.example.com/schemas/user.yaml');
41
- });
42
- });
43
- (0, node_test_1.describe)('LOCAL_FRAGMENT', () => {
44
- (0, node_test_1.test)('internal link in the child file → path to the model by schema name', () => {
45
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
46
- mainSpecPath,
47
- parentFilePath: '/Users/user/Developer/my_app/openapi/app/spec/accountSpec.yaml#/components/schemas/AccountField',
48
- refValuePath: '#/components/schemas/AccountField',
49
- outputModelsPath,
50
- });
51
- node_assert_1.strict.equal(normalizePath(result), './spec/AccountField');
52
- });
53
- (0, node_test_1.test)('internal link in the main file → model in the root output', () => {
54
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
55
- mainSpecPath,
56
- parentFilePath: mainSpecPath,
57
- refValuePath: '#/components/schemas/MainUser',
58
- outputModelsPath,
59
- });
60
- node_assert_1.strict.equal(normalizePath(result), './MainUser');
61
- });
62
- (0, node_test_1.test)('internal link without parentFilePath → uses mainSpecPath', () => {
63
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
64
- mainSpecPath,
65
- parentFilePath: '',
66
- refValuePath: '#/components/schemas/MainUser',
67
- outputModelsPath,
68
- });
69
- node_assert_1.strict.equal(normalizePath(result), './MainUser');
70
- });
71
- (0, node_test_1.test)('embedded internal link → folder structure is saved', () => {
72
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
73
- mainSpecPath,
74
- parentFilePath: '/Users/user/Developer/my_app/openapi/app/spec/nested/admin/schemas.yaml#/components/schemas/AdminUser',
75
- refValuePath: '#/components/schemas/AdminUser',
76
- outputModelsPath,
77
- });
78
- node_assert_1.strict.equal(normalizePath(result), './spec/nested/admin/AdminUser');
79
- });
80
- (0, node_test_1.test)('deep nesting — the path is built correctly', () => {
81
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
82
- mainSpecPath,
83
- parentFilePath: '/Users/user/Developer/my_app/openapi/app/spec/very/deep/config/models.yaml#/components/schemas/ConfigDto',
84
- refValuePath: '#/components/schemas/ConfigDto',
85
- outputModelsPath,
86
- });
87
- node_assert_1.strict.equal(normalizePath(result), './spec/very/deep/config/ConfigDto');
88
- });
89
- (0, node_test_1.test)('LOCAL_FRAGMENT with responses component', () => {
90
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
91
- mainSpecPath,
92
- parentFilePath: '/Users/user/Developer/my_app/openapi/app/spec/accountSpec.yaml',
93
- refValuePath: '#/components/responses/ErrorResponse',
94
- outputModelsPath,
95
- });
96
- node_assert_1.strict.equal(normalizePath(result), './spec/ErrorResponse');
97
- });
98
- (0, node_test_1.test)('LOCAL_FRAGMENT with parameters component', () => {
99
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
100
- mainSpecPath,
101
- parentFilePath: '/Users/user/Developer/my_app/openapi/app/spec/accountSpec.yaml',
102
- refValuePath: '#/components/parameters/PageParam',
103
- outputModelsPath,
104
- });
105
- node_assert_1.strict.equal(normalizePath(result), './spec/PageParam');
106
- });
107
- (0, node_test_1.test)('LOCAL_FRAGMENT with mainSpecPath as directory', () => {
108
- fileSystemHelpers_1.fileSystemHelpers.isDirectory = node_test_1.mock.fn(() => true);
109
- fileSystemHelpers_1.fileSystemHelpers.isPathToFile = node_test_1.mock.fn(() => false);
110
- const mainSpecDir = '/Users/user/Developer/my_app/openapi/app';
111
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
112
- mainSpecPath: mainSpecDir,
113
- parentFilePath: '/Users/user/Developer/my_app/openapi/app/spec/accountSpec.yaml',
114
- refValuePath: '#/components/schemas/AccountField',
115
- outputModelsPath,
116
- });
117
- node_assert_1.strict.equal(normalizePath(result), './spec/AccountField');
118
- });
119
- (0, node_test_1.test)('LOCAL_FRAGMENT when mapPathToTargetDirSafe maps correctly → returns relative path', () => {
120
- // Even with different output path, mapPathToTargetDirSafe finds common parent
121
- // and maps the path, so function returns relative path, not fallback
122
- const externalOutputPath = '/Users/user/Developer/other_project/generated/models';
123
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
124
- mainSpecPath,
125
- parentFilePath: '/Users/user/Developer/my_app/openapi/app/spec/accountSpec.yaml',
126
- refValuePath: '#/components/schemas/AccountField',
127
- outputModelsPath: externalOutputPath,
128
- });
129
- // The path is still mapped correctly via common parent
130
- node_assert_1.strict.equal(normalizePath(result), './spec/AccountField');
131
- });
132
- });
133
- (0, node_test_1.describe)('EXTERNAL_FILE_FRAGMENT', () => {
134
- (0, node_test_1.test)('external file with fragment → resolves to correct model path', () => {
135
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
136
- mainSpecPath,
137
- parentFilePath: '/Users/user/Developer/my_app/openapi/app/spec/accountSpec.yaml',
138
- refValuePath: './users-list.yaml#/components/schemas/UserList',
139
- outputModelsPath,
140
- });
141
- node_assert_1.strict.equal(normalizePath(result), './spec/UserList');
142
- });
143
- (0, node_test_1.test)('external file fragment with nested path', () => {
144
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
145
- mainSpecPath,
146
- parentFilePath: '/Users/user/Developer/my_app/openapi/app/spec/accountSpec.yaml',
147
- refValuePath: '../shared/common.yaml#/components/schemas/CommonModel',
148
- outputModelsPath,
149
- });
150
- // Should resolve relative to parent file directory
151
- const normalized = normalizePath(result);
152
- node_assert_1.strict.ok(normalized.includes('CommonModel') || normalized.includes('common'));
153
- });
154
- (0, node_test_1.test)('external file fragment without parentFilePath', () => {
155
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
156
- mainSpecPath,
157
- parentFilePath: '',
158
- refValuePath: './shared/models.yaml#/components/schemas/SharedModel',
159
- outputModelsPath,
160
- });
161
- const normalized = normalizePath(result);
162
- node_assert_1.strict.ok(normalized.includes('SharedModel') || normalized.includes('shared'));
163
- });
164
- (0, node_test_1.test)('external file fragment with responses component', () => {
165
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
166
- mainSpecPath,
167
- parentFilePath: '/Users/user/Developer/my_app/openapi/app/spec/accountSpec.yaml',
168
- refValuePath: './responses.yaml#/components/responses/ApiResponse',
169
- outputModelsPath,
170
- });
171
- const normalized = normalizePath(result);
172
- node_assert_1.strict.ok(normalized.includes('ApiResponse') || normalized.includes('spec'));
173
- });
174
- (0, node_test_1.test)('EXTERNAL_FILE_FRAGMENT when path is outside outputModelsPath → returns fallback', () => {
175
- const externalOutputPath = '/Users/user/Developer/other_project/generated/models';
176
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
177
- mainSpecPath,
178
- parentFilePath: '/Users/user/Developer/my_app/openapi/app/spec/accountSpec.yaml',
179
- refValuePath: './users-list.yaml#/components/schemas/UserList',
180
- outputModelsPath: externalOutputPath,
181
- });
182
- // mapPathToTargetDirSafe finds common parent and still maps the path,
183
- // so it returns relative path instead of fallback
184
- node_assert_1.strict.equal(normalizePath(result), './spec/UserList');
185
- });
186
- (0, node_test_1.test)('EXTERNAL_FILE_FRAGMENT self-reference → treated as LOCAL_FRAGMENT', () => {
187
- const parent = '/Users/user/Developer/my_app/openapi/app/spec/dir/some.yaml';
188
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
189
- mainSpecPath,
190
- parentFilePath: parent,
191
- refValuePath: '../some.yaml#/components/schemas/User',
192
- outputModelsPath,
193
- });
194
- node_assert_1.strict.equal(normalizePath(result), './spec/dir/User');
195
- });
196
- });
197
- (0, node_test_1.describe)('EXTERNAL_FILE', () => {
198
- (0, node_test_1.test)('external link to the file → correct name via getClassName', () => {
199
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
200
- mainSpecPath,
201
- parentFilePath: '/Users/user/Developer/my_app/openapi/app/spec/accountSpec.yaml',
202
- refValuePath: './users-list.yaml',
203
- outputModelsPath,
204
- });
205
- node_assert_1.strict.equal(normalizePath(result), './spec/UsersList');
206
- });
207
- (0, node_test_1.test)('the link to the file without the extension → is processed correctly', () => {
208
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
209
- mainSpecPath,
210
- parentFilePath: '/Users/user/Developer/my_app/openapi/app/spec/shared.yaml',
211
- refValuePath: './common/error',
212
- outputModelsPath,
213
- });
214
- node_assert_1.strict.equal(normalizePath(result), './spec/common/Error');
215
- });
216
- (0, node_test_1.test)('external file with relative path up directory', () => {
217
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
218
- mainSpecPath,
219
- parentFilePath: '/Users/user/Developer/my_app/openapi/app/spec/nested/accountSpec.yaml',
220
- refValuePath: '../shared/common.yaml',
221
- outputModelsPath,
222
- });
223
- const normalized = normalizePath(result);
224
- node_assert_1.strict.ok(normalized.includes('Common') || normalized.includes('spec/shared'));
225
- });
226
- (0, node_test_1.test)('external file with absolute path', () => {
227
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
228
- mainSpecPath,
229
- parentFilePath: '/Users/user/Developer/my_app/openapi/app/spec/accountSpec.yaml',
230
- refValuePath: '/Users/user/Developer/my_app/openapi/shared/models.yaml',
231
- outputModelsPath,
232
- });
233
- const normalized = normalizePath(result);
234
- // Absolute paths are handled in default case
235
- node_assert_1.strict.ok(typeof normalized === 'string');
236
- });
237
- (0, node_test_1.test)('EXTERNAL_FILE when path is outside outputModelsPath → returns fallback', () => {
238
- const externalOutputPath = '/Users/user/Developer/other_project/generated/models';
239
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
240
- mainSpecPath,
241
- parentFilePath: '/Users/user/Developer/my_app/openapi/app/spec/accountSpec.yaml',
242
- refValuePath: './users-list.yaml',
243
- outputModelsPath: externalOutputPath,
244
- });
245
- // mapPathToTargetDirSafe finds common parent and still maps the path,
246
- // so it returns relative path instead of fallback
247
- node_assert_1.strict.equal(normalizePath(result), './spec/UsersList');
248
- });
249
- (0, node_test_1.test)('external file reference from main spec file', () => {
250
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
251
- mainSpecPath,
252
- parentFilePath: mainSpecPath,
253
- refValuePath: './schemas/user.yaml',
254
- outputModelsPath,
255
- });
256
- const normalized = normalizePath(result);
257
- node_assert_1.strict.ok(normalized.includes('User') || normalized === './User');
258
- });
259
- node_test_1.test.skip('external file reference with parentFilePath as directory', () => {
260
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
261
- mainSpecPath: '/Developer/my-app/api/openapi_spec.yaml',
262
- parentFilePath: '/Developer/my-app/api/ui/components/dir/some.yaml',
263
- refValuePath: '../components/dir/file_name.yaml',
264
- outputModelsPath: '/generated/models',
265
- });
266
- // NOTE:
267
- // When parentFilePath is a directory, it is treated as a resolve base,
268
- // not as a namespace to be duplicated.
269
- node_assert_1.strict.equal(normalizePath(result), './ui/components/dir/FileName');
270
- });
271
- (0, node_test_1.test)('EXTERNAL_FILE self-reference via ./same.yaml → treated as LOCAL_FRAGMENT', () => {
272
- const parent = '/Users/user/Developer/my_app/openapi/app/spec/dir/some.yaml';
273
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
274
- mainSpecPath,
275
- parentFilePath: parent,
276
- refValuePath: './some.yaml',
277
- outputModelsPath,
278
- });
279
- node_assert_1.strict.equal(normalizePath(result), './spec/dir/Some');
280
- });
281
- (0, node_test_1.test)('EXTERNAL_FILE via ../same.yaml → treated as external sibling file', () => {
282
- const parent = '/Users/user/Developer/my_app/openapi/app/spec/dir/some.yaml';
283
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
284
- mainSpecPath,
285
- parentFilePath: parent,
286
- refValuePath: '../some.yaml',
287
- outputModelsPath,
288
- });
289
- node_assert_1.strict.equal(normalizePath(result), './spec/Some');
290
- });
291
- (0, node_test_1.test)('EXTERNAL_FILE self-reference via ./same.yaml', () => {
292
- const parent = '/Users/user/Developer/my_app/openapi/app/spec/dir/some.yaml';
293
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
294
- mainSpecPath,
295
- parentFilePath: parent,
296
- refValuePath: './some.yaml',
297
- outputModelsPath,
298
- });
299
- node_assert_1.strict.equal(normalizePath(result), './spec/dir/Some');
300
- });
301
- (0, node_test_1.test)('EXTERNAL_FILE with same basename but different path is NOT self-reference', () => {
302
- const parent = '/Users/user/Developer/my_app/openapi/app/spec/dir/some.yaml';
303
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
304
- mainSpecPath,
305
- parentFilePath: parent,
306
- refValuePath: '../other/some.yaml',
307
- outputModelsPath,
308
- });
309
- const normalized = normalizePath(result);
310
- node_assert_1.strict.ok(normalized.includes('Some') && normalized.includes('other'), 'should be treated as external file');
311
- });
312
- });
313
- (0, node_test_1.describe)('ABSOLUTE_PATH (default case)', () => {
314
- (0, node_test_1.test)('absolute path to file → resolves correctly', () => {
315
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
316
- mainSpecPath,
317
- parentFilePath: '/Users/user/Developer/my_app/openapi/app/spec/accountSpec.yaml',
318
- refValuePath: '/Users/user/Developer/my_app/openapi/shared/models/user.yaml',
319
- outputModelsPath,
320
- });
321
- const normalized = normalizePath(result);
322
- node_assert_1.strict.ok(typeof normalized === 'string' && normalized.length > 0);
323
- });
324
- (0, node_test_1.test)('absolute path when isPathToFile returns true', () => {
325
- fileSystemHelpers_1.fileSystemHelpers.isDirectory = node_test_1.mock.fn(() => false);
326
- fileSystemHelpers_1.fileSystemHelpers.isPathToFile = node_test_1.mock.fn((path) => {
327
- return path.includes('user.yaml');
328
- });
329
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
330
- mainSpecPath,
331
- parentFilePath: '/Users/user/Developer/my_app/openapi/app/spec/accountSpec.yaml',
332
- refValuePath: '/Users/user/Developer/my_app/openapi/shared/models/user.yaml',
333
- outputModelsPath,
334
- });
335
- const normalized = normalizePath(result);
336
- node_assert_1.strict.ok(typeof normalized === 'string');
337
- });
338
- (0, node_test_1.test)('absolute path when isPathToFile returns false (directory)', () => {
339
- fileSystemHelpers_1.fileSystemHelpers.isDirectory = node_test_1.mock.fn((path) => {
340
- return path.includes('models');
341
- });
342
- fileSystemHelpers_1.fileSystemHelpers.isPathToFile = node_test_1.mock.fn(() => false);
343
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
344
- mainSpecPath,
345
- parentFilePath: '/Users/user/Developer/my_app/openapi/app/spec/accountSpec.yaml',
346
- refValuePath: '/Users/user/Developer/my_app/openapi/shared/models',
347
- outputModelsPath,
348
- });
349
- const normalized = normalizePath(result);
350
- node_assert_1.strict.ok(typeof normalized === 'string');
351
- });
352
- (0, node_test_1.test)('absolute path when path is outside outputModelsPath → returns fallback', () => {
353
- const externalOutputPath = '/Users/user/Developer/other_project/generated/models';
354
- fileSystemHelpers_1.fileSystemHelpers.isDirectory = node_test_1.mock.fn(() => false);
355
- fileSystemHelpers_1.fileSystemHelpers.isPathToFile = node_test_1.mock.fn(() => true);
356
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
357
- mainSpecPath,
358
- parentFilePath: '/Users/user/Developer/my_app/openapi/app/spec/accountSpec.yaml',
359
- refValuePath: '/Users/user/Developer/my_app/openapi/shared/models/user.yaml',
360
- outputModelsPath: externalOutputPath,
361
- });
362
- // Should return fallback with basename
363
- const normalized = normalizePath(result);
364
- node_assert_1.strict.ok(normalized.includes('User') || normalized === './User');
365
- });
366
- (0, node_test_1.test)('absolute path with parentFilePath as directory', () => {
367
- fileSystemHelpers_1.fileSystemHelpers.isDirectory = node_test_1.mock.fn((path) => {
368
- return path.includes('app');
369
- });
370
- fileSystemHelpers_1.fileSystemHelpers.isPathToFile = node_test_1.mock.fn((path) => {
371
- return !path.includes('app');
372
- });
373
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
374
- mainSpecPath,
375
- parentFilePath: '/Users/user/Developer/my_app/openapi/app',
376
- refValuePath: '/Users/user/Developer/my_app/openapi/shared/models/user.yaml',
377
- outputModelsPath,
378
- });
379
- const normalized = normalizePath(result);
380
- node_assert_1.strict.ok(typeof normalized === 'string');
381
- });
382
- });
383
- (0, node_test_1.describe)('Edge cases', () => {
384
- (0, node_test_1.test)('parentFilePath with fragment but refValuePath is external file', () => {
385
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
386
- mainSpecPath,
387
- parentFilePath: '/Users/user/Developer/my_app/openapi/app/spec/accountSpec.yaml#/components/schemas/Account',
388
- refValuePath: './users-list.yaml',
389
- outputModelsPath,
390
- });
391
- node_assert_1.strict.equal(normalizePath(result), './spec/UsersList');
392
- });
393
- (0, node_test_1.test)('refValuePath starts with parent baseName → removes prefix correctly', () => {
394
- fileSystemHelpers_1.fileSystemHelpers.isDirectory = node_test_1.mock.fn(() => false);
395
- fileSystemHelpers_1.fileSystemHelpers.isPathToFile = node_test_1.mock.fn(() => true);
396
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
397
- mainSpecPath,
398
- parentFilePath: '/Users/user/Developer/my_app/openapi/app/spec/accountSpec.yaml',
399
- refValuePath: 'accountSpec.yaml/nested/model.yaml',
400
- outputModelsPath,
401
- });
402
- const normalized = normalizePath(result);
403
- node_assert_1.strict.ok(typeof normalized === 'string');
404
- });
405
- (0, node_test_1.test)('empty refValuePath with default handling', () => {
406
- // parseRef returns LOCAL_FRAGMENT for empty/invalid refs
407
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
408
- mainSpecPath,
409
- parentFilePath: mainSpecPath,
410
- refValuePath: '',
411
- outputModelsPath,
412
- });
413
- const normalized = normalizePath(result);
414
- node_assert_1.strict.ok(typeof normalized === 'string');
415
- });
416
- (0, node_test_1.test)('parentFilePath without filePath in parsed result', () => {
417
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
418
- mainSpecPath,
419
- parentFilePath: '#/components/schemas/Parent',
420
- refValuePath: './child.yaml',
421
- outputModelsPath,
422
- });
423
- const normalized = normalizePath(result);
424
- node_assert_1.strict.ok(typeof normalized === 'string');
425
- });
426
- (0, node_test_1.test)('when absModelPath equals absOutputModelsPath', () => {
427
- // This tests the condition: absModelPath !== absOutputModelsPath
428
- const customOutputPath = '/Users/user/Developer/openapi-codegen/generated/models';
429
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
430
- mainSpecPath: '/Users/user/Developer/my_app/openapi/app/openapi_spec.yaml',
431
- parentFilePath: '/Users/user/Developer/my_app/openapi/app/openapi_spec.yaml',
432
- refValuePath: '#/components/schemas/MainUser',
433
- outputModelsPath: customOutputPath,
434
- });
435
- const normalized = normalizePath(result);
436
- node_assert_1.strict.ok(typeof normalized === 'string');
437
- });
438
- });
439
- (0, node_test_1.test)('self-reference works even with redundant path segments', () => {
440
- const parent = '/Users/user/Developer/my_app/openapi/app/spec/dir/some.yaml';
441
- const result = (0, resolveRefToImportPath_1.resolveRefToImportPath)({
442
- mainSpecPath,
443
- parentFilePath: parent,
444
- refValuePath: './sub/../some.yaml',
445
- outputModelsPath,
446
- });
447
- node_assert_1.strict.equal(normalizePath(result), './spec/dir/Some');
448
- });
449
- });
@@ -1,7 +0,0 @@
1
- /**
2
- * Finds the common parent directory of two paths
3
- * @param path1 The value of the path
4
- * @param path2 The value of the path
5
- */
6
- export declare function findCommonParent(path1: string, path2: string): string | null;
7
- //# sourceMappingURL=findCommonParent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"findCommonParent.d.ts","sourceRoot":"","sources":["../../../src/core/utils/findCommonParent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAa5E"}
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findCommonParent = findCommonParent;
4
- /**
5
- * Finds the common parent directory of two paths
6
- * @param path1 The value of the path
7
- * @param path2 The value of the path
8
- */
9
- function findCommonParent(path1, path2) {
10
- const pathSep = '/';
11
- const parts1 = path1.split(pathSep).filter(Boolean);
12
- const parts2 = path2.split(pathSep).filter(Boolean);
13
- let i = 0;
14
- while (i < parts1.length && i < parts2.length && parts1[i] === parts2[i]) {
15
- i++;
16
- }
17
- if (i === 0)
18
- return null;
19
- return pathSep + parts1.slice(0, i).join(pathSep);
20
- }
@@ -1,4 +0,0 @@
1
- import { Context } from '../Context';
2
- import { RefWithType } from '../types/base/RefWithtype.model';
3
- export declare function getGatheringRefs(context: Context, object: Record<string, any>, references?: RefWithType[], root?: string, isSchema?: boolean): RefWithType[];
4
- //# sourceMappingURL=getGatheringRefs.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getGatheringRefs.d.ts","sourceRoot":"","sources":["../../../src/core/utils/getGatheringRefs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAe9D,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,UAAU,GAAE,WAAW,EAAO,EAAE,IAAI,GAAE,MAAW,EAAE,QAAQ,GAAE,OAAe,GAAG,WAAW,EAAE,CAqD3K"}
@@ -1,68 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getGatheringRefs = getGatheringRefs;
7
- const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
8
- const TypeRef_enum_1 = require("../types/enums/TypeRef.enum");
9
- const normalizeRef_1 = require("./normalizeRef");
10
- const parseRef_1 = require("./parseRef");
11
- const resolveRefPath_1 = require("./resolveRefPath");
12
- function includes(references, value) {
13
- return references.findIndex(item => (0, fast_deep_equal_1.default)(item.value, value)) !== -1;
14
- }
15
- function extractBasePath(path) {
16
- // Extracting the base path to the last `#`
17
- return path.includes('#') ? path.split('#')[0] : path;
18
- }
19
- function getGatheringRefs(context, object, references = [], root = '', isSchema = false) {
20
- // If the object is not valid, we return the links
21
- if (!object || typeof object !== 'object') {
22
- return references;
23
- }
24
- if (object.$ref) {
25
- // Parse the reference to understand its type
26
- const baseRoot = extractBasePath(root);
27
- const parsedRef = (0, parseRef_1.parseRef)(object.$ref);
28
- // Create normalized reference for context.get
29
- const normalizedRef = (0, normalizeRef_1.normalizeRef)(object.$ref, baseRoot);
30
- if (includes(references, normalizedRef)) {
31
- return references;
32
- }
33
- references.push({ value: normalizedRef, type: isSchema ? TypeRef_enum_1.TypeRef.SCHEMA : TypeRef_enum_1.TypeRef.OTHERS });
34
- const newObject = context.get(normalizedRef);
35
- // For recursive processing, determine the correct root path
36
- let newRoot;
37
- if (parsedRef.type === 'local_fragment') {
38
- // For local fragments, keep the same root
39
- newRoot = baseRoot;
40
- }
41
- else if (parsedRef.type === 'external_file' || parsedRef.type === 'external_file_fragment') {
42
- // For external files, use the resolved file path
43
- const resolvedPath = (0, resolveRefPath_1.resolveRefPath)(parsedRef, baseRoot);
44
- newRoot = resolvedPath;
45
- }
46
- else {
47
- // For other types, use the normalized path without fragment
48
- const [filePath] = normalizedRef.split('#');
49
- newRoot = filePath;
50
- }
51
- return getGatheringRefs(context, newObject, references, newRoot, isSchema);
52
- }
53
- else if (object.schema) {
54
- Object.values(object).forEach(value => {
55
- if (value instanceof Object) {
56
- getGatheringRefs(context, value, references, root, true);
57
- }
58
- });
59
- }
60
- else {
61
- Object.values(object).forEach(value => {
62
- if (value instanceof Object) {
63
- getGatheringRefs(context, value, references, root, isSchema);
64
- }
65
- });
66
- }
67
- return references;
68
- }
@@ -1,3 +0,0 @@
1
- import { Context } from '../Context';
2
- export declare function getRefFromSchema(context: Context, object: Record<string, any>): string[];
3
- //# sourceMappingURL=getRefFromSchema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getRefFromSchema.d.ts","sourceRoot":"","sources":["../../../src/core/utils/getRefFromSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAIrC,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,EAAE,CAGxF"}
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRefFromSchema = getRefFromSchema;
4
- const TypeRef_enum_1 = require("../types/enums/TypeRef.enum");
5
- const getGatheringRefs_1 = require("./getGatheringRefs");
6
- function getRefFromSchema(context, object) {
7
- const references = (0, getGatheringRefs_1.getGatheringRefs)(context, object);
8
- return references.filter(item => item.type === TypeRef_enum_1.TypeRef.SCHEMA).map(value => value.value);
9
- }
@@ -1,2 +0,0 @@
1
- export declare function isBoolean(value: any, defaultValue?: boolean): any;
2
- //# sourceMappingURL=isBoolean.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isBoolean.d.ts","sourceRoot":"","sources":["../../../src/core/utils/isBoolean.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,YAAY,UAAQ,OAUzD"}
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isBoolean = isBoolean;
4
- function isBoolean(value, defaultValue = false) {
5
- if (value === null || value === undefined) {
6
- return defaultValue;
7
- }
8
- if (value === true || value === false) {
9
- return value;
10
- }
11
- return defaultValue;
12
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * Checks if the string is just a file name (with an extension)
3
- * @param str - the line to check
4
- * @returns true, if this is the file name
5
- */
6
- export declare function isFileName(str: string): boolean;
7
- //# sourceMappingURL=isFileName.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isFileName.d.ts","sourceRoot":"","sources":["../../../src/core/utils/isFileName.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAmB/C"}
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isFileName = isFileName;
4
- /**
5
- * Checks if the string is just a file name (with an extension)
6
- * @param str - the line to check
7
- * @returns true, if this is the file name
8
- */
9
- function isFileName(str) {
10
- if (typeof str !== 'string' || !str)
11
- return false;
12
- // 1. Does not contain path separators
13
- if (str.includes('/') || str.includes('\\'))
14
- return false;
15
- // 2. Does not start with ./, ../, \
16
- if (/^\.\.?[\\/\\]/.test(str))
17
- return false;
18
- if (str.startsWith('/'))
19
- return false;
20
- // 3. Contains at least one dot and does not end with a dot.
21
- const parts = str.split('.');
22
- if (parts.length < 2)
23
- return false;
24
- if (parts[parts.length - 1] === '')
25
- return false; // ends with .
26
- // 4. The file name is not empty
27
- if (parts[0] === '')
28
- return false;
29
- return true;
30
- }