jsonschema_rs 0.61.1 → 0.62.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 +110 -1
- data/Cargo.toml +2 -2
- data/MIGRATION.md +10 -12
- data/README.md +44 -32
- data/ext/jsonschema/Cargo.lock +22 -22
- data/ext/jsonschema/Cargo.toml +3 -3
- data/lib/jsonschema/version.rb +1 -1
- data/sig/jsonschema.rbs +90 -63
- data/src/canonical.rs +19 -19
- data/src/error_kind.rs +4 -2
- data/src/evaluation.rs +4 -8
- data/src/lib.rs +16 -76
- data/src/options.rs +59 -29
- data/src/registry.rs +24 -3
- data/src/ser.rs +2 -424
- data/src/static_id.rs +2 -5
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 80269187c4e9b0ad91da5f78b96da06d106644e83e2a551381ed3770deffc509
|
|
4
|
+
data.tar.gz: cd9809d9012bfb27d46eb1dc5d0646552fde6c47d295eec7d89f26ba1d53d268
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fe4ad2642951b8ab030fd359db326843e1ccf3afcb929cd582421428ce867539e38cb9d8ffab8053d38f939fb784e9dee1c62abc87efcaef6589d84ef74fd4da
|
|
7
|
+
data.tar.gz: b4b75ab7a2c63575026b413fbda73fd653953dde5eb2c1aaf2ac776e231ddded9ce56673e015b8fe0e4b7eeb70a71ed69562bb32a5e2f4bd38d9a530bfdc018b
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,113 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.62.0] - 2026-11-21
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- `syntax: :engine` on `RegexOptions` and `FancyRegexOptions` to match `pattern` and `patternProperties` in the regex engine's own syntax, without the ECMA 262 translation. [#1895](https://github.com/Stranger6667/jsonschema/issues/1895)
|
|
10
|
+
- `Resolver#lookup_dynamic_ref` to resolve a `$dynamicRef` through the dynamic scope. [#1923](https://github.com/Stranger6667/jsonschema/issues/1923)
|
|
11
|
+
- `minContains` and `maxContains` error kinds.
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- Non-string keys of a root `Hash` raising only when validation reads them, like keys of nested ones, instead of on every call.
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
#### References and `$schema`
|
|
20
|
+
|
|
21
|
+
- `$ref` to a `$dynamicAnchor` resolving through the dynamic scope like `$dynamicRef`, to an outer `$dynamicAnchor` of the same name instead of the schema it names. [#1923](https://github.com/Stranger6667/jsonschema/issues/1923)
|
|
22
|
+
- `$dynamicRef` in a `$ref` cycle resolving as on the first pass through the cycle, ignoring a `$dynamicAnchor` that a later pass brings into the dynamic scope.
|
|
23
|
+
- `$recursiveRef` stopping at a resource without `$recursiveAnchor: true` in the dynamic scope instead of resolving to the outermost resource with `$recursiveAnchor: true`.
|
|
24
|
+
- `$dynamicRef` landing in another resource leaving the resource that holds it out of the dynamic scope.
|
|
25
|
+
- `Validator` results depending on how references name a schema that a `$ref` cycle passes through, such as `cycle` and `#` inside it.
|
|
26
|
+
- `Validator` results for a schema that references itself with `#` differing from the same schema reached through a `$ref`, such as `{"not": {"$ref": "#"}}` rejecting every instance.
|
|
27
|
+
- A subschema's own `$schema` ignored through a `$ref` and in the meta-schema check, which could fail or pass it against the wrong draft.
|
|
28
|
+
- `validator_map_for` entries accepting every value for a subschema in Draft 2019-09 or later under a Draft 7 or earlier root.
|
|
29
|
+
- `validator_map_for` entries below the root differing from the same subschema reached through a `$ref`.
|
|
30
|
+
- `$recursiveRef` and `$dynamicRef` inside a subschema with its own `$id` leaving the resource that holds it out of the dynamic scope when that subschema is reached inline or through a JSON Pointer `$ref`.
|
|
31
|
+
|
|
32
|
+
#### `evaluate` output
|
|
33
|
+
|
|
34
|
+
- Schemas with both `minLength` and `maxLength` leaving out the `maxLength` unit for accepted strings, and nesting it under a failing `minLength` unit for longer ones.
|
|
35
|
+
- Messages for a `type` that lists several types differing from `validate`, as `is not of types (null, string)` instead of `is not of types "null", "string"`.
|
|
36
|
+
- `properties` or `patternProperties` beside `additionalProperties` reporting their subschemas inside the `additionalProperties` unit instead of in units of their own.
|
|
37
|
+
- One `required` name beside `properties` and `additionalProperties: false` reporting the name inside the `additionalProperties` unit, and only when missing.
|
|
38
|
+
- `additionalProperties: false` reporting one error for the whole object instead of a failing unit for each extra member.
|
|
39
|
+
- Two `required` names beside `properties` reporting them inside the `properties` unit, failing it, and only when missing.
|
|
40
|
+
- `propertyNames: false` reporting one error for the whole object instead of a failing unit for each name.
|
|
41
|
+
- `dependentRequired` and the array form of `dependencies` reporting missing names in a nested unit at a schema location that does not exist.
|
|
42
|
+
- Array-form `items` and `additionalItems` missing their annotations, and `additionalItems` reporting the extra items in one error instead of a unit for each.
|
|
43
|
+
- `contains` beside `minContains` or `maxContains` missing the matching items and their indices, and locating the subschema at the bound keyword instead of at `contains`.
|
|
44
|
+
- `then` and `else` reported inside the `if` unit instead of in units of their own.
|
|
45
|
+
- `oneOf` with more than one valid subschema reporting a different message than `validate`.
|
|
46
|
+
- `contains` annotating an instance that is not an array.
|
|
47
|
+
- Locating a `$ref` target at the URI its document was registered under instead of the `$id` that document declares.
|
|
48
|
+
|
|
49
|
+
#### Error locations and messages
|
|
50
|
+
|
|
51
|
+
- Evaluation paths of custom keyword errors leaving out the `$ref` the keyword was reached through.
|
|
52
|
+
- Evaluation paths below a subschema reached both inline and through a `$ref` taking part of their path from the other route.
|
|
53
|
+
- Error messages for `minContains` and `maxContains` claiming that no item is valid under the `contains` subschema.
|
|
54
|
+
- Evaluation paths of `propertyNames` errors leaving out a `$ref` inside `propertyNames`.
|
|
55
|
+
- `absolute_keyword_location` of errors for names missing under `dependentRequired` or `dependencies` pointing to a schema location that does not exist.
|
|
56
|
+
- `absolute_keyword_location` of errors from a resource without a base URI, such as one registered under a `json-schema:///` URI, naming the `$ref` or other keyword that reached it from a resource with one, instead of being absent.
|
|
57
|
+
- `propertyNames` errors reporting `propertyNames` as their absolute keyword location instead of the keyword that rejected the name.
|
|
58
|
+
|
|
59
|
+
#### Keywords
|
|
60
|
+
|
|
61
|
+
- `unevaluatedItems` in Draft 2019-09 treating items matched by `contains` as evaluated.
|
|
62
|
+
- `contentEncoding` going unchecked in Draft 7 beside an unsupported `contentMediaType`.
|
|
63
|
+
- `contentEncoding` and `contentMediaType` asserted in Draft 6, which does not define them.
|
|
64
|
+
- `unevaluatedProperties` and `unevaluatedItems` errors and `evaluate` output counting members as evaluated by a subschema that fails, such as a `$ref` target.
|
|
65
|
+
- `multipleOf` with an integer divisor above 2^53 accepting numbers too small for `Float`, such as `BigDecimal("1e-400")`.
|
|
66
|
+
- `pattern` with a large bounded count the regex engine matches, such as `^x?.{0,404600}$`, failing with a regex engine error on the empty string when the size limit was raised to compile it.
|
|
67
|
+
|
|
68
|
+
#### `dereference`
|
|
69
|
+
|
|
70
|
+
- `dereference` dropping siblings of `$ref` in Draft 2019-09 and later when the referenced schema defines the same keyword with another value or is a boolean.
|
|
71
|
+
- `dereference` merging siblings of `$ref` into the referenced schema in Draft 2019-09 and later when they change what its keywords accept, such as `properties` beside `additionalProperties`.
|
|
72
|
+
- `dereference` keeping siblings of `$ref` that Draft 4, 6 and 7 ignore, such as `minimum` or `$id`.
|
|
73
|
+
|
|
74
|
+
### Performance
|
|
75
|
+
|
|
76
|
+
#### Building validators
|
|
77
|
+
|
|
78
|
+
- Fewer allocations per subschema when building a validator.
|
|
79
|
+
- Faster validator builds for valid schemas, which skip collecting meta-schema errors.
|
|
80
|
+
|
|
81
|
+
#### Validation
|
|
82
|
+
|
|
83
|
+
- Lower cost of collecting errors over the valid parts of an instance.
|
|
84
|
+
- Fewer allocations in `evaluate` for arrays, with every `items` and `additionalItems` annotation sharing one value.
|
|
85
|
+
- Lower cost of `evaluate` for arrays whose `items` is a single `type`, such as `{"type": "number"}`, with consecutive accepted items recorded together instead of as output units per item.
|
|
86
|
+
- `Hash` instances with up to 16 members read without copying them into a Ruby array on the first walk, and the copy kept for repeated walks read and written in place.
|
|
87
|
+
- `Hash` member snapshots built in place and filled without a GC write barrier per member.
|
|
88
|
+
- `pattern` and `patternProperties` with alternations of anchored sequences, such as `^[1-5](?:[0-9]{2}|XX)$`, matched in one pass without a regex engine.
|
|
89
|
+
- `unevaluatedProperties` matching names against sequence-shaped `patternProperties`, such as `^[a-z0-9-]+$` or `^[1-5](?:[0-9]{2}|XX)$`, without a regex engine.
|
|
90
|
+
- `properties` and a sibling `unevaluatedProperties` checked in one pass over the object by `is_valid`.
|
|
91
|
+
- `pattern` and `patternProperties` with fixed-length optional groups, exactly repeated groups, a leading group of alternatives, or a run of varying length after fixed characters, such as `^[a-z][a-z0-9-_]{1,63}$`, matched without a regex engine.
|
|
92
|
+
|
|
93
|
+
## [0.61.2] - 2026-11-12
|
|
94
|
+
|
|
95
|
+
### Fixed
|
|
96
|
+
|
|
97
|
+
- References inside a registered resource resolving against the URI it was registered under instead of its `$id`. [#1862](https://github.com/Stranger6667/jsonschema/issues/1862)
|
|
98
|
+
|
|
99
|
+
### Performance
|
|
100
|
+
|
|
101
|
+
- Validation of deeply nested instances against recursive schemas takes time linear in their nesting depth.
|
|
102
|
+
- `unevaluatedProperties` next to `if`, `dependentSchemas`, `anyOf` or `oneOf` checked in one pass over the object by `is_valid`, without validating those subschemas again.
|
|
103
|
+
- `allOf` branches that only check `properties`, `required` or `type: object` checked in one pass over the object by `is_valid`.
|
|
104
|
+
- `required` beside `properties` and `additionalProperties: false` checked in the same pass over the object by `is_valid`.
|
|
105
|
+
- `$ref`s to a subschema another `$ref` already compiled dispatched once instead of twice.
|
|
106
|
+
- `unevaluatedProperties` matching property names by their first and last bytes instead of hashing them.
|
|
107
|
+
- `additionalProperties` that only checks `type` decided without entering the subschema for each value by `is_valid`.
|
|
108
|
+
- Literal-prefix patterns rejecting a property name on its first byte before comparing the rest.
|
|
109
|
+
- Integer `const` and `enum` values compared directly instead of through their decimal forms.
|
|
110
|
+
- `propertyNames` validating each `String` key itself instead of a new string built from its text.
|
|
111
|
+
|
|
5
112
|
## [0.61.1] - 2026-11-10
|
|
6
113
|
|
|
7
114
|
### Fixed
|
|
@@ -747,7 +854,9 @@
|
|
|
747
854
|
|
|
748
855
|
- Initial public release
|
|
749
856
|
|
|
750
|
-
[Unreleased]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.
|
|
857
|
+
[Unreleased]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.62.0...HEAD
|
|
858
|
+
[0.62.0]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.61.2...ruby-v0.62.0
|
|
859
|
+
[0.61.2]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.61.1...ruby-v0.61.2
|
|
751
860
|
[0.61.1]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.61.0...ruby-v0.61.1
|
|
752
861
|
[0.61.0]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.60.2...ruby-v0.61.0
|
|
753
862
|
[0.60.2]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.60.1...ruby-v0.60.2
|
data/Cargo.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "jsonschema-rb"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.62.0"
|
|
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.62.0", default-features = false, features = ["magnus", "arbitrary-precision", "resolve-http", "resolve-file", "tls-ring", "macros", "idna"] }
|
|
18
18
|
magnus = { version = "0.9", features = ["rb-sys"] }
|
|
19
19
|
rb-sys = "0.9"
|
|
20
20
|
serde = { workspace = true }
|
data/MIGRATION.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Quick Reference
|
|
4
4
|
|
|
5
|
-
| json_schemer |
|
|
5
|
+
| json_schemer | jsonschema_rs |
|
|
6
6
|
|---|---|
|
|
7
7
|
| `JSONSchemer.schema(s)` | `JSONSchema.validator_for(s)` |
|
|
8
8
|
| `JSONSchemer.schema(s, meta_schema: 'draft7')` | `JSONSchema::Draft7Validator.new(s)` |
|
|
@@ -18,18 +18,16 @@
|
|
|
18
18
|
| `ref_resolver: proc` | `retriever: proc` |
|
|
19
19
|
| `format: true` | `validate_formats: true` |
|
|
20
20
|
|
|
21
|
-
Draft-specific validators are also available: `JSONSchema::Draft7Validator.new(schema)`
|
|
22
|
-
|
|
23
21
|
## What Stays the Same
|
|
24
22
|
|
|
25
23
|
- JSON Schema documents work as-is
|
|
26
24
|
- `valid?` and `validate!` method names
|
|
27
|
-
- Custom format validators via `formats
|
|
25
|
+
- Custom format validators via `formats:`, as procs that take the string
|
|
28
26
|
- One-off validation: `JSONSchema.valid?(schema, data)`
|
|
29
27
|
|
|
30
28
|
## Error Objects
|
|
31
29
|
|
|
32
|
-
json_schemer returns hashes,
|
|
30
|
+
json_schemer returns hashes, jsonschema_rs returns `ValidationError` objects:
|
|
33
31
|
|
|
34
32
|
```ruby
|
|
35
33
|
# json_schemer
|
|
@@ -38,16 +36,16 @@ error["schema_pointer"] # => "/properties/foo/minimum"
|
|
|
38
36
|
error["type"] # => "minimum"
|
|
39
37
|
error["error"] # => "value is less than 10"
|
|
40
38
|
|
|
41
|
-
#
|
|
39
|
+
# jsonschema_rs
|
|
42
40
|
error.instance_path # => ["foo", "bar"]
|
|
43
41
|
error.instance_path_pointer # => "/foo/bar" (same format as data_pointer)
|
|
44
42
|
error.schema_path # => ["properties", "foo", "minimum"]
|
|
45
43
|
error.schema_path_pointer # => "/properties/foo/minimum"
|
|
46
44
|
error.kind.name # => "minimum"
|
|
47
|
-
error.message # => "
|
|
45
|
+
error.message # => "5 is less than the minimum of 10"
|
|
48
46
|
|
|
49
47
|
# Need a hash? Use to_h on error kind
|
|
50
|
-
error.kind.to_h # => {
|
|
48
|
+
error.kind.to_h # => { name: "minimum", value: { limit: 10 } }
|
|
51
49
|
```
|
|
52
50
|
|
|
53
51
|
## Reference Resolution
|
|
@@ -56,10 +54,10 @@ error.kind.to_h # => { "name" => "minimum", "value" => { "limit" => 10 }
|
|
|
56
54
|
# json_schemer
|
|
57
55
|
JSONSchemer.schema(schema, ref_resolver: refs.to_proc)
|
|
58
56
|
|
|
59
|
-
#
|
|
57
|
+
# jsonschema_rs — retriever
|
|
60
58
|
JSONSchema.validator_for(schema, retriever: ->(uri) { fetch_schema(uri) })
|
|
61
59
|
|
|
62
|
-
#
|
|
60
|
+
# jsonschema_rs — registry
|
|
63
61
|
registry = JSONSchema::Registry.new([["http://example.com/s", sub_schema]])
|
|
64
62
|
JSONSchema.validator_for(schema, registry: registry)
|
|
65
63
|
```
|
|
@@ -70,11 +68,11 @@ JSONSchema.validator_for(schema, registry: registry)
|
|
|
70
68
|
- **Custom keywords** — extend JSON Schema with domain-specific validation rules
|
|
71
69
|
- **Error masking** — hide sensitive data in error messages with `mask:`
|
|
72
70
|
- **Regex engine configuration** — choose between fancy-regex (default) and linear-time regex
|
|
73
|
-
- **Email validation options** —
|
|
71
|
+
- **Email validation options** — TLD, IP-literal, display-name and domain-segment rules for `format: email`
|
|
74
72
|
|
|
75
73
|
## Not Supported
|
|
76
74
|
|
|
77
|
-
- `insert_property_defaults` —
|
|
75
|
+
- `insert_property_defaults` — jsonschema_rs is a validator, not a data transformer
|
|
78
76
|
- OpenAPI document parsing — use a dedicated OpenAPI library
|
|
79
77
|
|
|
80
78
|
## Migration Checklist
|
data/README.md
CHANGED
|
@@ -53,7 +53,7 @@ end
|
|
|
53
53
|
- 🎨 Structured Output v1 reports (flag/list/hierarchical)
|
|
54
54
|
- ✨ Meta-schema validation for schema documents, including custom metaschemas
|
|
55
55
|
- 🧮 Experimental schema canonicalization
|
|
56
|
-
- ♦️ Supports Ruby 3.2
|
|
56
|
+
- ♦️ Supports Ruby 3.2+
|
|
57
57
|
|
|
58
58
|
### Supported drafts
|
|
59
59
|
|
|
@@ -117,9 +117,11 @@ validator = JSONSchema::Draft7Validator.new(schema)
|
|
|
117
117
|
# Draft201909Validator, Draft202012Validator
|
|
118
118
|
```
|
|
119
119
|
|
|
120
|
+
With a chosen draft (a draft-specific class or `draft:`), the `$schema` URI is not retrieved: pass a custom meta-schema in `registry:` so its `$vocabulary` applies.
|
|
121
|
+
|
|
120
122
|
### Custom format validators
|
|
121
123
|
|
|
122
|
-
Pass a
|
|
124
|
+
Pass a Proc or lambda that takes a `String` and returns a boolean via `formats`. Drafts 2019-09 and 2020-12 treat `format` as an annotation, so set `validate_formats: true` to get it checked:
|
|
123
125
|
|
|
124
126
|
```ruby
|
|
125
127
|
phone_format = ->(value) { value.match?(/^\+?[1-9]\d{1,14}$/) }
|
|
@@ -298,7 +300,7 @@ Use it to deduplicate schemas that differ only in key order.
|
|
|
298
300
|
|
|
299
301
|
> **Experimental**: the canonicalization API may change in minor releases.
|
|
300
302
|
|
|
301
|
-
`JSONSchema.canonicalize` reduces a schema to a normal form that accepts the same values.
|
|
303
|
+
`JSONSchema.canonicalize` reduces a schema to a normal form that accepts the same values. Many schemas that accept the same values reduce to equal `CanonicalSchema` objects, and a schema proven to accept nothing reduces to `false`:
|
|
302
304
|
|
|
303
305
|
```ruby
|
|
304
306
|
canonical = JSONSchema.canonicalize(
|
|
@@ -308,7 +310,7 @@ canonical.to_json_schema
|
|
|
308
310
|
# => {"$schema"=>"https://json-schema.org/draft/2020-12/schema",
|
|
309
311
|
# "type"=>"integer", "minimum"=>10, "maximum"=>100}
|
|
310
312
|
|
|
311
|
-
#
|
|
313
|
+
# Written differently, these two schemas accept the same values and compare equal
|
|
312
314
|
canonical == JSONSchema.canonicalize({ "type" => "integer", "maximum" => 100, "minimum" => 10 })
|
|
313
315
|
# => true
|
|
314
316
|
|
|
@@ -317,34 +319,34 @@ JSONSchema.canonicalize({ "type" => "integer", "minimum" => 10, "maximum" => 5 }
|
|
|
317
319
|
# => :no, which is JSONSchema::Canonical::Satisfiability::NO
|
|
318
320
|
```
|
|
319
321
|
|
|
320
|
-
A schema the canonical form cannot model exactly comes back unchanged, with `kind == :raw`. Its `view.reason` names
|
|
322
|
+
A schema the canonical form cannot model exactly comes back unchanged, with `kind == :raw`. Its `view.reason` names why it stayed raw, and `view.pointer` the subschema at fault when a single one is.
|
|
321
323
|
|
|
322
324
|
Canonical schemas combine like sets of values. Every emitted schema carries `$schema`; the comments below leave it out:
|
|
323
325
|
|
|
324
326
|
```ruby
|
|
325
|
-
|
|
326
|
-
bounded
|
|
327
|
+
non_negative = JSONSchema.canonicalize({ "type" => "integer", "minimum" => 0 })
|
|
328
|
+
bounded = JSONSchema.canonicalize({ "type" => "integer", "maximum" => 100 })
|
|
327
329
|
|
|
328
|
-
# Every value both
|
|
329
|
-
|
|
330
|
+
# Every value both accept
|
|
331
|
+
non_negative.intersect(bounded).to_json_schema
|
|
330
332
|
# => {"type"=>"integer", "minimum"=>0, "maximum"=>100}
|
|
331
333
|
|
|
332
|
-
# Every value either
|
|
333
|
-
|
|
334
|
+
# Every value either accepts
|
|
335
|
+
non_negative.union(bounded).to_json_schema
|
|
334
336
|
# => {"type"=>"integer"}
|
|
335
337
|
|
|
336
|
-
# Every value `
|
|
337
|
-
|
|
338
|
+
# Every value `non_negative` accepts and `bounded` rejects
|
|
339
|
+
non_negative.subtract(bounded).to_json_schema
|
|
338
340
|
# => {"type"=>"integer", "minimum"=>101}
|
|
339
341
|
|
|
340
|
-
# Every value `
|
|
341
|
-
|
|
342
|
+
# Every value `non_negative` rejects: other types, negative integers and non-integer numbers
|
|
343
|
+
non_negative.negate.to_json_schema
|
|
342
344
|
# => {"anyOf"=>[{"type"=>["null", "boolean", "string", "array", "object"]},
|
|
343
345
|
# {"type"=>"integer", "maximum"=>-1},
|
|
344
346
|
# {"type"=>"number", "not"=>{"multipleOf"=>1}}]}
|
|
345
347
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
+
non_negative.covers(bounded) # => :no: `bounded` accepts negative integers, `non_negative` rejects them
|
|
349
|
+
non_negative.satisfiability # => :yes
|
|
348
350
|
```
|
|
349
351
|
|
|
350
352
|
### Comparing two versions of a schema
|
|
@@ -375,7 +377,7 @@ The direction to check depends on who sends the value:
|
|
|
375
377
|
- `satisfiability`: only `:no` proves a schema accepts nothing. Treat `:unknown` like `:yes`.
|
|
376
378
|
- `a.covers(b)`: only `:yes` proves `a` accepts every value `b` accepts. Treat `:unknown` like `:no`.
|
|
377
379
|
|
|
378
|
-
`
|
|
380
|
+
`Containment`, `Satisfiability`, `Distinctness`, `Kind` and `RawReason` under `JSONSchema::Canonical` hold these symbols as constants, each with an `ALL` list.
|
|
379
381
|
|
|
380
382
|
The set operations raise `IncompatibleOperands` when the operands differ in draft, `format` assertion or regular-expression engine, or resolve `#` or one external resource to different schemas. They raise `UnsupportedOperand` when an operand is `:raw`, and `UnsupportedResult` when the canonical form cannot express the result exactly. All three live under `JSONSchema::Canonical`.
|
|
381
383
|
|
|
@@ -404,7 +406,7 @@ reasons.key?("/properties/name")
|
|
|
404
406
|
# => false
|
|
405
407
|
```
|
|
406
408
|
|
|
407
|
-
A reason is a `LiteralReason` (written as `false`), an `EmptyReason` (one part
|
|
409
|
+
A reason is a `LiteralReason` (written as `false`), an `EmptyReason` (one part accepts nothing by itself) or a `ConflictReason` (each part accepts values, together they accept none). A missing pointer does not prove that subschema satisfiable. For a document the canonical form cannot model, `find_unsatisfiable` reports nothing, the same way `satisfiability` answers `:unknown`.
|
|
408
410
|
|
|
409
411
|
## Schema Bundling and Dereferencing
|
|
410
412
|
|
|
@@ -573,6 +575,14 @@ validator = JSONSchema.validator_for(
|
|
|
573
575
|
dfa_size_limit: 10240 # Maximum DFA cache size
|
|
574
576
|
)
|
|
575
577
|
)
|
|
578
|
+
|
|
579
|
+
# Patterns in the engine's own syntax instead of ECMA 262:
|
|
580
|
+
# `\d` matches every Unicode decimal digit, as in the Rust `regex` crate
|
|
581
|
+
validator = JSONSchema.validator_for(
|
|
582
|
+
{ "type" => "string", "pattern" => "^\\d+$" },
|
|
583
|
+
pattern_options: JSONSchema::RegexOptions.new(syntax: :engine)
|
|
584
|
+
)
|
|
585
|
+
validator.valid?("٣") # => true
|
|
576
586
|
```
|
|
577
587
|
|
|
578
588
|
- `FancyRegexOptions`: default engine, supports lookaround and backreferences
|
|
@@ -586,6 +596,8 @@ validator = JSONSchema.validator_for(
|
|
|
586
596
|
- `size_limit`: Maximum compiled regex size in bytes
|
|
587
597
|
- `dfa_size_limit`: Maximum DFA cache size in bytes
|
|
588
598
|
|
|
599
|
+
Both take `syntax:`: `:ecma262` (default) translates patterns for the engine, `:engine` passes them to it unchanged. Use `:engine` for schemas whose patterns are written for the Rust [`regex`](https://docs.rs/regex/latest/regex/#syntax) or [`fancy-regex`](https://docs.rs/fancy-regex/latest/fancy_regex/#syntax) crate.
|
|
600
|
+
|
|
589
601
|
If you validate against schemas from untrusted sources, use `RegexOptions`: a crafted pattern cannot make it backtrack.
|
|
590
602
|
|
|
591
603
|
## Email Format Configuration
|
|
@@ -627,7 +639,7 @@ validator = JSONSchema.validator_for(
|
|
|
627
639
|
|
|
628
640
|
## Error Handling
|
|
629
641
|
|
|
630
|
-
A `ValidationError` carries the message,
|
|
642
|
+
A `ValidationError` carries the message, the instance and schema paths, and a `kind` with keyword-specific details:
|
|
631
643
|
|
|
632
644
|
```ruby
|
|
633
645
|
schema = { "type" => "string", "maxLength" => 5 }
|
|
@@ -643,8 +655,8 @@ rescue JSONSchema::ValidationError => error
|
|
|
643
655
|
|
|
644
656
|
# Detailed error information via `kind`
|
|
645
657
|
error.kind.name # => "maxLength"
|
|
646
|
-
error.kind.value # => {
|
|
647
|
-
error.kind.to_h # => {
|
|
658
|
+
error.kind.value # => { limit: 5 }
|
|
659
|
+
error.kind.to_h # => { name: "maxLength", value: { limit: 5 } }
|
|
648
660
|
end
|
|
649
661
|
```
|
|
650
662
|
|
|
@@ -655,8 +667,8 @@ end
|
|
|
655
667
|
```ruby
|
|
656
668
|
JSONSchema.each_error({ "minimum" => 5 }, 3).each do |error|
|
|
657
669
|
error.kind.name # => "minimum"
|
|
658
|
-
error.kind.value # => {
|
|
659
|
-
error.kind.to_h # => {
|
|
670
|
+
error.kind.value # => { limit: 5 }
|
|
671
|
+
error.kind.to_h # => { name: "minimum", value: { limit: 5 } }
|
|
660
672
|
error.kind.to_s # => "minimum"
|
|
661
673
|
end
|
|
662
674
|
```
|
|
@@ -680,16 +692,16 @@ begin
|
|
|
680
692
|
validator.validate!({ "password" => "123", "api_key" => "secret_key_123" })
|
|
681
693
|
rescue JSONSchema::ValidationError => exc
|
|
682
694
|
puts exc.message
|
|
683
|
-
# => '[REDACTED]
|
|
695
|
+
# => '[REDACTED] is shorter than 8 characters'
|
|
684
696
|
puts exc.verbose_message
|
|
685
|
-
# => '[REDACTED]
|
|
697
|
+
# => '[REDACTED] is shorter than 8 characters\n\nFailed validating...\nOn instance["password"]:\n [REDACTED]'
|
|
686
698
|
end
|
|
687
699
|
```
|
|
688
700
|
|
|
689
701
|
### Exception Classes
|
|
690
702
|
|
|
691
703
|
- **`JSONSchema::ValidationError`**: raised on validation failure
|
|
692
|
-
- `message`, `verbose_message`, `instance_path`, `schema_path`, `evaluation_path`, `kind`, `instance`
|
|
704
|
+
- `message`, `verbose_message`, `instance_path`, `schema_path`, `evaluation_path`, `kind`, `instance`, `absolute_keyword_location`
|
|
693
705
|
- JSON Pointer helpers: `instance_path_pointer`, `schema_path_pointer`, `evaluation_path_pointer`
|
|
694
706
|
- **`JSONSchema::ReferencingError`**: raised when a `$ref` cannot be resolved
|
|
695
707
|
|
|
@@ -716,7 +728,7 @@ JSONSchema.valid?(schema, instance,
|
|
|
716
728
|
)
|
|
717
729
|
```
|
|
718
730
|
|
|
719
|
-
`evaluate` accepts the same options except `mask
|
|
731
|
+
`evaluate` accepts the same options except `mask`.
|
|
720
732
|
|
|
721
733
|
`validator_for` accepts the same options except `draft:`. To pin a draft, use a draft-specific class such as `Draft7Validator.new`.
|
|
722
734
|
|
|
@@ -726,9 +738,9 @@ Valid draft symbols: `:draft4`, `:draft6`, `:draft7`, `:draft201909`, `:draft202
|
|
|
726
738
|
|
|
727
739
|
Compared with other Ruby validators:
|
|
728
740
|
|
|
729
|
-
- **
|
|
730
|
-
- **
|
|
731
|
-
- **
|
|
741
|
+
- **96-2,891,549x** faster than `json_schemer`
|
|
742
|
+
- **987-342,162x** faster than `json-schema` where supported
|
|
743
|
+
- **25-1,638,462x** faster than `rj_schema` (RapidJSON/C++) where supported
|
|
732
744
|
|
|
733
745
|
Full results and methodology are in [BENCHMARKS.md](https://github.com/Stranger6667/jsonschema/blob/master/crates/jsonschema-rb/BENCHMARKS.md).
|
|
734
746
|
|
|
@@ -737,7 +749,7 @@ Full results and methodology are in [BENCHMARKS.md](https://github.com/Stranger6
|
|
|
737
749
|
If you ship your own extension and know the schema at build time, the Rust crate's
|
|
738
750
|
`#[jsonschema::validator(..., backend = Magnus)]` macro compiles it into a validator that reads
|
|
739
751
|
Ruby objects directly, so nothing is parsed or compiled when your extension is loaded, and
|
|
740
|
-
validation runs up to
|
|
752
|
+
validation runs up to 2.6x faster than with a validator built at run time. See the
|
|
741
753
|
[macro documentation](https://docs.rs/jsonschema/latest/jsonschema/#ruby-extension-modules).
|
|
742
754
|
|
|
743
755
|
This is not available from the `jsonschema_rs` gem, which takes its schemas at run time.
|
data/ext/jsonschema/Cargo.lock
CHANGED
|
@@ -220,9 +220,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
|
|
220
220
|
|
|
221
221
|
[[package]]
|
|
222
222
|
name = "fancy-regex"
|
|
223
|
-
version = "0.20.
|
|
223
|
+
version = "0.20.2"
|
|
224
224
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
225
|
-
checksum = "
|
|
225
|
+
checksum = "0a2e16b9a584b602f1e0e5e22c30ca0906786088c27500653e432d086def8b53"
|
|
226
226
|
dependencies = [
|
|
227
227
|
"bit-set",
|
|
228
228
|
"regex-automata",
|
|
@@ -693,9 +693,9 @@ dependencies = [
|
|
|
693
693
|
|
|
694
694
|
[[package]]
|
|
695
695
|
name = "jsonschema"
|
|
696
|
-
version = "0.
|
|
696
|
+
version = "0.62.0"
|
|
697
697
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
698
|
-
checksum = "
|
|
698
|
+
checksum = "4c5400a8dc340fa3ed743068cf8f3c1719f4f71e1260115dffc64da6bf339135"
|
|
699
699
|
dependencies = [
|
|
700
700
|
"ahash",
|
|
701
701
|
"bytecount",
|
|
@@ -727,9 +727,9 @@ dependencies = [
|
|
|
727
727
|
|
|
728
728
|
[[package]]
|
|
729
729
|
name = "jsonschema-macros"
|
|
730
|
-
version = "0.
|
|
730
|
+
version = "0.62.0"
|
|
731
731
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
732
|
-
checksum = "
|
|
732
|
+
checksum = "06ad04ffcaff9f9eb2e8ed0f3d42f66008358e595edfac7e374575529033f3d0"
|
|
733
733
|
dependencies = [
|
|
734
734
|
"jsonschema-macros-core",
|
|
735
735
|
"proc-macro2",
|
|
@@ -737,9 +737,9 @@ dependencies = [
|
|
|
737
737
|
|
|
738
738
|
[[package]]
|
|
739
739
|
name = "jsonschema-macros-core"
|
|
740
|
-
version = "0.
|
|
740
|
+
version = "0.62.0"
|
|
741
741
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
742
|
-
checksum = "
|
|
742
|
+
checksum = "e869997df6b45ae196cfa9261861bd21f0b6cc786fc12e8e041e2f0ccf8690f7"
|
|
743
743
|
dependencies = [
|
|
744
744
|
"fancy-regex",
|
|
745
745
|
"indexmap",
|
|
@@ -751,12 +751,12 @@ dependencies = [
|
|
|
751
751
|
"referencing",
|
|
752
752
|
"regex",
|
|
753
753
|
"serde_json",
|
|
754
|
-
"syn
|
|
754
|
+
"syn 3.0.6",
|
|
755
755
|
]
|
|
756
756
|
|
|
757
757
|
[[package]]
|
|
758
758
|
name = "jsonschema-rb-ext"
|
|
759
|
-
version = "0.
|
|
759
|
+
version = "0.62.0"
|
|
760
760
|
dependencies = [
|
|
761
761
|
"jsonschema",
|
|
762
762
|
"magnus",
|
|
@@ -770,18 +770,18 @@ dependencies = [
|
|
|
770
770
|
|
|
771
771
|
[[package]]
|
|
772
772
|
name = "jsonschema-regex"
|
|
773
|
-
version = "0.
|
|
773
|
+
version = "0.62.0"
|
|
774
774
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
775
|
-
checksum = "
|
|
775
|
+
checksum = "7fdaef5fd9b5ee4cc56b9f8d373d811fc4d7b8fdcb0902cf3b7749e5c478118d"
|
|
776
776
|
dependencies = [
|
|
777
777
|
"regex-syntax",
|
|
778
778
|
]
|
|
779
779
|
|
|
780
780
|
[[package]]
|
|
781
781
|
name = "jsonschema-value"
|
|
782
|
-
version = "0.
|
|
782
|
+
version = "0.62.0"
|
|
783
783
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
784
|
-
checksum = "
|
|
784
|
+
checksum = "fcb55c1402635417a02ce0a53e890ce191cf5b276fc1ec92284fc544d257d127"
|
|
785
785
|
dependencies = [
|
|
786
786
|
"ahash",
|
|
787
787
|
"bytecount",
|
|
@@ -1137,9 +1137,9 @@ dependencies = [
|
|
|
1137
1137
|
|
|
1138
1138
|
[[package]]
|
|
1139
1139
|
name = "referencing"
|
|
1140
|
-
version = "0.
|
|
1140
|
+
version = "0.62.0"
|
|
1141
1141
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1142
|
-
checksum = "
|
|
1142
|
+
checksum = "5658eec40ff1065debe70c744f3c36accc3b41566359e098942a101e30d0029e"
|
|
1143
1143
|
dependencies = [
|
|
1144
1144
|
"ahash",
|
|
1145
1145
|
"fluent-uri",
|
|
@@ -1154,9 +1154,9 @@ dependencies = [
|
|
|
1154
1154
|
|
|
1155
1155
|
[[package]]
|
|
1156
1156
|
name = "regex"
|
|
1157
|
-
version = "1.
|
|
1157
|
+
version = "1.13.2"
|
|
1158
1158
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1159
|
-
checksum = "
|
|
1159
|
+
checksum = "9807af0e638c12e753aa1b4e601791bf2a8f71274023c8bbeec12fc149950857"
|
|
1160
1160
|
dependencies = [
|
|
1161
1161
|
"aho-corasick",
|
|
1162
1162
|
"memchr",
|
|
@@ -1166,9 +1166,9 @@ dependencies = [
|
|
|
1166
1166
|
|
|
1167
1167
|
[[package]]
|
|
1168
1168
|
name = "regex-automata"
|
|
1169
|
-
version = "0.4.
|
|
1169
|
+
version = "0.4.19"
|
|
1170
1170
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1171
|
-
checksum = "
|
|
1171
|
+
checksum = "41d60ef07df457506a0a1a2073112eb4aae5733dbd2813c3da77d1b0fd441158"
|
|
1172
1172
|
dependencies = [
|
|
1173
1173
|
"aho-corasick",
|
|
1174
1174
|
"memchr",
|
|
@@ -1177,9 +1177,9 @@ dependencies = [
|
|
|
1177
1177
|
|
|
1178
1178
|
[[package]]
|
|
1179
1179
|
name = "regex-syntax"
|
|
1180
|
-
version = "0.8.
|
|
1180
|
+
version = "0.8.12"
|
|
1181
1181
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1182
|
-
checksum = "
|
|
1182
|
+
checksum = "d902046e6a28a1e4c3cab97258a0ce11e994903f01c2d97a9447a0b3df85f4f6"
|
|
1183
1183
|
|
|
1184
1184
|
[[package]]
|
|
1185
1185
|
name = "reqwest"
|
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.62.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.62.0", default-features = false, features = ["magnus", "arbitrary-precision", "resolve-http", "resolve-file", "tls-ring", "macros", "idna"] }
|
|
14
14
|
magnus = { version = "0.9", features = ["rb-sys"] }
|
|
15
15
|
rb-sys = "0.9"
|
|
16
|
-
referencing = "0.
|
|
16
|
+
referencing = "0.62.0"
|
|
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