use serde_json::Value;
pub fn is_empty_type(avro_type: &Value) -> bool {
if avro_type.is_null() {
return true;
}
if avro_type.is_array() {
return avro_type.as_array().unwrap().iter().all(is_empty_type);
}
if avro_type.is_object() {
let obj = avro_type.as_object().unwrap();
if !obj.contains_key("type") {
return true;
}
match obj.get("type").and_then(|v| v.as_str()) {
Some("record") => {
!obj.contains_key("fields")
|| obj
.get("fields")
.and_then(|f| f.as_array())
.is_none_or(|f| f.is_empty())
}
Some("enum") => {
!obj.contains_key("symbols")
|| obj
.get("symbols")
.and_then(|s| s.as_array())
.is_none_or(|s| s.is_empty())
}
Some("array") => {
!obj.contains_key("items") || obj.get("items").is_none_or(is_empty_type)
}
Some("map") => {
!obj.contains_key("values") || obj.get("values").is_none_or(is_empty_type)
}
_ => false,
}
} else {
false
}
}
pub fn is_empty_json_type(json_type: &Value) -> bool {
if json_type.is_null() {
return true;
}
if json_type.is_array() {
return json_type.as_array().unwrap().iter().all(is_empty_json_type);
}
if json_type.is_object() {
let obj = json_type.as_object().unwrap();
if obj.is_empty() || !obj.contains_key("type") {
return true;
}
}
false
}