pub mod downgrade;
use crate::{
model::document::{Document, SpecVersion},
validate::violation::SpecError,
};
impl Document {
pub fn to_json(&self) -> Result<String, serde_json::Error> {
serde_json::to_string_pretty(self)
}
#[cfg(feature = "yaml")]
pub fn to_yaml(&self) -> Result<String, serde_yaml_ng::Error> {
serde_yaml_ng::to_string(self)
}
pub fn emit(&self, version: SpecVersion) -> Result<Self, SpecError> {
let blockers = downgrade::three_two_only_constructs(self);
if !version.supports_3_2() && !blockers.is_empty() {
return Err(SpecError::RequiresV3_2 { blockers });
}
let mut emitted = self.clone();
version.as_str().clone_into(&mut emitted.openapi);
Ok(emitted)
}
}
#[cfg(test)]
mod tests;