@@ -65,7 +65,7 @@ def test_to_gemini_schema_array_string_types(self):
6565 "nonnullable_string" : {"type" : ["string" ]},
6666 "nullable_string" : {"type" : ["string" , "null" ]},
6767 "nullable_number" : {"type" : ["null" , "integer" ]},
68- "object_nullable" : {"type" : " null" },
68+ "object_nullable" : {"type" : [ "object" , " null"] },
6969 "multi_types_nullable" : {"type" : ["string" , "null" , "integer" ]},
7070 "empty_default_object" : {},
7171 },
@@ -87,7 +87,10 @@ def test_to_gemini_schema_array_string_types(self):
8787 assert gemini_schema .properties ["object_nullable" ].type == Type .OBJECT
8888 assert gemini_schema .properties ["object_nullable" ].nullable
8989
90- assert gemini_schema .properties ["multi_types_nullable" ].type == Type .STRING
90+ assert gemini_schema .properties ["multi_types_nullable" ].any_of == [
91+ Schema (type = Type .STRING ),
92+ Schema (type = Type .INTEGER ),
93+ ]
9194 assert gemini_schema .properties ["multi_types_nullable" ].nullable
9295
9396 assert gemini_schema .properties ["empty_default_object" ].type == Type .OBJECT
@@ -146,6 +149,25 @@ def test_to_gemini_schema_any_of(self):
146149 assert gemini_schema .any_of [0 ].type == Type .STRING
147150 assert gemini_schema .any_of [1 ].type == Type .INTEGER
148151
152+ def test_to_gemini_schema_any_of_nullable (self ):
153+ openapi_schema = {
154+ "anyOf" : [{"type" : "string" }, {"type" : "null" }],
155+ }
156+ gemini_schema = _to_gemini_schema (openapi_schema )
157+ assert gemini_schema .type == Type .STRING
158+ assert gemini_schema .nullable == True
159+
160+ def test_to_gemini_schema_any_of_nullable_multiple_types (self ):
161+ openapi_schema = {
162+ "anyOf" : [{"type" : "string" }, {"type" : "integer" }, {"type" : "null" }],
163+ }
164+ gemini_schema = _to_gemini_schema (openapi_schema )
165+ assert gemini_schema .any_of == [
166+ Schema (type = Type .STRING ),
167+ Schema (type = Type .INTEGER ),
168+ ]
169+ assert gemini_schema .nullable == True
170+
149171 def test_to_gemini_schema_general_list (self ):
150172 openapi_schema = {
151173 "type" : "array" ,
@@ -524,51 +546,6 @@ def test_sanitize_schema_formats_for_gemini(self):
524546 "null" ,
525547 ]
526548
527- def test_sanitize_schema_formats_for_gemini_nullable (self ):
528- openapi_schema = {
529- "properties" : {
530- "case_id" : {
531- "description" : "The ID of the case." ,
532- "title" : "Case Id" ,
533- "type" : "string" ,
534- },
535- "next_page_token" : {
536- "anyOf" : [{"type" : "string" }, {"type" : "null" }],
537- "default" : None ,
538- "description" : (
539- "The nextPageToken to fetch the next page of results."
540- ),
541- "title" : "Next Page Token" ,
542- },
543- },
544- "required" : ["case_id" ],
545- "title" : "list_alerts_by_caseArguments" ,
546- "type" : "object" ,
547- }
548- openapi_schema = _sanitize_schema_formats_for_gemini (openapi_schema )
549- assert openapi_schema == {
550- "properties" : {
551- "case_id" : {
552- "description" : "The ID of the case." ,
553- "title" : "Case Id" ,
554- "type" : "string" ,
555- },
556- "next_page_token" : {
557- "any_of" : [
558- {"type" : "string" },
559- {"type" : ["object" , "null" ]},
560- ],
561- "description" : (
562- "The nextPageToken to fetch the next page of results."
563- ),
564- "title" : "Next Page Token" ,
565- },
566- },
567- "required" : ["case_id" ],
568- "title" : "list_alerts_by_caseArguments" ,
569- "type" : "object" ,
570- }
571-
572549 def test_to_gemini_schema_properties_is_none (self ):
573550 """Tests schema conversion when 'properties' field is None."""
574551 openapi_schema = {"type" : "object" , "properties" : None }
0 commit comments