ts-runtime-validation 1.6.16 → 1.8.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.
- package/CONTRIBUTING.md +430 -0
- package/README.md +505 -62
- package/dist/ICommandOptions.js +3 -0
- package/dist/ICommandOptions.js.map +1 -0
- package/dist/SchemaGenerator.deterministic-extended.test.js +420 -0
- package/dist/SchemaGenerator.deterministic-extended.test.js.map +1 -0
- package/dist/SchemaGenerator.deterministic.test.js +251 -0
- package/dist/SchemaGenerator.deterministic.test.js.map +1 -0
- package/dist/SchemaGenerator.integration.test.js +323 -0
- package/dist/SchemaGenerator.integration.test.js.map +1 -0
- package/dist/SchemaGenerator.js +120 -0
- package/dist/SchemaGenerator.js.map +1 -0
- package/dist/SchemaGenerator.test.js +226 -0
- package/dist/SchemaGenerator.test.js.map +1 -0
- package/dist/cli.test.js +155 -0
- package/dist/cli.test.js.map +1 -0
- package/dist/errors/index.js +95 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/index.test.js +232 -0
- package/dist/errors/index.test.js.map +1 -0
- package/dist/getPosixPath.js +13 -0
- package/dist/getPosixPath.js.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/lib.js.map +1 -0
- package/dist/services/CodeGenerator.js +321 -0
- package/dist/services/CodeGenerator.js.map +1 -0
- package/dist/services/FileDiscovery.js +123 -0
- package/dist/services/FileDiscovery.js.map +1 -0
- package/dist/services/FileDiscovery.test.js +184 -0
- package/dist/services/FileDiscovery.test.js.map +1 -0
- package/dist/services/SchemaProcessor.js +198 -0
- package/dist/services/SchemaProcessor.js.map +1 -0
- package/dist/services/SchemaProcessor.test.js +455 -0
- package/dist/services/SchemaProcessor.test.js.map +1 -0
- package/dist/services/SchemaWriter.js +76 -0
- package/dist/services/SchemaWriter.js.map +1 -0
- package/dist/services/SchemaWriter.test.js +255 -0
- package/dist/services/SchemaWriter.test.js.map +1 -0
- package/dist/test/basic-scenario/types.jsonschema.js +3 -0
- package/dist/test/basic-scenario/types.jsonschema.js.map +1 -0
- package/dist/test/duplicate-symbols-different-implementation/IBaseType.js +3 -0
- package/dist/test/duplicate-symbols-different-implementation/IBaseType.js.map +1 -0
- package/dist/test/duplicate-symbols-different-implementation/IBaseTypeDefinitionReplicated.js +3 -0
- package/dist/test/duplicate-symbols-different-implementation/IBaseTypeDefinitionReplicated.js.map +1 -0
- package/dist/test/duplicate-symbols-different-implementation/IBasicTypesA.jsonschema.js +3 -0
- package/dist/test/duplicate-symbols-different-implementation/IBasicTypesA.jsonschema.js.map +1 -0
- package/dist/test/duplicate-symbols-different-implementation/IBasicTypesB.jsonschema.js +3 -0
- package/dist/test/duplicate-symbols-different-implementation/IBasicTypesB.jsonschema.js.map +1 -0
- package/dist/test/duplicate-symbols-identitcal-implementation/IBaseType.js +3 -0
- package/dist/test/duplicate-symbols-identitcal-implementation/IBaseType.js.map +1 -0
- package/dist/test/duplicate-symbols-identitcal-implementation/IBaseTypeDefinitionReplicated.js +3 -0
- package/dist/test/duplicate-symbols-identitcal-implementation/IBaseTypeDefinitionReplicated.js.map +1 -0
- package/dist/test/duplicate-symbols-identitcal-implementation/IBasicTypesA.jsonschema.js +3 -0
- package/dist/test/duplicate-symbols-identitcal-implementation/IBasicTypesA.jsonschema.js.map +1 -0
- package/dist/test/duplicate-symbols-identitcal-implementation/IBasicTypesB.jsonschema.js +3 -0
- package/dist/test/duplicate-symbols-identitcal-implementation/IBasicTypesB.jsonschema.js.map +1 -0
- package/dist/utils/ProgressReporter.js +67 -0
- package/dist/utils/ProgressReporter.js.map +1 -0
- package/dist/utils/ProgressReporter.test.js +267 -0
- package/dist/utils/ProgressReporter.test.js.map +1 -0
- package/dist/writeLine.js +12 -0
- package/dist/writeLine.js.map +1 -0
- package/package.json +2 -2
- package/src/ICommandOptions.ts +7 -0
- package/src/SchemaGenerator.deterministic-extended.test.ts +429 -0
- package/src/SchemaGenerator.deterministic.test.ts +276 -0
- package/src/SchemaGenerator.integration.test.ts +411 -0
- package/src/SchemaGenerator.test.ts +118 -0
- package/src/SchemaGenerator.ts +112 -298
- package/src/cli.test.ts +130 -0
- package/src/errors/index.test.ts +319 -0
- package/src/errors/index.ts +92 -0
- package/src/index.ts +8 -1
- package/src/services/CodeGenerator.ts +370 -0
- package/src/services/FileDiscovery.test.ts +216 -0
- package/src/services/FileDiscovery.ts +140 -0
- package/src/services/SchemaProcessor.test.ts +536 -0
- package/src/services/SchemaProcessor.ts +194 -0
- package/src/services/SchemaWriter.test.ts +304 -0
- package/src/services/SchemaWriter.ts +75 -0
- package/src/utils/ProgressReporter.test.ts +357 -0
- package/src/utils/ProgressReporter.ts +76 -0
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const fs_1 = __importDefault(require("fs"));
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const SchemaProcessor_1 = require("./SchemaProcessor");
|
|
18
|
+
const errors_1 = require("../errors");
|
|
19
|
+
const testDir = path_1.default.resolve(__dirname, "../../.test-tmp/schema-processor");
|
|
20
|
+
const createTestFile = (filePath, content) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
const fullPath = path_1.default.resolve(testDir, filePath);
|
|
22
|
+
yield fs_1.default.promises.mkdir(path_1.default.dirname(fullPath), { recursive: true });
|
|
23
|
+
yield fs_1.default.promises.writeFile(fullPath, content);
|
|
24
|
+
return fullPath;
|
|
25
|
+
});
|
|
26
|
+
const cleanup = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
if (fs_1.default.existsSync(testDir)) {
|
|
28
|
+
yield fs_1.default.promises.rm(testDir, { recursive: true, force: true });
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
beforeEach(cleanup);
|
|
32
|
+
afterAll(cleanup);
|
|
33
|
+
describe("SchemaProcessor", () => {
|
|
34
|
+
describe("processFiles", () => {
|
|
35
|
+
it("should process valid TypeScript files", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
const filePath = yield createTestFile("user.jsonschema.ts", `
|
|
37
|
+
export interface IUser {
|
|
38
|
+
id: string;
|
|
39
|
+
name: string;
|
|
40
|
+
email?: string;
|
|
41
|
+
}
|
|
42
|
+
`);
|
|
43
|
+
const processor = new SchemaProcessor_1.SchemaProcessor({
|
|
44
|
+
additionalProperties: false,
|
|
45
|
+
parallel: false,
|
|
46
|
+
verbose: false
|
|
47
|
+
});
|
|
48
|
+
const files = [{ path: filePath }];
|
|
49
|
+
const schemaMap = yield processor.processFiles(files);
|
|
50
|
+
expect(schemaMap.size).toBe(1);
|
|
51
|
+
expect(schemaMap.has(filePath)).toBe(true);
|
|
52
|
+
const schema = schemaMap.get(filePath);
|
|
53
|
+
expect(schema.definitions).toBeDefined();
|
|
54
|
+
expect(schema.definitions.IUser).toBeDefined();
|
|
55
|
+
expect(schema.definitions.IUser).toMatchObject({
|
|
56
|
+
type: "object",
|
|
57
|
+
properties: {
|
|
58
|
+
id: { type: "string" },
|
|
59
|
+
name: { type: "string" },
|
|
60
|
+
email: { type: "string" }
|
|
61
|
+
},
|
|
62
|
+
required: ["id", "name"],
|
|
63
|
+
additionalProperties: false
|
|
64
|
+
});
|
|
65
|
+
}));
|
|
66
|
+
it("should handle parallel processing", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
+
const file1 = yield createTestFile("user.jsonschema.ts", `
|
|
68
|
+
export interface IUser {
|
|
69
|
+
id: string;
|
|
70
|
+
name: string;
|
|
71
|
+
}
|
|
72
|
+
`);
|
|
73
|
+
const file2 = yield createTestFile("product.jsonschema.ts", `
|
|
74
|
+
export interface IProduct {
|
|
75
|
+
id: string;
|
|
76
|
+
title: string;
|
|
77
|
+
price: number;
|
|
78
|
+
}
|
|
79
|
+
`);
|
|
80
|
+
const processor = new SchemaProcessor_1.SchemaProcessor({
|
|
81
|
+
additionalProperties: false,
|
|
82
|
+
parallel: true,
|
|
83
|
+
verbose: false
|
|
84
|
+
});
|
|
85
|
+
const files = [
|
|
86
|
+
{ path: file1 },
|
|
87
|
+
{ path: file2 }
|
|
88
|
+
];
|
|
89
|
+
const schemaMap = yield processor.processFiles(files);
|
|
90
|
+
expect(schemaMap.size).toBe(2);
|
|
91
|
+
expect(schemaMap.has(file1)).toBe(true);
|
|
92
|
+
expect(schemaMap.has(file2)).toBe(true);
|
|
93
|
+
}));
|
|
94
|
+
it("should handle sequential processing", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
|
+
const file1 = yield createTestFile("user.jsonschema.ts", `
|
|
96
|
+
export interface IUser {
|
|
97
|
+
id: string;
|
|
98
|
+
name: string;
|
|
99
|
+
}
|
|
100
|
+
`);
|
|
101
|
+
const processor = new SchemaProcessor_1.SchemaProcessor({
|
|
102
|
+
additionalProperties: false,
|
|
103
|
+
parallel: false,
|
|
104
|
+
verbose: false
|
|
105
|
+
});
|
|
106
|
+
const files = [{ path: file1 }];
|
|
107
|
+
const schemaMap = yield processor.processFiles(files);
|
|
108
|
+
expect(schemaMap.size).toBe(1);
|
|
109
|
+
}));
|
|
110
|
+
it("should handle files with syntax errors gracefully", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
111
|
+
const validFile = yield createTestFile("valid.jsonschema.ts", `
|
|
112
|
+
export interface IValid {
|
|
113
|
+
id: string;
|
|
114
|
+
}
|
|
115
|
+
`);
|
|
116
|
+
const invalidFile = yield createTestFile("invalid.jsonschema.ts", `
|
|
117
|
+
export interface IInvalid {
|
|
118
|
+
id: string
|
|
119
|
+
// missing semicolon and other syntax errors
|
|
120
|
+
name string;
|
|
121
|
+
}
|
|
122
|
+
`);
|
|
123
|
+
const processor = new SchemaProcessor_1.SchemaProcessor({
|
|
124
|
+
additionalProperties: false,
|
|
125
|
+
parallel: false,
|
|
126
|
+
verbose: false
|
|
127
|
+
});
|
|
128
|
+
const files = [
|
|
129
|
+
{ path: validFile },
|
|
130
|
+
{ path: invalidFile }
|
|
131
|
+
];
|
|
132
|
+
// Should not throw but should process valid files
|
|
133
|
+
const schemaMap = yield processor.processFiles(files);
|
|
134
|
+
// At least valid file should be processed
|
|
135
|
+
expect(schemaMap.size).toBeGreaterThan(0);
|
|
136
|
+
expect(schemaMap.has(validFile)).toBe(true);
|
|
137
|
+
}));
|
|
138
|
+
it("should respect additionalProperties setting", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
139
|
+
const filePath = yield createTestFile("user.jsonschema.ts", `
|
|
140
|
+
export interface IUser {
|
|
141
|
+
id: string;
|
|
142
|
+
name: string;
|
|
143
|
+
}
|
|
144
|
+
`);
|
|
145
|
+
const processorStrict = new SchemaProcessor_1.SchemaProcessor({
|
|
146
|
+
additionalProperties: false,
|
|
147
|
+
parallel: false
|
|
148
|
+
});
|
|
149
|
+
const processorLoose = new SchemaProcessor_1.SchemaProcessor({
|
|
150
|
+
additionalProperties: true,
|
|
151
|
+
parallel: false
|
|
152
|
+
});
|
|
153
|
+
const files = [{ path: filePath }];
|
|
154
|
+
const strictSchema = yield processorStrict.processFiles(files);
|
|
155
|
+
const looseSchema = yield processorLoose.processFiles(files);
|
|
156
|
+
const strictUser = strictSchema.get(filePath).definitions.IUser;
|
|
157
|
+
const looseUser = looseSchema.get(filePath).definitions.IUser;
|
|
158
|
+
expect(strictUser.additionalProperties).toBe(false);
|
|
159
|
+
// Note: ts-json-schema-generator may not set additionalProperties: true explicitly
|
|
160
|
+
expect(looseUser.additionalProperties === true || looseUser.additionalProperties === undefined).toBe(true);
|
|
161
|
+
}));
|
|
162
|
+
});
|
|
163
|
+
describe("validateSchemaCompatibility", () => {
|
|
164
|
+
it("should pass with identical schemas", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
165
|
+
const file1 = yield createTestFile("user1.jsonschema.ts", `
|
|
166
|
+
export interface IUser {
|
|
167
|
+
id: string;
|
|
168
|
+
name: string;
|
|
169
|
+
}
|
|
170
|
+
`);
|
|
171
|
+
const file2 = yield createTestFile("user2.jsonschema.ts", `
|
|
172
|
+
export interface IUser {
|
|
173
|
+
id: string;
|
|
174
|
+
name: string;
|
|
175
|
+
}
|
|
176
|
+
`);
|
|
177
|
+
const processor = new SchemaProcessor_1.SchemaProcessor({
|
|
178
|
+
additionalProperties: false,
|
|
179
|
+
parallel: false
|
|
180
|
+
});
|
|
181
|
+
const files = [
|
|
182
|
+
{ path: file1 },
|
|
183
|
+
{ path: file2 }
|
|
184
|
+
];
|
|
185
|
+
const schemaMap = yield processor.processFiles(files);
|
|
186
|
+
expect(() => {
|
|
187
|
+
processor.validateSchemaCompatibility(schemaMap);
|
|
188
|
+
}).not.toThrow();
|
|
189
|
+
}));
|
|
190
|
+
it("should throw DuplicateSymbolError for conflicting schemas", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
191
|
+
const file1 = yield createTestFile("user1.jsonschema.ts", `
|
|
192
|
+
export interface IUser {
|
|
193
|
+
id: string;
|
|
194
|
+
name: string;
|
|
195
|
+
}
|
|
196
|
+
`);
|
|
197
|
+
const file2 = yield createTestFile("user2.jsonschema.ts", `
|
|
198
|
+
export interface IUser {
|
|
199
|
+
id: string;
|
|
200
|
+
email: string;
|
|
201
|
+
}
|
|
202
|
+
`);
|
|
203
|
+
const processor = new SchemaProcessor_1.SchemaProcessor({
|
|
204
|
+
additionalProperties: false,
|
|
205
|
+
parallel: false
|
|
206
|
+
});
|
|
207
|
+
const files = [
|
|
208
|
+
{ path: file1 },
|
|
209
|
+
{ path: file2 }
|
|
210
|
+
];
|
|
211
|
+
const schemaMap = yield processor.processFiles(files);
|
|
212
|
+
expect(() => {
|
|
213
|
+
processor.validateSchemaCompatibility(schemaMap);
|
|
214
|
+
}).toThrow(errors_1.DuplicateSymbolError);
|
|
215
|
+
}));
|
|
216
|
+
it("should allow different symbols with same name in different contexts", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
217
|
+
const file1 = yield createTestFile("api/user.jsonschema.ts", `
|
|
218
|
+
export interface IUser {
|
|
219
|
+
id: string;
|
|
220
|
+
name: string;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export interface IProduct {
|
|
224
|
+
id: string;
|
|
225
|
+
title: string;
|
|
226
|
+
}
|
|
227
|
+
`);
|
|
228
|
+
const processor = new SchemaProcessor_1.SchemaProcessor({
|
|
229
|
+
additionalProperties: false,
|
|
230
|
+
parallel: false
|
|
231
|
+
});
|
|
232
|
+
const files = [{ path: file1 }];
|
|
233
|
+
const schemaMap = yield processor.processFiles(files);
|
|
234
|
+
expect(() => {
|
|
235
|
+
processor.validateSchemaCompatibility(schemaMap);
|
|
236
|
+
}).not.toThrow();
|
|
237
|
+
}));
|
|
238
|
+
});
|
|
239
|
+
describe("mergeSchemas", () => {
|
|
240
|
+
it("should merge multiple schemas correctly", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
241
|
+
const file1 = yield createTestFile("user.jsonschema.ts", `
|
|
242
|
+
export interface IUser {
|
|
243
|
+
id: string;
|
|
244
|
+
name: string;
|
|
245
|
+
}
|
|
246
|
+
`);
|
|
247
|
+
const file2 = yield createTestFile("product.jsonschema.ts", `
|
|
248
|
+
export interface IProduct {
|
|
249
|
+
id: string;
|
|
250
|
+
title: string;
|
|
251
|
+
price: number;
|
|
252
|
+
}
|
|
253
|
+
`);
|
|
254
|
+
const processor = new SchemaProcessor_1.SchemaProcessor({
|
|
255
|
+
additionalProperties: false,
|
|
256
|
+
parallel: false
|
|
257
|
+
});
|
|
258
|
+
const files = [
|
|
259
|
+
{ path: file1 },
|
|
260
|
+
{ path: file2 }
|
|
261
|
+
];
|
|
262
|
+
const schemaMap = yield processor.processFiles(files);
|
|
263
|
+
const mergedSchema = processor.mergeSchemas(schemaMap);
|
|
264
|
+
expect(mergedSchema.$schema).toBe("http://json-schema.org/draft-07/schema#");
|
|
265
|
+
expect(mergedSchema.definitions).toBeDefined();
|
|
266
|
+
expect(mergedSchema.definitions.IUser).toBeDefined();
|
|
267
|
+
expect(mergedSchema.definitions.IProduct).toBeDefined();
|
|
268
|
+
}));
|
|
269
|
+
it("should preserve schema version from first file", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
270
|
+
const file1 = yield createTestFile("user.jsonschema.ts", `
|
|
271
|
+
export interface IUser {
|
|
272
|
+
id: string;
|
|
273
|
+
name: string;
|
|
274
|
+
}
|
|
275
|
+
`);
|
|
276
|
+
const processor = new SchemaProcessor_1.SchemaProcessor({
|
|
277
|
+
additionalProperties: false,
|
|
278
|
+
parallel: false
|
|
279
|
+
});
|
|
280
|
+
const files = [{ path: file1 }];
|
|
281
|
+
const schemaMap = yield processor.processFiles(files);
|
|
282
|
+
const mergedSchema = processor.mergeSchemas(schemaMap);
|
|
283
|
+
expect(mergedSchema.$schema).toMatch(/json-schema\.org/);
|
|
284
|
+
}));
|
|
285
|
+
it("should handle empty schema map", () => {
|
|
286
|
+
const processor = new SchemaProcessor_1.SchemaProcessor({
|
|
287
|
+
additionalProperties: false,
|
|
288
|
+
parallel: false
|
|
289
|
+
});
|
|
290
|
+
const schemaMap = new Map();
|
|
291
|
+
const mergedSchema = processor.mergeSchemas(schemaMap);
|
|
292
|
+
expect(mergedSchema.$schema).toBe("http://json-schema.org/draft-07/schema#");
|
|
293
|
+
expect(mergedSchema.definitions).toEqual({});
|
|
294
|
+
});
|
|
295
|
+
it("should sort definitions alphabetically in merged schema", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
296
|
+
const file1 = yield createTestFile("types1.jsonschema.ts", `
|
|
297
|
+
export interface ZebraType {
|
|
298
|
+
id: string;
|
|
299
|
+
}
|
|
300
|
+
export interface AppleType {
|
|
301
|
+
name: string;
|
|
302
|
+
}
|
|
303
|
+
`);
|
|
304
|
+
const file2 = yield createTestFile("types2.jsonschema.ts", `
|
|
305
|
+
export interface MiddleType {
|
|
306
|
+
value: number;
|
|
307
|
+
}
|
|
308
|
+
export interface BananaType {
|
|
309
|
+
flag: boolean;
|
|
310
|
+
}
|
|
311
|
+
`);
|
|
312
|
+
const processor = new SchemaProcessor_1.SchemaProcessor({
|
|
313
|
+
additionalProperties: false,
|
|
314
|
+
parallel: false
|
|
315
|
+
});
|
|
316
|
+
const files = [
|
|
317
|
+
{ path: file1 },
|
|
318
|
+
{ path: file2 }
|
|
319
|
+
];
|
|
320
|
+
const schemaMap = yield processor.processFiles(files);
|
|
321
|
+
const mergedSchema = processor.mergeSchemas(schemaMap);
|
|
322
|
+
const definitionKeys = Object.keys(mergedSchema.definitions || {});
|
|
323
|
+
const sortedKeys = [...definitionKeys].sort();
|
|
324
|
+
expect(definitionKeys).toEqual(sortedKeys);
|
|
325
|
+
expect(definitionKeys).toEqual(['AppleType', 'BananaType', 'MiddleType', 'ZebraType']);
|
|
326
|
+
}));
|
|
327
|
+
it("should maintain alphabetical order for definitions with numbers and special characters", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
328
|
+
const file1 = yield createTestFile("special.jsonschema.ts", `
|
|
329
|
+
export interface Type1 {
|
|
330
|
+
id: string;
|
|
331
|
+
}
|
|
332
|
+
export interface TypeA {
|
|
333
|
+
name: string;
|
|
334
|
+
}
|
|
335
|
+
export interface Type10 {
|
|
336
|
+
value: number;
|
|
337
|
+
}
|
|
338
|
+
export interface Type2 {
|
|
339
|
+
flag: boolean;
|
|
340
|
+
}
|
|
341
|
+
`);
|
|
342
|
+
const processor = new SchemaProcessor_1.SchemaProcessor({
|
|
343
|
+
additionalProperties: false,
|
|
344
|
+
parallel: false
|
|
345
|
+
});
|
|
346
|
+
const files = [{ path: file1 }];
|
|
347
|
+
const schemaMap = yield processor.processFiles(files);
|
|
348
|
+
const mergedSchema = processor.mergeSchemas(schemaMap);
|
|
349
|
+
const definitionKeys = Object.keys(mergedSchema.definitions || {});
|
|
350
|
+
const sortedKeys = [...definitionKeys].sort();
|
|
351
|
+
expect(definitionKeys).toEqual(sortedKeys);
|
|
352
|
+
// Natural alphabetical order: numbers before letters
|
|
353
|
+
expect(definitionKeys).toEqual(['Type1', 'Type10', 'Type2', 'TypeA']);
|
|
354
|
+
}));
|
|
355
|
+
});
|
|
356
|
+
describe("error handling", () => {
|
|
357
|
+
it("should handle missing files gracefully", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
358
|
+
const processor = new SchemaProcessor_1.SchemaProcessor({
|
|
359
|
+
additionalProperties: false,
|
|
360
|
+
parallel: false,
|
|
361
|
+
verbose: false
|
|
362
|
+
});
|
|
363
|
+
const files = [
|
|
364
|
+
{ path: "/nonexistent/file.ts" }
|
|
365
|
+
];
|
|
366
|
+
// Should not throw but return empty map
|
|
367
|
+
const schemaMap = yield processor.processFiles(files);
|
|
368
|
+
expect(schemaMap.size).toBe(0);
|
|
369
|
+
}));
|
|
370
|
+
it("should provide verbose error information", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
371
|
+
const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation();
|
|
372
|
+
const processor = new SchemaProcessor_1.SchemaProcessor({
|
|
373
|
+
additionalProperties: false,
|
|
374
|
+
parallel: false,
|
|
375
|
+
verbose: true
|
|
376
|
+
});
|
|
377
|
+
const files = [
|
|
378
|
+
{ path: "/nonexistent/file.ts" }
|
|
379
|
+
];
|
|
380
|
+
yield processor.processFiles(files);
|
|
381
|
+
expect(consoleWarnSpy).toHaveBeenCalled();
|
|
382
|
+
consoleWarnSpy.mockRestore();
|
|
383
|
+
}));
|
|
384
|
+
});
|
|
385
|
+
describe("TypeScript features", () => {
|
|
386
|
+
it("should handle union types", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
387
|
+
const filePath = yield createTestFile("types.jsonschema.ts", `
|
|
388
|
+
export type Status = "active" | "inactive" | "pending";
|
|
389
|
+
|
|
390
|
+
export interface IUser {
|
|
391
|
+
id: string;
|
|
392
|
+
status: Status;
|
|
393
|
+
}
|
|
394
|
+
`);
|
|
395
|
+
const processor = new SchemaProcessor_1.SchemaProcessor({
|
|
396
|
+
additionalProperties: false,
|
|
397
|
+
parallel: false
|
|
398
|
+
});
|
|
399
|
+
const files = [{ path: filePath }];
|
|
400
|
+
const schemaMap = yield processor.processFiles(files);
|
|
401
|
+
expect(schemaMap.size).toBe(1);
|
|
402
|
+
const schema = schemaMap.get(filePath);
|
|
403
|
+
expect(schema.definitions.Status).toBeDefined();
|
|
404
|
+
expect(schema.definitions.IUser).toBeDefined();
|
|
405
|
+
}));
|
|
406
|
+
it("should handle optional properties", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
407
|
+
const filePath = yield createTestFile("user.jsonschema.ts", `
|
|
408
|
+
export interface IUser {
|
|
409
|
+
id: string;
|
|
410
|
+
name?: string;
|
|
411
|
+
email?: string;
|
|
412
|
+
age: number;
|
|
413
|
+
}
|
|
414
|
+
`);
|
|
415
|
+
const processor = new SchemaProcessor_1.SchemaProcessor({
|
|
416
|
+
additionalProperties: false,
|
|
417
|
+
parallel: false
|
|
418
|
+
});
|
|
419
|
+
const files = [{ path: filePath }];
|
|
420
|
+
const schemaMap = yield processor.processFiles(files);
|
|
421
|
+
const schema = schemaMap.get(filePath);
|
|
422
|
+
const userSchema = schema.definitions.IUser;
|
|
423
|
+
expect(userSchema.required).toEqual(expect.arrayContaining(["id", "age"]));
|
|
424
|
+
expect(userSchema.required).not.toContain("name");
|
|
425
|
+
expect(userSchema.required).not.toContain("email");
|
|
426
|
+
}));
|
|
427
|
+
it("should handle nested interfaces", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
428
|
+
const filePath = yield createTestFile("nested.jsonschema.ts", `
|
|
429
|
+
export interface IAddress {
|
|
430
|
+
street: string;
|
|
431
|
+
city: string;
|
|
432
|
+
country: string;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
export interface IUser {
|
|
436
|
+
id: string;
|
|
437
|
+
name: string;
|
|
438
|
+
address: IAddress;
|
|
439
|
+
}
|
|
440
|
+
`);
|
|
441
|
+
const processor = new SchemaProcessor_1.SchemaProcessor({
|
|
442
|
+
additionalProperties: false,
|
|
443
|
+
parallel: false
|
|
444
|
+
});
|
|
445
|
+
const files = [{ path: filePath }];
|
|
446
|
+
const schemaMap = yield processor.processFiles(files);
|
|
447
|
+
const schema = schemaMap.get(filePath);
|
|
448
|
+
expect(schema.definitions.IAddress).toBeDefined();
|
|
449
|
+
expect(schema.definitions.IUser).toBeDefined();
|
|
450
|
+
const userSchema = schema.definitions.IUser;
|
|
451
|
+
expect(userSchema.properties.address.$ref).toBe("#/definitions/IAddress");
|
|
452
|
+
}));
|
|
453
|
+
});
|
|
454
|
+
});
|
|
455
|
+
//# sourceMappingURL=SchemaProcessor.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaProcessor.test.js","sourceRoot":"","sources":["../../src/services/SchemaProcessor.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,uDAAoD;AAEpD,sCAAiD;AAEjD,MAAM,OAAO,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,kCAAkC,CAAC,CAAC;AAE5E,MAAM,cAAc,GAAG,CAAO,QAAgB,EAAE,OAAe,EAAE,EAAE;IAC/D,MAAM,QAAQ,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACjD,MAAM,YAAE,CAA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,CAAC,iCAAiC,EAAE,GAAS,EAAE;YAC7C,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC,sBAAsB,EAAE;;;;;;;;;;;;aAY7D,CAAC,CAAC;YAEH,MAAM,SAAS,GAAG,IAAI,iCAAe,CAAC;gBAClC,oBAAoB,EAAE,KAAK;gBAC3B,QAAQ,EAAE,KAAK;aAClB,CAAC,CAAC;YAEH,MAAM,KAAK,GAAe,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;YAC/C,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;YAEtD,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAE,CAAC;YACxC,MAAM,CAAC,MAAM,CAAC,WAAY,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;YACnD,MAAM,CAAC,MAAM,CAAC,WAAY,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;YAEhD,MAAM,UAAU,GAAG,MAAM,CAAC,WAAY,CAAC,KAAY,CAAC;YACpD,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QAC9E,CAAC,CAAA,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.SchemaWriter = void 0;
|
|
16
|
+
const fs_1 = __importDefault(require("fs"));
|
|
17
|
+
const path_1 = __importDefault(require("path"));
|
|
18
|
+
const errors_1 = require("../errors");
|
|
19
|
+
class SchemaWriter {
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.options = options;
|
|
22
|
+
}
|
|
23
|
+
writeJsonSchema(schema, outputFile) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
try {
|
|
26
|
+
yield this.ensureOutputPath();
|
|
27
|
+
const content = this.options.minify
|
|
28
|
+
? JSON.stringify(schema)
|
|
29
|
+
: JSON.stringify(schema, null, 4);
|
|
30
|
+
yield fs_1.default.promises.writeFile(outputFile, content, 'utf-8');
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
throw new errors_1.CodeGenerationError(`Failed to write JSON schema: ${error instanceof Error ? error.message : String(error)}`, outputFile);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
writeTypeScriptFile(content, outputFile) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
try {
|
|
40
|
+
yield this.ensureOutputPath();
|
|
41
|
+
yield fs_1.default.promises.writeFile(outputFile, content, 'utf-8');
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
throw new errors_1.CodeGenerationError(`Failed to write TypeScript file: ${error instanceof Error ? error.message : String(error)}`, outputFile);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
ensureOutputPath() {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
if (!fs_1.default.existsSync(this.options.outputPath)) {
|
|
51
|
+
yield fs_1.default.promises.mkdir(this.options.outputPath, { recursive: true });
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
cleanOutputDirectory() {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
try {
|
|
58
|
+
if (fs_1.default.existsSync(this.options.outputPath)) {
|
|
59
|
+
const files = yield fs_1.default.promises.readdir(this.options.outputPath);
|
|
60
|
+
for (const file of files) {
|
|
61
|
+
const filePath = path_1.default.join(this.options.outputPath, file);
|
|
62
|
+
const stat = yield fs_1.default.promises.stat(filePath);
|
|
63
|
+
if (stat.isFile() && (file.endsWith('.ts') || file.endsWith('.json'))) {
|
|
64
|
+
yield fs_1.default.promises.unlink(filePath);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
throw new errors_1.CodeGenerationError(`Failed to clean output directory: ${error instanceof Error ? error.message : String(error)}`);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.SchemaWriter = SchemaWriter;
|
|
76
|
+
//# sourceMappingURL=SchemaWriter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaWriter.js","sourceRoot":"","sources":["../../src/services/SchemaWriter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAExB,sCAAgD;AAOhD,MAAa,YAAY;IACrB,YAAoB,OAA4B;QAA5B,YAAO,GAAP,OAAO,CAAqB;IAAG,CAAC;IAEvC,eAAe,CACxB,MAAc,EACd,UAAkB;;YAElB,IAAI,CAAC;gBACD,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;gBAE9B,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM;oBAC/B,CAAC,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