@@ -44,12 +44,18 @@ fn gather_definition_ref(schema_ref_dict: &Bound<'_, PyDict>, ctx: &mut GatherCt
4444 if * ctx. refs_recursion_count . entry ( schema_ref_str. to_string ( ) ) . or_insert ( 0 ) == 0 {
4545 if let Some ( def) = ctx. definitions_dict . get_item ( schema_ref_pystr) ? {
4646 * ctx. refs_recursion_count . get_mut ( schema_ref_str) . unwrap ( ) += 1 ;
47+ ctx. def_refs_chain . push ( schema_ref_str. to_string ( ) ) ;
4748 gather_schema ( def. downcast_exact :: < PyDict > ( ) ?, ctx) ?;
49+ ctx. def_refs_chain . pop ( ) ;
4850 * ctx. refs_recursion_count . get_mut ( schema_ref_str) . unwrap ( ) -= 1 ;
4951 }
5052 Ok ( false )
5153 } else {
5254 ctx. recursive_def_refs . add ( schema_ref_pystr) ?;
55+ for r in & ctx. def_refs_chain {
56+ ctx. recursive_def_refs . add ( PyString :: new_bound ( schema_ref. py ( ) , r) ) ?;
57+ }
58+ ctx. def_refs_chain . clear ( ) ;
5359 Ok ( true )
5460 }
5561 } else {
@@ -183,6 +189,7 @@ pub struct GatherCtx<'a, 'py> {
183189 pub recursive_def_refs : Bound < ' py , PySet > ,
184190 pub discriminators : Bound < ' py , PyList > ,
185191 refs_recursion_count : HashMap < String , i32 > ,
192+ def_refs_chain : Vec < String > ,
186193}
187194
188195impl < ' a , ' py > GatherCtx < ' a , ' py > {
@@ -193,6 +200,7 @@ impl<'a, 'py> GatherCtx<'a, 'py> {
193200 recursive_def_refs : PySet :: empty_bound ( definitions. py ( ) ) ?,
194201 discriminators : PyList :: empty_bound ( definitions. py ( ) ) ,
195202 refs_recursion_count : HashMap :: default ( ) ,
203+ def_refs_chain : Vec :: new ( ) ,
196204 } ;
197205 Ok ( ctx)
198206 }
0 commit comments