jsonschema_rs 0.57.0 → 0.58.1
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 +21 -1
- data/Cargo.toml +2 -2
- data/README.md +12 -0
- data/ext/jsonschema/Cargo.lock +14 -13
- data/ext/jsonschema/Cargo.toml +3 -3
- data/lib/jsonschema/version.rb +1 -1
- data/src/lib.rs +92 -53
- 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: 3d103456dca13639e36727ecaf9167a8987ed63700a9bc4ff3c1bca7cc63f8cb
|
|
4
|
+
data.tar.gz: 7c039aab47da8511612717a0c99d2b88ae31ecf1e7a12ea3bc1543b65ff9d8dc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e7236e4000dd7689d44b1acdd46706100626e9cc5c4530a3572d46a9cf0321ba11f22f20c39dfa99966b487d67cbf792fc56ced20ade29e8bf5bab9dda8b6c53
|
|
7
|
+
data.tar.gz: 0a795afa9e35a5d7f1a9c2dfdef3b6c24120af1908269fe4b71c53ba662a13a49a15d244c17ab122fff705a0e69325efccefd7f449bf72aa0627f4f349bfc7f0
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.58.1] - 2026-09-26
|
|
6
|
+
|
|
7
|
+
### Performance
|
|
8
|
+
|
|
9
|
+
- `uri` and `uri-reference` formats check the syntax directly instead of parsing each value into a URI.
|
|
10
|
+
|
|
11
|
+
## [0.58.0] - 2026-09-25
|
|
12
|
+
|
|
13
|
+
### Performance
|
|
14
|
+
|
|
15
|
+
- `oneOf` and `anyOf` whose branches each require a property fixed to a distinct string validate only the branch matching the instance's value.
|
|
16
|
+
- `Meta.valid?` and `Meta.validate!` check a schema against the bundled drafts without converting it first, 2 to 5x faster on the benchmarked schemas.
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- `Canonical.find_unsatisfiable` missing a `oneOf` over `$ref` branches beside a sibling none of them admits.
|
|
21
|
+
- A value with no JSON form nested under `type: null` failing validation silently (it should raise `TypeError`).
|
|
22
|
+
|
|
5
23
|
## [0.57.0] - 2026-09-22
|
|
6
24
|
|
|
7
25
|
### Added
|
|
@@ -577,7 +595,9 @@
|
|
|
577
595
|
|
|
578
596
|
- Initial public release
|
|
579
597
|
|
|
580
|
-
[Unreleased]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.
|
|
598
|
+
[Unreleased]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.58.1...HEAD
|
|
599
|
+
[0.58.1]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.58.0...ruby-v0.58.1
|
|
600
|
+
[0.58.0]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.57.0...ruby-v0.58.0
|
|
581
601
|
[0.57.0]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.56.0...ruby-v0.57.0
|
|
582
602
|
[0.56.0]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.55.1...ruby-v0.56.0
|
|
583
603
|
[0.55.1]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.55.0...ruby-v0.55.1
|
data/Cargo.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "jsonschema-rb"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.58.1"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
authors = ["Dmitry Dygalo <dmitry@dygalo.dev>"]
|
|
6
6
|
license = "MIT"
|
|
@@ -14,7 +14,7 @@ crate-type = ["cdylib"]
|
|
|
14
14
|
|
|
15
15
|
[dependencies]
|
|
16
16
|
strum = "0.28.0"
|
|
17
|
-
jsonschema = { version = "0.
|
|
17
|
+
jsonschema = { version = "0.58.1", default-features = false, features = ["magnus", "arbitrary-precision", "resolve-http", "resolve-file", "tls-ring", "macros", "idna"] }
|
|
18
18
|
magnus = { version = "0.8", features = ["rb-sys"] }
|
|
19
19
|
rb-sys = "0.9"
|
|
20
20
|
serde = { workspace = true }
|
data/README.md
CHANGED
|
@@ -700,6 +700,18 @@ Valid draft symbols: `:draft4`, `:draft6`, `:draft7`, `:draft201909`, `:draft202
|
|
|
700
700
|
|
|
701
701
|
For detailed benchmarks, see our [full performance comparison](https://github.com/Stranger6667/jsonschema/blob/master/crates/jsonschema-rb/BENCHMARKS.md).
|
|
702
702
|
|
|
703
|
+
### Compile-Time Validators
|
|
704
|
+
|
|
705
|
+
If you ship your own extension and know the schema at build time, the Rust crate's
|
|
706
|
+
`#[jsonschema::validator(..., backend = Magnus)]` macro compiles it into a validator that reads
|
|
707
|
+
Ruby objects directly, so nothing is parsed or compiled when your extension is loaded, and
|
|
708
|
+
validation runs up to 3.5x faster than with a validator built at run time. See the
|
|
709
|
+
[macro documentation](https://docs.rs/jsonschema/latest/jsonschema/#ruby-extension-modules).
|
|
710
|
+
|
|
711
|
+
This is not available from the `jsonschema_rs` gem, which takes its schemas at run time.
|
|
712
|
+
A complete extension with its build and test commands lives in
|
|
713
|
+
[`examples/magnus-extension`](https://github.com/Stranger6667/jsonschema/tree/master/examples/magnus-extension).
|
|
714
|
+
|
|
703
715
|
## Acknowledgements
|
|
704
716
|
|
|
705
717
|
This library draws API design inspiration from the Python [`jsonschema`](https://github.com/python-jsonschema/jsonschema) package. We're grateful to the Python `jsonschema` maintainers and contributors for their pioneering work in JSON Schema validation.
|
data/ext/jsonschema/Cargo.lock
CHANGED
|
@@ -693,9 +693,9 @@ dependencies = [
|
|
|
693
693
|
|
|
694
694
|
[[package]]
|
|
695
695
|
name = "jsonschema"
|
|
696
|
-
version = "0.
|
|
696
|
+
version = "0.58.1"
|
|
697
697
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
698
|
-
checksum = "
|
|
698
|
+
checksum = "0a083dc3204bad08c6654f3648b2e840668d843044605df8850b16d2b24d307f"
|
|
699
699
|
dependencies = [
|
|
700
700
|
"ahash",
|
|
701
701
|
"bytecount",
|
|
@@ -709,6 +709,7 @@ dependencies = [
|
|
|
709
709
|
"jsonschema-macros",
|
|
710
710
|
"jsonschema-regex",
|
|
711
711
|
"jsonschema-value",
|
|
712
|
+
"magnus",
|
|
712
713
|
"num-bigint",
|
|
713
714
|
"num-cmp",
|
|
714
715
|
"num-traits",
|
|
@@ -726,9 +727,9 @@ dependencies = [
|
|
|
726
727
|
|
|
727
728
|
[[package]]
|
|
728
729
|
name = "jsonschema-macros"
|
|
729
|
-
version = "0.
|
|
730
|
+
version = "0.58.1"
|
|
730
731
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
731
|
-
checksum = "
|
|
732
|
+
checksum = "3d4122586f4bc6260bc1daf3782617bb4bce181df639ab379b2ba0e911882ed2"
|
|
732
733
|
dependencies = [
|
|
733
734
|
"jsonschema-macros-core",
|
|
734
735
|
"proc-macro2",
|
|
@@ -736,9 +737,9 @@ dependencies = [
|
|
|
736
737
|
|
|
737
738
|
[[package]]
|
|
738
739
|
name = "jsonschema-macros-core"
|
|
739
|
-
version = "0.
|
|
740
|
+
version = "0.58.1"
|
|
740
741
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
741
|
-
checksum = "
|
|
742
|
+
checksum = "846b779b6a48769d491d2c44ebf57ad04f27a6d1edbe9e7f257926d57c98e739"
|
|
742
743
|
dependencies = [
|
|
743
744
|
"fancy-regex",
|
|
744
745
|
"indexmap",
|
|
@@ -755,7 +756,7 @@ dependencies = [
|
|
|
755
756
|
|
|
756
757
|
[[package]]
|
|
757
758
|
name = "jsonschema-rb-ext"
|
|
758
|
-
version = "0.
|
|
759
|
+
version = "0.58.1"
|
|
759
760
|
dependencies = [
|
|
760
761
|
"jsonschema",
|
|
761
762
|
"magnus",
|
|
@@ -769,18 +770,18 @@ dependencies = [
|
|
|
769
770
|
|
|
770
771
|
[[package]]
|
|
771
772
|
name = "jsonschema-regex"
|
|
772
|
-
version = "0.
|
|
773
|
+
version = "0.58.1"
|
|
773
774
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
774
|
-
checksum = "
|
|
775
|
+
checksum = "655372e8fbbefa3e5bd9b7397b4937bf75b4a71f1f84d85122cbd7758b57c8b0"
|
|
775
776
|
dependencies = [
|
|
776
777
|
"regex-syntax",
|
|
777
778
|
]
|
|
778
779
|
|
|
779
780
|
[[package]]
|
|
780
781
|
name = "jsonschema-value"
|
|
781
|
-
version = "0.
|
|
782
|
+
version = "0.58.1"
|
|
782
783
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
783
|
-
checksum = "
|
|
784
|
+
checksum = "0a6ed45167e78187301842eab0510c7dd5d7e7d065d275ef0fe01ddd25f6607b"
|
|
784
785
|
dependencies = [
|
|
785
786
|
"ahash",
|
|
786
787
|
"bytecount",
|
|
@@ -1135,9 +1136,9 @@ dependencies = [
|
|
|
1135
1136
|
|
|
1136
1137
|
[[package]]
|
|
1137
1138
|
name = "referencing"
|
|
1138
|
-
version = "0.
|
|
1139
|
+
version = "0.58.1"
|
|
1139
1140
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1140
|
-
checksum = "
|
|
1141
|
+
checksum = "c9bf6d3c834f2614907b0fd413854581ecb48f0a713ea5d6cdfbce36f24e700e"
|
|
1141
1142
|
dependencies = [
|
|
1142
1143
|
"ahash",
|
|
1143
1144
|
"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.58.1"
|
|
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.58.1", default-features = false, features = ["magnus", "arbitrary-precision", "resolve-http", "resolve-file", "tls-ring", "macros", "idna"] }
|
|
14
14
|
magnus = { version = "0.8", features = ["rb-sys"] }
|
|
15
15
|
rb-sys = "0.9"
|
|
16
|
-
referencing = "0.
|
|
16
|
+
referencing = "0.58.1"
|
|
17
17
|
serde = { version = "1", features = ["derive"] }
|
|
18
18
|
serde_json = { version = "1", features = ["arbitrary_precision"] }
|
|
19
19
|
strum = "0.28.0"
|
data/lib/jsonschema/version.rb
CHANGED
data/src/lib.rs
CHANGED
|
@@ -18,7 +18,7 @@ mod validator_map;
|
|
|
18
18
|
use jsonschema::{
|
|
19
19
|
json::{
|
|
20
20
|
magnus_child, magnus_invalidate_members_cache, magnus_is_object, magnus_probe_root,
|
|
21
|
-
magnus_take_pending_error, Magnus, MagnusPendingErrorScope,
|
|
21
|
+
magnus_take_pending_error, Magnus, MagnusPendingErrorScope, RbNode,
|
|
22
22
|
},
|
|
23
23
|
paths::LocationSegment,
|
|
24
24
|
ValidationOptions,
|
|
@@ -550,19 +550,10 @@ fn handle_callback_panic(ruby: &Ruby, err: Box<dyn std::any::Any + Send>) -> Err
|
|
|
550
550
|
})
|
|
551
551
|
}
|
|
552
552
|
|
|
553
|
-
fn pending_error_to_ruby(ruby: &Ruby, error: PendingError) -> Error {
|
|
554
|
-
match error {
|
|
555
|
-
PendingError::Type(message) => Error::new(ruby.exception_type_error(), message),
|
|
556
|
-
PendingError::Encoding(message) => Error::new(ruby.exception_encoding_error(), message),
|
|
557
|
-
PendingError::Argument(message) => Error::new(ruby.exception_arg_error(), message),
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
|
|
561
553
|
/// Run validation over `instance` in place, raising anything the representation could only record.
|
|
562
554
|
///
|
|
563
555
|
/// Accessors cannot fail, so a value the representation cannot read is stashed and surfaced here.
|
|
564
556
|
fn surface_pending_errors<T>(
|
|
565
|
-
ruby: &Ruby,
|
|
566
557
|
instance: Value,
|
|
567
558
|
run: impl FnOnce(RbNode<'_>) -> Result<T, Error>,
|
|
568
559
|
) -> Result<T, Error> {
|
|
@@ -573,11 +564,11 @@ fn surface_pending_errors<T>(
|
|
|
573
564
|
let node = RbNode::new(instance.as_raw());
|
|
574
565
|
magnus_probe_root(node);
|
|
575
566
|
if let Some(error) = magnus_take_pending_error() {
|
|
576
|
-
return Err(
|
|
567
|
+
return Err(Error::from(error));
|
|
577
568
|
}
|
|
578
569
|
let result = run(node)?;
|
|
579
570
|
if let Some(error) = magnus_take_pending_error() {
|
|
580
|
-
return Err(
|
|
571
|
+
return Err(Error::from(error));
|
|
581
572
|
}
|
|
582
573
|
Ok(result)
|
|
583
574
|
}
|
|
@@ -633,14 +624,14 @@ impl Validator {
|
|
|
633
624
|
}
|
|
634
625
|
|
|
635
626
|
fn is_valid(ruby: &Ruby, rb_self: &Self, instance: Value) -> Result<bool, Error> {
|
|
636
|
-
surface_pending_errors(
|
|
627
|
+
surface_pending_errors(instance, |node| {
|
|
637
628
|
let result = catch_unwind_silent(AssertUnwindSafe(|| rb_self.validator.is_valid(node)));
|
|
638
629
|
result.map_err(|err| handle_callback_panic(ruby, err))
|
|
639
630
|
})
|
|
640
631
|
}
|
|
641
632
|
|
|
642
633
|
fn validate(ruby: &Ruby, rb_self: &Self, instance: Value) -> Result<(), Error> {
|
|
643
|
-
surface_pending_errors(
|
|
634
|
+
surface_pending_errors(instance, |node| {
|
|
644
635
|
let _scope = KeywordCauseScope::enter();
|
|
645
636
|
let result = catch_unwind_silent(AssertUnwindSafe(|| rb_self.validator.validate(node)));
|
|
646
637
|
match result {
|
|
@@ -657,7 +648,7 @@ impl Validator {
|
|
|
657
648
|
}
|
|
658
649
|
|
|
659
650
|
fn iter_errors(ruby: &Ruby, rb_self: &Self, instance: Value) -> Result<Value, Error> {
|
|
660
|
-
surface_pending_errors(
|
|
651
|
+
surface_pending_errors(instance, |node| {
|
|
661
652
|
let _scope = KeywordCauseScope::enter();
|
|
662
653
|
|
|
663
654
|
if ruby.block_given() {
|
|
@@ -704,7 +695,7 @@ impl Validator {
|
|
|
704
695
|
}
|
|
705
696
|
|
|
706
697
|
fn evaluate(ruby: &Ruby, rb_self: &Self, instance: Value) -> Result<Evaluation, Error> {
|
|
707
|
-
surface_pending_errors(
|
|
698
|
+
surface_pending_errors(instance, |node| {
|
|
708
699
|
let _scope = KeywordCauseScope::enter();
|
|
709
700
|
let result = catch_unwind_silent(AssertUnwindSafe(|| rb_self.validator.evaluate(node)));
|
|
710
701
|
match result {
|
|
@@ -923,7 +914,7 @@ fn is_valid(ruby: &Ruby, args: &[Value]) -> Result<bool, Error> {
|
|
|
923
914
|
&json_schema,
|
|
924
915
|
)?;
|
|
925
916
|
|
|
926
|
-
surface_pending_errors(
|
|
917
|
+
surface_pending_errors(instance, |node| {
|
|
927
918
|
let _callback_roots =
|
|
928
919
|
has_ruby_callbacks.then(|| CallbackRootGuard::new(ruby, &callback_roots));
|
|
929
920
|
catch_unwind_silent(AssertUnwindSafe(|| validator.is_valid(node)))
|
|
@@ -954,7 +945,7 @@ fn validate(ruby: &Ruby, args: &[Value]) -> Result<(), Error> {
|
|
|
954
945
|
&json_schema,
|
|
955
946
|
)?;
|
|
956
947
|
|
|
957
|
-
surface_pending_errors(
|
|
948
|
+
surface_pending_errors(instance, |node| {
|
|
958
949
|
let _callback_roots =
|
|
959
950
|
has_ruby_callbacks.then(|| CallbackRootGuard::new(ruby, &callback_roots));
|
|
960
951
|
match catch_unwind_silent(AssertUnwindSafe(|| validator.validate(node))) {
|
|
@@ -993,7 +984,7 @@ fn each_error(ruby: &Ruby, args: &[Value]) -> Result<Value, Error> {
|
|
|
993
984
|
&json_schema,
|
|
994
985
|
)?;
|
|
995
986
|
|
|
996
|
-
surface_pending_errors(
|
|
987
|
+
surface_pending_errors(instance, |node| {
|
|
997
988
|
let _callback_roots =
|
|
998
989
|
has_ruby_callbacks.then(|| CallbackRootGuard::new(ruby, &callback_roots));
|
|
999
990
|
|
|
@@ -1057,7 +1048,7 @@ fn evaluate(ruby: &Ruby, args: &[Value]) -> Result<Evaluation, Error> {
|
|
|
1057
1048
|
&json_schema,
|
|
1058
1049
|
)?;
|
|
1059
1050
|
|
|
1060
|
-
surface_pending_errors(
|
|
1051
|
+
surface_pending_errors(instance, |node| {
|
|
1061
1052
|
let _callback_roots =
|
|
1062
1053
|
has_ruby_callbacks.then(|| CallbackRootGuard::new(ruby, &callback_roots));
|
|
1063
1054
|
match catch_unwind_silent(AssertUnwindSafe(|| validator.evaluate(node))) {
|
|
@@ -1161,24 +1152,40 @@ define_draft_validator!(
|
|
|
1161
1152
|
jsonschema::Draft::Draft202012
|
|
1162
1153
|
);
|
|
1163
1154
|
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
let
|
|
1167
|
-
|
|
1168
|
-
let
|
|
1169
|
-
|
|
1170
|
-
|
|
1155
|
+
// A Ruby string holds JSON text; anything else is read in place.
|
|
1156
|
+
fn json_text_schema(schema: Value) -> Option<serde_json::Value> {
|
|
1157
|
+
let rstring = RString::from_value(schema)?;
|
|
1158
|
+
#[allow(unsafe_code)]
|
|
1159
|
+
let bytes = unsafe { rstring.as_slice() };
|
|
1160
|
+
serde_json::from_slice(bytes).ok()
|
|
1161
|
+
}
|
|
1171
1162
|
|
|
1172
|
-
|
|
1163
|
+
// The bundled meta-schemas are compiled in and read the Ruby object in place; `None` sends a
|
|
1164
|
+
// `$schema` outside them through its chain.
|
|
1165
|
+
fn compiled_meta_is_valid(schema: Value) -> Option<Result<bool, Error>> {
|
|
1166
|
+
#[allow(unsafe_code)]
|
|
1167
|
+
let node = RbNode::new(schema.as_raw());
|
|
1168
|
+
match jsonschema::meta::magnus::draft_of(node) {
|
|
1169
|
+
jsonschema::Draft::Unknown => None,
|
|
1170
|
+
draft => Some(jsonschema::meta::magnus::is_valid_fn(draft)(&schema)),
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
1173
|
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1174
|
+
fn compiled_meta_validate(
|
|
1175
|
+
schema: &Value,
|
|
1176
|
+
) -> Option<Result<Result<(), jsonschema::ValidationError<'_>>, Error>> {
|
|
1177
|
+
#[allow(unsafe_code)]
|
|
1178
|
+
let node = RbNode::new(schema.as_raw());
|
|
1179
|
+
match jsonschema::meta::magnus::draft_of(node) {
|
|
1180
|
+
jsonschema::Draft::Unknown => None,
|
|
1181
|
+
draft => Some(jsonschema::meta::magnus::validate_fn(draft)(schema)),
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1181
1184
|
|
|
1185
|
+
fn meta_result_to_bool(
|
|
1186
|
+
ruby: &Ruby,
|
|
1187
|
+
result: Result<(), jsonschema::ValidationError<'_>>,
|
|
1188
|
+
) -> Result<bool, Error> {
|
|
1182
1189
|
match result {
|
|
1183
1190
|
Ok(()) => Ok(true),
|
|
1184
1191
|
Err(error) => {
|
|
@@ -1190,7 +1197,7 @@ fn meta_is_valid(ruby: &Ruby, args: &[Value]) -> Result<bool, Error> {
|
|
|
1190
1197
|
}
|
|
1191
1198
|
}
|
|
1192
1199
|
|
|
1193
|
-
fn
|
|
1200
|
+
fn meta_is_valid(ruby: &Ruby, args: &[Value]) -> Result<bool, Error> {
|
|
1194
1201
|
use magnus::scan_args::get_kwargs;
|
|
1195
1202
|
let parsed_args = scan_args::<(Value,), (), (), (), _, ()>(args)?;
|
|
1196
1203
|
let (schema,) = parsed_args.required;
|
|
@@ -1198,27 +1205,59 @@ fn meta_validate(ruby: &Ruby, args: &[Value]) -> Result<(), Error> {
|
|
|
1198
1205
|
get_kwargs(parsed_args.keywords, &[], &[*options::KW_REGISTRY])?;
|
|
1199
1206
|
let registry = kw.optional.0.flatten();
|
|
1200
1207
|
|
|
1201
|
-
let
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
jsonschema::meta::options()
|
|
1208
|
+
if let Some(registry) = registry {
|
|
1209
|
+
let json_schema = to_schema_value(ruby, schema)?;
|
|
1210
|
+
let result = jsonschema::meta::options()
|
|
1205
1211
|
.with_registry(registry.inner.as_ref())
|
|
1206
|
-
.validate(&json_schema)
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1212
|
+
.validate(&json_schema);
|
|
1213
|
+
return meta_result_to_bool(ruby, result);
|
|
1214
|
+
}
|
|
1215
|
+
if let Some(json_schema) = json_text_schema(schema) {
|
|
1216
|
+
return meta_result_to_bool(ruby, jsonschema::meta::validate(&json_schema));
|
|
1217
|
+
}
|
|
1218
|
+
surface_pending_errors(schema, |node| {
|
|
1219
|
+
if let Some(result) = compiled_meta_is_valid(schema) {
|
|
1220
|
+
return result;
|
|
1221
|
+
}
|
|
1222
|
+
match jsonschema::meta::is_valid_for::<Magnus>(node) {
|
|
1223
|
+
Ok(valid) => Ok(valid),
|
|
1224
|
+
Err(error) => meta_result_to_bool(ruby, Err(error)),
|
|
1225
|
+
}
|
|
1226
|
+
})
|
|
1227
|
+
}
|
|
1210
1228
|
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1229
|
+
fn meta_validate(ruby: &Ruby, args: &[Value]) -> Result<(), Error> {
|
|
1230
|
+
use magnus::scan_args::get_kwargs;
|
|
1231
|
+
let parsed_args = scan_args::<(Value,), (), (), (), _, ()>(args)?;
|
|
1232
|
+
let (schema,) = parsed_args.required;
|
|
1233
|
+
let kw: magnus::scan_args::KwArgs<(), (Option<Option<&Registry>>,), ()> =
|
|
1234
|
+
get_kwargs(parsed_args.keywords, &[], &[*options::KW_REGISTRY])?;
|
|
1235
|
+
let registry = kw.optional.0.flatten();
|
|
1236
|
+
|
|
1237
|
+
let raise = |error: jsonschema::ValidationError<'_>| {
|
|
1238
|
+
if let jsonschema::error::ValidationErrorKind::Referencing(err) = error.kind() {
|
|
1239
|
+
return referencing_error(ruby, err.to_string());
|
|
1220
1240
|
}
|
|
1241
|
+
#[allow(unsafe_code)]
|
|
1242
|
+
let node = RbNode::new(schema.as_raw());
|
|
1243
|
+
raise_validation_error(ruby, error, Some(node), None)
|
|
1244
|
+
};
|
|
1245
|
+
if let Some(registry) = registry {
|
|
1246
|
+
let json_schema = to_schema_value(ruby, schema)?;
|
|
1247
|
+
return jsonschema::meta::options()
|
|
1248
|
+
.with_registry(registry.inner.as_ref())
|
|
1249
|
+
.validate(&json_schema)
|
|
1250
|
+
.map_err(raise);
|
|
1221
1251
|
}
|
|
1252
|
+
if let Some(json_schema) = json_text_schema(schema) {
|
|
1253
|
+
return jsonschema::meta::validate(&json_schema).map_err(raise);
|
|
1254
|
+
}
|
|
1255
|
+
surface_pending_errors(schema, |node| {
|
|
1256
|
+
if let Some(result) = compiled_meta_validate(&schema) {
|
|
1257
|
+
return result?.map_err(raise);
|
|
1258
|
+
}
|
|
1259
|
+
jsonschema::meta::validate_for::<Magnus>(node).map_err(raise)
|
|
1260
|
+
})
|
|
1222
1261
|
}
|
|
1223
1262
|
|
|
1224
1263
|
// ValidationError instance methods (defined from Rust, called on exception instances)
|