jsonschema_rs 0.42.2 → 0.43.0

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: 5e7d5176039d2b2ed57477cf0df4ae678c7621a1bdd58928f446c248c891faaa
4
- data.tar.gz: '09bb34e4ab1ade80c168cd1e0a5261f9a84915f4f044a1a7d3172b0c8e381b7a'
3
+ metadata.gz: 511735bb41a48b95a424e5b92436aafe412822923eb943c0afd831ccbbcc94f8
4
+ data.tar.gz: 15ee16fe53ab1c97071e21cce8cf2f3ff5b74d758d63319f25133f5165a8c74c
5
5
  SHA512:
6
- metadata.gz: d0b1526111cdbe307b01244486e827f93cfa390f79daf41e1ccfb920ec1ab9050e6474d49282627d303e5e28af8da629e7c35153a2321e6ae22b8e323b04b2b1
7
- data.tar.gz: ebc8c709a96970c566bb26ee36a9373a13c91b7ebdb3634c43c0b33250dc7df8a227836e727d86497c190d41a853d911e03bd3cd625a75050c04b970253da759
6
+ metadata.gz: ead73ff80442e834f88215faa2c7d56f90bfdc4d8d3340211a313f74ba0ded0cb0da35e4400fb6554aafd3e0295b6c2ba18f94f26768cda847192941549f0c58
7
+ data.tar.gz: 5af852de21e182955493ab5dc5ffc0b7e71735128d98247508d0ff153432014387590398ca38c138ff72d2cd55bbf2ab4db0a32e83f7da810769c6ad5eeb239c
data/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.43.0] - 2026-02-28
6
+
7
+ ### Added
8
+
9
+ - `validator_cls_for(schema)` function to detect and return the appropriate validator class for a schema.
10
+
11
+ ### Fixed
12
+
13
+ - `anyOf`, `format`, `unevaluatedProperties`, and `unevaluatedItems` now correctly collect annotations per spec.
14
+
15
+ ### Performance
16
+
17
+ - Optimize `pattern` and `patternProperties` for `^(a|b|c)$` alternations via linear array scan.
18
+ - Optimize `^\S*$` patterns by replacing regex with a direct ECMA-262 whitespace check.
19
+
5
20
  ## [0.42.2] - 2026-02-26
6
21
 
7
22
  ### Changed
@@ -28,6 +43,7 @@
28
43
 
29
44
  - Initial public release
30
45
 
31
- [Unreleased]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.42.2...HEAD
46
+ [Unreleased]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.43.0...HEAD
47
+ [0.43.0]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.42.2...ruby-v0.43.0
32
48
  [0.42.2]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.42.1...ruby-v0.42.2
33
49
  [0.42.1]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.42.0...ruby-v0.42.1
data/Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "jsonschema-rb"
3
- version = "0.42.2"
3
+ version = "0.43.0"
4
4
  edition = "2021"
5
5
  authors = ["Dmitry Dygalo <dmitry@dygalo.dev>"]
6
6
  license = "MIT"
@@ -13,7 +13,7 @@ publish = false
13
13
  crate-type = ["cdylib"]
14
14
 
15
15
  [dependencies]
16
- jsonschema = { version = "0.42.2", default-features = false, features = ["arbitrary-precision", "resolve-http", "resolve-file", "tls-ring"] }
16
+ jsonschema = { version = "0.43.0", default-features = false, features = ["arbitrary-precision", "resolve-http", "resolve-file", "tls-ring"] }
17
17
  magnus = { version = "0.8", features = ["rb-sys"] }
18
18
  rb-sys = "0.9"
19
19
  serde = { workspace = true }
