use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Severity {
Fatal,
Error,
Warning,
Information,
}
impl Severity {
#[must_use]
pub const fn code(self) -> &'static str {
match self {
Self::Fatal => "fatal",
Self::Error => "error",
Self::Warning => "warning",
Self::Information => "information",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum IssueType {
Invalid,
Structure,
Required,
Value,
Invariant,
Security,
Login,
Unknown,
Expired,
Forbidden,
Suppressed,
Processing,
NotSupported,
Duplicate,
MultipleMatches,
NotFound,
Deleted,
TooLong,
CodeInvalid,
Extension,
TooCostly,
BusinessRule,
Conflict,
Transient,
LockError,
NoStore,
Exception,
Timeout,
Incomplete,
Throttled,
Informational,
}
impl IssueType {
#[must_use]
pub const fn code(self) -> &'static str {
match self {
Self::Invalid => "invalid",
Self::Structure => "structure",
Self::Required => "required",
Self::Value => "value",
Self::Invariant => "invariant",
Self::Security => "security",
Self::Login => "login",
Self::Unknown => "unknown",
Self::Expired => "expired",
Self::Forbidden => "forbidden",
Self::Suppressed => "suppressed",
Self::Processing => "processing",
Self::NotSupported => "not-supported",
Self::Duplicate => "duplicate",
Self::MultipleMatches => "multiple-matches",
Self::NotFound => "not-found",
Self::Deleted => "deleted",
Self::TooLong => "too-long",
Self::CodeInvalid => "code-invalid",
Self::Extension => "extension",
Self::TooCostly => "too-costly",
Self::BusinessRule => "business-rule",
Self::Conflict => "conflict",
Self::Transient => "transient",
Self::LockError => "lock-error",
Self::NoStore => "no-store",
Self::Exception => "exception",
Self::Timeout => "timeout",
Self::Incomplete => "incomplete",
Self::Throttled => "throttled",
Self::Informational => "informational",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum MessageId {
NotAnObject,
UnknownResourceType,
ProfileTypeMismatch,
UnknownElement,
WrongJsonType,
WrongShape,
EmptyObject,
EmptyArray,
EmptyString,
NullValue,
MisalignedArrays,
DuplicateChoice,
ChoiceTypeNotAllowed,
MinCardinality,
MaxCardinality,
LexicalForm,
IntegerRange,
TooLong,
MaxLength,
FixedMismatch,
PatternMismatch,
UnknownExtension,
UnknownModifierExtension,
NotAnExtension,
RelativeExtensionUrl,
ModifierMismatch,
UnmatchedSliceItem,
SliceOrder,
OpenAtEnd,
OverlappingSlices,
UnresolvedReference,
TypeProfileMismatch,
ResourceTypeNotAllowed,
ConstraintUnevaluated,
AllOk,
}
impl MessageId {
#[must_use]
pub const fn code(self) -> &'static str {
match self {
Self::NotAnObject => "not-an-object",
Self::UnknownResourceType => "unknown-resource-type",
Self::ProfileTypeMismatch => "profile-type-mismatch",
Self::UnknownElement => "unknown-element",
Self::WrongJsonType => "wrong-json-type",
Self::WrongShape => "wrong-shape",
Self::EmptyObject => "empty-object",
Self::EmptyArray => "empty-array",
Self::EmptyString => "empty-string",
Self::NullValue => "null-value",
Self::MisalignedArrays => "misaligned-arrays",
Self::DuplicateChoice => "duplicate-choice",
Self::ChoiceTypeNotAllowed => "choice-type-not-allowed",
Self::MinCardinality => "min-cardinality",
Self::MaxCardinality => "max-cardinality",
Self::LexicalForm => "lexical-form",
Self::IntegerRange => "integer-range",
Self::TooLong => "too-long",
Self::MaxLength => "max-length",
Self::FixedMismatch => "fixed-mismatch",
Self::PatternMismatch => "pattern-mismatch",
Self::UnknownExtension => "unknown-extension",
Self::UnknownModifierExtension => "unknown-modifier-extension",
Self::NotAnExtension => "not-an-extension",
Self::RelativeExtensionUrl => "relative-extension-url",
Self::ModifierMismatch => "modifier-mismatch",
Self::UnmatchedSliceItem => "unmatched-slice-item",
Self::SliceOrder => "slice-order",
Self::OpenAtEnd => "open-at-end",
Self::OverlappingSlices => "overlapping-slices",
Self::UnresolvedReference => "unresolved-reference",
Self::TypeProfileMismatch => "type-profile-mismatch",
Self::ResourceTypeNotAllowed => "resource-type-not-allowed",
Self::ConstraintUnevaluated => "constraint-unevaluated",
Self::AllOk => "all-ok",
}
}
}
impl fmt::Display for MessageId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.code())
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Rule {
Message(MessageId),
Constraint {
key: String,
source: String,
},
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Issue {
pub severity: Severity,
pub code: IssueType,
pub expression: String,
pub rule: Rule,
pub message: String,
}