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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use Ok;
// use core::panic;
// use jsonschema::Draft;
// use jsonschema::Validator;
// use serde_json::json;
// use serde_json::Value;
use Result;
const _SCHEMA_JSON: &str = include_str!;
const _DEFS_JSON: &str = include_str!;
/*
fn validate_data(schema: &Value, data: &Value) -> Result<(), Vec<jsonschema::ValidationError>> {
let compiled_schema = Validator::options()
.with_draft(Draft::Draft7) // Adjust the draft version as needed
.compile(schema)?;
compiled_schema.validate(data).map_err(|e| e.collect())
}
pub fn load(schema_file: &str) -> Result<jsonschema::Validator> {
let schema_context = SchemaContext::builtin()?;
Ok(schema_context.compiled_schema)
/*
if schema_file == "builtin" {
println!("Loading schema from {}...", schema_file);
print!("schema:\n{}", builtin_schema);
match jsonschema::Validator::compile(&serde_json::from_str(&builtin_schema)?) {
Ok(schema) => return Ok(schema),
Err(e) => return Err(anyhow!("failed to compile builtin schema {}", e)),
}
}
*/
//panic!("not implemented yet loading from other sources")
}
pub fn validate(schema: &jsonschema::Validator, doc_data: &[u8]) -> Result<()> {
let doc = serde_json::from_slice(doc_data)?;
match schema.validate(&doc) {
Ok(_) => (),
Err(_e) => return Err(anyhow!("validation failed")),
}
Ok(())
}
*/