rusty_json_schema 0.5.0 → 0.15.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: b08915b084567c0b3e6538c697087291a41a5503bbe746c6e9c779a1b83f889c
4
- data.tar.gz: 4f80c40236138fc5f063e45a804b642470836190fb3defc6430bbb2972f91667
3
+ metadata.gz: 29f2fb5ead80040422387ea9ee95e400f8a48a3e376dcfc1755330d4db14a52a
4
+ data.tar.gz: 7588135d9a3f0cc439195f272f6f142937060282a43668681e5e8570d05317a1
5
5
  SHA512:
6
- metadata.gz: 823b2666a7422de6d00ef4acab4d49844e94503000c31d3a16b213dd3b4ddf866d10d35bbdf2cd1700918deb038a5ad38cf01b4fd8291f5cbe96561c66ef40a8
7
- data.tar.gz: ae9884e9efe7db0395e89cff031dcaccc71562259d1dafd6b77164629d0e9e6c4bb216382054f2ac2bf4a9c9fd3ec169657738b1f0b114b56d4609063694dba2
6
+ metadata.gz: 5ca5e12925de57af28fb53216313181409a9523e91414f711615d9ab4ea819c19e5be1ef76e0c6868942082e16263ac0ed5ff25867cb5f0a2a94ae3b87711dc1
7
+ data.tar.gz: e140c075a9d5e0d58dc7d391abf250c53704e9f5cb1bc14e742f5f31e57e1335a085b117b589ab1b6fab8520cfcd565078da1a7b86e92977f115f5a9f31f3458
data/Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "json_schema"
3
- version = "0.5.0"
3
+ version = "0.15.0"
4
4
  authors = ["Leszek Zalewski <leszekzalewski@fastmail.fm>"]
5
5
  edition = "2018"
6
6
 
@@ -9,6 +9,6 @@ name = "json_schema"
9
9
  crate-type = ["cdylib"]
10
10
 
11
11
  [dependencies]
12
- libc = "0.2.81"
13
- jsonschema = "0.5.0"
12
+ libc = "0.2.121"
13
+ jsonschema = "0.15.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.5.0"
5
+ VERSION = "0.15.0"
6
6
 
7
7
  end
@@ -16,12 +16,13 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
16
16
  Currently during heavy development.
17
17
  STR
18
18
 
19
- spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
19
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
20
20
 
21
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
22
- spec.metadata["homepage_uri"] = spec.homepage
23
- spec.metadata["source_code_uri"] = spec.homepage
24
- spec.metadata["changelog_uri"] = "https://github.com/driv3r/rusty_json_schema/blob/main/CHANGELOG.md"
21
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = spec.homepage
24
+ spec.metadata["changelog_uri"] = "https://github.com/driv3r/rusty_json_schema/blob/main/CHANGELOG.md"
25
+ spec.metadata["rubygems_mfa_required"] = "true"
25
26
 
26
27
  spec.files = Dir[
27
28
  "lib/**/*",
data/src/lib.rs CHANGED
@@ -7,29 +7,24 @@ use std::ffi::{CStr, CString};
7
7
  use std::os::raw::{c_char, c_uint};
8
8
 
9
9
  /*
10
- * Our wrapper struct for schema and schema value,
11
- * we need to hold onto value in order to not have
12
- * it freed up, as JSONSchema uses it as reference.
10
+ * Our wrapper struct for schema, we need to hold
11
+ * onto value in order to not have it freed up.
13
12
  */
14
13
  pub struct Validator {
15
- schema: &'static JSONSchema<'static>,
16
- schema_value: &'static Value,
14
+ schema: &'static JSONSchema,
17
15
  }
18
16
 
19
17
  impl Validator {
20
18
  /*
21
- * With Box::leak we avoid freeing up of schema
22
- * and schema value, we free them up separately
23
- * in the Drop implementation
19
+ * With Box::leak we avoid freeing up of schema,
20
+ * we free them up separately in the Drop implementation
24
21
  */
25
22
  fn new(schema: Value) -> Validator {
26
- let boxed_schema: &'static Value = Box::leak(Box::new(schema));
27
- let boxed_compile: &'static JSONSchema<'static> =
28
- Box::leak(Box::new(JSONSchema::compile(boxed_schema).unwrap()));
23
+ let boxed_compile: &'static JSONSchema =
24
+ Box::leak(Box::new(JSONSchema::compile(&schema).unwrap()));
29
25
 
30
26
  Validator {
31
27
  schema: boxed_compile,
32
- schema_value: boxed_schema,
33
28
  }
34
29
  }
35
30
 
@@ -42,7 +37,12 @@ impl Validator {
42
37
 
43
38
  if let Err(validation_errors) = self.schema.validate(event) {
44
39
  for error in validation_errors {
45
- errors.push(error.to_string());
40
+ let path = match format!("{}", error.instance_path).as_str() {
41
+ "" => "/".to_string(),
42
+ p => p.to_string(),
43
+ };
44
+
45
+ errors.push(format!("path \"{}\": {}", path, error));
46
46
  }
47
47
  }
48
48
 
@@ -58,7 +58,6 @@ impl Drop for Validator {
58
58
  fn drop(&mut self) {
59
59
  unsafe {
60
60
  Box::from_raw(self.schema as *const _ as *mut JSONSchema);
61
- Box::from_raw(self.schema_value as *const _ as *mut Value);
62
61
  }
63
62
  }
64
63
  }
@@ -209,9 +208,9 @@ mod tests {
209
208
  let result = unsafe { helper_validate_result_as_vec(raw_result) };
210
209
 
211
210
  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"),
211
+ String::from("path \"/bar\": \"rusty\" is not of type \"number\""),
212
+ String::from("path \"/foo\": 1 is not of type \"string\""),
213
+ String::from("path \"/\": \"baz\" is a required property"),
215
214
  ];
216
215
 
217
216
  assert_eq!(result, expectation);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rusty_json_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leszek Zalewski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-01 00:00:00.000000000 Z
11
+ date: 2022-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thermite
@@ -85,6 +85,7 @@ metadata:
85
85
  homepage_uri: https://github.com/driv3r/rusty_json_schema
86
86
  source_code_uri: https://github.com/driv3r/rusty_json_schema
87
87
  changelog_uri: https://github.com/driv3r/rusty_json_schema/blob/main/CHANGELOG.md
88
+ rubygems_mfa_required: 'true'
88
89
  post_install_message:
89
90
  rdoc_options: []
90
91
  require_paths:
@@ -93,15 +94,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
94
  requirements:
94
95
  - - ">="
95
96
  - !ruby/object:Gem::Version
96
- version: 2.5.0
97
+ version: 2.6.0
97
98
  required_rubygems_version: !ruby/object:Gem::Requirement
98
99
  requirements:
99
100
  - - ">="
100
101
  - !ruby/object:Gem::Version
101
102
  version: '0'
102
103
  requirements: []
103
- rubyforge_project:
104
- rubygems_version: 2.7.3
104
+ rubygems_version: 3.0.1
105
105
  signing_key:
106
106
  specification_version: 4
107
107
  summary: FFI wrapper around jsonschema-rs Rust library.