rust_json_schema 0.1.1-arm-linux → 0.2.1-arm-linux

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: 8f422049544619170cd38d18de349ab4d32a5e6714474b7fd4c1e87e6a3ae82c
4
- data.tar.gz: 69d23a30a9a43a730312f996827a0b108473622f2cabe636b59311519eb1b9ac
3
+ metadata.gz: 0dd7381e7f853f39055d0670bc28f30380f4219111be9783cb8f67b2cdf019d0
4
+ data.tar.gz: 13fdddb46bc2b202d69bd751986143cabeec305422c0392421ff54e6e9b7296f
5
5
  SHA512:
6
- metadata.gz: 1dbb51b2d4628c56474a57c30bb98cc23a6e96050d3d661c2626ba083bce7d99ff1de1d8168d4bff7e0dce9adb3f0ad2c33c89227e56fef9c9f5bcdfb5426358
7
- data.tar.gz: e55b9fd7f6df2a6f252c7f0922bb5f230974f4ee39fc45f9efac6893e0b62501ca701277df1a39583a168d43721c871bd6f31a06da5110ee8c5fda1aa05b700f
6
+ metadata.gz: d991233520839f9874c327d7fb039fd058cc834422a18e58f6abac1fd4fa890a45eaeba1b9f0e2d91b2ceac6bc4a7499a339d4bf4bb8303efe970bff66418caf
7
+ data.tar.gz: 7bd22f1f3c472ffaa0d8561efa8a2f2b1e18c7795bcf107bd444593a923123eca1043a7f4ce9c1d900cc67f1c286d389978f1b0b18a5a69f5e401dc48c092d3c
data/README.md CHANGED
@@ -1,14 +1,18 @@
1
1
  # `rust_json_schema`
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/rust_json_schema.svg)](https://rubygems.org/gems/rust_json_schema)
4
+
3
5
  `rust_json_schema` is a Ruby wrapper gem for Rust's [jsonschema-rs crate](https://github.com/Stranger6667/jsonschema-rs).
4
6
 
5
- ## Warning
7
+ The minimum Ruby version required by this gem is 3.0, due to the runtime Rust libraries that make the extensions possible (and easy).
8
+
9
+ This gem ships with precompiled binaries for Linux and macOS. Check the available gems on [Rubygems](https://rubygems.org/gems/rust_json_schema). Precompiled binaries do not exist for non-standard rubies like JRuby or TruffleRuby, nor do they exist for Windows. I will review and accept PRs if you would like to work on adding these build targets.
6
10
 
7
- 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.
11
+ [rusty_json_schema](https://github.com/driv3r/rusty_json_schema) is a direct source of inspiration. 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).
8
12
 
9
- [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).
13
+ ## Warning
10
14
 
11
- Eventually I intend to ship common platform binaries as part of this gem, eliminating the need for a Rust toolchain on client machines, but that is not yet the case.
15
+ My experience with Rust is limited, but this gem does have tests, and it is deployed in production. Please confirm that the gem is working as expected before using it in any production-critical situation. If you are using this gem in a production environment, and have any comments or feedback, I would love to hear about it.
12
16
 
13
17
  ## Installation
14
18
 
@@ -23,17 +27,23 @@ If bundler is not being used to manage dependencies, install the gem by executin
23
27
  ## Usage
24
28
 
25
29
  ```ruby
26
- validator = RustJSONSchema::Validator.new(<<~JSON)
30
+ schema = <<~JSON
27
31
  {
28
32
  "properties": {
29
33
  "foo": { "type": "string" },
30
34
  "bar": { "type": "integer" },
31
- "baz": {},
35
+ "baz": {}
32
36
  },
33
- "required": ["foo", "baz"],
37
+ "required": ["foo", "baz"]
34
38
  }
35
39
  JSON
36
40
 
41
+ validator = RustJSONSchema::Validator.new(
42
+ schema,
43
+ draft: :draft7,
44
+ with_meta_schemas: false
45
+ )
46
+
37
47
  errors = validator.validate('{ "foo": 1, "bar": "wadus" }')
38
48
  # => [
39
49
  # 'path "/bar": "wadus" is not of type "number"',
@@ -42,15 +52,21 @@ errors = validator.validate('{ "foo": 1, "bar": "wadus" }')
42
52
  # ]
43
53
  ```
44
54
 
55
+ ### Options
56
+
57
+ - `:draft` - Select the JSON schema draft number to use. Valid options are `draft4`, `draft6`, `draft7`, `draft201909`, and `draft202012`. Supported drafts are entirely determined by the `jsonschema` crate. The default draft is also determined by the crate. If new versions of the crate support additional draft versions, a code change in this gem will be required. I'm open to PRs to solve this problem - I don't know enough Rust to tell if it's easily done. *Both `draft201909` and `draft202012` are reported to have "some keywords not implemented", so use them at your own risk.*
58
+ - `:with_meta_schemas` - See [docs.rs/jsonschema CompilationOptions with_meta_schemas](https://docs.rs/jsonschema/0.17.1/jsonschema/struct.CompilationOptions.html#method.with_meta_schemas). `false` by default.
59
+
60
+ Any additional options provided by the `jsonschema` crate are options I do not understand or may not make sense to implement in a wrapper library such as this.
61
+
62
+ `RustJSONSchema::Validator#options` is provided and will return a Hash containing configuration options from the underlying Rust library. While I make an effort for them to look similar, or identical, to the options passed into the `Validator` initializer, the initializer arguments and the returned Hash should not be considered one-to-one. It exists as a way to confirm the configuration of the underlying schema validator instance.
63
+
45
64
  ### Errors
46
65
 
47
66
  - All errors are subclasses of `RustJSONSchema::Error`.
48
67
  - Calling `RustJSONSchema::Validator#new`, `#validate` or `#valid?` with a string which is not valid JSON will raise `RustJSONSchema::JSONParseError`.
49
68
  - Calling `RustJSONSchema::Validator#new` with an invalid schema will raise `RustJSONSchema::SchemaParseError`.
50
-
51
- ## TODO
52
-
53
- - Support passing options as `jsonschema-rs` does
69
+ - Calling `RustJSONSchema::Validator#new` with an invalid draft version value will raise `RustJSONSchema::InvalidOptionsError`.
54
70
 
55
71
  ## Development
56
72
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RustJSONSchema
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.1"
5
5
  end
@@ -2,18 +2,20 @@
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
12
-
13
5
  module RustJSONSchema
14
6
  class Error < StandardError; end
15
7
 
16
8
  class JSONParseError < Error; end
17
9
 
18
10
  class SchemaParseError < Error; end
11
+
12
+ class InvalidOptionsError < Error; end
13
+ end
14
+
15
+ # Tries to require the extension for the given Ruby version first
16
+ begin
17
+ RUBY_VERSION =~ /(\d+\.\d+)/
18
+ require "rust_json_schema/#{Regexp.last_match(1)}/rust_json_schema"
19
+ rescue LoadError
20
+ require_relative "rust_json_schema/rust_json_schema"
19
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rust_json_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: arm-linux
6
6
  authors:
7
7
  - Taylor Thurlow
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-12 00:00:00.000000000 Z
11
+ date: 2024-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler