pub fn enforce_nesting_depth(
schema: &mut Value,
max_depth: usize,
current: usize,
)Expand description
Enforces a maximum nesting depth for object schemas.
Tracks nesting depth through object schemas. When current >= max_depth,
replaces the schema with {"type": "object"} and emits a tracing::warn!()
log. Recurses into properties/items/etc, incrementing depth for object schemas.
§Arguments
schema- The schema to enforce depth on.max_depth- Maximum allowed nesting depth.current- Current depth (start at 0).
§Example
use serde_json::json;
use adk_core::schema_utils::enforce_nesting_depth;
let mut schema = json!({
"type": "object",
"properties": {
"level1": {
"type": "object",
"properties": {
"level2": { "type": "string" }
}
}
}
});
enforce_nesting_depth(&mut schema, 1, 0);
// level1 is at depth 1, so it gets replaced
assert_eq!(schema["properties"]["level1"], json!({"type": "object"}));