@@ -35,14 +35,6 @@ impl<F: FnMut(Change)> DiffWalker<F> {
35
35
if let ( Some ( lhs_any_of) , Some ( rhs_any_of) ) =
36
36
( & mut lhs. subschemas ( ) . any_of , & mut rhs. subschemas ( ) . any_of )
37
37
{
38
- match ( lhs_any_of. len ( ) , rhs_any_of. len ( ) ) {
39
- ( l, r) if l <= r => {
40
- lhs_any_of. append ( & mut vec ! [ Schema :: Bool ( false ) ; r - l] ) ;
41
- }
42
- ( l, r) => {
43
- rhs_any_of. append ( & mut vec ! [ Schema :: Bool ( false ) ; l - r] ) ;
44
- }
45
- }
46
38
let max_len = lhs_any_of. len ( ) . max ( rhs_any_of. len ( ) ) ;
47
39
lhs_any_of. resize ( max_len, Schema :: Bool ( false ) ) ;
48
40
rhs_any_of. resize ( max_len, Schema :: Bool ( false ) ) ;
@@ -57,11 +49,7 @@ impl<F: FnMut(Change)> DiffWalker<F> {
57
49
self . lhs_root . clone ( ) ,
58
50
self . rhs_root . clone ( ) ,
59
51
)
60
- . diff (
61
- "" ,
62
- & mut l. clone ( ) . into_object ( ) ,
63
- & mut r. clone ( ) . into_object ( ) ,
64
- ) ?;
52
+ . diff ( "" , l, r) ?;
65
53
mat[ ( i, j) ] = count;
66
54
}
67
55
}
@@ -178,15 +166,11 @@ impl<F: FnMut(Change)> DiffWalker<F> {
178
166
}
179
167
180
168
for common in rhs_props. intersection ( & lhs_props) {
181
- let lhs_child = lhs. object ( ) . properties . get ( common. as_str ( ) ) . unwrap ( ) ;
182
- let rhs_child = rhs. object ( ) . properties . get ( common. as_str ( ) ) . unwrap ( ) ;
169
+ let lhs_child = lhs. object ( ) . properties . get_mut ( common. as_str ( ) ) . unwrap ( ) ;
170
+ let rhs_child = rhs. object ( ) . properties . get_mut ( common. as_str ( ) ) . unwrap ( ) ;
183
171
184
172
let new_path = format ! ( "{json_path}.{common}" ) ;
185
- self . diff (
186
- & new_path,
187
- & mut lhs_child. clone ( ) . into_object ( ) ,
188
- & mut rhs_child. clone ( ) . into_object ( ) ,
189
- ) ?;
173
+ self . diff ( & new_path, lhs_child, rhs_child) ?;
190
174
}
191
175
192
176
Ok ( ( ) )
@@ -198,17 +182,17 @@ impl<F: FnMut(Change)> DiffWalker<F> {
198
182
lhs : & mut SchemaObject ,
199
183
rhs : & mut SchemaObject ,
200
184
) -> Result < ( ) , Error > {
201
- if let ( Some ( ref lhs_additional_properties) , Some ( ref rhs_additional_properties) ) = (
202
- & lhs. object ( ) . additional_properties ,
203
- & rhs. object ( ) . additional_properties ,
185
+ if let ( Some ( lhs_additional_properties) , Some ( rhs_additional_properties) ) = (
186
+ & mut lhs. object ( ) . additional_properties ,
187
+ & mut rhs. object ( ) . additional_properties ,
204
188
) {
205
189
if rhs_additional_properties != lhs_additional_properties {
206
190
let new_path = format ! ( "{json_path}.<additionalProperties>" ) ;
207
191
208
192
self . diff (
209
193
& new_path,
210
- & mut lhs_additional_properties. clone ( ) . into_object ( ) ,
211
- & mut rhs_additional_properties. clone ( ) . into_object ( ) ,
194
+ lhs_additional_properties,
195
+ rhs_additional_properties,
212
196
) ?;
213
197
}
214
198
}
@@ -270,7 +254,7 @@ impl<F: FnMut(Change)> DiffWalker<F> {
270
254
lhs : & mut SchemaObject ,
271
255
rhs : & mut SchemaObject ,
272
256
) -> Result < ( ) , Error > {
273
- match ( & lhs. array ( ) . items , & rhs. array ( ) . items ) {
257
+ match ( & mut lhs. array ( ) . items , & mut rhs. array ( ) . items ) {
274
258
( Some ( SingleOrVec :: Vec ( lhs_items) ) , Some ( SingleOrVec :: Vec ( rhs_items) ) ) => {
275
259
if lhs_items. len ( ) != rhs_items. len ( ) {
276
260
( self . cb ) ( Change {
@@ -282,23 +266,15 @@ impl<F: FnMut(Change)> DiffWalker<F> {
282
266
}
283
267
284
268
for ( i, ( lhs_inner, rhs_inner) ) in
285
- lhs_items. iter ( ) . zip ( rhs_items. iter ( ) ) . enumerate ( )
269
+ lhs_items. iter_mut ( ) . zip ( rhs_items. iter_mut ( ) ) . enumerate ( )
286
270
{
287
271
let new_path = format ! ( "{json_path}.{i}" ) ;
288
- self . diff (
289
- & new_path,
290
- & mut lhs_inner. clone ( ) . into_object ( ) ,
291
- & mut rhs_inner. clone ( ) . into_object ( ) ,
292
- ) ?;
272
+ self . diff ( & new_path, lhs_inner, rhs_inner) ?;
293
273
}
294
274
}
295
275
( Some ( SingleOrVec :: Single ( lhs_inner) ) , Some ( SingleOrVec :: Single ( rhs_inner) ) ) => {
296
276
let new_path = format ! ( "{json_path}.?" ) ;
297
- self . diff (
298
- & new_path,
299
- & mut lhs_inner. clone ( ) . into_object ( ) ,
300
- & mut rhs_inner. clone ( ) . into_object ( ) ,
301
- ) ?;
277
+ self . diff ( & new_path, lhs_inner, rhs_inner) ?;
302
278
}
303
279
( Some ( SingleOrVec :: Single ( lhs_inner) ) , Some ( SingleOrVec :: Vec ( rhs_items) ) ) => {
304
280
( self . cb ) ( Change {
@@ -308,13 +284,9 @@ impl<F: FnMut(Change)> DiffWalker<F> {
308
284
} ,
309
285
} ) ;
310
286
311
- for ( i, rhs_inner) in rhs_items. iter ( ) . enumerate ( ) {
287
+ for ( i, rhs_inner) in rhs_items. iter_mut ( ) . enumerate ( ) {
312
288
let new_path = format ! ( "{json_path}.{i}" ) ;
313
- self . diff (
314
- & new_path,
315
- & mut lhs_inner. clone ( ) . into_object ( ) ,
316
- & mut rhs_inner. clone ( ) . into_object ( ) ,
317
- ) ?;
289
+ self . diff ( & new_path, lhs_inner, rhs_inner) ?;
318
290
}
319
291
}
320
292
( Some ( SingleOrVec :: Vec ( lhs_items) ) , Some ( SingleOrVec :: Single ( rhs_inner) ) ) => {
@@ -325,13 +297,9 @@ impl<F: FnMut(Change)> DiffWalker<F> {
325
297
} ,
326
298
} ) ;
327
299
328
- for ( i, lhs_inner) in lhs_items. iter ( ) . enumerate ( ) {
300
+ for ( i, lhs_inner) in lhs_items. iter_mut ( ) . enumerate ( ) {
329
301
let new_path = format ! ( "{json_path}.{i}" ) ;
330
- self . diff (
331
- & new_path,
332
- & mut lhs_inner. clone ( ) . into_object ( ) ,
333
- & mut rhs_inner. clone ( ) . into_object ( ) ,
334
- ) ?;
302
+ self . diff ( & new_path, lhs_inner, rhs_inner) ?;
335
303
}
336
304
}
337
305
( None , None ) => ( ) ,
@@ -507,10 +475,24 @@ impl<F: FnMut(Change)> DiffWalker<F> {
507
475
pub fn diff (
508
476
& mut self ,
509
477
json_path : & str ,
510
- lhs : & mut SchemaObject ,
511
- rhs : & mut SchemaObject ,
478
+ lhs : & mut Schema ,
479
+ rhs : & mut Schema ,
512
480
) -> Result < ( ) , Error > {
513
- self . do_diff ( json_path, false , lhs, rhs)
481
+ match ( lhs, rhs) {
482
+ ( Schema :: Object ( lhs) , Schema :: Object ( rhs) ) => self . do_diff ( json_path, false , lhs, rhs) ,
483
+ ( bool_lhs, Schema :: Object ( rhs) ) => {
484
+ self . do_diff ( json_path, false , & mut bool_lhs. clone ( ) . into_object ( ) , rhs)
485
+ }
486
+ ( Schema :: Object ( lhs) , bool_rhs) => {
487
+ self . do_diff ( json_path, false , lhs, & mut bool_rhs. clone ( ) . into_object ( ) )
488
+ }
489
+ ( bool_lhs, bool_rhs) => self . do_diff (
490
+ json_path,
491
+ false ,
492
+ & mut bool_lhs. clone ( ) . into_object ( ) ,
493
+ & mut bool_rhs. clone ( ) . into_object ( ) ,
494
+ ) ,
495
+ }
514
496
}
515
497
}
516
498
0 commit comments