-
Notifications
You must be signed in to change notification settings - Fork 278
Expand file tree
/
Copy pathvalidate.ts
More file actions
32 lines (25 loc) · 956 Bytes
/
validate.ts
File metadata and controls
32 lines (25 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import Ajv from "ajv";
import assert from "node:assert/strict";
import * as schema from "../schemas/data.schema.json" with { type: "json" };
import * as proposedSchema from "../schemas/data.proposed.schema.json" with { type: "json" };
const ajv = new Ajv({ allErrors: true, allowUnionTypes: true });
// TODO: turn on strictNullChecks, fix all the errors, and replace this with:
// const validator = ajv.compile<WebFeaturesData>(schema);
const validator = ajv.compile(schema);
assert.equal(
validator({}),
false,
"Failed confidence check: schema validates empty object",
);
const proposedValidator = ajv.compile(proposedSchema);
assert.equal(
proposedValidator({}),
false,
"Failed confidence check: schema validates empty object",
);
assert.equal(
proposedValidator({ features: {} }),
true,
"Failed confidence check: schema rejects empty features object",
);
export { validator as validate, proposedValidator as validateProposed };