use serde_json::Value;
pub fn unwrap_allof(schema: &Value) -> &Value {
if let Some(all_of) = schema.get("allOf").and_then(|v| v.as_array())
&& all_of.len() == 1
{
return &all_of[0];
}
schema
}
pub fn is_enum_schema(schema: &Value) -> bool {
schema.get("enum").is_some()
|| (schema.get("oneOf").is_some() && schema.get("properties").is_none())
}
pub fn extract_inner_type(type_str: &str) -> String {
if let Some(start) = type_str.find('<')
&& let Some(end) = type_str.rfind('>')
&& start < end
{
return type_str[start + 1..end].to_string();
}
if type_str.ends_with('>') && !type_str.contains('<') {
return type_str.trim_end_matches('>').to_string();
}
type_str.to_string()
}
pub fn schema_to_json_type(schema: &Value) -> String {
schema
.get("type")
.and_then(|v| v.as_str())
.unwrap_or("object")
.to_string()
}