-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmaximum.ts
34 lines (32 loc) · 972 Bytes
/
maximum.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
26
27
28
29
30
31
32
33
34
import { Keyword, JsonSchemaValidatorParams } from "../Keyword";
export const maximumKeyword: Keyword = {
id: "maximum",
keyword: "maximum",
addValidate: ({ schema }) => !isNaN(schema.maximum),
validate: validateMaximum
};
function validateMaximum({ node, data, pointer }: JsonSchemaValidatorParams) {
if (isNaN(data as number)) {
return undefined;
}
const { schema } = node;
if (schema.maximum && schema.maximum < data) {
return node.createError("maximum-error", {
maximum: schema.maximum,
length: data,
value: data,
pointer,
schema
});
}
if (schema.maximum && schema.exclusiveMaximum === true && schema.maximum === data) {
return node.createError("maximum-error", {
maximum: schema.maximum,
length: data,
pointer,
schema,
value: data
});
}
return undefined;
}