rust_json_schema 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Cargo.lock +1 -0
- data/README.md +44 -12
- data/Rakefile +7 -1
- data/ext/rust_json_schema/Cargo.toml +1 -0
- data/lib/rust_json_schema/version.rb +1 -1
- data/lib/rust_json_schema.rb +9 -1
- metadata +32 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64fe337a421bd1dc7c86285685347052694d0277ec43517e575a0d18abe53a19
|
4
|
+
data.tar.gz: 64840e47fb7a9f03b8a40bb626b227f465a956e1b34c4f3247a0ec9c19894c48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f91e752ffd9b53875f496e1872ef155428901fe080cfcae390be74074ddc4b642936886d80d23624c35924b53557a8eaee3a4a9bd49a73cd8202ca7719ecf1b
|
7
|
+
data.tar.gz: fce2704fcbfcc943b1c4013a67a2a4b30313695fe9be6f7787c8fbd1db3b6c16aca54bfff0612edf7f6b44828d2a70f0aba90c0c083c7fe3d8df9823a186478d
|
data/Cargo.lock
CHANGED
data/README.md
CHANGED
@@ -1,34 +1,66 @@
|
|
1
|
-
#
|
1
|
+
# `rust_json_schema`
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/rust_json_schema.svg)](https://rubygems.org/gems/rust_json_schema)
|
4
4
|
|
5
|
-
|
5
|
+
`rust_json_schema` is a Ruby wrapper gem for Rust's [jsonschema-rs crate](https://github.com/Stranger6667/jsonschema-rs).
|
6
6
|
|
7
|
-
|
7
|
+
This gem ships with precompiled binaries for Linux and macOS. Check the available gems on [Rubygems](https://rubygems.org/gems/rust_json_schema).
|
8
|
+
|
9
|
+
## Warning
|
10
|
+
|
11
|
+
I do not have any significant Rust programming experience, but this gem satisifies a need for a performant JSON Schema validation tool in Ruby land. While I intend to use this gem in a production environment, consider this code and library entirely experimental, at least until a 1.0 release, if it ever comes to that.
|
8
12
|
|
9
|
-
|
13
|
+
[rusty_json_schema](https://github.com/driv3r/rusty_json_schema) is a direct source of inspiration (and in some cases, literal copy and paste, like some fixtures/specs). Now that [bundler has explicit support for rust-backed Ruby gems](https://bundler.io/blog/2023/01/31/rust-gem-skeleton.html) as of early 2023, the Rust library code is a lot simpler that it previously needed to be, largely thanks to [magnus crate](https://github.com/matsadler/magnus) and the [rb-sys gem](https://github.com/oxidize-rb/rb-sys/tree/main/gem), and by extension, the [oxidize-rb team](https://github.com/oxidize-rb).
|
14
|
+
|
15
|
+
## Installation
|
10
16
|
|
11
17
|
Install the gem and add to the application's Gemfile by executing:
|
12
18
|
|
13
|
-
$ bundle add
|
19
|
+
$ bundle add rust_json_schema
|
14
20
|
|
15
21
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
22
|
|
17
|
-
$ gem install
|
23
|
+
$ gem install rust_json_schema
|
18
24
|
|
19
25
|
## Usage
|
20
26
|
|
21
|
-
|
27
|
+
```ruby
|
28
|
+
validator = RustJSONSchema::Validator.new(<<~JSON)
|
29
|
+
{
|
30
|
+
"properties": {
|
31
|
+
"foo": { "type": "string" },
|
32
|
+
"bar": { "type": "integer" },
|
33
|
+
"baz": {}
|
34
|
+
},
|
35
|
+
"required": ["foo", "baz"]
|
36
|
+
}
|
37
|
+
JSON
|
22
38
|
|
23
|
-
|
39
|
+
errors = validator.validate('{ "foo": 1, "bar": "wadus" }')
|
40
|
+
# => [
|
41
|
+
# 'path "/bar": "wadus" is not of type "number"',
|
42
|
+
# 'path "/foo": 1 is not of type "string"',
|
43
|
+
# 'path "/": "baz" is a required property'
|
44
|
+
# ]
|
45
|
+
```
|
24
46
|
|
25
|
-
|
47
|
+
### Errors
|
48
|
+
|
49
|
+
- All errors are subclasses of `RustJSONSchema::Error`.
|
50
|
+
- Calling `RustJSONSchema::Validator#new`, `#validate` or `#valid?` with a string which is not valid JSON will raise `RustJSONSchema::JSONParseError`.
|
51
|
+
- Calling `RustJSONSchema::Validator#new` with an invalid schema will raise `RustJSONSchema::SchemaParseError`.
|
52
|
+
|
53
|
+
## TODO
|
54
|
+
|
55
|
+
- Support passing options as `jsonschema-rs` does
|
56
|
+
|
57
|
+
## Development
|
26
58
|
|
27
|
-
|
59
|
+
TODO
|
28
60
|
|
29
61
|
## Contributing
|
30
62
|
|
31
|
-
Bug reports and pull requests are welcome
|
63
|
+
Bug reports and pull requests are welcome.
|
32
64
|
|
33
65
|
## License
|
34
66
|
|
data/Rakefile
CHANGED
@@ -11,8 +11,14 @@ require "rb_sys/extensiontask"
|
|
11
11
|
|
12
12
|
task build: :compile
|
13
13
|
|
14
|
-
|
14
|
+
rubies = ["3.3.0", "3.2.0", "3.1.0", "3.0.0"]
|
15
|
+
ENV["RUBY_CC_VERSION"] ||= rubies.join(":")
|
16
|
+
|
17
|
+
spec = Bundler::GemHelper.gemspec
|
18
|
+
RbSys::ExtensionTask.new("rust_json_schema", spec) do |ext|
|
15
19
|
ext.lib_dir = "lib/rust_json_schema"
|
20
|
+
|
21
|
+
ext.cross_compile = true
|
16
22
|
end
|
17
23
|
|
18
24
|
task default: %i[compile spec standard]
|
data/lib/rust_json_schema.rb
CHANGED
@@ -1,11 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "rust_json_schema/version"
|
4
|
-
|
4
|
+
|
5
|
+
# Tries to require the extension for the given Ruby version first
|
6
|
+
begin
|
7
|
+
RUBY_VERSION =~ /(\d+\.\d+)/
|
8
|
+
require "rust_json_schema/#{Regexp.last_match(1)}/rust_json_schema"
|
9
|
+
rescue LoadError
|
10
|
+
require_relative "rust_json_schema/rust_json_schema"
|
11
|
+
end
|
5
12
|
|
6
13
|
module RustJSONSchema
|
7
14
|
class Error < StandardError; end
|
8
15
|
|
9
16
|
class JSONParseError < Error; end
|
17
|
+
|
10
18
|
class SchemaParseError < Error; end
|
11
19
|
end
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rust_json_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taylor Thurlow
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
12
|
-
dependencies:
|
11
|
+
date: 2024-01-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake-compiler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake-compiler-dock
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
description: Ruby wrapper for jsonschema-rs
|
14
42
|
email:
|
15
43
|
- thurlow@hey.com
|
@@ -53,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
81
|
- !ruby/object:Gem::Version
|
54
82
|
version: 3.3.11
|
55
83
|
requirements: []
|
56
|
-
rubygems_version: 3.4
|
84
|
+
rubygems_version: 3.5.4
|
57
85
|
signing_key:
|
58
86
|
specification_version: 4
|
59
87
|
summary: Ruby wrapper for jsonschema-rs
|