rusty_json_schema 0.6.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Cargo.toml +1 -1
- data/README.md +1 -1
- data/ext/json_schema.so.x64-mingw32.default +0 -0
- data/ext/json_schema.so.x86_64-darwin.default +0 -0
- data/ext/json_schema.so.x86_64-linux.default +0 -0
- data/lib/rusty_json_schema/validator.rb +17 -0
- data/lib/rusty_json_schema/version.rb +1 -1
- data/src/lib.rs +9 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bf92f5d1ed9c0186380f1ada17deae759ecfaf396f9f997094b6672df710d33
|
4
|
+
data.tar.gz: 0a7dc445d6b9765794ac4a19c030c862a503e90e679191b6abddfba595fbb092
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f620866be4dc3ec9ba8c0cf544a888034e6352587f212c5bbb7e9589a7bd93055f0073337d9f465e0ba79abe1686745f1abe48cd0a39b4830683014406ddf898
|
7
|
+
data.tar.gz: bf084b4eefbc2f3988894ccf1ef8224c500ebce40373d2737b3fe86715fc4964599634edb7c3d12bd8997ae3b4a31c3a56dba0d2c1c1ef6e1def7227bfda01d7
|
data/Cargo.toml
CHANGED
data/README.md
CHANGED
Binary file
|
Binary file
|
Binary file
|
@@ -17,10 +17,27 @@ module RustyJSONSchema
|
|
17
17
|
|
18
18
|
# Simple validation without actual error messages
|
19
19
|
#
|
20
|
+
# ## Examples
|
21
|
+
#
|
22
|
+
# validator = RustyJSONSchema.build(json_schema)
|
23
|
+
# validator.valid?(event)
|
24
|
+
# # => false|true
|
25
|
+
#
|
20
26
|
def valid?(event)
|
21
27
|
Binding.is_valid(self, RustyJSONSchema.dump(event))
|
22
28
|
end
|
23
29
|
|
30
|
+
# Full validation and error messages
|
31
|
+
#
|
32
|
+
# ## Examples
|
33
|
+
#
|
34
|
+
# validator = RustyJSONSchema.build(json_schema)
|
35
|
+
# validator.validate(event)
|
36
|
+
# # => [
|
37
|
+
# # 'path "/foo": "rusty" is not a "number"',
|
38
|
+
# # ...
|
39
|
+
# # ]
|
40
|
+
#
|
24
41
|
def validate(event)
|
25
42
|
Binding.validate(self, RustyJSONSchema.dump(event)).to_a
|
26
43
|
end
|
data/src/lib.rs
CHANGED
@@ -42,7 +42,12 @@ impl Validator {
|
|
42
42
|
|
43
43
|
if let Err(validation_errors) = self.schema.validate(event) {
|
44
44
|
for error in validation_errors {
|
45
|
-
|
45
|
+
let path = match format!("{}", error.instance_path).as_str() {
|
46
|
+
"" => "/".to_string(),
|
47
|
+
p => p.to_string(),
|
48
|
+
};
|
49
|
+
|
50
|
+
errors.push(format!("path \"{}\": {}", path, error));
|
46
51
|
}
|
47
52
|
}
|
48
53
|
|
@@ -209,9 +214,9 @@ mod tests {
|
|
209
214
|
let result = unsafe { helper_validate_result_as_vec(raw_result) };
|
210
215
|
|
211
216
|
let expectation: Vec<String> = vec![
|
212
|
-
String::from("\
|
213
|
-
String::from("\
|
214
|
-
String::from("\
|
217
|
+
String::from("path \"/bar\": \"rusty\" is not of type \"number\""),
|
218
|
+
String::from("path \"/foo\": 1 is not of type \"string\""),
|
219
|
+
String::from("path \"/\": \"baz\" is a required property"),
|
215
220
|
];
|
216
221
|
|
217
222
|
assert_eq!(result, expectation);
|