1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1
2
import { expect , test } from "@jest/globals" ;
2
3
import { z } from "zod" ;
3
4
import { zodToGeminiParameters } from "../utils/zod_to_gemini_parameters.js" ;
@@ -18,7 +19,7 @@ test("zodToGeminiParameters can convert zod schema to gemini schema", () => {
18
19
19
20
expect ( convertedSchema . type ) . toBe ( "object" ) ;
20
21
expect ( convertedSchema . description ) . toBe ( "A simple calculator tool" ) ;
21
- expect ( convertedSchema ) . not . toContain ( "additionalProperties" ) ;
22
+ expect ( ( convertedSchema as any ) . additionalProperties ) . toBeUndefined ( ) ;
22
23
expect ( convertedSchema . properties ) . toEqual ( {
23
24
operation : {
24
25
type : "string" ,
@@ -45,3 +46,37 @@ test("zodToGeminiParameters can convert zod schema to gemini schema", () => {
45
46
"childObject" ,
46
47
] ) ;
47
48
} ) ;
49
+
50
+ test ( "zodToGeminiParameters removes additional properties from arrays" , ( ) => {
51
+ const zodSchema = z
52
+ . object ( {
53
+ people : z
54
+ . object ( {
55
+ name : z . string ( ) . describe ( "The name of a person" ) ,
56
+ } )
57
+ . array ( )
58
+ . describe ( "person elements" ) ,
59
+ } )
60
+ . describe ( "A list of people" ) ;
61
+
62
+ const convertedSchema = zodToGeminiParameters ( zodSchema ) ;
63
+ expect ( convertedSchema . type ) . toBe ( "object" ) ;
64
+ expect ( convertedSchema . description ) . toBe ( "A list of people" ) ;
65
+ expect ( ( convertedSchema as any ) . additionalProperties ) . toBeUndefined ( ) ;
66
+
67
+ const peopleSchema = convertedSchema ?. properties ?. people ;
68
+ expect ( peopleSchema ) . not . toBeUndefined ( ) ;
69
+
70
+ if ( peopleSchema !== undefined ) {
71
+ expect ( peopleSchema . type ) . toBe ( "array" ) ;
72
+ expect ( ( peopleSchema as any ) . additionalProperties ) . toBeUndefined ( ) ;
73
+ expect ( peopleSchema . description ) . toBe ( "person elements" ) ;
74
+ }
75
+
76
+ const arrayItemsSchema = peopleSchema ?. items ;
77
+ expect ( arrayItemsSchema ) . not . toBeUndefined ( ) ;
78
+ if ( arrayItemsSchema !== undefined ) {
79
+ expect ( arrayItemsSchema . type ) . toBe ( "object" ) ;
80
+ expect ( ( arrayItemsSchema as any ) . additionalProperties ) . toBeUndefined ( ) ;
81
+ }
82
+ } ) ;
0 commit comments