use serde_json::Value;
pub struct SchemaWalker<'a> {
root: &'a Value,
}
impl<'a> SchemaWalker<'a> {
pub fn new(root: &'a Value) -> Self {
Self { root }
}
pub fn ref_type_name(ref_str: &str) -> Option<&str> {
ref_str.rsplit('/').next()
}
pub fn get_definitions(&self) -> Vec<(&'a str, &'a Value)> {
let mut defs = Vec::new();
if let Some(obj) = self.root.get("$defs").and_then(|v| v.as_object()) {
for (name, schema) in obj {
defs.push((name.as_str(), schema));
}
}
defs
}
pub fn root_title(&self) -> Option<&'a str> {
self.root.get("title").and_then(|v| v.as_str())
}
pub fn root_schema(&self) -> &'a Value {
self.root
}
}