rusty_json_schema 0.6.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0898afb3388ad9f5ff7ac27fedc0bbde902f802b23a71ae4c67cd42eb6a93ab5'
4
- data.tar.gz: '073396f70a8b35c1670b13330479dccde247cd7dd66d6d8e9482ce0e46bb60c1'
3
+ metadata.gz: 3bf92f5d1ed9c0186380f1ada17deae759ecfaf396f9f997094b6672df710d33
4
+ data.tar.gz: 0a7dc445d6b9765794ac4a19c030c862a503e90e679191b6abddfba595fbb092
5
5
  SHA512:
6
- metadata.gz: b382459eca3e4f31a77ccb4c5e9dce4d15c5f24497955299c10f1c191df079098173d7687855d8cc11c393ecc62b87a78b01f225d9ac2def2440b2c1baf2eb05
7
- data.tar.gz: 71a88a2751f3db9e05fc1a3c90240d8ac63ff51b3878f1ee2db7d7a42f9d87415935f8f2f5d1b8b69927a17bf3dad2d799fa90e740653ad135f42d6858b89678
6
+ metadata.gz: f620866be4dc3ec9ba8c0cf544a888034e6352587f212c5bbb7e9589a7bd93055f0073337d9f465e0ba79abe1686745f1abe48cd0a39b4830683014406ddf898
7
+ data.tar.gz: bf084b4eefbc2f3988894ccf1ef8224c500ebce40373d2737b3fe86715fc4964599634edb7c3d12bd8997ae3b4a31c3a56dba0d2c1c1ef6e1def7227bfda01d7
data/Cargo.toml CHANGED
@@ -10,5 +10,5 @@ crate-type = ["cdylib"]
10
10
 
11
11
  [dependencies]
12
12
  libc = "0.2.81"
13
- jsonschema = "0.6.1"
13
+ jsonschema = "0.9.0"
14
14
  serde_json = "1.0"
data/README.md CHANGED
@@ -47,7 +47,7 @@ To get validation errors
47
47
 
48
48
  ```ruby
49
49
  validator.validate(event_json)
50
- # => ["invalid...", ...]
50
+ # => ["path \"...\": invalid...", ...]
51
51
  ```
52
52
 
53
53
  ## Development
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RustyJSONSchema
4
4
 
5
- VERSION = "0.6.1"
5
+ VERSION = "0.9.0"
6
6
 
7
7
  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
- errors.push(error.to_string());
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("\'\"rusty\"\' is not of type \'number\'"),
213
- String::from("\'1\' is not of type \'string\'"),
214
- String::from("\'baz\' is a required property"),
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);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rusty_json_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leszek Zalewski