@@ -73,3 +73,72 @@ func TestToolWithRawSchema(t *testing.T) {
73
73
assert .True (t , ok )
74
74
assert .Contains (t , required , "query" )
75
75
}
76
+
77
+ func TestUnmarshalToolWithRawSchema (t * testing.T ) {
78
+ // Create a complex raw schema
79
+ rawSchema := json .RawMessage (`{
80
+ "type": "object",
81
+ "properties": {
82
+ "query": {"type": "string", "description": "Search query"},
83
+ "limit": {"type": "integer", "minimum": 1, "maximum": 50}
84
+ },
85
+ "required": ["query"]
86
+ }` )
87
+
88
+ // Create a tool with raw schema
89
+ tool := NewToolWithRawSchema ("search-tool" , "Search API" , rawSchema )
90
+
91
+ // Marshal to JSON
92
+ data , err := json .Marshal (tool )
93
+ assert .NoError (t , err )
94
+
95
+ // Unmarshal to verify the structure
96
+ var toolUnmarshalled Tool
97
+ err = json .Unmarshal (data , & toolUnmarshalled )
98
+ assert .NoError (t , err )
99
+
100
+ // Verify tool properties
101
+ assert .Equal (t , tool .Name , toolUnmarshalled .Name )
102
+ assert .Equal (t , tool .Description , toolUnmarshalled .Description )
103
+
104
+ // Verify schema was properly included
105
+ assert .Equal (t , "object" , toolUnmarshalled .InputSchema .Type )
106
+ assert .Contains (t , toolUnmarshalled .InputSchema .Properties , "query" )
107
+ assert .Subset (t , toolUnmarshalled .InputSchema .Properties ["query" ], map [string ]interface {}{
108
+ "type" : "string" ,
109
+ "description" : "Search query" ,
110
+ })
111
+ assert .Contains (t , toolUnmarshalled .InputSchema .Properties , "limit" )
112
+ assert .Subset (t , toolUnmarshalled .InputSchema .Properties ["limit" ], map [string ]interface {}{
113
+ "type" : "integer" ,
114
+ "minimum" : 1.0 ,
115
+ "maximum" : 50.0 ,
116
+ })
117
+ assert .Subset (t , toolUnmarshalled .InputSchema .Required , []string {"query" })
118
+ }
119
+
120
+ func TestUnmarshalToolWithoutRawSchema (t * testing.T ) {
121
+ // Create a tool with both schemas set
122
+ tool := NewTool ("dual-schema-tool" ,
123
+ WithDescription ("A tool with both schemas set" ),
124
+ WithString ("input" , Description ("Test input" )),
125
+ )
126
+
127
+ data , err := json .Marshal (tool )
128
+ assert .Nil (t , err )
129
+
130
+ // Unmarshal to verify the structure
131
+ var toolUnmarshalled Tool
132
+ err = json .Unmarshal (data , & toolUnmarshalled )
133
+ assert .NoError (t , err )
134
+
135
+ // Verify tool properties
136
+ assert .Equal (t , tool .Name , toolUnmarshalled .Name )
137
+ assert .Equal (t , tool .Description , toolUnmarshalled .Description )
138
+ assert .Subset (t , toolUnmarshalled .InputSchema .Properties ["input" ], map [string ]interface {}{
139
+ "type" : "string" ,
140
+ "description" : "Test input" ,
141
+ })
142
+ assert .Empty (t , toolUnmarshalled .InputSchema .Required )
143
+ assert .Empty (t , toolUnmarshalled .RawInputSchema )
144
+ }
0 commit comments