Enum SchemaValidateError

Source
pub enum SchemaValidateError {
    NoSuchDefinition(String),
    NonRootDefinitions,
    EmptyEnum,
    RepeatedProperty(String),
    NullableMapping,
    NonPropertiesMapping,
    RepeatedDiscriminator(String),
}
Expand description

Errors that may arise from Schema::validate.

Variants§

§

NoSuchDefinition(String)

Indicates the schema has a ref to a definition that doesn’t exist.

use jtd::{Schema, SchemaValidateError};

assert_eq!(
    Err(SchemaValidateError::NoSuchDefinition("foo".into())),

    // a "ref" without definitions is always invalid
    Schema::Ref {
        definitions: Default::default(),
        metadata: Default::default(),
        nullable: Default::default(),
        ref_: "foo".into(),
    }.validate(),
)
§

NonRootDefinitions

Indicates the schema has non-empty definitions below the root level.

use jtd::{Schema, SchemaValidateError};

assert_eq!(
    Err(SchemaValidateError::NonRootDefinitions),

    // definitions can only be present at the root level
    Schema::Elements {
        definitions: Default::default(),
        metadata: Default::default(),
        nullable: Default::default(),
        elements: Box::new(Schema::Empty {
            definitions: vec![(
                "foo".to_owned(),
                Schema::Empty {
                    definitions: Default::default(),
                    metadata: Default::default(),
                }
            )].into_iter().collect(),
            metadata: Default::default(),
        }),
    }.validate(),
)
§

EmptyEnum

Indicates the schema has an enum with no values in it.

use jtd::{Schema, SchemaValidateError};

assert_eq!(
    Err(SchemaValidateError::EmptyEnum),

    // empty enums are illegal
    Schema::Enum {
        definitions: Default::default(),
        metadata: Default::default(),
        nullable: Default::default(),
        enum_: Default::default(),
    }.validate(),
)
§

RepeatedProperty(String)

Indicates the schema has the same property appear in properties and optional_properties.

use jtd::{Schema, SchemaValidateError};

assert_eq!(
    Err(SchemaValidateError::RepeatedProperty("foo".into())),

    // properties and optional_properties must not overlap
    Schema::Properties {
        definitions: Default::default(),
        metadata: Default::default(),
        nullable: Default::default(),
        properties: vec![(
            "foo".to_owned(),
            Schema::Empty {
                definitions: Default::default(),
                metadata: Default::default(),
            },
        )].into_iter().collect(),
        optional_properties: vec![(
            "foo".to_owned(),
            Schema::Empty {
                definitions: Default::default(),
                metadata: Default::default(),
            },
        )].into_iter().collect(),
        properties_is_present: true,
        additional_properties: false,
    }.validate(),
)
§

NullableMapping

Indicates the schema has a value in mapping with nullable set to true.

use jtd::{Schema, SchemaValidateError};

assert_eq!(
    Err(SchemaValidateError::NullableMapping),

    // mappings must not be nullable
    Schema::Discriminator {
        definitions: Default::default(),
        metadata: Default::default(),
        nullable: Default::default(),
        discriminator: "foo".into(),
        mapping: vec![(
            "bar".to_owned(),
            Schema::Properties {
                definitions: Default::default(),
                metadata: Default::default(),
                nullable: true,
                properties: Default::default(),
                optional_properties: Default::default(),
                properties_is_present: true,
                additional_properties: false,
            }
        )].into_iter().collect(),
    }.validate(),
);
§

NonPropertiesMapping

Indicates the schema has a value in mapping that isn’t a Schema::Properties.

use jtd::{Schema, SchemaValidateError};

assert_eq!(
    Err(SchemaValidateError::NonPropertiesMapping),

    // mappings must be of the properties form
    Schema::Discriminator {
        definitions: Default::default(),
        metadata: Default::default(),
        nullable: Default::default(),
        discriminator: "foo".into(),
        mapping: vec![(
            "bar".to_owned(),
            Schema::Empty {
                definitions: Default::default(),
                metadata: Default::default(),
            }
        )].into_iter().collect(),
    }.validate(),
);
§

RepeatedDiscriminator(String)

Indicates the schema has a value in mapping whose properties or optional_properties contains discriminator.

use jtd::{Schema, SchemaValidateError};

assert_eq!(
    Err(SchemaValidateError::RepeatedDiscriminator("foo".into())),

    // mappings must not re-define the discriminator property
    Schema::Discriminator {
        definitions: Default::default(),
        metadata: Default::default(),
        nullable: Default::default(),
        discriminator: "foo".into(),
        mapping: vec![(
            "bar".to_owned(),
            Schema::Properties {
                definitions: Default::default(),
                metadata: Default::default(),
                nullable: Default::default(),
                properties: vec![(
                    "foo".into(),
                    Schema::Empty {
                        definitions: Default::default(),
                        metadata: Default::default(),
                    }
                )].into_iter().collect(),
                optional_properties: Default::default(),
                properties_is_present: true,
                additional_properties: false,
            }
        )].into_iter().collect(),
    }.validate(),
);

Trait Implementations§

Source§

impl Clone for SchemaValidateError

Source§

fn clone(&self) -> SchemaValidateError

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SchemaValidateError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for SchemaValidateError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for SchemaValidateError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl PartialEq for SchemaValidateError

Source§

fn eq(&self, other: &SchemaValidateError) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for SchemaValidateError

Source§

impl StructuralPartialEq for SchemaValidateError

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.