You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							37 lines
						
					
					
						
							1.0 KiB
						
					
					
				
			
		
		
	
	
							37 lines
						
					
					
						
							1.0 KiB
						
					
					
				| import type {
 | |
|   CodeKeywordDefinition,
 | |
|   KeywordErrorDefinition,
 | |
|   ErrorObject,
 | |
|   AnySchema,
 | |
| } from "../../types"
 | |
| import type {KeywordCxt} from "../../compile/validate"
 | |
| import {_, str} from "../../compile/codegen"
 | |
| import {alwaysValidSchema} from "../../compile/util"
 | |
| import {validateArray} from "../code"
 | |
| import {validateAdditionalItems} from "./additionalItems"
 | |
| 
 | |
| export type ItemsError = ErrorObject<"items", {limit: number}, AnySchema>
 | |
| 
 | |
| const error: KeywordErrorDefinition = {
 | |
|   message: ({params: {len}}) => str`must NOT have more than ${len} items`,
 | |
|   params: ({params: {len}}) => _`{limit: ${len}}`,
 | |
| }
 | |
| 
 | |
| const def: CodeKeywordDefinition = {
 | |
|   keyword: "items",
 | |
|   type: "array",
 | |
|   schemaType: ["object", "boolean"],
 | |
|   before: "uniqueItems",
 | |
|   error,
 | |
|   code(cxt: KeywordCxt) {
 | |
|     const {schema, parentSchema, it} = cxt
 | |
|     const {prefixItems} = parentSchema
 | |
|     it.items = true
 | |
|     if (alwaysValidSchema(it, schema)) return
 | |
|     if (prefixItems) validateAdditionalItems(cxt, prefixItems)
 | |
|     else cxt.ok(validateArray(cxt))
 | |
|   },
 | |
| }
 | |
| 
 | |
| export default def
 |