use serde::de::DeserializeOwned;
use crate::error::Error;
use super::Builder;
impl<T: DeserializeOwned> Builder<T> {
pub fn explain(&self, path: &str) -> Result<crate::Explanation, Error> {
let explanation = self.with_spec(|spec| crate::explain::explain(spec, path))?;
if let Some(secrets) = &self.secrets {
if crate::touches_secret(path, secrets) {
return Ok(explanation.redacted());
}
}
Ok(explanation)
}
pub fn source_of(&self, path: &str) -> Result<Option<crate::Origin>, Error> {
self.with_spec(|spec| crate::loader::source_of(spec, path))
}
pub fn is_set(&self, path: &str) -> Result<bool, Error> {
self.with_spec(|spec| crate::loader::is_set(spec, path))
}
pub fn snapshot(&self) -> Result<crate::Snapshot, Error> {
self.with_spec(crate::loader::snapshot)
}
pub fn check(&self) -> Result<crate::Report, Error> {
self.with_spec(|spec| crate::check::<T>(spec, self.fields))
}
}
#[cfg(feature = "schema")]
#[cfg_attr(docsrs, doc(cfg(feature = "schema")))]
impl<T: DeserializeOwned> Builder<T> {
#[must_use]
pub fn schema(&self) -> serde_json::Value
where
T: schemars::JsonSchema,
{
let secrets = self.secrets.clone().unwrap_or_default();
let secret_refs: Vec<&str> = secrets.iter().map(String::as_str).collect();
crate::schema::section(&self.key, schemars::schema_for!(T).into(), &secret_refs)
}
}