Struct JSONASchemaValidator

Source
pub struct JSONASchemaValidator { /* private fields */ }

Implementations§

Source§

impl JSONASchemaValidator

Source

pub fn validate(&self, node: &Node) -> Vec<JSONASchemaValidationError>

Examples found in repository?
examples/validate.rs (line 22)
4fn main() {
5    let mut args = std::env::args();
6    args.next();
7    let (schema_jsona_path, plain_jsona_path) =
8        if let (Some(v1), Some(v2)) = (args.next(), args.next()) {
9            (v1, v2)
10        } else {
11            println!("Usage: validate <schema-jsona> <to-validate-jsona>");
12            return;
13        };
14    let schema_jsona = std::fs::read_to_string(std::path::Path::new(&schema_jsona_path))
15        .expect("not found schema jsona file");
16    let schema_node: Node = schema_jsona.parse().expect("invalid schema jsona file");
17    let validator =
18        JSONASchemaValidator::try_from(&schema_node).expect("invalid schema jsona schema");
19    let plain_jsona = std::fs::read_to_string(std::path::Path::new(&plain_jsona_path))
20        .expect("not found to validate jsona file");
21    let plain_node: Node = plain_jsona.parse().expect("invalid to validate jsona file");
22    let errors = validator.validate(&plain_node);
23    errors.iter().for_each(|err| {
24        println!("{}", err);
25    });
26}
Source

pub fn pointer(&self, keys: &Keys) -> Vec<&Schema>

Examples found in repository?
examples/query-schema.rs (line 19)
4fn main() {
5    let mut args = std::env::args();
6    let jsona_file = args
7        .nth(1)
8        .expect("Usage: query-schema <schema-jsona-file> [keys]");
9    let keys = args.next();
10    let jsona_file_path = std::path::Path::new(&jsona_file);
11    let jsona_content =
12        std::fs::read_to_string(jsona_file_path).expect("not found schema jsona file");
13    let node: Node = jsona_content.parse().expect("invalid file");
14    let validator = JSONASchemaValidator::try_from(&node).expect("invalid schema");
15    let keys = match keys {
16        Some(keys) => keys.parse().expect("invalid query path"),
17        None => Keys::default(),
18    };
19    let result = serde_json::to_string_pretty(&validator.pointer(&keys)).unwrap();
20    println!("{}", result);
21}
Source

pub fn get_entry_schema(&self, key: &str) -> Option<&Schema>

Source

pub fn contains_annotation_key(&self, key: &str) -> bool

Trait Implementations§

Source§

impl Debug for JSONASchemaValidator

Source§

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

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

impl TryFrom<&Node> for JSONASchemaValidator

Source§

type Error = Vec<SchemaError>

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

fn try_from(value: &Node) -> Result<Self, Self::Error>

Performs the conversion.

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,