use crate::{
annotation::UNCHECKED_SCHEMA_ANNOTATION,
model::{body::media_type::MediaType, schema::Schema},
validate::{
rules::parameters::check_header_map,
violation::{SpecError, Violation, pointer_token},
},
};
pub(in crate::validate) fn check_media_type(
location: &str,
content: &MediaType,
violations: &mut Vec<Violation>,
) {
if let Some(schema) = &content.schema {
if is_unchecked(schema) {
violations.push(Violation::warning(location, SpecError::UncheckedSchema));
}
}
#[cfg(feature = "openapi32")]
if !content.encoding.is_empty()
&& (content.prefix_encoding.is_some() || content.item_encoding.is_some())
{
violations.push(Violation::error(location, SpecError::ConflictingEncoding));
}
for (property, encoding) in &content.encoding {
check_header_map(
&format!("{location}/encoding/{}/headers", pointer_token(property)),
&encoding.headers,
violations,
);
}
}
fn is_unchecked(schema: &Schema) -> bool {
match schema {
Schema::Bool(true) => true,
Schema::Object(object) => object
.unknown_keywords
.contains_key(UNCHECKED_SCHEMA_ANNOTATION),
Schema::Bool(false) => false,
}
}