@@ -3,16 +3,26 @@ func items(context: Context, items: Any, instance: Any, schema: [String: Any]) t
3
3
return AnySequence ( EmptyCollection ( ) )
4
4
}
5
5
6
+ let instances : [ ( Int , Any ) ]
7
+ if let prefixItems = schema [ " prefixItems " ] as? [ Any ] {
8
+ guard instance. count > prefixItems. count else {
9
+ return AnySequence ( EmptyCollection ( ) )
10
+ }
11
+ instances = Array ( Array ( instance. enumerated ( ) ) [ prefixItems. count... ] )
12
+ } else {
13
+ instances = Array ( instance. enumerated ( ) )
14
+ }
15
+
6
16
if let items = items as? [ String : Any ] {
7
- return try AnySequence ( Array ( instance . enumerated ( ) ) . map { ( index, instance) throws -> AnySequence < ValidationError > in
17
+ return try AnySequence ( instances . map { ( index, instance) throws -> AnySequence < ValidationError > in
8
18
context. instanceLocation. push ( index. description)
9
19
defer { context. instanceLocation. pop ( ) }
10
20
return try context. descend ( instance: instance, subschema: items)
11
21
} . joined ( ) )
12
22
}
13
23
14
24
if let items = items as? Bool {
15
- return try AnySequence ( Array ( instance . enumerated ( ) ) . map { ( index, instance) throws -> AnySequence < ValidationError > in
25
+ return try AnySequence ( instances . map { ( index, instance) throws -> AnySequence < ValidationError > in
16
26
context. instanceLocation. push ( index. description)
17
27
defer { context. instanceLocation. pop ( ) }
18
28
return try context. descend ( instance: instance, subschema: items)
@@ -22,7 +32,7 @@ func items(context: Context, items: Any, instance: Any, schema: [String: Any]) t
22
32
if let items = items as? [ Any ] {
23
33
var results = [ AnySequence < ValidationError > ] ( )
24
34
25
- for (index, item) in instance . enumerated ( ) where index < items. count {
35
+ for (index, item) in instances where index < items. count {
26
36
context. instanceLocation. push ( index. description)
27
37
defer { context. instanceLocation. pop ( ) }
28
38
results. append ( try context. descend ( instance: item, subschema: items [ index] ) )
0 commit comments