rust_json_schema 0.4.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce192da113649540dd4360240d1c41b4521ab9c38634760b662221c5140fcffd
4
- data.tar.gz: d552e955deaffa4071a890cc8c14156e0118906f34fbf3821af3fbd822f9c489
3
+ metadata.gz: '08d45d30995ae73eebb9c76dd80c04ff3bc05188dab177c67038219f2dcbb81a'
4
+ data.tar.gz: b1c8f4728945ed3fdeca3bc1d1349774fa56a2d4d0ca733919c189f753f72e0d
5
5
  SHA512:
6
- metadata.gz: 144d2dafa41715dcf9eadcb73d8a25d896ce33282f897f1e9aa8ae3d26d44df0e610c14c47ba8dab70fd0fd9eea417cd12156b4138e9b2d0a22378586b8b41ad
7
- data.tar.gz: 95ffc870bf347e543b632c06c0cc6ba8f9e8268ac2ca9ed87f14053098dcd11881b32eacad20edd34abeeb8ba7254bdebc765c185612bd7ee4a93d0e437b1c24
6
+ metadata.gz: 031c02949574d76c2685d20437e8afc24f4dc18500e5ce67190d09da2450ede226229cbfc39d4a2630cf43c6b1f592a67b4c7036b0182b10cd5804691c8f1ece
7
+ data.tar.gz: 6ccd2c1b4a076986a27b126bed100d160a650983db428b392661d0245f4891d87a03b3f401c1715bbf5bf078ec8a42477510c0507b13fac23b1f648235f5fec0
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 4.0.6
data/Cargo.lock CHANGED
@@ -69,16 +69,14 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
69
69
 
70
70
  [[package]]
71
71
  name = "bindgen"
72
- version = "0.69.5"
72
+ version = "0.72.1"
73
73
  source = "registry+https://github.com/rust-lang/crates.io-index"
