use std::fmt;
use serde::{Deserialize, Serialize};
use crate::types::SourceLocation;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[must_use]
pub struct ValidationDiagnostic {
pub path: String,
pub severity: Severity,
pub code: DiagnosticCode,
pub message: String,
pub source_location: Option<SourceLocation>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[must_use]
pub enum Severity {
Error,
Warning,
Info,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[non_exhaustive]
#[must_use]
pub enum DiagnosticCode {
UnknownType,
DeprecatedType,
PendingType,
UnknownProperty,
PropertyNotForType,
DeprecatedProperty,
PendingProperty,
InvalidValueType,
ExpectedUrlGotText,
ExpectedTextGotNode,
InvalidEnumValue,
InvalidBoolean,
InvalidNumber,
RequiredFieldMissing,
RecommendedFieldMissing,
NestedRequiredFieldMissing,
InvalidFieldValue,
EligibilityRestricted,
}
impl fmt::Display for Severity {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Error => write!(f, "error"),
Self::Warning => write!(f, "warning"),
Self::Info => write!(f, "info"),
}
}
}
impl fmt::Display for DiagnosticCode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match self {
Self::UnknownType => "unknown-type",
Self::DeprecatedType => "deprecated-type",
Self::PendingType => "pending-type",
Self::UnknownProperty => "unknown-property",
Self::PropertyNotForType => "property-not-for-type",
Self::DeprecatedProperty => "deprecated-property",
Self::PendingProperty => "pending-property",
Self::InvalidValueType => "invalid-value-type",
Self::ExpectedUrlGotText => "expected-url-got-text",
Self::ExpectedTextGotNode => "expected-text-got-node",
Self::InvalidEnumValue => "invalid-enum-value",
Self::InvalidBoolean => "invalid-boolean",
Self::InvalidNumber => "invalid-number",
Self::RequiredFieldMissing => "required-field-missing",
Self::RecommendedFieldMissing => "recommended-field-missing",
Self::NestedRequiredFieldMissing => "nested-required-field-missing",
Self::InvalidFieldValue => "invalid-field-value",
Self::EligibilityRestricted => "eligibility-restricted",
};
write!(f, "{s}")
}
}