ts-runtime-validation 1.6.1 → 1.6.2
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/dist/SchemaGenerator.js +301 -0
- package/dist/SchemaGenerator.js.map +1 -0
- package/dist/SchemaGenerator.test.js +125 -0
- package/dist/SchemaGenerator.test.js.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.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/package.json +1 -1
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.SchemaGenerator = void 0;
|
|
39
|
+
const fdir_1 = require("fdir");
|
|
40
|
+
const fs_1 = __importDefault(require("fs"));
|
|
41
|
+
const picomatch_1 = __importDefault(require("picomatch"));
|
|
42
|
+
const path_1 = __importDefault(require("path"));
|
|
43
|
+
const ts_morph_1 = require("ts-morph");
|
|
44
|
+
const tsj = __importStar(require("ts-json-schema-generator"));
|
|
45
|
+
const assert_1 = __importDefault(require("assert"));
|
|
46
|
+
const defaultTsMorphProjectSettings = {
|
|
47
|
+
manipulationSettings: {
|
|
48
|
+
indentationText: ts_morph_1.IndentationText.FourSpaces,
|
|
49
|
+
newLineKind: ts_morph_1.NewLineKind.LineFeed,
|
|
50
|
+
quoteKind: ts_morph_1.QuoteKind.Double,
|
|
51
|
+
usePrefixAndSuffixTextForRename: false,
|
|
52
|
+
useTrailingCommas: true,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
const defaultCreateFileOptions = {
|
|
56
|
+
overwrite: true,
|
|
57
|
+
};
|
|
58
|
+
const validationSchemaFileName = "validation.schema.json";
|
|
59
|
+
const schemaDefinitionFileName = "SchemaDefinition.ts";
|
|
60
|
+
const validationInterfacesFile = "ValidationType.ts";
|
|
61
|
+
class SchemaGenerator {
|
|
62
|
+
constructor(options) {
|
|
63
|
+
this.options = options;
|
|
64
|
+
this.outputPath = path_1.default.join(this.options.rootPath, this.options.output);
|
|
65
|
+
this.jsonSchemaOutputFile = path_1.default.join(this.options.rootPath, this.options.output, validationSchemaFileName);
|
|
66
|
+
this.tsSchemaDefinitionOutputFile = path_1.default.join(this.options.rootPath, this.options.output, schemaDefinitionFileName);
|
|
67
|
+
this.validationTypesOutputFile = path_1.default.join(this.options.rootPath, this.options.output, validationInterfacesFile);
|
|
68
|
+
this.isValidSchemaOutputFile = path_1.default.join(this.options.rootPath, this.options.output, "isValidSchema.ts");
|
|
69
|
+
this.Generate = () => __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
const { helpers, glob } = this.options;
|
|
71
|
+
const fileList = yield this.getMatchingFiles();
|
|
72
|
+
process.stdout.write(`Found ${fileList.length} schema file(s)`);
|
|
73
|
+
if (fileList.length === 0) {
|
|
74
|
+
process.stdout.write(`Aborting - no files found with glob: ${glob}`);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const fileSchemas = yield this.getJsonSchemasForFiles(fileList);
|
|
78
|
+
if (fileSchemas.size === 0) {
|
|
79
|
+
process.stdout.write(`Aborting - no types found: ${glob}`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
this.writeSchemaMapToValidationSchema(fileSchemas);
|
|
83
|
+
if (helpers === false) {
|
|
84
|
+
process.stdout.write("Skipping helper file generation");
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
yield this.writeSchemaMapToValidationTypes(fileSchemas);
|
|
88
|
+
this.writeValidatorFunction();
|
|
89
|
+
process.stdout.write("Writing validation types file");
|
|
90
|
+
this.writeValidationTypes(fileSchemas);
|
|
91
|
+
});
|
|
92
|
+
this.getMatchingFiles = () => __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
const { glob, rootPath } = this.options;
|
|
94
|
+
const api = new fdir_1.fdir().crawlWithOptions(rootPath, {
|
|
95
|
+
includeBasePath: true,
|
|
96
|
+
includeDirs: false,
|
|
97
|
+
filters: [
|
|
98
|
+
(path) => {
|
|
99
|
+
return picomatch_1.default.isMatch(path, glob, { contains: true });
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
});
|
|
103
|
+
return api.withPromise();
|
|
104
|
+
});
|
|
105
|
+
this.getJsonSchemasForFiles = (filesList) => __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
const { additionalProperties, tsconfigPath } = this.options;
|
|
107
|
+
const schemaMap = new Map();
|
|
108
|
+
const tsconfig = tsconfigPath.length > 0 ? tsconfigPath : undefined;
|
|
109
|
+
filesList.forEach((file, index) => {
|
|
110
|
+
process.stdout.write(`\rProcessing file ${index + 1} of ${filesList.length}: ${file}`);
|
|
111
|
+
const config = Object.assign({ path: file, type: "*", additionalProperties, encodeRefs: false, sortProps: true }, (tsconfig !== null ? { tsconfig } : {}));
|
|
112
|
+
const schemaGenerator = tsj.createGenerator(config);
|
|
113
|
+
const fileSchemas = schemaGenerator.createSchema(config.type);
|
|
114
|
+
schemaMap.set(file, fileSchemas);
|
|
115
|
+
});
|
|
116
|
+
return schemaMap;
|
|
117
|
+
});
|
|
118
|
+
this.getSchemaVersion = (schemaMap) => {
|
|
119
|
+
var _a;
|
|
120
|
+
const firstEntry = schemaMap.values().next().value;
|
|
121
|
+
return (_a = firstEntry["$schema"]) !== null && _a !== void 0 ? _a : "";
|
|
122
|
+
};
|
|
123
|
+
this.ensureOutputPathExists = () => {
|
|
124
|
+
if (!fs_1.default.existsSync(this.outputPath)) {
|
|
125
|
+
fs_1.default.mkdirSync(this.outputPath, { recursive: true });
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
this.writeSchemaMapToValidationSchema = (schemaMap) => {
|
|
129
|
+
const definitions = {};
|
|
130
|
+
schemaMap.forEach((fileSchema) => {
|
|
131
|
+
var _a;
|
|
132
|
+
const defs = (_a = fileSchema.definitions) !== null && _a !== void 0 ? _a : {};
|
|
133
|
+
Object.keys(defs).forEach((key) => {
|
|
134
|
+
if (definitions[key] !== undefined) {
|
|
135
|
+
try {
|
|
136
|
+
assert_1.default.deepEqual(definitions[key], defs[key]);
|
|
137
|
+
}
|
|
138
|
+
catch (e) {
|
|
139
|
+
console.error(`Duplicate symbol: ${key} found with varying definitions.\nDefinition 1:\n${JSON.stringify(definitions[key], null, 4)}\nDefinition 2:\n${JSON.stringify(defs[key], null, 4)}`);
|
|
140
|
+
throw e;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const schema = defs[key];
|
|
144
|
+
definitions[key] = schema;
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
const outputBuffer = {
|
|
148
|
+
$schema: this.getSchemaVersion(schemaMap),
|
|
149
|
+
definitions,
|
|
150
|
+
};
|
|
151
|
+
this.ensureOutputPathExists();
|
|
152
|
+
fs_1.default.writeFileSync(this.jsonSchemaOutputFile, JSON.stringify(outputBuffer, null, 4));
|
|
153
|
+
};
|
|
154
|
+
this.writeSchemaMapToValidationTypes = (schemaMap) => __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
const project = new ts_morph_1.Project(defaultTsMorphProjectSettings);
|
|
156
|
+
const readerProject = new ts_morph_1.Project(defaultTsMorphProjectSettings);
|
|
157
|
+
const symbols = [];
|
|
158
|
+
const importMap = new Map();
|
|
159
|
+
schemaMap.forEach((schema, filePath) => {
|
|
160
|
+
var _a;
|
|
161
|
+
const dir = path_1.default.dirname(filePath);
|
|
162
|
+
const fileWithoutExtension = path_1.default.parse(filePath).name;
|
|
163
|
+
const relativeFilePath = path_1.default.relative(this.outputPath, dir);
|
|
164
|
+
const importPath = `${relativeFilePath}/${fileWithoutExtension}`;
|
|
165
|
+
const defs = (_a = schema.definitions) !== null && _a !== void 0 ? _a : {};
|
|
166
|
+
const readerSourceFile = readerProject.addSourceFileAtPath(filePath);
|
|
167
|
+
Object.keys(defs).forEach((symbol) => {
|
|
168
|
+
var _a;
|
|
169
|
+
const typeAlias = readerSourceFile.getTypeAlias(symbol);
|
|
170
|
+
const typeInterface = readerSourceFile.getInterface(symbol);
|
|
171
|
+
const hasTypeOrInterface = (typeAlias !== null && typeAlias !== void 0 ? typeAlias : typeInterface) !== undefined;
|
|
172
|
+
if (hasTypeOrInterface) {
|
|
173
|
+
const namedImports = (_a = importMap.get(importPath)) !== null && _a !== void 0 ? _a : [];
|
|
174
|
+
namedImports.push(symbol);
|
|
175
|
+
importMap.set(importPath, namedImports);
|
|
176
|
+
symbols.push(symbol);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
const sourceFile = project.createSourceFile(this.tsSchemaDefinitionOutputFile, {}, defaultCreateFileOptions);
|
|
181
|
+
importMap.forEach((namedImports, importPath) => {
|
|
182
|
+
sourceFile.addImportDeclaration({ namedImports, moduleSpecifier: importPath });
|
|
183
|
+
});
|
|
184
|
+
sourceFile.addVariableStatement({
|
|
185
|
+
isExported: true,
|
|
186
|
+
declarationKind: ts_morph_1.VariableDeclarationKind.Const,
|
|
187
|
+
declarations: [
|
|
188
|
+
{
|
|
189
|
+
name: "schemas",
|
|
190
|
+
type: "Record<keyof ISchema, string>",
|
|
191
|
+
initializer: (writer) => {
|
|
192
|
+
writer.writeLine(`{`);
|
|
193
|
+
symbols.forEach((symbol) => {
|
|
194
|
+
writer.writeLine(`["#/definitions/${symbol}"] : "${symbol}",`);
|
|
195
|
+
}),
|
|
196
|
+
writer.writeLine(`}`);
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
});
|
|
201
|
+
sourceFile.addInterface({
|
|
202
|
+
kind: ts_morph_1.StructureKind.Interface,
|
|
203
|
+
name: "ISchema",
|
|
204
|
+
isExported: true,
|
|
205
|
+
properties: symbols.map((symbol) => {
|
|
206
|
+
return { name: `readonly ["#/definitions/${symbol}"]`, type: symbol };
|
|
207
|
+
}),
|
|
208
|
+
});
|
|
209
|
+
yield project.save();
|
|
210
|
+
});
|
|
211
|
+
this.writeValidatorFunction = () => __awaiter(this, void 0, void 0, function* () {
|
|
212
|
+
const project = new ts_morph_1.Project(defaultTsMorphProjectSettings);
|
|
213
|
+
const sourceFile = project.createSourceFile(this.isValidSchemaOutputFile, {}, defaultCreateFileOptions);
|
|
214
|
+
sourceFile.addImportDeclaration({ namespaceImport: "schema", moduleSpecifier: `./${validationSchemaFileName}` });
|
|
215
|
+
sourceFile.addImportDeclaration({ defaultImport: "Ajv", moduleSpecifier: "ajv" });
|
|
216
|
+
sourceFile.addImportDeclaration({
|
|
217
|
+
namedImports: ["ISchema", "schemas"],
|
|
218
|
+
moduleSpecifier: `./${path_1.default.parse(schemaDefinitionFileName).name}`,
|
|
219
|
+
});
|
|
220
|
+
sourceFile.addVariableStatement({
|
|
221
|
+
isExported: true,
|
|
222
|
+
declarationKind: ts_morph_1.VariableDeclarationKind.Const,
|
|
223
|
+
declarations: [
|
|
224
|
+
{
|
|
225
|
+
name: "validator",
|
|
226
|
+
initializer: (writer) => {
|
|
227
|
+
writer.writeLine(`new Ajv({ allErrors: true });`);
|
|
228
|
+
writer.writeLine(`validator.compile(schema)`);
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
],
|
|
232
|
+
});
|
|
233
|
+
sourceFile.addVariableStatement({
|
|
234
|
+
declarationKind: ts_morph_1.VariableDeclarationKind.Const,
|
|
235
|
+
isExported: true,
|
|
236
|
+
declarations: [
|
|
237
|
+
{
|
|
238
|
+
name: "isValidSchema",
|
|
239
|
+
initializer: (writer) => {
|
|
240
|
+
writer.writeLine(`<T extends keyof typeof schemas>(data: unknown, schemaKeyRef: T): data is ISchema[T] => {`);
|
|
241
|
+
writer.writeLine(`validator.validate(schemaKeyRef as string, data);`);
|
|
242
|
+
writer.writeLine(`return Boolean(validator.errors) === false;`);
|
|
243
|
+
writer.writeLine(`}`);
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
],
|
|
247
|
+
});
|
|
248
|
+
yield project.save();
|
|
249
|
+
});
|
|
250
|
+
this.writeValidationTypes = (schemaMap) => __awaiter(this, void 0, void 0, function* () {
|
|
251
|
+
const project = new ts_morph_1.Project(defaultTsMorphProjectSettings);
|
|
252
|
+
const readerProject = new ts_morph_1.Project(defaultTsMorphProjectSettings);
|
|
253
|
+
const symbols = [];
|
|
254
|
+
const importMap = new Map();
|
|
255
|
+
schemaMap.forEach((schema, filePath) => {
|
|
256
|
+
var _a;
|
|
257
|
+
const dir = path_1.default.dirname(filePath);
|
|
258
|
+
const fileWithoutExtension = path_1.default.parse(filePath).name;
|
|
259
|
+
const relativeFilePath = path_1.default.relative(this.outputPath, dir);
|
|
260
|
+
const importPath = `${relativeFilePath}/${fileWithoutExtension}`;
|
|
261
|
+
const defs = (_a = schema.definitions) !== null && _a !== void 0 ? _a : {};
|
|
262
|
+
const readerSourceFile = readerProject.addSourceFileAtPath(filePath);
|
|
263
|
+
Object.keys(defs).forEach((symbol) => {
|
|
264
|
+
var _a;
|
|
265
|
+
const typeAlias = readerSourceFile.getTypeAlias(symbol);
|
|
266
|
+
const typeInterface = readerSourceFile.getInterface(symbol);
|
|
267
|
+
const hasTypeOrInterface = (typeAlias !== null && typeAlias !== void 0 ? typeAlias : typeInterface) !== undefined;
|
|
268
|
+
if (hasTypeOrInterface) {
|
|
269
|
+
const namedImports = (_a = importMap.get(importPath)) !== null && _a !== void 0 ? _a : [];
|
|
270
|
+
namedImports.push(symbol);
|
|
271
|
+
importMap.set(importPath, namedImports);
|
|
272
|
+
symbols.push(symbol);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
const sourceFile = project.createSourceFile(this.validationTypesOutputFile, {}, defaultCreateFileOptions);
|
|
277
|
+
importMap.forEach((namedImports, importPath) => {
|
|
278
|
+
const declaration = sourceFile.addImportDeclaration({ moduleSpecifier: importPath });
|
|
279
|
+
namedImports.forEach((namedImport) => {
|
|
280
|
+
const name = namedImport.valueOf();
|
|
281
|
+
const alias = `_${name}`;
|
|
282
|
+
declaration.addNamedImport({ name, alias });
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
const namespace = sourceFile.addModule({
|
|
286
|
+
name: "ValidationType",
|
|
287
|
+
isExported: true,
|
|
288
|
+
});
|
|
289
|
+
importMap.forEach((namedImports) => {
|
|
290
|
+
namedImports.forEach((namedImport) => {
|
|
291
|
+
const name = namedImport.valueOf();
|
|
292
|
+
const alias = `_${name}`;
|
|
293
|
+
namespace.addTypeAlias({ name, type: alias, isExported: true });
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
yield project.save();
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
exports.SchemaGenerator = SchemaGenerator;
|
|
301
|
+
//# sourceMappingURL=SchemaGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaGenerator.js","sourceRoot":"","sources":["../src/SchemaGenerator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAA4B;AAE5B,4CAAoB;AACpB,0DAAkC;AAClC,gDAAwB;AACxB,uCAUkB;AAClB,8DAAgD;AAEhD,oDAA4B;AAE5B,MAAM,6BAA6B,GAAmB;IAClD,oBAAoB,EAAE;QAClB,eAAe,EAAE,0BAAe,CAAC,UAAU;QAC3C,WAAW,EAAE,sBAAW,CAAC,QAAQ;QACjC,SAAS,EAAE,oBAAS,CAAC,MAAM;QAC3B,+BAA+B,EAAE,KAAK;QACtC,iBAAiB,EAAE,IAAI;KAC1B;CACJ,CAAC;AAEF,MAAM,wBAAwB,GAA4B;IACtD,SAAS,EAAE,IAAI;CAClB,CAAC;AAEF,MAAM,wBAAwB,GAAG,wBAAwB,CAAC;AAC1D,MAAM,wBAAwB,GAAG,qBAAqB,CAAC;AACvD,MAAM,wBAAwB,GAAG,mBAAmB,CAAC;AAErD,MAAa,eAAe;IAOxB,YAA2B,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;QAN3C,eAAU,GAAG,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACnE,yBAAoB,GAAG,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;QACvG,iCAA4B,GAAG,cAAI,CAAC,IAAI,CAAC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AAC,CAAC,CAAC;YAEH,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC;QACzB,CAAC,CAAA,CAAC;IA3QoD,CAAC;CA4Q1D;AAnRD,0CAmRC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
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 SchemaGenerator_1 = require("./SchemaGenerator");
|
|
18
|
+
const cleanupTestOutput = () => {
|
|
19
|
+
const outputDir = path_1.default.resolve(__dirname, "./test/output");
|
|
20
|
+
const doesDirectoryExist = fs_1.default.existsSync(outputDir);
|
|
21
|
+
if (doesDirectoryExist) {
|
|
22
|
+
fs_1.default.rmSync(outputDir, { recursive: true });
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const getGeneratorConfig = (scenarioPath) => {
|
|
26
|
+
const options = {
|
|
27
|
+
glob: "*.jsonschema.ts",
|
|
28
|
+
rootPath: path_1.default.resolve(__dirname, `./test/${scenarioPath}`),
|
|
29
|
+
output: `../output/${scenarioPath}`,
|
|
30
|
+
helpers: true,
|
|
31
|
+
additionalProperties: false,
|
|
32
|
+
tsconfigPath: "",
|
|
33
|
+
};
|
|
34
|
+
return options;
|
|
35
|
+
};
|
|
36
|
+
const getOutputSchemaPath = (scenarioPath) => {
|
|
37
|
+
return path_1.default.resolve(__dirname, `./test/output/${scenarioPath}`, "validation.schema.json");
|
|
38
|
+
};
|
|
39
|
+
beforeAll(cleanupTestOutput);
|
|
40
|
+
afterAll(cleanupTestOutput);
|
|
41
|
+
describe("SchemaGenerator", () => {
|
|
42
|
+
test("it should generate the correct schema for a basic interface", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
const scenarioPath = "basic-scenario";
|
|
44
|
+
const options = getGeneratorConfig(scenarioPath);
|
|
45
|
+
const generator = new SchemaGenerator_1.SchemaGenerator(options);
|
|
46
|
+
yield generator.Generate();
|
|
47
|
+
const rawFile = fs_1.default.readFileSync(getOutputSchemaPath(scenarioPath)).toString();
|
|
48
|
+
const result = JSON.parse(rawFile);
|
|
49
|
+
const expected = {
|
|
50
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
51
|
+
definitions: {
|
|
52
|
+
IBasicTypes: {
|
|
53
|
+
type: "object",
|
|
54
|
+
properties: {
|
|
55
|
+
propertyA: {
|
|
56
|
+
type: "string",
|
|
57
|
+
},
|
|
58
|
+
propertyB: {
|
|
59
|
+
type: "string",
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
required: ["propertyA", "propertyB"],
|
|
63
|
+
additionalProperties: false,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
expect(result).toStrictEqual(expected);
|
|
68
|
+
}));
|
|
69
|
+
test("it should throw an error when there are different implementations of an interface", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
+
const options = getGeneratorConfig("duplicate-symbols-different-implementation");
|
|
71
|
+
const generator = new SchemaGenerator_1.SchemaGenerator(options);
|
|
72
|
+
yield expect(generator.Generate()).rejects.toThrow();
|
|
73
|
+
}));
|
|
74
|
+
test("it should not an error when there are identical definitions interface", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
|
+
const scenarioPath = "duplicate-symbols-identitcal-implementation";
|
|
76
|
+
const options = getGeneratorConfig(scenarioPath);
|
|
77
|
+
const generator = new SchemaGenerator_1.SchemaGenerator(options);
|
|
78
|
+
yield generator.Generate();
|
|
79
|
+
const rawFile = fs_1.default.readFileSync(getOutputSchemaPath(scenarioPath)).toString();
|
|
80
|
+
const result = JSON.parse(rawFile);
|
|
81
|
+
const expected = {
|
|
82
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
83
|
+
definitions: {
|
|
84
|
+
IBasicTypesA: {
|
|
85
|
+
type: "object",
|
|
86
|
+
properties: {
|
|
87
|
+
propertyA: {
|
|
88
|
+
$ref: "#/definitions/IBaseType",
|
|
89
|
+
},
|
|
90
|
+
propertyB: {
|
|
91
|
+
$ref: "#/definitions/IBaseType",
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
required: ["propertyA", "propertyB"],
|
|
95
|
+
additionalProperties: false,
|
|
96
|
+
},
|
|
97
|
+
IBaseType: {
|
|
98
|
+
type: "object",
|
|
99
|
+
properties: {
|
|
100
|
+
someProperty: {
|
|
101
|
+
type: "string",
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
required: ["someProperty"],
|
|
105
|
+
additionalProperties: false,
|
|
106
|
+
},
|
|
107
|
+
IBasicTypesB: {
|
|
108
|
+
type: "object",
|
|
109
|
+
properties: {
|
|
110
|
+
propertyA: {
|
|
111
|
+
$ref: "#/definitions/IBaseType",
|
|
112
|
+
},
|
|
113
|
+
propertyB: {
|
|
114
|
+
$ref: "#/definitions/IBaseType",
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
required: ["propertyA", "propertyB"],
|
|
118
|
+
additionalProperties: false,
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
expect(result).toStrictEqual(expected);
|
|
123
|
+
}));
|
|
124
|
+
});
|
|
125
|
+
//# sourceMappingURL=SchemaGenerator.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaGenerator.test.js","sourceRoot":"","sources":["../src/SchemaGenerator.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAExB,uDAAoD;AAEpD,MAAM,iBAAiB,GAAG,GAAG,EAAE;IAC3B,MAAM,SAAS,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;IAC3D,MAAM,kBAAkB,GAAG,YAAE,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IACpD,IAAI,kBAAkB,EAAE;QACpB,YAAE,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;KAC7C;AACL,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,YAAoB,EAAE,EAAE;IAChD,MAAM,OAAO,GAAoB;QAC7B,IAAI,EAAE,iBAAiB;QACvB,QAAQ,EAAE,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,YAAY,EAAE,CAAC;QAC3D,MAAM,EAAE,aAAa,YAAY,EAAE;QACnC,OAAO,EAAE,IAAI;QACb,oBAAoB,EAAE,KAAK;QAC3B,YAAY,EAAE,EAAE;KACnB,CAAC;IACF,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,mBAAmB,GAAG,CAAC,YAAoB,EAAE,EAAE;IACjD,OAAO,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,iBAAiB,YAAY,EAAE,EAAE,wBAAwB,CAAC,CAAC;AAC9F,CAAC,CAAC;AAEF,SAAS,CAAC,iBAAiB,CAAC,CAAC;AAC7B,QAAQ,CAAC,iBAAiB,CAAC,CAAC;AAE5B,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC7B,IAAI,CAAC,6DAA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
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const SchemaGenerator_1 = require("./SchemaGenerator");
|
|
5
|
+
const commander_1 = require("commander");
|
|
6
|
+
const defaultGlobPattern = "*.jsonschema.{ts,tsx}";
|
|
7
|
+
const defaultRootPath = "./src";
|
|
8
|
+
const defaultOutputFolder = "./.ts-runtime-validation";
|
|
9
|
+
const defaultTsconfig = "";
|
|
10
|
+
commander_1.program.option("--glob", `Glob file path of typescript files to generate ts-interface -> json-schema validations - default: ${defaultGlobPattern}`, defaultGlobPattern);
|
|
11
|
+
commander_1.program.option("--rootPath <rootFolder>", `RootPath of source`, defaultRootPath);
|
|
12
|
+
commander_1.program.option("--output <outputFolder>", `Code generation output directory (relative to root path)`, defaultOutputFolder);
|
|
13
|
+
commander_1.program.option("--tsconfigPath <tsconfigPath>", `Path to customt tsconfig (relative to root path)`, defaultTsconfig);
|
|
14
|
+
commander_1.program.option("--generate-helpers", "Only generate JSON schema without typescript helper files", true);
|
|
15
|
+
commander_1.program.option("--additionalProperties", "Allow additional properties to pass validation", false);
|
|
16
|
+
commander_1.program.parse();
|
|
17
|
+
const options = commander_1.program.opts();
|
|
18
|
+
const generator = new SchemaGenerator_1.SchemaGenerator(options);
|
|
19
|
+
generator.Generate();
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAEA,uDAAoD;AACpD,yCAAoC;AAEpC,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;AAEnD,MAAM,eAAe,GAAG,OAAO,CAAC;AAChC,MAAM,mBAAmB,GAAG,0BAA0B,CAAC;AACvD,MAAM,eAAe,GAAG,EAAE,CAAC;AAW3B,mBAAO,CAAC,MAAM,CACV,QAAQ,EACR,qGAAqG,kBAAkB,EAAE,EACzH,kBAAkB,CACrB,CAAC;AACF,mBAAO,CAAC,MAAM,CAAC,yBAAyB,EAAE,oBAAoB,EAAE,eAAe,CAAC,CAAC;AACjF,mBAAO,CAAC,MAAM,CAAC,yBAAyB,EAAE,0DAA0D,EAAE,mBAAmB,CAAC,CAAC;AAC3H,mBAAO,CAAC,MAAM,CAAC,+BAA+B,EAAE,kDAAkD,EAAE,eAAe,CAAC,CAAC;AACrH,mBAAO,CAAC,MAAM,CAAC,oBAAoB,EAAE,2DAA2D,EAAE,IAAI,CAAC,CAAC;AACxG,mBAAO,CAAC,MAAM,CAAC,wBAAwB,EAAE,gDAAgD,EAAE,KAAK,CAAC,CAAC;AAElG,mBAAO,CAAC,KAAK,EAAE,CAAC;AAEhB,MAAM,OAAO,GAAG,mBAAO,CAAC,IAAI,EAAmB,CAAC;AAEhD,MAAM,SAAS,GAAG,IAAI,iCAAe,CAAC,OAAO,CAAC,CAAC;AAC/C,SAAS,CAAC,QAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.jsonschema.js","sourceRoot":"","sources":["../../../src/test/basic-scenario/types.jsonschema.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IBaseType.js","sourceRoot":"","sources":["../../../src/test/duplicate-symbols-different-implementation/IBaseType.ts"],"names":[],"mappings":""}
|
package/dist/test/duplicate-symbols-different-implementation/IBaseTypeDefinitionReplicated.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IBaseTypeDefinitionReplicated.js","sourceRoot":"","sources":["../../../src/test/duplicate-symbols-different-implementation/IBaseTypeDefinitionReplicated.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IBasicTypesA.jsonschema.js","sourceRoot":"","sources":["../../../src/test/duplicate-symbols-different-implementation/IBasicTypesA.jsonschema.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IBasicTypesB.jsonschema.js","sourceRoot":"","sources":["../../../src/test/duplicate-symbols-different-implementation/IBasicTypesB.jsonschema.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IBaseType.js","sourceRoot":"","sources":["../../../src/test/duplicate-symbols-identitcal-implementation/IBaseType.ts"],"names":[],"mappings":""}
|
package/dist/test/duplicate-symbols-identitcal-implementation/IBaseTypeDefinitionReplicated.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IBaseTypeDefinitionReplicated.js","sourceRoot":"","sources":["../../../src/test/duplicate-symbols-identitcal-implementation/IBaseTypeDefinitionReplicated.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IBasicTypesA.jsonschema.js","sourceRoot":"","sources":["../../../src/test/duplicate-symbols-identitcal-implementation/IBasicTypesA.jsonschema.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IBasicTypesB.jsonschema.js","sourceRoot":"","sources":["../../../src/test/duplicate-symbols-identitcal-implementation/IBasicTypesB.jsonschema.ts"],"names":[],"mappings":""}
|