-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathnot.ts
25 lines (22 loc) · 850 Bytes
/
not.ts
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
import { Keyword, JsonSchemaValidatorParams } from "../Keyword";
import { SchemaNode } from "../types";
import { validateNode } from "../validateNode";
export const notKeyword: Keyword = {
id: "not",
keyword: "not",
parse: parseNot,
addValidate: (node) => node.not != null,
validate: validateNot
};
export function parseNot(node: SchemaNode) {
const { schema, evaluationPath, schemaLocation } = node;
if (schema.not != null) {
node.not = node.compileSchema(schema.not, `${evaluationPath}/not`, `${schemaLocation}/not`);
}
}
function validateNot({ node, data, pointer, path }: JsonSchemaValidatorParams) {
const { schema } = node;
if (validateNode(node.not, data, pointer, path).length === 0) {
return node.createError("not-error", { value: data, not: schema.not, pointer, schema });
}
}