@@ -3,7 +3,7 @@ use std::collections::BTreeSet;
33use schemars:: schema:: { InstanceType , RootSchema , Schema , SchemaObject , SingleOrVec } ;
44use serde_json:: Value ;
55
6- use crate :: { Change , ChangeKind , Error , JsonSchemaType } ;
6+ use crate :: { Change , ChangeKind , Error , JsonSchemaType , Range } ;
77
88pub struct DiffWalker {
99 pub changes : Vec < Change > ,
@@ -143,6 +143,42 @@ impl DiffWalker {
143143 Ok ( ( ) )
144144 }
145145
146+ fn diff_range (
147+ & mut self ,
148+ json_path : & str ,
149+ lhs : & mut SchemaObject ,
150+ rhs : & mut SchemaObject ,
151+ ) -> Result < ( ) , Error > {
152+ let mut diff = |lhs, rhs, range| match ( lhs, rhs) {
153+ ( None , Some ( value) ) => self . changes . push ( Change {
154+ path : json_path. to_owned ( ) ,
155+ change : ChangeKind :: RangeAdd {
156+ added : range,
157+ value,
158+ } ,
159+ } ) ,
160+ ( Some ( value) , None ) => self . changes . push ( Change {
161+ path : json_path. to_owned ( ) ,
162+ change : ChangeKind :: RangeRemove {
163+ removed : range,
164+ value,
165+ } ,
166+ } ) ,
167+ ( Some ( lhs) , Some ( rhs) ) if lhs != rhs => self . changes . push ( Change {
168+ path : json_path. to_owned ( ) ,
169+ change : ChangeKind :: RangeChange {
170+ changed : range,
171+ old_value : lhs,
172+ new_value : rhs,
173+ } ,
174+ } ) ,
175+ _ => ( ) ,
176+ } ;
177+ diff ( lhs. number ( ) . minimum , rhs. number ( ) . minimum , Range :: Minimum ) ;
178+ diff ( lhs. number ( ) . maximum , rhs. number ( ) . maximum , Range :: Maximum ) ;
179+ Ok ( ( ) )
180+ }
181+
146182 fn diff_array_items (
147183 & mut self ,
148184 json_path : & str ,
@@ -263,6 +299,7 @@ impl DiffWalker {
263299 self . diff_any_of ( json_path, lhs, rhs) ?;
264300 self . diff_instance_types ( json_path, lhs, rhs) ;
265301 self . diff_properties ( json_path, lhs, rhs) ?;
302+ self . diff_range ( json_path, lhs, rhs) ?;
266303 self . diff_additional_properties ( json_path, lhs, rhs) ?;
267304 self . diff_array_items ( json_path, lhs, rhs) ?;
268305 Ok ( ( ) )
0 commit comments