use crate::common::helpers::{Context, ValidateWithContext, validate_required_string};
use crate::common::reference::RefOr;
use crate::v3_0::schema::Schema;
use crate::v3_0::spec::Spec;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default)]
pub struct Discriminator {
#[serde(rename = "propertyName")]
pub property_name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub mapping: Option<BTreeMap<String, String>>,
}
impl ValidateWithContext<Spec> for Discriminator {
fn validate_with_context(&self, ctx: &mut Context<Spec>, path: String) {
validate_required_string(&self.property_name, ctx, format!("{path}.propertyName"));
if let Some(mapping) = &self.mapping {
for (k, v) in mapping {
let schema_ref = RefOr::<Schema>::new_ref(format!("#/components/schemas/{v}"));
schema_ref.validate_with_context(ctx, format!("{path}.mapping[{k}]"));
}
}
}
}