rusty_json_schema 0.2.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Cargo.toml +2 -2
- data/README.md +3 -1
- data/ext/Rakefile +51 -0
- 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/binding.rb +1 -7
- data/lib/rusty_json_schema/validator.rb +17 -0
- data/lib/rusty_json_schema/version.rb +1 -1
- data/lib/tasks/thermite_dir_patch.rb +13 -0
- data/rusty_json_schema.gemspec +15 -3
- data/src/lib.rs +9 -4
- metadata +25 -14
- data/lib/ext/json_schema.d +0 -1
- data/lib/ext/json_schema.dll +0 -0
- data/lib/ext/json_schema.dll.exp +0 -0
- data/lib/ext/json_schema.dll.lib +0 -0
- data/lib/ext/json_schema.pdb +0 -0
- data/lib/ext/libjson_schema.d +0 -1
- data/lib/ext/libjson_schema.dylib +0 -0
- data/lib/ext/libjson_schema.so +0 -0
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
@@ -1,6 +1,6 @@
|
|
1
1
|
[package]
|
2
2
|
name = "json_schema"
|
3
|
-
version = "0.1
|
3
|
+
version = "0.6.1"
|
4
4
|
authors = ["Leszek Zalewski <leszekzalewski@fastmail.fm>"]
|
5
5
|
edition = "2018"
|
6
6
|
|
@@ -10,5 +10,5 @@ crate-type = ["cdylib"]
|
|
10
10
|
|
11
11
|
[dependencies]
|
12
12
|
libc = "0.2.81"
|
13
|
-
jsonschema = "0.
|
13
|
+
jsonschema = "0.9.0"
|
14
14
|
serde_json = "1.0"
|
data/README.md
CHANGED
@@ -8,6 +8,8 @@ Currently during heavy development.
|
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
11
|
+
> **NOTE**: Compilation requires openssl-dev / openssl-devel package
|
12
|
+
|
11
13
|
Add this line to your application's Gemfile:
|
12
14
|
|
13
15
|
```ruby
|
@@ -45,7 +47,7 @@ To get validation errors
|
|
45
47
|
|
46
48
|
```ruby
|
47
49
|
validator.validate(event_json)
|
48
|
-
# => ["invalid...", ...]
|
50
|
+
# => ["path \"...\": invalid...", ...]
|
49
51
|
```
|
50
52
|
|
51
53
|
## Development
|
data/ext/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "thermite/tasks"
|
4
|
+
require_relative "../lib/tasks/thermite_dir_patch"
|
5
|
+
|
6
|
+
project_dir = File.dirname(File.dirname(__FILE__))
|
7
|
+
thermite = Thermite::Tasks.new(cargo_project_path: project_dir,
|
8
|
+
ruby_project_path: project_dir,
|
9
|
+
optional_rust_extension: true)
|
10
|
+
|
11
|
+
namespace :thermite do # rubocop:disable Metrics/BlockLength
|
12
|
+
desc "Clean up default binaries"
|
13
|
+
task :clean_binnaries do
|
14
|
+
puts "Cleaning up"
|
15
|
+
Dir["#{thermite.config.ruby_extension_path}.*.default"].each do |file|
|
16
|
+
FileUtils.rm(file)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Try to build extension if cargo is available or setup default lib"
|
21
|
+
task :build_or_default do
|
22
|
+
platform = "#{Gem::Platform.local.cpu}-#{Gem::Platform.local.os}"
|
23
|
+
default_ext_path = "#{thermite.config.ruby_extension_path}.#{platform}.default"
|
24
|
+
|
25
|
+
if thermite.cargo
|
26
|
+
profile = ENV.fetch("CARGO_PROFILE", "release")
|
27
|
+
thermite.run_cargo_rustc(profile)
|
28
|
+
|
29
|
+
FileUtils.cp(thermite.config.cargo_target_path(profile, thermite.config.cargo_shared_library),
|
30
|
+
thermite.config.ruby_extension_path)
|
31
|
+
elsif File.exist?(default_ext_path)
|
32
|
+
puts "NOTE: Defaults to pre-build binary #{default_ext_path.inspect} => your mileage may vary."
|
33
|
+
|
34
|
+
FileUtils.mv(default_ext_path,
|
35
|
+
thermite.config.ruby_extension_path)
|
36
|
+
|
37
|
+
thermite.inform_user_about_cargo
|
38
|
+
else
|
39
|
+
# Prebuild binary is not available for a given platform, install cargo to
|
40
|
+
# compile the gem
|
41
|
+
raise thermite.cargo_required_msg
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
desc "Cleanup cargo artifacts"
|
46
|
+
task :cargo_clean do
|
47
|
+
thermite.run_cargo_if_exists "clean", *thermite.cargo_manifest_path_args
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
task default: %w[thermite:build_or_default thermite:cargo_clean thermite:clean_binnaries]
|
Binary file
|
Binary file
|
Binary file
|
@@ -9,13 +9,7 @@ module RustyJSONSchema
|
|
9
9
|
|
10
10
|
extend FFI::Library
|
11
11
|
|
12
|
-
|
13
|
-
case ::FFI::Platform::LIBSUFFIX
|
14
|
-
when "so", "dylib" then "libjson_schema"
|
15
|
-
when "dll" then "json_schema"
|
16
|
-
end
|
17
|
-
|
18
|
-
ffi_lib File.expand_path("../ext/#{lib_name}.#{::FFI::Platform::LIBSUFFIX}", __dir__)
|
12
|
+
ffi_lib File.expand_path("../../ext/json_schema.so", __dir__)
|
19
13
|
|
20
14
|
attach_function :new, :validator_new, [:string], Validator
|
21
15
|
attach_function :free, :validator_free, [Validator], :void
|
@@ -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/rusty_json_schema.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative "lib/rusty_json_schema/version"
|
4
4
|
|
5
|
-
Gem::Specification.new do |spec|
|
5
|
+
Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
|
6
6
|
spec.name = "rusty_json_schema"
|
7
7
|
spec.version = RustyJSONSchema::VERSION
|
8
8
|
spec.authors = ["Leszek Zalewski"]
|
@@ -16,17 +16,29 @@ Gem::Specification.new do |spec|
|
|
16
16
|
Currently during heavy development.
|
17
17
|
STR
|
18
18
|
|
19
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
19
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
|
20
20
|
|
21
21
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
22
22
|
spec.metadata["homepage_uri"] = spec.homepage
|
23
23
|
spec.metadata["source_code_uri"] = spec.homepage
|
24
24
|
spec.metadata["changelog_uri"] = "https://github.com/driv3r/rusty_json_schema/blob/main/CHANGELOG.md"
|
25
25
|
|
26
|
-
spec.files = Dir[
|
26
|
+
spec.files = Dir[
|
27
|
+
"lib/**/*",
|
28
|
+
"src/**/*.rs",
|
29
|
+
"rusty_json_schema.gemspec",
|
30
|
+
"Cargo.toml",
|
31
|
+
"LICENSE",
|
32
|
+
"README.md",
|
33
|
+
"ext/Rakefile",
|
34
|
+
"ext/*.default"
|
35
|
+
]
|
27
36
|
|
28
37
|
spec.require_paths = ["lib"]
|
29
38
|
|
39
|
+
spec.extensions << "ext/Rakefile"
|
40
|
+
spec.add_runtime_dependency "thermite", "~> 0"
|
41
|
+
|
30
42
|
# Uncomment to register a new dependency of your gem
|
31
43
|
spec.add_dependency "ffi", "~> 1.14"
|
32
44
|
spec.add_dependency "json", ">= 1.0"
|
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);
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rusty_json_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.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:
|
11
|
+
date: 2021-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thermite
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: ffi
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,24 +59,22 @@ description: |2
|
|
45
59
|
email:
|
46
60
|
- leszekzalewski@fastmail.fm
|
47
61
|
executables: []
|
48
|
-
extensions:
|
62
|
+
extensions:
|
63
|
+
- ext/Rakefile
|
49
64
|
extra_rdoc_files: []
|
50
65
|
files:
|
51
66
|
- Cargo.toml
|
52
67
|
- README.md
|
53
|
-
-
|
54
|
-
-
|
55
|
-
-
|
56
|
-
-
|
57
|
-
- lib/ext/json_schema.pdb
|
58
|
-
- lib/ext/libjson_schema.d
|
59
|
-
- lib/ext/libjson_schema.dylib
|
60
|
-
- lib/ext/libjson_schema.so
|
68
|
+
- ext/Rakefile
|
69
|
+
- ext/json_schema.so.x64-mingw32.default
|
70
|
+
- ext/json_schema.so.x86_64-darwin.default
|
71
|
+
- ext/json_schema.so.x86_64-linux.default
|
61
72
|
- lib/rusty_json_schema.rb
|
62
73
|
- lib/rusty_json_schema/binding.rb
|
63
74
|
- lib/rusty_json_schema/nodes_array.rb
|
64
75
|
- lib/rusty_json_schema/validator.rb
|
65
76
|
- lib/rusty_json_schema/version.rb
|
77
|
+
- lib/tasks/thermite_dir_patch.rb
|
66
78
|
- rusty_json_schema.gemspec
|
67
79
|
- src/lib.rs
|
68
80
|
homepage: https://github.com/driv3r/rusty_json_schema
|
@@ -81,15 +93,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
93
|
requirements:
|
82
94
|
- - ">="
|
83
95
|
- !ruby/object:Gem::Version
|
84
|
-
version: 2.
|
96
|
+
version: 2.6.0
|
85
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
98
|
requirements:
|
87
99
|
- - ">="
|
88
100
|
- !ruby/object:Gem::Version
|
89
101
|
version: '0'
|
90
102
|
requirements: []
|
91
|
-
|
92
|
-
rubygems_version: 2.7.3
|
103
|
+
rubygems_version: 3.0.1
|
93
104
|
signing_key:
|
94
105
|
specification_version: 4
|
95
106
|
summary: FFI wrapper around jsonschema-rs Rust library.
|
data/lib/ext/json_schema.d
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
D:\a\rusty_json_schema\rusty_json_schema\target\x86_64-pc-windows-msvc\release\json_schema.dll: D:\a\rusty_json_schema\rusty_json_schema\src\lib.rs
|
data/lib/ext/json_schema.dll
DELETED
Binary file
|
data/lib/ext/json_schema.dll.exp
DELETED
Binary file
|
data/lib/ext/json_schema.dll.lib
DELETED
Binary file
|
data/lib/ext/json_schema.pdb
DELETED
Binary file
|
data/lib/ext/libjson_schema.d
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
/home/runner/work/rusty_json_schema/rusty_json_schema/target/x86_64-unknown-linux-gnu/release/libjson_schema.so: /home/runner/work/rusty_json_schema/rusty_json_schema/src/lib.rs
|
Binary file
|
data/lib/ext/libjson_schema.so
DELETED
Binary file
|