use std::path::Path;
use crate::errors::ManifestError;
use super::schema::Manifest;
pub fn parse_manifest(source: &str, path: Option<&Path>) -> Result<Manifest, ManifestError> {
let value: serde_yaml_ng::Value =
serde_yaml_ng::from_str(source).map_err(|source| ManifestError::ParseYaml {
source,
path: path.map(Path::to_path_buf),
})?;
if !value.is_mapping() {
return Err(ManifestError::Schema {
message: "top level must be a YAML mapping".into(),
path: path.map(Path::to_path_buf),
});
}
serde_yaml_ng::from_value::<Manifest>(value).map_err(|source| ManifestError::Schema {
message: source.to_string(),
path: path.map(Path::to_path_buf),
})
}