@@ -306,6 +306,31 @@ def test_deeply_nested_anyof_and_exclusive_minimum() -> None:
306306 assert result == expected
307307
308308
309+ def test_preserve_other_types_and_lists () -> None :
310+ """Nullable/optional types handling."""
311+ original = {
312+ "type" : "object" ,
313+ "required" : ["a" , "b" ],
314+ "properties" : {
315+ "a" : {"type" : "integer" },
316+ "b" : {"anyOf" : [{"type" : "boolean" }, {"type" : "null" }]},
317+ },
318+ }
319+ expected = {
320+ "type" : "object" ,
321+ "required" : ["a" , "b" ],
322+ "properties" : {
323+ "a" : {"type" : "integer" },
324+ "b" : {"type" : "boolean" , "nullable" : True },
325+ },
326+ }
327+ # perform the update
328+ result = recursive_update (original )
329+
330+ # non-empty dict with known content should be returned
331+ assert result == expected
332+
333+
309334def test_handles_none_values () -> None :
310335 """None values should be preserved."""
311336 original = {"key" : None }
@@ -316,3 +341,71 @@ def test_handles_none_values() -> None:
316341
317342 # non-empty dict with known content should be returned
318343 assert result == expected
344+
345+
346+ def test_handles_empty_lists () -> None :
347+ """Empty list values should be preserved."""
348+ original : dict [str , Any ] = {"key" : []}
349+ expected = original .copy ()
350+
351+ # perform the update
352+ result = recursive_update (original )
353+
354+ # non-empty dict with known content should be returned
355+ assert result == expected
356+
357+
358+ def test_handles_empty_maps () -> None :
359+ """Empty maps values should be preserved."""
360+ original : dict [str , Any ] = {"key" : {}}
361+ expected = original .copy ()
362+
363+ # perform the update
364+ result = recursive_update (original )
365+
366+ # non-empty dict with known content should be returned
367+ assert result == expected
368+
369+
370+ def test_anyof_with_additional_fields_on_first_item () -> None :
371+ """Optional (nullable) types with additional fields."""
372+ original = {
373+ "anyOf" : [
374+ {"type" : "string" , "format" : "email" , "maxLength" : 50 },
375+ {"type" : "null" },
376+ ]
377+ }
378+ expected = {
379+ "type" : "string" ,
380+ "nullable" : True ,
381+ }
382+
383+ # perform the update
384+ result = recursive_update (original )
385+
386+ # non-empty dict with known content should be returned
387+ assert result == expected
388+
389+
390+ def test_anyof_with_additional_fields_more_items () -> None :
391+ """Optional (nullable) types with additional fields."""
392+ original = {
393+ "exclusiveMinimum" : 5 ,
394+ "anyOf" : [
395+ {"type" : "string" , "format" : "email" , "maxLength" : 50 },
396+ {"type" : "null" },
397+ ],
398+ "description" : "example" ,
399+ }
400+ expected = {
401+ "minimum" : 5 ,
402+ "type" : "string" ,
403+ "nullable" : True ,
404+ "description" : "example" ,
405+ }
406+
407+ # perform the update
408+ result = recursive_update (original )
409+
410+ # non-empty dict with known content should be returned
411+ assert result == expected
0 commit comments