rust_json_schema 0.1.2-x86_64-darwin → 0.2.0-x86_64-darwin

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: d476842b08273f774e3d8cfbb5745eaa9744f91ca1774689ac0e4dbf0c0e127e
4
- data.tar.gz: be50ccab168f53ea5851f96557f1f1feb67ba0188a4595c2f929674012911e87
3
+ metadata.gz: 62ce9f87ef6ecd7f85c93fe9f770fdc443a85beb9f28495de48eb323b4c24682
4
+ data.tar.gz: 566fdcf2afdadf6a500c89408a0d8e09724d8e022ba794afb7dcc38d2008c29a
5
5
  SHA512:
6
- metadata.gz: 758a60e333cec443c956464c1a8aa0da2a982441a2a9e1ec613e411aa7bd4c02361615676ca54eabe015cb5d5626f439dcc95ba8ee830ca61446ee02dc17255e
7
- data.tar.gz: 97e1695a0cea8bd81c3c5cf8169b3617c35fccf184a5a15dbe962307b4b4a29d496c9fe6a2749aed7a4a145859a369930c0ae1a0f5915c4b38c0cc12cb49de90
6
+ metadata.gz: 470b0e4b241e04d1e1d0825840c7982397cdce0c3bf2a13ed82a3d1e8409ba9782619b03b9eb16288a45472a4c69c30d59a71820da5b61f9600c7f81f72a9e34
7
+ data.tar.gz: a119945d0ef9660f524bfb951ddb33d6df72263e88fa3eab170a8b260d8ec0e18b557e100b8427039bc83e36338360a5feb377ac971a02d15453fbc432ce275b
data/README.md CHANGED
@@ -4,13 +4,15 @@
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
- This gem ships with precompiled binaries for Linux and macOS. Check the available gems on [Rubygems](https://rubygems.org/gems/rust_json_schema).
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
8
 
9
- ## Warning
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.
10
+
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).
10
12
 
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.
13
+ ## Warning
12
14
 
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).
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.
14
16
 
15
17
  ## Installation
16
18
 
@@ -25,7 +27,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
25
27
  ## Usage
26
28
 
27
29
  ```ruby
28
- validator = RustJSONSchema::Validator.new(<<~JSON)
30
+ schema = <<~JSON
29
31
  {
30
32
  "properties": {
31
33
  "foo": { "type": "string" },
@@ -36,6 +38,12 @@ validator = RustJSONSchema::Validator.new(<<~JSON)
36
38
  }
37
39
  JSON
38
40
 
41
+ validator = RustJSONSchema::Validator.new(
42
+ schema,
43
+ draft: :draft7,
44
+ with_meta_schemas: false
45
+ )
46
+
39
47
  errors = validator.validate('{ "foo": 1, "bar": "wadus" }')
40
48
  # => [
41
49
  # 'path "/bar": "wadus" is not of type "number"',
@@ -44,15 +52,21 @@ errors = validator.validate('{ "foo": 1, "bar": "wadus" }')
44
52
  # ]
45
53
  ```
46
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
+
47
64
  ### Errors
48
65
 
49
66
  - All errors are subclasses of `RustJSONSchema::Error`.
50
67
  - Calling `RustJSONSchema::Validator#new`, `#validate` or `#valid?` with a string which is not valid JSON will raise `RustJSONSchema::JSONParseError`.
51
68
  - Calling `RustJSONSchema::Validator#new` with an invalid schema will raise `RustJSONSchema::SchemaParseError`.
52
-
53
- ## TODO
54
-
55
- - Support passing options as `jsonschema-rs` does
69
+ - Calling `RustJSONSchema::Validator#new` with an invalid draft version value will raise `RustJSONSchema::InvalidOptionsError`.
56
70
 
57
71
  ## Development
58
72
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RustJSONSchema
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -8,6 +8,8 @@ module RustJSONSchema
8
8
  class JSONParseError < Error; end
9
9
 
10
10
  class SchemaParseError < Error; end
11
+
12
+ class InvalidOptionsError < Error; end
11
13
  end
12
14
 
13
15
  # Tries to require the extension for the given Ruby version first
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.2
4
+ version: 0.2.0
5
5
  platform: x86_64-darwin
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