@@ -75,26 +75,34 @@ def _to_snake_case(text: str) -> str:
75
75
76
76
77
77
def _sanitize_schema_type (schema : dict [str , Any ]) -> dict [str , Any ]:
78
- if ("type" not in schema or not schema ["type" ]) and schema .keys ().isdisjoint (
79
- schema
80
- ):
81
- schema ["type" ] = "object"
82
- if isinstance (schema .get ("type" ), list ):
83
- nullable = False
84
- non_null_type = None
85
- for t in schema ["type" ]:
86
- if t == "null" :
87
- nullable = True
88
- elif not non_null_type :
89
- non_null_type = t
90
- if not non_null_type :
91
- non_null_type = "object"
92
- if nullable :
93
- schema ["type" ] = [non_null_type , "null" ]
94
- else :
95
- schema ["type" ] = non_null_type
96
- elif schema .get ("type" ) == "null" :
97
- schema ["type" ] = ["object" , "null" ]
78
+ """Sanitizes the 'type' field and adds default 'items' for arrays."""
79
+ type_val = schema .get ("type" )
80
+ non_null_type = None
81
+ nullable = False
82
+
83
+ # First, determine the base type and nullability
84
+ if isinstance (type_val , list ):
85
+ nullable = "null" in type_val
86
+ non_null_types = [t for t in type_val if t != "null" ]
87
+ non_null_type = non_null_types [0 ] if non_null_types else None
88
+ elif type_val == "null" :
89
+ nullable = True
90
+ else :
91
+ non_null_type = type_val
92
+
93
+ # Default to 'object' if no other type is found
94
+ if not non_null_type :
95
+ non_null_type = "object"
96
+
97
+ # Single, consolidated check to add default 'items' for arrays
98
+ if non_null_type == "array" and "items" not in schema :
99
+ schema ["items" ] = {"type" : "string" }
100
+
101
+ # Finally, set the schema 'type' based on nullability
102
+ if nullable :
103
+ schema ["type" ] = [non_null_type , "null" ]
104
+ else :
105
+ schema ["type" ] = non_null_type
98
106
99
107
return schema
100
108
0 commit comments