jsonschema_rs 0.49.0 → 0.49.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 +9 -1
- data/Cargo.toml +2 -2
- data/ext/jsonschema/Cargo.lock +13 -13
- data/ext/jsonschema/Cargo.toml +3 -3
- data/lib/jsonschema/version.rb +1 -1
- data/sig/jsonschema.rbs +5 -1
- data/src/canonical.rs +23 -4
- data/src/options.rs +39 -26
- 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: 9d150c4402ac7014d11674fba8a3e7ae36638e1a671010b4b8494ede16c03858
|
|
4
|
+
data.tar.gz: 4af066e13c47db2d317113d3a6454eae0e2ad60f16c52b31648da7889055bef3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 75713f7e5827481f37962d21c00ed968c8386f020ad1ec054f33d742b7036ad13354741f62e35eba0b82eb161be1b189a83f71e3a99f3fceacd917c2f56d334c
|
|
7
|
+
data.tar.gz: a7e7405400ba4dbf94954510ab490372c52258c16c61fe423285d73edcf8837e839601d462fe163bc289a040312d5bb32b9c25a7cd78323bf55b96de52abb613
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.49.1] - 2026-07-25
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- `JSONSchema.canonicalize` rejecting `pattern_options` (it should take the same regex configuration as validators).
|
|
10
|
+
- `InvalidPattern` failures raising the base `CanonicalizationError` (they should raise `JSONSchema::Canonical::InvalidPattern`).
|
|
11
|
+
|
|
5
12
|
## [0.49.0] - 2026-07-25
|
|
6
13
|
|
|
7
14
|
### Added
|
|
@@ -219,7 +226,8 @@
|
|
|
219
226
|
|
|
220
227
|
- Initial public release
|
|
221
228
|
|
|
222
|
-
[Unreleased]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.49.
|
|
229
|
+
[Unreleased]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.49.1...HEAD
|
|
230
|
+
[0.49.1]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.49.0...ruby-v0.49.1
|
|
223
231
|
[0.49.0]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.48.5...ruby-v0.49.0
|
|
224
232
|
[0.48.5]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.48.2...ruby-v0.48.5
|
|
225
233
|
[0.48.2]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.48.1...ruby-v0.48.2
|
data/Cargo.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "jsonschema-rb"
|
|
3
|
-
version = "0.49.
|
|
3
|
+
version = "0.49.1"
|
|
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.49.
|
|
16
|
+
jsonschema = { version = "0.49.1", default-features = false, features = ["magnus", "arbitrary-precision", "resolve-http", "resolve-file", "tls-ring", "macros"] }
|
|
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
|
@@ -693,9 +693,9 @@ dependencies = [
|
|
|
693
693
|
|
|
694
694
|
[[package]]
|
|
695
695
|
name = "jsonschema"
|
|
696
|
-
version = "0.49.
|
|
696
|
+
version = "0.49.1"
|
|
697
697
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
698
|
-
checksum = "
|
|
698
|
+
checksum = "9cc9116a0f75b7336e55eb2a2a0ddef86c37cadf02924a571751aa123d5a0290"
|
|
699
699
|
dependencies = [
|
|
700
700
|
"ahash",
|
|
701
701
|
"bytecount",
|
|
@@ -726,9 +726,9 @@ dependencies = [
|
|
|
726
726
|
|
|
727
727
|
[[package]]
|
|
728
728
|
name = "jsonschema-macros"
|
|
729
|
-
version = "0.49.
|
|
729
|
+
version = "0.49.1"
|
|
730
730
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
731
|
-
checksum = "
|
|
731
|
+
checksum = "b78efbcc1da165d63e1944fa687b3c2c09e8e418e9481e25aeada6062160c1bf"
|
|
732
732
|
dependencies = [
|
|
733
733
|
"jsonschema-macros-core",
|
|
734
734
|
"proc-macro2",
|
|
@@ -736,9 +736,9 @@ dependencies = [
|
|
|
736
736
|
|
|
737
737
|
[[package]]
|
|
738
738
|
name = "jsonschema-macros-core"
|
|
739
|
-
version = "0.49.
|
|
739
|
+
version = "0.49.1"
|
|
740
740
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
741
|
-
checksum = "
|
|
741
|
+
checksum = "10c6550900b4a6be61392b8ddeb62b5c057975371ce93fca76d92542015f98bf"
|
|
742
742
|
dependencies = [
|
|
743
743
|
"fancy-regex",
|
|
744
744
|
"indexmap",
|
|
@@ -755,7 +755,7 @@ dependencies = [
|
|
|
755
755
|
|
|
756
756
|
[[package]]
|
|
757
757
|
name = "jsonschema-rb-ext"
|
|
758
|
-
version = "0.49.
|
|
758
|
+
version = "0.49.1"
|
|
759
759
|
dependencies = [
|
|
760
760
|
"jsonschema",
|
|
761
761
|
"magnus",
|
|
@@ -768,18 +768,18 @@ dependencies = [
|
|
|
768
768
|
|
|
769
769
|
[[package]]
|
|
770
770
|
name = "jsonschema-regex"
|
|
771
|
-
version = "0.49.
|
|
771
|
+
version = "0.49.1"
|
|
772
772
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
773
|
-
checksum = "
|
|
773
|
+
checksum = "628a1f02bda4651d9a6088ee6386a92f0ee96255b0c99e9dfe1be91bf83bd838"
|
|
774
774
|
dependencies = [
|
|
775
775
|
"regex-syntax",
|
|
776
776
|
]
|
|
777
777
|
|
|
778
778
|
[[package]]
|
|
779
779
|
name = "jsonschema-value"
|
|
780
|
-
version = "0.49.
|
|
780
|
+
version = "0.49.1"
|
|
781
781
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
782
|
-
checksum = "
|
|
782
|
+
checksum = "75d94a372f8d81d070fd405065c6b1168d8248d1d6adad073ac708de254698c6"
|
|
783
783
|
dependencies = [
|
|
784
784
|
"ahash",
|
|
785
785
|
"bytecount",
|
|
@@ -1132,9 +1132,9 @@ dependencies = [
|
|
|
1132
1132
|
|
|
1133
1133
|
[[package]]
|
|
1134
1134
|
name = "referencing"
|
|
1135
|
-
version = "0.49.
|
|
1135
|
+
version = "0.49.1"
|
|
1136
1136
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1137
|
-
checksum = "
|
|
1137
|
+
checksum = "978badf4419c9d0e1bc6e7466e99277f829d768257670c46d88121ca75e34bf7"
|
|
1138
1138
|
dependencies = [
|
|
1139
1139
|
"ahash",
|
|
1140
1140
|
"fluent-uri",
|
data/ext/jsonschema/Cargo.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "jsonschema-rb-ext"
|
|
3
|
-
version = "0.49.
|
|
3
|
+
version = "0.49.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.49.
|
|
13
|
+
jsonschema = { version = "0.49.1", default-features = false, features = ["magnus", "arbitrary-precision", "resolve-http", "resolve-file", "tls-ring", "macros"] }
|
|
14
14
|
magnus = { version = "0.8", features = ["rb-sys"] }
|
|
15
15
|
rb-sys = "0.9"
|
|
16
|
-
referencing = "0.49.
|
|
16
|
+
referencing = "0.49.1"
|
|
17
17
|
serde = { version = "1", features = ["derive"] }
|
|
18
18
|
serde_json = { version = "1", features = ["arbitrary_precision"] }
|
|
19
19
|
zmij = "1"
|
data/lib/jsonschema/version.rb
CHANGED
data/sig/jsonschema.rbs
CHANGED
|
@@ -29,6 +29,9 @@ module JSONSchema
|
|
|
29
29
|
class InvalidSchemaType < CanonicalizationError
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
+
class InvalidPattern < CanonicalizationError
|
|
33
|
+
end
|
|
34
|
+
|
|
32
35
|
# A schema reduced to canonical form: schemas accepting the same values share one form.
|
|
33
36
|
class CanonicalSchema
|
|
34
37
|
def to_json_schema: () -> untyped
|
|
@@ -164,7 +167,8 @@ module JSONSchema
|
|
|
164
167
|
def self.canonicalize: (
|
|
165
168
|
untyped schema,
|
|
166
169
|
?draft: draft?,
|
|
167
|
-
?validate_formats: bool
|
|
170
|
+
?validate_formats: bool?,
|
|
171
|
+
?pattern_options: (RegexOptions | FancyRegexOptions)?
|
|
168
172
|
) -> Canonical::CanonicalSchema
|
|
169
173
|
|
|
170
174
|
# Create a validator with auto-detected draft version.
|
data/src/canonical.rs
CHANGED
|
@@ -14,13 +14,17 @@ use magnus::{
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
use crate::{
|
|
17
|
-
options::parse_draft_symbol,
|
|
17
|
+
options::{extract_pattern_options, parse_draft_symbol, RbPatternOptions},
|
|
18
18
|
ser::{to_schema_value, value_to_ruby},
|
|
19
19
|
static_id::define_rb_intern,
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
define_rb_intern!(static CANONICAL_KW_DRAFT: "draft");
|
|
23
23
|
define_rb_intern!(static CANONICAL_KW_VALIDATE_FORMATS: "validate_formats");
|
|
24
|
+
define_rb_intern!(static CANONICAL_KW_PATTERN_OPTIONS: "pattern_options");
|
|
25
|
+
|
|
26
|
+
type CanonicalKwArgs =
|
|
27
|
+
magnus::scan_args::KwArgs<(), (Option<Value>, Option<bool>, Option<Value>), ()>;
|
|
24
28
|
|
|
25
29
|
macro_rules! canonical_error_class {
|
|
26
30
|
($static_name:ident, $class_name:literal) => {
|
|
@@ -42,6 +46,7 @@ macro_rules! canonical_error_class {
|
|
|
42
46
|
|
|
43
47
|
canonical_error_class!(CANONICALIZATION_ERROR_CLASS, "CanonicalizationError");
|
|
44
48
|
canonical_error_class!(INVALID_SCHEMA_TYPE_CLASS, "InvalidSchemaType");
|
|
49
|
+
canonical_error_class!(INVALID_PATTERN_CLASS, "InvalidPattern");
|
|
45
50
|
|
|
46
51
|
fn canonicalization_error(ruby: &Ruby, error: CanonicalizationError) -> Error {
|
|
47
52
|
if let CanonicalizationError::ValidationError(validation_error) = error {
|
|
@@ -52,6 +57,9 @@ fn canonicalization_error(ruby: &Ruby, error: CanonicalizationError) -> Error {
|
|
|
52
57
|
CanonicalizationError::InvalidSchemaType(_) => {
|
|
53
58
|
Error::new(ruby.get_inner(&INVALID_SCHEMA_TYPE_CLASS), message)
|
|
54
59
|
}
|
|
60
|
+
CanonicalizationError::InvalidPattern { .. } => {
|
|
61
|
+
Error::new(ruby.get_inner(&INVALID_PATTERN_CLASS), message)
|
|
62
|
+
}
|
|
55
63
|
// `ValidationError` returns above; future variants fall back to the base canonical error.
|
|
56
64
|
_ => Error::new(ruby.get_inner(&CANONICALIZATION_ERROR_CLASS), message),
|
|
57
65
|
}
|
|
@@ -892,12 +900,16 @@ fn canonicalize(ruby: &Ruby, args: &[Value]) -> Result<Value, Error> {
|
|
|
892
900
|
let parsed = scan_args::<(Value,), (), (), (), _, ()>(args)?;
|
|
893
901
|
let (schema_arg,) = parsed.required;
|
|
894
902
|
let keywords: RHash = parsed.keywords;
|
|
895
|
-
let base_kwargs:
|
|
903
|
+
let base_kwargs: CanonicalKwArgs = get_kwargs(
|
|
896
904
|
keywords,
|
|
897
905
|
&[],
|
|
898
|
-
&[
|
|
906
|
+
&[
|
|
907
|
+
*CANONICAL_KW_DRAFT,
|
|
908
|
+
*CANONICAL_KW_VALIDATE_FORMATS,
|
|
909
|
+
*CANONICAL_KW_PATTERN_OPTIONS,
|
|
910
|
+
],
|
|
899
911
|
)?;
|
|
900
|
-
let (draft_val, validate_formats) = base_kwargs.optional;
|
|
912
|
+
let (draft_val, validate_formats, pattern_options) = base_kwargs.optional;
|
|
901
913
|
|
|
902
914
|
let schema_value = to_schema_value(ruby, schema_arg)?;
|
|
903
915
|
let mut options = jsonschema::canonical::options();
|
|
@@ -907,6 +919,12 @@ fn canonicalize(ruby: &Ruby, args: &[Value]) -> Result<Value, Error> {
|
|
|
907
919
|
if let Some(validate_formats) = validate_formats {
|
|
908
920
|
options = options.should_validate_formats(validate_formats);
|
|
909
921
|
}
|
|
922
|
+
if let Some(val) = pattern_options {
|
|
923
|
+
match extract_pattern_options(ruby, val)? {
|
|
924
|
+
RbPatternOptions::Fancy(inner) => options = options.with_pattern_options(inner),
|
|
925
|
+
RbPatternOptions::Regex(inner) => options = options.with_pattern_options(inner),
|
|
926
|
+
}
|
|
927
|
+
}
|
|
910
928
|
options
|
|
911
929
|
.canonicalize(&schema_value)
|
|
912
930
|
.map(|inner| ruby.obj_wrap(RbCanonicalSchema { inner }).as_value())
|
|
@@ -919,6 +937,7 @@ pub(crate) fn init_canonical(ruby: &Ruby, module: &RModule) -> Result<(), Error>
|
|
|
919
937
|
let base_error =
|
|
920
938
|
canonical_module.define_error("CanonicalizationError", ruby.exception_standard_error())?;
|
|
921
939
|
canonical_module.define_error("InvalidSchemaType", base_error)?;
|
|
940
|
+
canonical_module.define_error("InvalidPattern", base_error)?;
|
|
922
941
|
|
|
923
942
|
let canonical_schema = canonical_module.define_class("CanonicalSchema", ruby.class_object())?;
|
|
924
943
|
canonical_schema.define_method(
|
data/src/options.rs
CHANGED
|
@@ -741,32 +741,9 @@ pub fn make_options_from_kwargs(
|
|
|
741
741
|
}
|
|
742
742
|
|
|
743
743
|
if let Some(val) = pattern_options_val {
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
po = po.backtrack_limit(limit);
|
|
748
|
-
}
|
|
749
|
-
if let Some(limit) = fancy_opts.size_limit {
|
|
750
|
-
po = po.size_limit(limit);
|
|
751
|
-
}
|
|
752
|
-
if let Some(limit) = fancy_opts.dfa_size_limit {
|
|
753
|
-
po = po.dfa_size_limit(limit);
|
|
754
|
-
}
|
|
755
|
-
opts = opts.with_pattern_options(po);
|
|
756
|
-
} else if let Ok(regex_opts) = <&RegexOptions>::try_convert(val) {
|
|
757
|
-
let mut po = jsonschema::PatternOptions::regex();
|
|
758
|
-
if let Some(limit) = regex_opts.size_limit {
|
|
759
|
-
po = po.size_limit(limit);
|
|
760
|
-
}
|
|
761
|
-
if let Some(limit) = regex_opts.dfa_size_limit {
|
|
762
|
-
po = po.dfa_size_limit(limit);
|
|
763
|
-
}
|
|
764
|
-
opts = opts.with_pattern_options(po);
|
|
765
|
-
} else {
|
|
766
|
-
return Err(Error::new(
|
|
767
|
-
ruby.exception_type_error(),
|
|
768
|
-
"pattern_options must be a RegexOptions or FancyRegexOptions instance",
|
|
769
|
-
));
|
|
744
|
+
match extract_pattern_options(ruby, val)? {
|
|
745
|
+
RbPatternOptions::Fancy(inner) => opts = opts.with_pattern_options(inner),
|
|
746
|
+
RbPatternOptions::Regex(inner) => opts = opts.with_pattern_options(inner),
|
|
770
747
|
}
|
|
771
748
|
}
|
|
772
749
|
|
|
@@ -953,6 +930,42 @@ impl RegexOptions {
|
|
|
953
930
|
}
|
|
954
931
|
}
|
|
955
932
|
|
|
933
|
+
/// A `pattern_options` argument converted into [`jsonschema::PatternOptions`].
|
|
934
|
+
pub(crate) enum RbPatternOptions {
|
|
935
|
+
Fancy(jsonschema::PatternOptions<jsonschema::FancyRegex>),
|
|
936
|
+
Regex(jsonschema::PatternOptions<jsonschema::Regex>),
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
pub(crate) fn extract_pattern_options(ruby: &Ruby, val: Value) -> Result<RbPatternOptions, Error> {
|
|
940
|
+
if let Ok(fancy_opts) = <&FancyRegexOptions>::try_convert(val) {
|
|
941
|
+
let mut po = jsonschema::PatternOptions::fancy_regex();
|
|
942
|
+
if let Some(limit) = fancy_opts.backtrack_limit {
|
|
943
|
+
po = po.backtrack_limit(limit);
|
|
944
|
+
}
|
|
945
|
+
if let Some(limit) = fancy_opts.size_limit {
|
|
946
|
+
po = po.size_limit(limit);
|
|
947
|
+
}
|
|
948
|
+
if let Some(limit) = fancy_opts.dfa_size_limit {
|
|
949
|
+
po = po.dfa_size_limit(limit);
|
|
950
|
+
}
|
|
951
|
+
Ok(RbPatternOptions::Fancy(po))
|
|
952
|
+
} else if let Ok(regex_opts) = <&RegexOptions>::try_convert(val) {
|
|
953
|
+
let mut po = jsonschema::PatternOptions::regex();
|
|
954
|
+
if let Some(limit) = regex_opts.size_limit {
|
|
955
|
+
po = po.size_limit(limit);
|
|
956
|
+
}
|
|
957
|
+
if let Some(limit) = regex_opts.dfa_size_limit {
|
|
958
|
+
po = po.dfa_size_limit(limit);
|
|
959
|
+
}
|
|
960
|
+
Ok(RbPatternOptions::Regex(po))
|
|
961
|
+
} else {
|
|
962
|
+
Err(Error::new(
|
|
963
|
+
ruby.exception_type_error(),
|
|
964
|
+
"pattern_options must be a RegexOptions or FancyRegexOptions instance",
|
|
965
|
+
))
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
|
|
956
969
|
#[magnus::wrap(class = "JSONSchema::FancyRegexOptions", free_immediately, size)]
|
|
957
970
|
pub struct FancyRegexOptions {
|
|
958
971
|
pub backtrack_limit: Option<usize>,
|