1 | "use strict";
|
2 | var chai_1 = require("chai");
|
3 | var TJS = require("../typescript-json-schema");
|
4 | var fs_1 = require("fs");
|
5 | var path_1 = require("path");
|
6 | var Ajv = require("ajv");
|
7 | var ajv = new Ajv();
|
8 | var base = "test/programs/";
|
9 | function assertSchema(group, name, type, settings, compilerOptions) {
|
10 | it(group + " should create correct schema", function () {
|
11 | if (!settings) {
|
12 | settings = TJS.getDefaultArgs();
|
13 | settings.generateRequired = true;
|
14 | }
|
15 | var actual = TJS.generateSchema(TJS.getProgramFromFiles([path_1.resolve(base + group + "/" + name)], compilerOptions), type, settings);
|
16 | var file = fs_1.readFileSync(base + group + "/schema.json", "utf8");
|
17 | var expected = JSON.parse(file);
|
18 | chai_1.assert.isObject(actual);
|
19 | chai_1.assert.deepEqual(actual, expected, "The schema is not as expected");
|
20 | ajv.validateSchema(actual);
|
21 | chai_1.assert.equal(ajv.errors, null, "The schema is not valid");
|
22 | });
|
23 | }
|
24 | exports.assertSchema = assertSchema;
|
25 | describe("schema", function () {
|
26 | assertSchema("array-and-description", "main.ts", "MyObject");
|
27 | assertSchema("class-single", "main.ts", "MyObject");
|
28 | assertSchema("interface-single", "main.ts", "MyObject");
|
29 | assertSchema("interface-multi", "main.ts", "MyObject");
|
30 | var settings = TJS.getDefaultArgs();
|
31 | settings.useRootRef = true;
|
32 | assertSchema("interface-recursion", "main.ts", "MyObject", settings);
|
33 | assertSchema("module-interface-single", "main.ts", "MyObject");
|
34 | assertSchema("enums-string", "main.ts", "MyObject");
|
35 | assertSchema("enums-number", "main.ts", "MyObject");
|
36 | assertSchema("enums-number-initialized", "main.ts", "Enum");
|
37 | assertSchema("enums-compiled-compute", "main.ts", "Enum");
|
38 | assertSchema("enums-mixed", "main.ts", "MyObject");
|
39 | assertSchema("string-literals", "main.ts", "MyObject");
|
40 | assertSchema("string-literals-inline", "main.ts", "MyObject");
|
41 | assertSchema("array-types", "main.ts", "MyArray");
|
42 | assertSchema("map-types", "main.ts", "MyObject");
|
43 | assertSchema("namespace", "main.ts", "Type");
|
44 | assertSchema("type-union", "main.ts", "MyObject");
|
45 | assertSchema("type-intersection", "main.ts", "MyObject");
|
46 | assertSchema("type-aliases", "main.ts", "MyString");
|
47 | assertSchema("type-aliases-fixed-size-array", "main.ts", "MyFixedSizeArray");
|
48 | assertSchema("type-aliases-multitype-array", "main.ts", "MyArray");
|
49 | assertSchema("type-anonymous", "main.ts", "MyObject");
|
50 | assertSchema("type-primitives", "main.ts", "MyObject");
|
51 | assertSchema("type-nullable", "main.ts", "MyObject");
|
52 | assertSchema("optionals", "main.ts", "MyObject");
|
53 | assertSchema("comments", "main.ts", "MyObject");
|
54 | assertSchema("comments-override", "main.ts", "MyObject");
|
55 | assertSchema("type-union-tagged", "main.ts", "Shape");
|
56 | assertSchema("type-aliases-union-namespace", "main.ts", "MyModel");
|
57 | assertSchema("strict-null-checks", "main.ts", "MyObject", undefined, {
|
58 | strictNullChecks: true
|
59 | });
|
60 | });
|
61 |
|
\ | No newline at end of file |