74
- checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088"
74
+ checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895"
75
75
  dependencies = [
76
76
  "bitflags",
77
77
  "cexpr",
78
78
  "clang-sys",
79
79
  "itertools",
80
- "lazy_static",
81
- "lazycell",
82
80
  "proc-macro2",
83
81
  "quote",
84
82
  "regex",
@@ -186,9 +184,9 @@ dependencies = [
186
184
 
187
185
  [[package]]
188
186
  name = "fancy-regex"
189
- version = "0.14.0"
187
+ version = "0.16.1"
190
188
  source = "registry+https://github.com/rust-lang/crates.io-index"
191
- checksum = "6e24cb5a94bcae1e5408b0effca5cd7172ea3c5755049c5f3af4cd283a165298"
189
+ checksum = "bf04c5ec15464ace8355a7b440a33aece288993475556d461154d7a62ad9947c"
192
190
  dependencies = [
193
191
  "bit-set",
194
192
  "regex-automata",
@@ -555,9 +553,9 @@ dependencies = [
555
553
 
556
554
  [[package]]
557
555
  name = "jsonschema"
558
- version = "0.29.1"
556
+ version = "0.32.1"
559
557
  source = "registry+https://github.com/rust-lang/crates.io-index"
560
- checksum = "161c33c3ec738cfea3288c5c53dfcdb32fd4fc2954de86ea06f71b5a1a40bfcd"
558
+ checksum = "24690c68dfcdde5980d676b0f1820981841016b1f29eecb4c42ad48ab4118681"
561
559
  dependencies = [
562
560
  "ahash",
563
561
  "base64",
@@ -568,9 +566,11 @@ dependencies = [
568
566
  "idna",
569
567
  "itoa",
570
568
  "num-cmp",
569
+ "num-traits",
571
570
  "once_cell",
572
571
  "percent-encoding",
573
572
  "referencing",
573
+ "regex",
574
574
  "regex-syntax",
575
575
  "reqwest",
576
576
  "serde",
@@ -584,12 +584,6 @@ version = "1.5.0"
584
584
  source = "registry+https://github.com/rust-lang/crates.io-index"
585
585
  checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
586
586
 
587
- [[package]]
588
- name = "lazycell"
589
- version = "1.3.0"
590
- source = "registry+https://github.com/rust-lang/crates.io-index"
591
- checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
592
-
593
587
  [[package]]
594
588
  name = "libc"
595
589
  version = "0.2.171"
@@ -630,9 +624,9 @@ checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
630
624
 
631
625
  [[package]]
632
626
  name = "magnus"
633
- version = "0.7.1"
627
+ version = "0.8.2"
634
628
  source = "registry+https://github.com/rust-lang/crates.io-index"
635
- checksum = "3d87ae53030f3a22e83879e666cb94e58a7bdf31706878a0ba48752994146dab"
629
+ checksum = "3b36a5b126bbe97eb0d02d07acfeb327036c6319fd816139a49824a83b7f9012"
636
630
  dependencies = [
637
631
  "magnus-macros",
638
632
  "rb-sys",
@@ -642,9 +636,9 @@ dependencies = [
642
636
 
643
637
  [[package]]
644
638
  name = "magnus-macros"
645
- version = "0.6.0"
639
+ version = "0.8.0"
646
640
  source = "registry+https://github.com/rust-lang/crates.io-index"
647
- checksum = "5968c820e2960565f647819f5928a42d6e874551cab9d88d75e3e0660d7f71e3"
641
+ checksum = "47607461fd8e1513cb4f2076c197d8092d921a1ea75bd08af97398f593751892"
648
642
  dependencies = [
649
643
  "proc-macro2",
650
644
  "quote",
@@ -860,18 +854,18 @@ dependencies = [
860
854
 
861
855
  [[package]]
862
856
  name = "rb-sys"
863
- version = "0.9.111"
857
+ version = "0.9.128"
864
858
  source = "registry+https://github.com/rust-lang/crates.io-index"
865
- checksum = "becea799ce051c16fb140be80f5e7cf781070f99ca099332383c2b17861249af"
859
+ checksum = "45ca28513560e56cfb79a62b1fce363c73af170a182024ce880c77ee9429920a"
866
860
  dependencies = [
867
861
  "rb-sys-build",
868
862
  ]
869
863
 
870
864
  [[package]]
871
865
  name = "rb-sys-build"
872
- version = "0.9.111"
866
+ version = "0.9.128"
873
867
  source = "registry+https://github.com/rust-lang/crates.io-index"
874
- checksum = "64691175abc704862f60a9ca8ef06174080cc50615f2bf1d4759f46db18b4d29"
868
+ checksum = "ce04b2c55eff3a21aaa623fcc655d94373238e72cac6b3e1a3641ff31649f99a"
875
869
  dependencies = [
876
870
  "bindgen",
877
871
  "lazy_static",
@@ -884,9 +878,9 @@ dependencies = [
884
878
 
885
879
  [[package]]
886
880
  name = "rb-sys-env"
887
- version = "0.1.2"
881
+ version = "0.2.3"
888
882
  source = "registry+https://github.com/rust-lang/crates.io-index"
889
- checksum = "a35802679f07360454b418a5d1735c89716bde01d35b1560fc953c1415a0b3bb"
883
+ checksum = "cca7ad6a7e21e72151d56fe2495a259b5670e204c3adac41ee7ef676ea08117a"
890
884
 
891
885
  [[package]]
892
886
  name = "redox_syscall"
@@ -919,9 +913,9 @@ dependencies = [
919
913
 
920
914
  [[package]]
921
915
  name = "referencing"
922
- version = "0.29.1"
916
+ version = "0.32.1"
923
917
  source = "registry+https://github.com/rust-lang/crates.io-index"
924
- checksum = "40a64b3a635fad9000648b4d8a59c8710c523ab61a23d392a7d91d47683f5adc"
918
+ checksum = "7a3d769362109497b240e66462606bc28af68116436c8669bac17069533b908e"
925
919
  dependencies = [
926
920
  "ahash",
927
921
  "fluent-uri",
@@ -1015,9 +1009,9 @@ checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
1015
1009
 
1016
1010
  [[package]]
1017
1011
  name = "rustc-hash"
1018
- version = "1.1.0"
1012
+ version = "2.1.3"
1019
1013
  source = "registry+https://github.com/rust-lang/crates.io-index"
1020
- checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
1014
+ checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d"
1021
1015
 
1022
1016
  [[package]]
1023
1017
  name = "rustversion"
data/README.md CHANGED
@@ -5,7 +5,7 @@
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
  > [!IMPORTANT]
8
- > This gem is built with `json_schema` crate version `0.29.1`, and therefore does not support any features for any potential future versions of the crate. I will review and accept PRs if you would like to work on adding support for newer versions of the crate. I generally am trying to keep things up to date but I am not cutting new releases for each new patch version of the crate.
8
+ > This gem is built with `json_schema` crate version `0.32.1`, and therefore does not support any features for any potential future versions of the crate. I will review and accept PRs if you would like to work on adding support for newer versions of the crate. I am trying to keep things up to date occasionally, but I am not regularly cutting new releases for each new version of the crate.
9
9
 
10
10
  The minimum Ruby version required by this gem is 3.0, due to the runtime Rust libraries that make the extensions possible (and easy).
11
11
 
@@ -55,7 +55,9 @@ errors = validator.validate('{ "foo": 1, "bar": "wadus" }')
55
55
 
56
56
  - `: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._
57
57
 
58
- 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.
58
+ - `:with_base_uri` - Sets a base URI to use when resolving relative schema references during validation. Relative URIs within the schema will be evaluated relative to this base URI. This is especially useful when validating schemas loaded from sources without an inherent base URL.
59
+
60
+ Any additional options provided by the `jsonschema` crate are either options I do not understand as a whole, have not figured out how to (or tried to) implement, or may not make sense to implement in a wrapper library such as this.
59
61
 
60
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.
61
63
 
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ require "rb_sys/extensiontask"
11
11
 
12
12
  task build: :compile
13
13
 
14
- rubies = ["3.3.0", "3.2.0", "3.1.0", "3.0.0"]
14
+ rubies = ["4.0.0", "3.4.0", "3.3.0", "3.2.0", "3.1.0", "3.0.0"]
15
15
  ENV["RUBY_CC_VERSION"] ||= rubies.join(":")
16
16
 
17
17
  spec = Bundler::GemHelper.gemspec
@@ -10,7 +10,7 @@ publish = false
10
10
  crate-type = ["cdylib"]
11
11
 
12
12
  [dependencies]
13
- jsonschema = "0.29.1"
14
- magnus = "0.7"
13
+ jsonschema = "0.32.1"
14
+ magnus = "0.8"
15
15
  serde_json = "1.0"
16
- rb-sys = { version = "*", default-features = false, features = ["ruby-static"] }
16
+ rb-sys = { version = "*", default-features = false }
@@ -9,21 +9,37 @@ use magnus::{
9
9
  prelude::*,
10
10
  scan_args::{get_kwargs, scan_args},
11
11
  value::Lazy,
12
- wrap, Error, RHash, RModule, Ruby, StaticSymbol, Value,
12
+ wrap, Error, RHash, RModule, Ruby, Value,
13
13
  };
14
14
 
15
15
  #[wrap(class = "RustJSONSchema::Validator")]
16
16
  struct Validator {
17
17
  schema: jsonschema::Validator,
18
18
  draft: Draft,
19
+ base_uri: Option<String>,
19
20
  }
20
21
 
21
22
  impl Validator {
22
23
  fn new(args: &[Value]) -> Result<Validator, Error> {
23
24
  let args = scan_args::<_, (), (), (), _, ()>(args)?;
24
25
  let (json,): (String,) = args.required;
25
- let kwargs = get_kwargs::<_, (), (Option<Value>,), ()>(args.keywords, &[], &["draft"])?;
26
- let (draft_arg,): (Option<Value>,) = kwargs.optional;
26
+
27
+ let value: serde_json::Value = match serde_json::from_str(&json) {
28
+ Ok(value) => value,
29
+ Err(error) => {
30
+ return Err(Error::new(
31
+ Self::ruby().get_inner(&JSON_PARSE_ERROR),
32
+ error.to_string(),
33
+ ))
34
+ }
35
+ };
36
+
37
+ let kwargs = get_kwargs::<_, (), (Option<Value>, Option<Value>), ()>(
38
+ args.keywords,
39
+ &[],
40
+ &["draft", "with_base_uri"],
41
+ )?;
42
+ let (draft_arg, with_base_uri_arg): (Option<Value>, Option<Value>) = kwargs.optional;
27
43
 
28
44
  let draft = match draft_arg {
29
45
  Some(draft) => match draft.to_string().to_lowercase().as_str() {
@@ -42,17 +58,19 @@ impl Validator {
42
58
  None => jsonschema::Draft::default(),
43
59
  };
44
60
 
45
- let value: serde_json::Value = match serde_json::from_str(&json) {
46
- Ok(value) => value,
47
- Err(error) => {
48
- return Err(Error::new(
49
- Self::ruby().get_inner(&JSON_PARSE_ERROR),
50
- error.to_string(),
51
- ))
52
- }
61
+ let options = jsonschema::options().with_draft(draft);
62
+
63
+ let base_uri = match with_base_uri_arg {
64
+ Some(uri) if !uri.is_nil() => Some(uri.to_string()),
65
+ _ => None,
66
+ };
67
+
68
+ let options = match base_uri {
69
+ Some(ref uri) => options.with_base_uri(uri),
70
+ None => options,
53
71
  };
54
72
 
55
- let schema = match jsonschema::options().with_draft(draft).build(&value) {
73
+ let schema = match options.build(&value) {
56
74
  Ok(schema) => schema,
57
75
  Err(error) => {
58
76
  return Err(Error::new(
@@ -62,7 +80,11 @@ impl Validator {
62
80
  }
63
81
  };
64
82
 
65
- Ok(Validator { schema, draft })
83
+ Ok(Validator {
84
+ schema,
85
+ draft,
86
+ base_uri,
87
+ })
66
88
  }
67
89
 
68
90
  fn is_valid(&self, json: String) -> Result<bool, Error> {
@@ -80,16 +102,19 @@ impl Validator {
80
102
  }
81
103
 
82
104
  fn options(&self) -> Result<RHash, Error> {
83
- let options = RHash::new();
105
+ let ruby = Self::ruby();
106
+ let result = ruby.hash_new();
107
+
108
+ result.aset(
109
+ ruby.sym_new("draft"),
110
+ ruby.sym_new(format!("{:?}", self.draft).to_lowercase()),
111
+ )?;
84
112
 
85
- options
86
- .aset(
87
- StaticSymbol::new("draft"),
88
- StaticSymbol::new(format!("{:?}", self.draft).to_lowercase()),
89
- )
90
- .unwrap();
113
+ if let Some(uri) = &self.base_uri {
114
+ result.aset(ruby.sym_new("with_base_uri"), ruby.str_new(uri))?;
115
+ }
91
116
 
92
- Ok(options)
117
+ Ok(result)
93
118
  }
94
119
 
95
120
  fn validate(&self, json: String) -> Result<Vec<String>, Error> {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RustJSONSchema
4
- VERSION = "0.4.1"
4
+ VERSION = "0.5.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rust_json_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Thurlow
@@ -46,6 +46,7 @@ extensions:
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - ".rspec"
49
+ - ".ruby-version"
49
50
  - ".standard.yml"
50
51
  - Cargo.lock
51
52
  - Cargo.toml
@@ -79,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
80
  - !ruby/object:Gem::Version
80
81
  version: 3.3.11
81
82
  requirements: []
82
- rubygems_version: 3.6.8
83
+ rubygems_version: 4.0.17
83
84
  specification_version: 4
84
85
  summary: Ruby wrapper for jsonschema-rs
85
86
  test_files: []