jsonschema_rs 0.42.0 → 0.42.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 -0
- data/Cargo.toml +2 -2
- data/README.md +72 -29
- data/ext/jsonschema/Cargo.lock +5 -5
- data/ext/jsonschema/Cargo.toml +3 -3
- data/lib/jsonschema/version.rb +1 -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: f7f354d248faf1bee6e0165b05f80dbff15b3a3edc1d3ccc037d7cea59c798c4
|
|
4
|
+
data.tar.gz: 4ee7a0389b58e6d71fe410bfce9e52e881fb1a805cbf0c93aa24c400748a56e2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '097f632cf1db882708a7b8e2e45e7e4659c52f3de17147e0680cd24f2ef86aaa34624a8a9edd665b3029e1cf94983bd8053421797fb3d4ea1a1bc78d5f1050a3'
|
|
7
|
+
data.tar.gz: a51f9f9969c44d8119960caac5e018bf91b0ecd9372122d53e24881f1b9a08139401b28db07f024e48afafa45a080b83c77406bb7d58190df9d42f72283abaaf
|
data/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.42.1] - 2026-02-17
|
|
6
|
+
|
|
7
|
+
### Performance
|
|
8
|
+
|
|
9
|
+
- Reduce dynamic dispatch overhead for non-recursive `$ref` resolution.
|
|
10
|
+
- Cache ECMA regex transformations during `format: "regex"` validation.
|
|
11
|
+
|
|
5
12
|
## 0.42.0 - 2026-02-15
|
|
6
13
|
|
|
7
14
|
- Initial public release
|
|
8
15
|
|
|
16
|
+
[Unreleased]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.42.1...HEAD
|
|
17
|
+
[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.
|
|
3
|
+
version = "0.42.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.42.
|
|
16
|
+
jsonschema = { version = "0.42.1", 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/README.md
CHANGED
|
@@ -36,8 +36,8 @@ validator.valid?(instance) # => true
|
|
|
36
36
|
|
|
37
37
|
# Structured output (JSON Schema Output v1)
|
|
38
38
|
evaluation = validator.evaluate(instance)
|
|
39
|
-
evaluation.
|
|
40
|
-
puts "
|
|
39
|
+
evaluation.errors.each do |err|
|
|
40
|
+
puts "Error at #{err[:instanceLocation]}: #{err[:error]}"
|
|
41
41
|
end
|
|
42
42
|
```
|
|
43
43
|
|
|
@@ -86,7 +86,7 @@ If no pre-built gem is available for your platform, it will be compiled from sou
|
|
|
86
86
|
### Reusable validators
|
|
87
87
|
|
|
88
88
|
For validating multiple instances against the same schema, create a reusable validator.
|
|
89
|
-
`validator_for` automatically detects the draft version from the `$schema` keyword in the schema:
|
|
89
|
+
`validator_for` automatically detects the draft version from the `$schema` keyword in the schema and falls back to Draft 2020-12:
|
|
90
90
|
|
|
91
91
|
```ruby
|
|
92
92
|
validator = JSONSchema.validator_for({
|
|
@@ -149,7 +149,7 @@ Each custom keyword class must implement:
|
|
|
149
149
|
|
|
150
150
|
### Structured evaluation output
|
|
151
151
|
|
|
152
|
-
When you need more than a boolean result, use the `evaluate` API to access the JSON Schema Output v1 formats:
|
|
152
|
+
When you need more than a boolean result, use the `evaluate` API to access the [JSON Schema Output v1](https://json-schema.org/draft/2020-12/json-schema-core#name-output-formatting) formats:
|
|
153
153
|
|
|
154
154
|
```ruby
|
|
155
155
|
schema = {
|
|
@@ -165,34 +165,79 @@ validator = JSONSchema.validator_for(schema)
|
|
|
165
165
|
evaluation = validator.evaluate({ "age" => "not_an_integer" })
|
|
166
166
|
|
|
167
167
|
evaluation.valid? # => false
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**Flag output** — simplest, just valid/invalid:
|
|
168
171
|
|
|
169
|
-
|
|
172
|
+
```ruby
|
|
170
173
|
evaluation.flag
|
|
171
|
-
# => {
|
|
174
|
+
# => {valid: false}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**List output** — flat list of all evaluation nodes:
|
|
172
178
|
|
|
173
|
-
|
|
179
|
+
```ruby
|
|
174
180
|
evaluation.list
|
|
175
|
-
# => {
|
|
176
|
-
#
|
|
177
|
-
#
|
|
178
|
-
#
|
|
179
|
-
#
|
|
180
|
-
#
|
|
181
|
-
|
|
182
|
-
#
|
|
181
|
+
# => {valid: false,
|
|
182
|
+
# details: [
|
|
183
|
+
# {valid: false, evaluationPath: "", schemaLocation: "", instanceLocation: ""},
|
|
184
|
+
# {valid: true, evaluationPath: "/type", schemaLocation: "/type", instanceLocation: ""},
|
|
185
|
+
# {valid: false, evaluationPath: "/required", schemaLocation: "/required",
|
|
186
|
+
# instanceLocation: "",
|
|
187
|
+
# errors: {"required" => "\"name\" is a required property"}},
|
|
188
|
+
# {valid: false, evaluationPath: "/properties", schemaLocation: "/properties",
|
|
189
|
+
# instanceLocation: "", droppedAnnotations: ["age"]},
|
|
190
|
+
# {valid: false, evaluationPath: "/properties/age", schemaLocation: "/properties/age",
|
|
191
|
+
# instanceLocation: "/age"},
|
|
192
|
+
# {valid: false, evaluationPath: "/properties/age/type",
|
|
193
|
+
# schemaLocation: "/properties/age/type", instanceLocation: "/age",
|
|
194
|
+
# errors: {"type" => "\"not_an_integer\" is not of type \"integer\""}}
|
|
195
|
+
# ]}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**Hierarchical output** — nested tree following schema structure:
|
|
199
|
+
|
|
200
|
+
```ruby
|
|
183
201
|
evaluation.hierarchical
|
|
184
|
-
# => {
|
|
185
|
-
#
|
|
202
|
+
# => {valid: false, evaluationPath: "", schemaLocation: "", instanceLocation: "",
|
|
203
|
+
# details: [
|
|
204
|
+
# {valid: true, evaluationPath: "/type", schemaLocation: "/type", instanceLocation: ""},
|
|
205
|
+
# {valid: false, evaluationPath: "/required", schemaLocation: "/required",
|
|
206
|
+
# instanceLocation: "",
|
|
207
|
+
# errors: {"required" => "\"name\" is a required property"}},
|
|
208
|
+
# {valid: false, evaluationPath: "/properties", schemaLocation: "/properties",
|
|
209
|
+
# instanceLocation: "", droppedAnnotations: ["age"],
|
|
210
|
+
# details: [
|
|
211
|
+
# {valid: false, evaluationPath: "/properties/age",
|
|
212
|
+
# schemaLocation: "/properties/age", instanceLocation: "/age",
|
|
213
|
+
# details: [
|
|
214
|
+
# {valid: false, evaluationPath: "/properties/age/type",
|
|
215
|
+
# schemaLocation: "/properties/age/type", instanceLocation: "/age",
|
|
216
|
+
# errors: {"type" => "\"not_an_integer\" is not of type \"integer\""}}
|
|
217
|
+
# ]}
|
|
218
|
+
# ]}
|
|
219
|
+
# ]}
|
|
220
|
+
```
|
|
186
221
|
|
|
187
|
-
|
|
222
|
+
**Collected errors** — flat list of all errors across evaluation nodes:
|
|
223
|
+
|
|
224
|
+
```ruby
|
|
188
225
|
evaluation.errors
|
|
189
|
-
# => [{
|
|
190
|
-
#
|
|
226
|
+
# => [{schemaLocation: "/required", absoluteKeywordLocation: nil,
|
|
227
|
+
# instanceLocation: "", error: "\"name\" is a required property"},
|
|
228
|
+
# {schemaLocation: "/properties/age/type", absoluteKeywordLocation: nil,
|
|
229
|
+
# instanceLocation: "/age",
|
|
230
|
+
# error: "\"not_an_integer\" is not of type \"integer\""}]
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
**Collected annotations** — flat list of annotations from successfully validated nodes.
|
|
234
|
+
When a node fails validation, its annotations appear as `droppedAnnotations` in the list/hierarchical output instead.
|
|
191
235
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
#
|
|
236
|
+
```ruby
|
|
237
|
+
valid_eval = validator.evaluate({ "name" => "Alice", "age" => 30 })
|
|
238
|
+
valid_eval.annotations
|
|
239
|
+
# => [{schemaLocation: "/properties", absoluteKeywordLocation: nil,
|
|
240
|
+
# instanceLocation: "", annotations: ["age", "name"]}]
|
|
196
241
|
```
|
|
197
242
|
|
|
198
243
|
## Meta-Schema Validation
|
|
@@ -460,14 +505,12 @@ Valid draft symbols: `:draft4`, `:draft6`, `:draft7`, `:draft201909`, `:draft202
|
|
|
460
505
|
|
|
461
506
|
`jsonschema` is designed for high performance, outperforming other Ruby JSON Schema validators in most scenarios:
|
|
462
507
|
|
|
463
|
-
- **
|
|
464
|
-
- **
|
|
465
|
-
- **7-
|
|
508
|
+
- **30-117x** faster than `json_schemer` for complex schemas and large instances
|
|
509
|
+
- **206-473x** faster than `json-schema` where supported
|
|
510
|
+
- **7-118x** faster than `rj_schema` (RapidJSON/C++)
|
|
466
511
|
|
|
467
512
|
For detailed benchmarks, see our [full performance comparison](https://github.com/Stranger6667/jsonschema/blob/master/crates/jsonschema-rb/BENCHMARKS.md).
|
|
468
513
|
|
|
469
|
-
**Tips:** Reuse validators. Use `valid?` for boolean checks (short-circuits on first error).
|
|
470
|
-
|
|
471
514
|
## Acknowledgements
|
|
472
515
|
|
|
473
516
|
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
|
@@ -667,9 +667,9 @@ dependencies = [
|
|
|
667
667
|
|
|
668
668
|
[[package]]
|
|
669
669
|
name = "jsonschema"
|
|
670
|
-
version = "0.42.
|
|
670
|
+
version = "0.42.1"
|
|
671
671
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
672
|
-
checksum = "
|
|
672
|
+
checksum = "6103dcd3815c9bd04239a6d0343dac2b7a18ee260e800d0a6e3eb5b9333504fb"
|
|
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.
|
|
700
|
+
version = "0.42.1"
|
|
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.
|
|
1047
|
+
version = "0.42.1"
|
|
1048
1048
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1049
|
-
checksum = "
|
|
1049
|
+
checksum = "1a76b0c93f3dd49da2900cfb3c6b883602471a0e3e34b1578a3310ca1269d418"
|
|
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.42.
|
|
3
|
+
version = "0.42.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.42.
|
|
13
|
+
jsonschema = { version = "0.42.1", 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.
|
|
16
|
+
referencing = "0.42.1"
|
|
17
17
|
serde = { version = "1", features = ["derive"] }
|
|
18
18
|
serde_json = { version = "1", features = ["arbitrary_precision"] }
|
|
19
19
|
|
data/lib/jsonschema/version.rb
CHANGED