source: trip-planner-front/node_modules/ajv/lib/vocabularies/validation/limitProperties.ts

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 846 bytes
RevLine 
[6a3a178]1import type {CodeKeywordDefinition, KeywordErrorDefinition} from "../../types"
2import type {KeywordCxt} from "../../compile/validate"
3import {_, str, operators} from "../../compile/codegen"
4
5const error: KeywordErrorDefinition = {
6 message({keyword, schemaCode}) {
7 const comp = keyword === "maxProperties" ? "more" : "fewer"
8 return str`must NOT have ${comp} than ${schemaCode} items`
9 },
10 params: ({schemaCode}) => _`{limit: ${schemaCode}}`,
11}
12
13const def: CodeKeywordDefinition = {
14 keyword: ["maxProperties", "minProperties"],
15 type: "object",
16 schemaType: "number",
17 $data: true,
18 error,
19 code(cxt: KeywordCxt) {
20 const {keyword, data, schemaCode} = cxt
21 const op = keyword === "maxProperties" ? operators.GT : operators.LT
22 cxt.fail$data(_`Object.keys(${data}).length ${op} ${schemaCode}`)
23 },
24}
25
26export default def
Note: See TracBrowser for help on using the repository browser.