Skip to main content

collapse_combiners

Function collapse_combiners 

Source
pub fn collapse_combiners(schema: &mut Value)
Expand description

Collapses anyOf/oneOf arrays to the first non-null sub-schema.

For each anyOf or oneOf array, finds the first sub-schema that is NOT {"type": "null"}, merges its fields into the parent schema, and removes the combiner key. If all sub-schemas are null, uses the first one.

Recurses into nested schemas after collapsing.

ยงExample

use serde_json::json;
use adk_core::schema_utils::collapse_combiners;

let mut schema = json!({
    "anyOf": [
        {"type": "null"},
        {"type": "string", "minLength": 1}
    ]
});

collapse_combiners(&mut schema);
assert_eq!(schema["type"], "string");
assert_eq!(schema["minLength"], 1);
assert!(schema.get("anyOf").is_none());