File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -336,7 +336,14 @@ fn diff_inner(
336
336
dbg ! ( & lhs) ;
337
337
}
338
338
339
- for ( i, ( lhs_inner, rhs_inner) ) in lhs. any_of . iter ( ) . zip ( rhs. any_of . iter ( ) ) . enumerate ( ) {
339
+ // hack to get a stable order for anyOf. serde_json::Value does not impl Hash or Ord, so we
340
+ // can't use a set.
341
+ let mut lhs_any_of = lhs. any_of . clone ( ) ;
342
+ let mut rhs_any_of = rhs. any_of . clone ( ) ;
343
+ lhs_any_of. sort_by_cached_key ( |x| format ! ( "{:?}" , x) ) ;
344
+ rhs_any_of. sort_by_cached_key ( |x| format ! ( "{:?}" , x) ) ;
345
+
346
+ for ( i, ( lhs_inner, rhs_inner) ) in lhs_any_of. iter ( ) . zip ( rhs_any_of. iter ( ) ) . enumerate ( ) {
340
347
let new_path = format ! ( "{json_path}.<anyOf:{i}>" ) ;
341
348
diff_inner ( rv, new_path, lhs_inner, rhs_inner) ?;
342
349
}
@@ -958,4 +965,25 @@ mod tests {
958
965
// rewrite crate on top of schemars::schema::Schema
959
966
assert_debug_snapshot ! ( diff, @"" ) ;
960
967
}
968
+
969
+ #[ test]
970
+ fn any_of_order_change ( ) {
971
+ let lhs = json ! { {
972
+ "anyOf" : [
973
+ { "type" : "array" } ,
974
+ { "type" : "string" } ,
975
+ ]
976
+ } } ;
977
+
978
+ let rhs = json ! { {
979
+ "anyOf" : [
980
+ { "type" : "string" } ,
981
+ { "type" : "array" } ,
982
+ ]
983
+ } } ;
984
+
985
+ let diff = diff ( lhs, rhs) . unwrap ( ) ;
986
+
987
+ assert_debug_snapshot ! ( diff, @"[]" ) ;
988
+ }
961
989
}
You can’t perform that action at this time.
0 commit comments