1- import { JsonSchemaSchema , StrictJsonSchemaSchema } from "../json-schema"
1+ import { ToolInputSchema } from "../json-schema"
22
3- describe ( "JsonSchemaSchema" , ( ) => {
4- it ( "should validate a simple schema" , ( ) => {
5- const schema = { type : "object" , properties : { name : { type : "string" } } }
6-
7- const result = JsonSchemaSchema . safeParse ( schema )
8-
9- expect ( result . success ) . toBe ( true )
10- if ( result . success ) {
11- expect ( result . data . type ) . toBe ( "object" )
12- }
13- } )
14-
15- it ( "should reject invalid type values" , ( ) => {
16- const schema = { type : "invalid-type" }
17-
18- const result = JsonSchemaSchema . safeParse ( schema )
19-
20- expect ( result . success ) . toBe ( false )
21- } )
22-
23- it ( "should validate nested schemas" , ( ) => {
24- const schema = {
25- type : "object" ,
26- properties : {
27- user : {
28- type : "object" ,
29- properties : {
30- name : { type : "string" } ,
31- age : { type : "integer" } ,
32- } ,
33- } ,
34- } ,
35- }
36-
37- const result = JsonSchemaSchema . safeParse ( schema )
38-
39- expect ( result . success ) . toBe ( true )
40- } )
41-
42- it ( "should validate array schemas" , ( ) => {
43- const schema = {
44- type : "array" ,
45- items : {
46- type : "object" ,
47- properties : {
48- id : { type : "number" } ,
49- } ,
50- } ,
51- }
52-
53- const result = JsonSchemaSchema . safeParse ( schema )
54-
55- expect ( result . success ) . toBe ( true )
56- } )
57-
58- it ( "should validate schemas with anyOf/oneOf/allOf" , ( ) => {
59- const schema = {
60- anyOf : [ { type : "string" } , { type : "number" } ] ,
61- }
62-
63- const result = JsonSchemaSchema . safeParse ( schema )
64-
65- expect ( result . success ) . toBe ( true )
66- } )
67-
68- it ( "should pass through unknown properties" , ( ) => {
69- const schema = {
70- type : "object" ,
71- customProperty : "custom value" ,
72- properties : {
73- name : { type : "string" } ,
74- } ,
75- }
76-
77- const result = JsonSchemaSchema . safeParse ( schema )
78-
79- expect ( result . success ) . toBe ( true )
80- if ( result . success ) {
81- expect ( result . data . customProperty ) . toBe ( "custom value" )
82- }
83- } )
84-
85- it ( "should accept empty object (valid JSON Schema)" , ( ) => {
86- const result = JsonSchemaSchema . safeParse ( { } )
87-
88- expect ( result . success ) . toBe ( true )
89- } )
90-
91- it ( "should NOT add additionalProperties (validation only)" , ( ) => {
92- const schema = {
93- type : "object" ,
94- properties : { name : { type : "string" } } ,
95- }
96-
97- const result = JsonSchemaSchema . parse ( schema )
98-
99- expect ( result . additionalProperties ) . toBeUndefined ( )
100- } )
101- } )
102-
103- describe ( "StrictJsonSchemaSchema" , ( ) => {
3+ describe ( "ToolInputSchema" , ( ) => {
1044 it ( "should validate and default additionalProperties to false" , ( ) => {
1055 const schema = {
1066 type : "object" ,
@@ -109,7 +9,7 @@ describe("StrictJsonSchemaSchema", () => {
1099 } ,
11010 }
11111
112- const result = StrictJsonSchemaSchema . parse ( schema )
12+ const result = ToolInputSchema . parse ( schema )
11313
11414 expect ( result . type ) . toBe ( "object" )
11515 expect ( result . additionalProperties ) . toBe ( false )
@@ -128,7 +28,7 @@ describe("StrictJsonSchemaSchema", () => {
12828 } ,
12929 }
13030
131- const result = StrictJsonSchemaSchema . parse ( schema )
31+ const result = ToolInputSchema . parse ( schema )
13232
13333 expect ( result . additionalProperties ) . toBe ( false )
13434 expect ( ( result . properties as any ) . user . additionalProperties ) . toBe ( false )
@@ -150,7 +50,7 @@ describe("StrictJsonSchemaSchema", () => {
15050 } ,
15151 }
15252
153- const result = StrictJsonSchemaSchema . parse ( schema )
53+ const result = ToolInputSchema . parse ( schema )
15454
15555 expect ( result . additionalProperties ) . toBe ( false )
15656 expect ( ( result . properties as any ) . items . items . additionalProperties ) . toBe ( false )
@@ -159,13 +59,13 @@ describe("StrictJsonSchemaSchema", () => {
15959 it ( "should throw on invalid schema" , ( ) => {
16060 const invalidSchema = { type : "invalid-type" }
16161
162- expect ( ( ) => StrictJsonSchemaSchema . parse ( invalidSchema ) ) . toThrow ( )
62+ expect ( ( ) => ToolInputSchema . parse ( invalidSchema ) ) . toThrow ( )
16363 } )
16464
16565 it ( "should use safeParse for error handling" , ( ) => {
16666 const invalidSchema = { type : "invalid-type" }
16767
168- const result = StrictJsonSchemaSchema . safeParse ( invalidSchema )
68+ const result = ToolInputSchema . safeParse ( invalidSchema )
16969
17070 expect ( result . success ) . toBe ( false )
17171 } )
@@ -175,7 +75,7 @@ describe("StrictJsonSchemaSchema", () => {
17575 anyOf : [ { type : "object" , properties : { a : { type : "string" } } } , { type : "string" } ] ,
17676 }
17777
178- const result = StrictJsonSchemaSchema . parse ( schema )
78+ const result = ToolInputSchema . parse ( schema )
17979
18080 expect ( ( result . anyOf as any ) [ 0 ] . additionalProperties ) . toBe ( false )
18181 expect ( ( result . anyOf as any ) [ 1 ] . additionalProperties ) . toBe ( false )
@@ -186,7 +86,7 @@ describe("StrictJsonSchemaSchema", () => {
18686 oneOf : [ { type : "object" , properties : { a : { type : "string" } } } , { type : "number" } ] ,
18787 }
18888
189- const result = StrictJsonSchemaSchema . parse ( schema )
89+ const result = ToolInputSchema . parse ( schema )
19090
19191 expect ( ( result . oneOf as any ) [ 0 ] . additionalProperties ) . toBe ( false )
19292 expect ( ( result . oneOf as any ) [ 1 ] . additionalProperties ) . toBe ( false )
@@ -200,7 +100,7 @@ describe("StrictJsonSchemaSchema", () => {
200100 ] ,
201101 }
202102
203- const result = StrictJsonSchemaSchema . parse ( schema )
103+ const result = ToolInputSchema . parse ( schema )
204104
205105 expect ( ( result . allOf as any ) [ 0 ] . additionalProperties ) . toBe ( false )
206106 expect ( ( result . allOf as any ) [ 1 ] . additionalProperties ) . toBe ( false )
@@ -220,7 +120,7 @@ describe("StrictJsonSchemaSchema", () => {
220120 } ,
221121 }
222122
223- const result = StrictJsonSchemaSchema . parse ( schema )
123+ const result = ToolInputSchema . parse ( schema )
224124
225125 const tupleItems = ( result . properties as any ) . tuple . items
226126 expect ( tupleItems [ 0 ] . additionalProperties ) . toBe ( false )
@@ -236,7 +136,7 @@ describe("StrictJsonSchemaSchema", () => {
236136 additionalProperties : false ,
237137 }
238138
239- const result = StrictJsonSchemaSchema . parse ( schema )
139+ const result = ToolInputSchema . parse ( schema )
240140
241141 expect ( result . additionalProperties ) . toBe ( false )
242142 } )
@@ -267,7 +167,7 @@ describe("StrictJsonSchemaSchema", () => {
267167 } ,
268168 }
269169
270- const result = StrictJsonSchemaSchema . parse ( schema )
170+ const result = ToolInputSchema . parse ( schema )
271171
272172 expect ( result . additionalProperties ) . toBe ( false )
273173 expect ( ( result . properties as any ) . level1 . additionalProperties ) . toBe ( false )
@@ -303,7 +203,7 @@ describe("StrictJsonSchemaSchema", () => {
303203 required : [ "entities" ] ,
304204 }
305205
306- const result = StrictJsonSchemaSchema . parse ( schema )
206+ const result = ToolInputSchema . parse ( schema )
307207
308208 // Top-level object should have additionalProperties: false
309209 expect ( result . additionalProperties ) . toBe ( false )
0 commit comments