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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c36da1bdb6ca6d908935441ca01210ba49b7cfc5427643f0ac0d83893962cfb7
4
- data.tar.gz: 424d5b0cd197dacfe27be70c9c7466f44e3b39724450721d2fd90cf0418cf1eb
3
+ metadata.gz: 64fe337a421bd1dc7c86285685347052694d0277ec43517e575a0d18abe53a19
4
+ data.tar.gz: 64840e47fb7a9f03b8a40bb626b227f465a956e1b34c4f3247a0ec9c19894c48
5
5
  SHA512:
6
- metadata.gz: 66a8095e957af413791c3f56c773045ff5ece4fa6f6ce2d4d82fe1aadc8e74b753f9ad216f6c19fef49529322516a9377bbcf004f16962f00c972dc97065f4c8
7
- data.tar.gz: 1690fe5ba55f3a2c1cceaf676e71580b42352679b280b1a44d346bedd8fc20be419738d00379badedf659ab87d9b71b0e79b9da898e59d0f2afdf3c4c6bbe10d
6
+ metadata.gz: 2f91e752ffd9b53875f496e1872ef155428901fe080cfcae390be74074ddc4b642936886d80d23624c35924b53557a8eaee3a4a9bd49a73cd8202ca7719ecf1b
7
+ data.tar.gz: fce2704fcbfcc943b1c4013a67a2a4b30313695fe9be6f7787c8fbd1db3b6c16aca54bfff0612edf7f6b44828d2a70f0aba90c0c083c7fe3d8df9823a186478d
data/Cargo.lock CHANGED
@@ -992,6 +992,7 @@ version = "0.1.0"
992
992
  dependencies = [
993
993
  "jsonschema",
994
994
  "magnus",
995
+ "rb-sys",
995
996
  "serde_json",
996
997
  ]
997
998
 
data/README.md CHANGED
@@ -1,34 +1,66 @@
1
- # RustJSONSchema
1
+ # `rust_json_schema`
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ [![Gem Version](https://badge.fury.io/rb/rust_json_schema.svg)](https://rubygems.org/gems/rust_json_schema)
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rust_json_schema`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ `rust_json_schema` is a Ruby wrapper gem for Rust's [jsonschema-rs crate](https://github.com/Stranger6667/jsonschema-rs).
6
6
 
7
- ## Installation
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
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
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 UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
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 UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
23
+ $ gem install rust_json_schema
18
24
 
19
25
  ## Usage
20
26
 
21
- TODO: Write usage instructions here
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
- ## Development
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
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
59
+ TODO
28
60
 
29
61
  ## Contributing
30
62
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rust_json_schema.
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
- RbSys::ExtensionTask.new("rust_json_schema") do |ext|
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]
@@ -13,3 +13,4 @@ crate-type = ["cdylib"]
13
13
  jsonschema = "0.17.1"
14
14
  magnus = "0.6"
15
15
  serde_json = "1.0"
16
+ rb-sys = { version = "*", default-features = false, features = ["ruby-static"] }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RustJSONSchema
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -1,11 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "rust_json_schema/version"
4
- require_relative "rust_json_schema/rust_json_schema"
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.0
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-11 00:00:00.000000000 Z
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.19
84
+ rubygems_version: 3.5.4
57
85
  signing_key:
58
86
  specification_version: 4
59
87
  summary: Ruby wrapper for jsonschema-rs