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 +4 -4
- data/CHANGELOG.md +17 -1
- data/Cargo.toml +2 -2
- data/ext/jsonschema/Cargo.lock +5 -5
- data/ext/jsonschema/Cargo.toml +3 -3
- data/lib/jsonschema/version.rb +1 -1
- data/sig/jsonschema.rbs +4 -0
- data/src/lib.rs +35 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 511735bb41a48b95a424e5b92436aafe412822923eb943c0afd831ccbbcc94f8
|
|
4
|
+
data.tar.gz: 15ee16fe53ab1c97071e21cce8cf2f3ff5b74d758d63319f25133f5165a8c74c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
|
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.
|
|
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.
|
|
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 }
|
data/ext/jsonschema/Cargo.lock
CHANGED
|
@@ -667,9 +667,9 @@ dependencies = [
|
|
|
667
667
|
|
|
668
668
|
[[package]]
|
|
669
669
|
name = "jsonschema"
|
|
670
|
-
version = "0.
|
|
670
|
+
version = "0.43.0"
|
|
671
671
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
672
|
-
checksum = "
|
|
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.
|
|
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.
|
|
1047
|
+
version = "0.43.0"
|
|
1048
1048
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1049
|
-
checksum = "
|
|
1049
|
+
checksum = "37add1aa1d619a975521d262d09f100f1f767791c9386c03679450f30acd78c1"
|
|
1050
1050
|
dependencies = [
|
|
1051
1051
|
"ahash",
|
|
1052
1052
|
"fluent-uri",
|
data/ext/jsonschema/Cargo.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "jsonschema-rb-ext"
|
|
3
|
-
version = "0.
|
|
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.
|
|
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.
|
|
16
|
+
referencing = "0.43.0"
|
|
17
17
|
serde = { version = "1", features = ["derive"] }
|
|
18
18
|
serde_json = { version = "1", features = ["arbitrary_precision"] }
|
|
19
19
|
|
data/lib/jsonschema/version.rb
CHANGED
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,
|
|
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))?;
|