pub struct JSONASchemaValidator { /* private fields */ }
Implementations§
Source§impl JSONASchemaValidator
impl JSONASchemaValidator
Sourcepub fn validate(&self, node: &Node) -> Vec<JSONASchemaValidationError>
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}
Sourcepub fn pointer(&self, keys: &Keys) -> Vec<&Schema>
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}
pub fn get_entry_schema(&self, key: &str) -> Option<&Schema>
pub fn contains_annotation_key(&self, key: &str) -> bool
Trait Implementations§
Source§impl Debug for JSONASchemaValidator
impl Debug for JSONASchemaValidator
Auto Trait Implementations§
impl Freeze for JSONASchemaValidator
impl RefUnwindSafe for JSONASchemaValidator
impl Send for JSONASchemaValidator
impl Sync for JSONASchemaValidator
impl Unpin for JSONASchemaValidator
impl UnwindSafe for JSONASchemaValidator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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