1
- import { isObject } from "../../utils/isObject" ;
2
1
import { Keyword , JsonSchemaResolverParams , JsonSchemaValidatorParams , ValidationResult } from "../../Keyword" ;
3
2
import { SchemaNode } from "../../types" ;
4
3
import { getValue } from "../../utils/getValue" ;
@@ -19,7 +18,7 @@ export const additionalItemsKeyword: Keyword = {
19
18
// must come as last resolver
20
19
export function parseAdditionalItems ( node : SchemaNode ) {
21
20
const { schema, evaluationPath, schemaLocation } = node ;
22
- if ( ( isObject ( schema . additionalItems ) || schema . additionalItems === true ) && Array . isArray ( schema . items ) ) {
21
+ if ( schema . additionalItems != null && Array . isArray ( schema . items ) ) {
23
22
node . items = node . compileSchema (
24
23
schema . additionalItems ,
25
24
`${ evaluationPath } /additionalItems` ,
@@ -39,7 +38,7 @@ function additionalItemsResolver({ node, key, data }: JsonSchemaResolverParams)
39
38
40
39
function validateAdditionalItems ( { node, data, pointer, path } : JsonSchemaValidatorParams ) {
41
40
const { schema } = node ;
42
- if ( ! Array . isArray ( data ) || data . length === 0 ) {
41
+ if ( ! Array . isArray ( data ) || data . length === 0 || node . items == null ) {
43
42
// - no items to validate
44
43
return ;
45
44
}
@@ -51,10 +50,8 @@ function validateAdditionalItems({ node, data, pointer, path }: JsonSchemaValida
51
50
const errors : ValidationResult [ ] = [ ] ;
52
51
for ( let i = startIndex ; i < data . length ; i += 1 ) {
53
52
const item = data [ i ] ;
54
- if ( node . items ) {
55
- const validationResult = validateNode ( node . items , item , `${ pointer } /${ i } ` , path ) ;
56
- validationResult && errors . push ( ...validationResult ) ;
57
- } else if ( schema . additionalItems === false ) {
53
+ // @ts -expect-error boolean-schema
54
+ if ( node . items ?. schema === false ) {
58
55
errors . push (
59
56
node . createError ( "additional-items-error" , {
60
57
key : i ,
@@ -63,6 +60,10 @@ function validateAdditionalItems({ node, data, pointer, path }: JsonSchemaValida
63
60
schema
64
61
} )
65
62
) ;
63
+ // @ts -expect-error boolean-schema
64
+ } else if ( node . items . schema !== true ) {
65
+ const validationResult = validateNode ( node . items , item , `${ pointer } /${ i } ` , path ) ;
66
+ validationResult && errors . push ( ...validationResult ) ;
66
67
}
67
68
}
68
69
return errors ;
0 commit comments