Skip to content

Commit 06b7a3a

Browse files
committed
Test whether the generated schemas are valid json schemas.
1 parent 01e2255 commit 06b7a3a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@
3636
"yargs": "^6.4.0"
3737
},
3838
"devDependencies": {
39+
"@types/ajv": "0.0.4",
3940
"@types/assertion-error": "^1.0.30",
4041
"@types/chai": "^3.4.34",
4142
"@types/glob": "^5.0.30",
4243
"@types/json-stable-stringify": "^1.0.29",
4344
"@types/mocha": "^2.2.33",
4445
"@types/node": "^6.0.51",
46+
"ajv": "^4.9.0",
4547
"chai": "^3.5.0",
4648
"mocha": "^3.1.2",
4749
"source-map-support": "^0.4.6",

test/schema.test.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ import {CompilerOptions} from "typescript";
33
import * as TJS from "../typescript-json-schema";
44
import {readFileSync} from "fs";
55
import {resolve} from "path";
6+
import * as Ajv from "ajv";
7+
8+
const ajv = new Ajv();
69

710
const base = "test/programs/";
811

912
export function assertSchema(group: string, name: string, type: string, settings?: any, compilerOptions?: CompilerOptions) {
1013
it(group + " should create correct schema", function() {
11-
if(!settings) {
14+
if (!settings) {
1215
settings = TJS.getDefaultArgs();
1316
settings.generateRequired = true;
1417
}
@@ -19,7 +22,11 @@ export function assertSchema(group: string, name: string, type: string, settings
1922
const expected = JSON.parse(file);
2023

2124
assert.isObject(actual);
22-
assert.deepEqual(actual, expected);
25+
assert.deepEqual(actual, expected, "The schema is not as expected");
26+
27+
// test against the meta schema
28+
ajv.validateSchema(actual);
29+
assert.equal(ajv.errors, null, "The schema is not valid");
2330
});
2431
}
2532

0 commit comments

Comments
 (0)