source: trip-planner-front/node_modules/ajv/lib/vocabularies/applicator/items2020.ts@ 84d0fbb

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

initial commit

  • Property mode set to 100644
File size: 1.0 KB
Line 
1import type {
2 CodeKeywordDefinition,
3 KeywordErrorDefinition,
4 ErrorObject,
5 AnySchema,
6} from "../../types"
7import type {KeywordCxt} from "../../compile/validate"
8import {_, str} from "../../compile/codegen"
9import {alwaysValidSchema} from "../../compile/util"
10import {validateArray} from "../code"
11import {validateAdditionalItems} from "./additionalItems"
12
13export type ItemsError = ErrorObject<"items", {limit: number}, AnySchema>
14
15const error: KeywordErrorDefinition = {
16 message: ({params: {len}}) => str`must NOT have more than ${len} items`,
17 params: ({params: {len}}) => _`{limit: ${len}}`,
18}
19
20const def: CodeKeywordDefinition = {
21 keyword: "items",
22 type: "array",
23 schemaType: ["object", "boolean"],
24 before: "uniqueItems",
25 error,
26 code(cxt: KeywordCxt) {
27 const {schema, parentSchema, it} = cxt
28 const {prefixItems} = parentSchema
29 it.items = true
30 if (alwaysValidSchema(it, schema)) return
31 if (prefixItems) validateAdditionalItems(cxt, prefixItems)
32 else cxt.ok(validateArray(cxt))
33 },
34}
35
36export default def
Note: See TracBrowser for help on using the repository browser.