| 173 | } |
| 174 | |
| 175 | bool ToolExecutor::validate_json_schema(const JsonValue& data, |
| 176 | const JsonValue& schema) { |
| 177 | // Basic JSON schema validation |
| 178 | // This is a simplified version - a full implementation would use a proper |
| 179 | // JSON schema validator |
| 180 | |
| 181 | if (!schema.contains("type")) { |
| 182 | return true; // No type constraint |
| 183 | } |
| 184 | |
| 185 | std::string expected_type = schema["type"]; |
| 186 | |
| 187 | if (expected_type == "object") { |
| 188 | if (!data.is_object()) { |
| 189 | return false; |
| 190 | } |
| 191 | |
| 192 | // Check required properties |
| 193 | if (schema.contains("required") && schema["required"].is_array()) { |
| 194 | for (const auto& required_prop : schema["required"]) { |
| 195 | if (!data.contains(required_prop.get<std::string>())) { |
| 196 | return false; |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | // Validate properties (basic check) |
| 202 | if (schema.contains("properties") && schema["properties"].is_object()) { |
| 203 | for (const auto& [prop_name, prop_schema] : |
| 204 | schema["properties"].items()) { |
| 205 | if (data.contains(prop_name)) { |
| 206 | if (!validate_json_schema(data[prop_name], prop_schema)) { |
| 207 | return false; |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | return true; |
| 214 | } else if (expected_type == "string") { |
| 215 | return data.is_string(); |
| 216 | } else if (expected_type == "number") { |
| 217 | return data.is_number(); |
| 218 | } else if (expected_type == "integer") { |
| 219 | return data.is_number_integer(); |
| 220 | } else if (expected_type == "boolean") { |
| 221 | return data.is_boolean(); |
| 222 | } else if (expected_type == "array") { |
| 223 | return data.is_array(); |
| 224 | } |
| 225 | |
| 226 | return true; // Unknown type, accept |
| 227 | } |
| 228 | |
| 229 | // Helper functions implementation |
| 230 |
nothing calls this directly
no outgoing calls
no test coverage detected