fn try_merge(data: &[&Value]) -> Option<Value> {
    if data
        .iter()
        .all(|item| item.get("type").unwrap() == "object")
    {
        let mut properties_types: BTreeMap<String, Vec<&Value>> = BTreeMap::new();
        let mut known_required: Vec<HashSet<&str>> = vec![];
        let mut new = json!({"type": "object"});
        for item in data.iter() {
            let properties = item.get("properties").unwrap().as_object().unwrap();
            for (name, schema) in properties {
                let known_types = properties_types
                    .entry(name.clone())
                    .or_insert_with(Vec::new);
                if !known_types.contains(&schema) {
                    known_types.push(schema)
                }
            }
            collect_required(&mut known_required, item);
        }
        let map = new.as_object_mut().unwrap();
        fill_required(map, known_required);
        fill_properties(map, &properties_types);
        return Some(new);
    }
    None
}
/// Try to merge multiple object schemas into one
Try to merge multiple object schemas into one
Try to merge multiple object schemas into one
fn try_merge(data: &[&Value]) -> Option<Value> {
    if data
        .iter()
        .all(|item| item.get("type").unwrap() == "object")
    {
        let mut properties_types: BTreeMap<String, Vec<&Value>> = BTreeMap::new();
        let mut known_required: Vec<HashSet<&str>> = vec![];
        let mut new = json!({"type": "object"});
        for item in data.iter() {
            let properties = item.get("properties").unwrap().as_object().unwrap();
            for (name, schema) in properties {
                let known_types = properties_types
                    .entry(name.clone())
                    .or_insert_with(Vec::new);
                if !known_types.contains(&schema) {
                    known_types.push(schema)
                }
            }
            collect_required(&mut known_required, item);
        }
        let map = new.as_object_mut().unwrap();
        fill_required(map, known_required);
        fill_properties(map, &properties_types);
        return Some(new);
    }
    None
}
fn try_merge ( data : & [ & Value ] ) -> Option < Value > { if data . iter ( ) . all ( | item | item . get ( " " ) . unwrap ( ) == " " ) { let mut properties_types : BTreeMap < String , Vec < & Value > > = BTreeMap :: new ( ) ; let mut known_required : Vec < HashSet < & str > > = vec ! [ ] ; let mut new = json ! ( { " " " " } ) ; for item in data . iter ( ) { let properties = item . get ( " " ) . unwrap ( ) . as_object ( ) . unwrap ( ) ; for ( name , schema ) in properties { let known_types = properties_types . entry ( name . clone ( ) ) . or_insert_with ( Vec :: new ) ; if ! known_types . contains ( & schema ) { known_types . push ( schema ) } } collect_required ( & mut known_required , item ) ; } let map = new . as_object_mut ( ) . unwrap ( ) ; fill_required ( map , known_required ) ; fill_properties ( map , & properties_types ) ; return Some ( new ) ; } None }
Try to merge multiple object schemas into one
Try to merge multiple object schemas into one
data
&[&Value]