From 0b124df2d1a1a660ad8e04363fb7ff219f2eb3d9 Mon Sep 17 00:00:00 2001 From: leynos Date: Fri, 22 May 2026 20:41:18 +0200 Subject: [PATCH] Flatten property schema validation branching (#36) Split nested array and object handling out of `validate_property_schema` so the validator keeps the same behaviour while staying below the nesting threshold. --- src/tools/tool/schema_helpers.rs | 41 ++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/tools/tool/schema_helpers.rs b/src/tools/tool/schema_helpers.rs index 9f436c27c..edb672b05 100644 --- a/src/tools/tool/schema_helpers.rs +++ b/src/tools/tool/schema_helpers.rs @@ -240,22 +240,33 @@ fn validate_property_schema( out: &mut Vec, ) { let prop_path = path.child(name); - if let Some(prop_type) = prop.get("type").and_then(|t| t.as_str()) { - match prop_type { - "object" => out.extend(validate_tool_schema_at(prop, &prop_path)), - "array" => { - if let Some(items) = prop.get("items") { - if items.get("type").and_then(|t| t.as_str()) == Some("object") { - let items_path = prop_path.child("items"); - out.extend(validate_tool_schema_at(items, &items_path)); - } - } else { - out.push(format!("{prop_path}: array property missing \"items\"")); - } - } - _ => {} - } + let Some(prop_type) = prop.get("type").and_then(|t| t.as_str()) else { + return; + }; + + match prop_type { + "object" => validate_nested_object_schema(prop, &prop_path, out), + "array" => validate_array_items(prop, &prop_path, out), + _ => {} + } +} + +fn validate_nested_object_schema(prop: &Value, prop_path: &SchemaPath, out: &mut Vec) { + out.extend(validate_tool_schema_at(prop, prop_path)); +} + +fn validate_array_items(prop: &Value, prop_path: &SchemaPath, out: &mut Vec) { + let Some(items) = prop.get("items") else { + out.push(format!("{prop_path}: array property missing \"items\"")); + return; + }; + + if !is_object_type(items) { + return; } + + let items_path = prop_path.child("items"); + out.extend(validate_tool_schema_at(items, &items_path)); } /// Lenient runtime validation of a tool's `parameters_schema()`.