forked from rewe-digital/schema2000
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate.rs
27 lines (23 loc) · 813 Bytes
/
validate.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use std::fs::File;
use std::io;
use std::io::Read;
use std::process::ExitCode;
/// meta-validation of a JSON-schema
///
/// Basically https://docs.rs/jsonschema/0.29.0/jsonschema/index.html#meta-schema-validation in executable
fn main() -> ExitCode {
let file_path = std::env::args().nth(1).unwrap_or("-".to_string());
let file_reader: Box<dyn Read> = if file_path == "-" {
Box::new(io::stdin())
} else {
Box::new(File::open(file_path).expect("Failed to open file"))
};
let schema: serde_json::Value = serde_json::from_reader(file_reader).unwrap();
let validation = jsonschema::meta::validate(&schema);
if let Err(validation_error) = validation {
println!("{:#?}", validation_error);
ExitCode::FAILURE
} else {
ExitCode::SUCCESS
}
}