@@ -667,9 +667,9 @@ dependencies = [
667
667
 
668
668
  [[package]]
669
669
  name = "jsonschema"
670
- version = "0.42.2"
670
+ version = "0.43.0"
671
671
  source = "registry+https://github.com/rust-lang/crates.io-index"
672
- checksum = "a44c9bb95f6ac9270bf4fd38d71c2f8704b9fe0323a293af7a5284cbd60a39b2"
672
+ checksum = "2dcfbe6df48e0121219eefc8d6a30b872ac2769c7896454bda06f7b64129fa22"
673
673
  dependencies = [
674
674
  "ahash",
675
675
  "bytecount",
@@ -697,7 +697,7 @@ dependencies = [
697
697
 
698
698
  [[package]]
699
699
  name = "jsonschema-rb-ext"
700
- version = "0.42.2"
700
+ version = "0.43.0"
701
701
  dependencies = [
702
702
  "jsonschema",
703
703
  "magnus",
@@ -1044,9 +1044,9 @@ dependencies = [
1044
1044
 
1045
1045
  [[package]]
1046
1046
  name = "referencing"
1047
- version = "0.42.2"
1047
+ version = "0.43.0"
1048
1048
  source = "registry+https://github.com/rust-lang/crates.io-index"
1049
- checksum = "97d4124f489451bb67c59d67fa16f3ae9b5690b290406a7538e38458632666df"
1049
+ checksum = "37add1aa1d619a975521d262d09f100f1f767791c9386c03679450f30acd78c1"
1050
1050
  dependencies = [
1051
1051
  "ahash",
1052
1052
  "fluent-uri",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "jsonschema-rb-ext"
3
- version = "0.42.2"
3
+ version = "0.43.0"
4
4
  edition = "2021"
5
5
  publish = false
6
6
 
@@ -10,10 +10,10 @@ name = "jsonschema_rb"
10
10
  path = "../../src/lib.rs"
11
11
 
12
12
  [dependencies]
13
- jsonschema = { version = "0.42.2", default-features = false, features = ["arbitrary-precision", "resolve-http", "resolve-file", "tls-ring"] }
13
+ jsonschema = { version = "0.43.0", default-features = false, features = ["arbitrary-precision", "resolve-http", "resolve-file", "tls-ring"] }
14
14
  magnus = { version = "0.8", features = ["rb-sys"] }
15
15
  rb-sys = "0.9"
16
- referencing = "0.42.2"
16
+ referencing = "0.43.0"
17
17
  serde = { version = "1", features = ["derive"] }
18
18
  serde_json = { version = "1", features = ["arbitrary_precision"] }
19
19
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JSONSchema
4
- VERSION = "0.42.2"
4
+ VERSION = "0.43.0"
5
5
  end
data/sig/jsonschema.rbs CHANGED
@@ -32,6 +32,10 @@ module JSONSchema
32
32
  ?http_options: HttpOptions?
33
33
  ) -> Validator
34
34
 
35
+ # Detect the JSON Schema draft for a schema and return the corresponding validator class.
36
+ # Draft is detected automatically from the `$schema` field. Defaults to Draft202012Validator.
37
+ def self.validator_cls_for: (untyped schema) -> (singleton(Draft4Validator) | singleton(Draft6Validator) | singleton(Draft7Validator) | singleton(Draft201909Validator) | singleton(Draft202012Validator))
38
+
35
39
  # One-off validation returning boolean.
36
40
  def self.valid?: (
37
41
  untyped schema,
data/src/lib.rs CHANGED
@@ -22,7 +22,8 @@ use magnus::{
22
22
  prelude::*,
23
23
  scan_args::scan_args,
24
24
  value::{Lazy, ReprValue},
25
- DataTypeFunctions, Error, Exception, ExceptionClass, RClass, RModule, RObject, Ruby, Value,
25
+ DataTypeFunctions, Error, Exception, ExceptionClass, RClass, RHash, RModule, RObject, Ruby,
26
+ Value,
26
27
  };
27
28
  use referencing::unescape_segment;
28
29
  use std::{
@@ -776,6 +777,38 @@ impl Validator {
776
777
  }
777
778
  }
778
779
 
780
+ /// validator_cls_for(schema) -> Class
781
+ ///
782
+ /// Detect the JSON Schema draft for a schema and return the corresponding validator class.
783
+ /// Draft is detected automatically from the `$schema` field. Defaults to Draft202012Validator.
784
+ ///
785
+ /// >>> cls = JSONSchema.validator_cls_for({"type" => "string"})
786
+ /// >>> validator = cls.new({"type" => "string"})
787
+ /// >>> cls = JSONSchema.validator_cls_for({"$schema" => "http://json-schema.org/draft-07/schema#", "type" => "string"})
788
+ /// >>> validator = cls.new({"$schema" => "http://json-schema.org/draft-07/schema#", "type" => "string"})
789
+ ///
790
+ fn validator_cls_for(ruby: &Ruby, schema: Value) -> Result<RClass, Error> {
791
+ let draft = if let Some(hash) = RHash::from_value(schema) {
792
+ if let Ok(uri) = hash.aref::<_, String>(ruby.str_new("$schema")) {
793
+ jsonschema::Draft::from_schema_uri(&uri)
794
+ } else {
795
+ jsonschema::Draft::default()
796
+ }
797
+ } else {
798
+ jsonschema::Draft::default()
799
+ };
800
+
801
+ let module = ruby.define_module("JSONSchema")?;
802
+ let cls_name = match draft {
803
+ jsonschema::Draft::Draft4 => "Draft4Validator",
804
+ jsonschema::Draft::Draft6 => "Draft6Validator",
805
+ jsonschema::Draft::Draft7 => "Draft7Validator",
806
+ jsonschema::Draft::Draft201909 => "Draft201909Validator",
807
+ jsonschema::Draft::Draft202012 | jsonschema::Draft::Unknown | _ => "Draft202012Validator",
808
+ };
809
+ module.const_get::<&str, RClass>(cls_name)
810
+ }
811
+
779
812
  fn validator_for(ruby: &Ruby, args: &[Value]) -> Result<Validator, Error> {
780
813
  let parsed_args = scan_args::<(Value,), (), (), (), _, ()>(args)?;
781
814
  let (schema,) = parsed_args.required;
@@ -1287,6 +1320,7 @@ fn init(ruby: &Ruby) -> Result<(), Error> {
1287
1320
  module.define_error("ReferencingError", ruby.exception_standard_error())?;
1288
1321
 
1289
1322
  // Module-level functions
1323
+ module.define_singleton_method("validator_cls_for", function!(validator_cls_for, 1))?;
1290
1324
  module.define_singleton_method("validator_for", function!(validator_for, -1))?;
1291
1325
  module.define_singleton_method("valid?", function!(is_valid, -1))?;
1292
1326
  module.define_singleton_method("validate!", function!(validate, -1))?;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonschema_rs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.42.2
4
+ version: 0.43.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Dygalo