jsonschema_rs 0.61.2-x86_64-linux → 0.63.0-x86_64-linux
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/MIGRATION.md +10 -12
- data/README.md +67 -31
- data/lib/jsonschema/3.3/jsonschema_rb.so +0 -0
- data/lib/jsonschema/3.4/jsonschema_rb.so +0 -0
- data/lib/jsonschema/4.0/jsonschema_rb.so +0 -0
- data/lib/jsonschema/version.rb +1 -1
- data/sig/jsonschema.rbs +139 -69
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1825db9327a8b87ba8f8f3b1a65ac219859e642390e2a8b38f20ee2bb5ce5804
|
|
4
|
+
data.tar.gz: 3f3a9d7f0999e1ea07a76bad0b41a744427a7d6b1ecc8166b70a38bd67ab2c27
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b9412ddaacac54d282e409cd28bcbdc9f6abe8a53802d8bc5407cc074b5239356e3ca4f22f9e768dc5907ace068fd66dc0b3683c60f8b6a0c0992d7da4de9da6
|
|
7
|
+
data.tar.gz: c60b43d1e4ad011a2220ce1e7752beccc1ecc2026801296ae02800ad2468c9889512926fd3dac8ffbe151913e2acd7f562ad85db87d9bf5ac5ed123546e968ad
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,113 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.63.0] - 2026-11-22
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- `JsonTextValidator`, validating instances given as JSON text without building Ruby objects for them.
|
|
10
|
+
- `JSONSchema.number_format`, a custom `format` check that reads numbers.
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- `$ref` to a bundled meta-schema of a draft other than the schema's own, such as `https://json-schema.org/draft/2020-12/schema` from a Draft 7 schema, failing to resolve.
|
|
15
|
+
- `$ref` to a `json-schema.org` URI with no bundled meta-schema, such as `http://json-schema.org/draft-03/schema#`, never retrieved.
|
|
16
|
+
- Error messages for an empty `enum` ending after "is not one of" instead of naming the empty `enum`.
|
|
17
|
+
- `HttpOptions.new(ca_cert: ...)` accepting a file without certificates.
|
|
18
|
+
- Draft 4 schemas with an empty `enum`, or one with equal members such as `[0, 0.0]`, passing the meta-schema check.
|
|
19
|
+
- `HttpOptions.new(ca_cert: ...)` reporting invalid PEM as an HTTP client build error instead of a certificate parse error that names the file.
|
|
20
|
+
- Custom keyword `iter_errors` returning a non-exception producing a message prefixed with `RuntimeError: ` and no `cause`.
|
|
21
|
+
- Named backreferences such as `(?<n>x)\k<n>` failing to build in `pattern`, `patternProperties` and `propertyNames`.
|
|
22
|
+
- Patterns with a backreference or lookaround matching `\d`, `\w`, `\s` and `.` beyond ECMA 262, and rejecting a backreference to a group that did not match.
|
|
23
|
+
|
|
24
|
+
## [0.62.0] - 2026-11-21
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
|
|
28
|
+
- `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)
|
|
29
|
+
- `Resolver#lookup_dynamic_ref` to resolve a `$dynamicRef` through the dynamic scope. [#1923](https://github.com/Stranger6667/jsonschema/issues/1923)
|
|
30
|
+
- `minContains` and `maxContains` error kinds.
|
|
31
|
+
|
|
32
|
+
### Changed
|
|
33
|
+
|
|
34
|
+
- Non-string keys of a root `Hash` raising only when validation reads them, like keys of nested ones, instead of on every call.
|
|
35
|
+
|
|
36
|
+
### Fixed
|
|
37
|
+
|
|
38
|
+
#### References and `$schema`
|
|
39
|
+
|
|
40
|
+
- `$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)
|
|
41
|
+
- `$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.
|
|
42
|
+
- `$recursiveRef` stopping at a resource without `$recursiveAnchor: true` in the dynamic scope instead of resolving to the outermost resource with `$recursiveAnchor: true`.
|
|
43
|
+
- `$dynamicRef` landing in another resource leaving the resource that holds it out of the dynamic scope.
|
|
44
|
+
- `Validator` results depending on how references name a schema that a `$ref` cycle passes through, such as `cycle` and `#` inside it.
|
|
45
|
+
- `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.
|
|
46
|
+
- 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.
|
|
47
|
+
- `validator_map_for` entries accepting every value for a subschema in Draft 2019-09 or later under a Draft 7 or earlier root.
|
|
48
|
+
- `validator_map_for` entries below the root differing from the same subschema reached through a `$ref`.
|
|
49
|
+
- `$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`.
|
|
50
|
+
|
|
51
|
+
#### `evaluate` output
|
|
52
|
+
|
|
53
|
+
- 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.
|
|
54
|
+
- 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"`.
|
|
55
|
+
- `properties` or `patternProperties` beside `additionalProperties` reporting their subschemas inside the `additionalProperties` unit instead of in units of their own.
|
|
56
|
+
- One `required` name beside `properties` and `additionalProperties: false` reporting the name inside the `additionalProperties` unit, and only when missing.
|
|
57
|
+
- `additionalProperties: false` reporting one error for the whole object instead of a failing unit for each extra member.
|
|
58
|
+
- Two `required` names beside `properties` reporting them inside the `properties` unit, failing it, and only when missing.
|
|
59
|
+
- `propertyNames: false` reporting one error for the whole object instead of a failing unit for each name.
|
|
60
|
+
- `dependentRequired` and the array form of `dependencies` reporting missing names in a nested unit at a schema location that does not exist.
|
|
61
|
+
- Array-form `items` and `additionalItems` missing their annotations, and `additionalItems` reporting the extra items in one error instead of a unit for each.
|
|
62
|
+
- `contains` beside `minContains` or `maxContains` missing the matching items and their indices, and locating the subschema at the bound keyword instead of at `contains`.
|
|
63
|
+
- `then` and `else` reported inside the `if` unit instead of in units of their own.
|
|
64
|
+
- `oneOf` with more than one valid subschema reporting a different message than `validate`.
|
|
65
|
+
- `contains` annotating an instance that is not an array.
|
|
66
|
+
- Locating a `$ref` target at the URI its document was registered under instead of the `$id` that document declares.
|
|
67
|
+
|
|
68
|
+
#### Error locations and messages
|
|
69
|
+
|
|
70
|
+
- Evaluation paths of custom keyword errors leaving out the `$ref` the keyword was reached through.
|
|
71
|
+
- Evaluation paths below a subschema reached both inline and through a `$ref` taking part of their path from the other route.
|
|
72
|
+
- Error messages for `minContains` and `maxContains` claiming that no item is valid under the `contains` subschema.
|
|
73
|
+
- Evaluation paths of `propertyNames` errors leaving out a `$ref` inside `propertyNames`.
|
|
74
|
+
- `absolute_keyword_location` of errors for names missing under `dependentRequired` or `dependencies` pointing to a schema location that does not exist.
|
|
75
|
+
- `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.
|
|
76
|
+
- `propertyNames` errors reporting `propertyNames` as their absolute keyword location instead of the keyword that rejected the name.
|
|
77
|
+
|
|
78
|
+
#### Keywords
|
|
79
|
+
|
|
80
|
+
- `unevaluatedItems` in Draft 2019-09 treating items matched by `contains` as evaluated.
|
|
81
|
+
- `contentEncoding` going unchecked in Draft 7 beside an unsupported `contentMediaType`.
|
|
82
|
+
- `contentEncoding` and `contentMediaType` asserted in Draft 6, which does not define them.
|
|
83
|
+
- `unevaluatedProperties` and `unevaluatedItems` errors and `evaluate` output counting members as evaluated by a subschema that fails, such as a `$ref` target.
|
|
84
|
+
- `multipleOf` with an integer divisor above 2^53 accepting numbers too small for `Float`, such as `BigDecimal("1e-400")`.
|
|
85
|
+
- `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.
|
|
86
|
+
|
|
87
|
+
#### `dereference`
|
|
88
|
+
|
|
89
|
+
- `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.
|
|
90
|
+
- `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`.
|
|
91
|
+
- `dereference` keeping siblings of `$ref` that Draft 4, 6 and 7 ignore, such as `minimum` or `$id`.
|
|
92
|
+
|
|
93
|
+
### Performance
|
|
94
|
+
|
|
95
|
+
#### Building validators
|
|
96
|
+
|
|
97
|
+
- Fewer allocations per subschema when building a validator.
|
|
98
|
+
- Faster validator builds for valid schemas, which skip collecting meta-schema errors.
|
|
99
|
+
|
|
100
|
+
#### Validation
|
|
101
|
+
|
|
102
|
+
- Lower cost of collecting errors over the valid parts of an instance.
|
|
103
|
+
- Fewer allocations in `evaluate` for arrays, with every `items` and `additionalItems` annotation sharing one value.
|
|
104
|
+
- 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.
|
|
105
|
+
- `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.
|
|
106
|
+
- `Hash` member snapshots built in place and filled without a GC write barrier per member.
|
|
107
|
+
- `pattern` and `patternProperties` with alternations of anchored sequences, such as `^[1-5](?:[0-9]{2}|XX)$`, matched in one pass without a regex engine.
|
|
108
|
+
- `unevaluatedProperties` matching names against sequence-shaped `patternProperties`, such as `^[a-z0-9-]+$` or `^[1-5](?:[0-9]{2}|XX)$`, without a regex engine.
|
|
109
|
+
- `properties` and a sibling `unevaluatedProperties` checked in one pass over the object by `is_valid`.
|
|
110
|
+
- `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.
|
|
111
|
+
|
|
5
112
|
## [0.61.2] - 2026-11-12
|
|
6
113
|
|
|
7
114
|
### Fixed
|
|
@@ -766,7 +873,9 @@
|
|
|
766
873
|
|
|
767
874
|
- Initial public release
|
|
768
875
|
|
|
769
|
-
[Unreleased]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.
|
|
876
|
+
[Unreleased]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.63.0...HEAD
|
|
877
|
+
[0.63.0]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.62.0...ruby-v0.63.0
|
|
878
|
+
[0.62.0]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.61.2...ruby-v0.62.0
|
|
770
879
|
[0.61.2]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.61.1...ruby-v0.61.2
|
|
771
880
|
[0.61.1]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.61.0...ruby-v0.61.1
|
|
772
881
|
[0.61.0]: https://github.com/Stranger6667/jsonschema/compare/ruby-v0.60.2...ruby-v0.61.0
|
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,27 @@ 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
|
+
|
|
122
|
+
### Validating JSON text
|
|
123
|
+
|
|
124
|
+
When instances arrive as JSON text, such as request bodies or queue messages,
|
|
125
|
+
`JsonTextValidator` validates the string directly, without building Ruby objects for it.
|
|
126
|
+
It takes the same keyword arguments as `validator_for`, plus `draft:`:
|
|
127
|
+
|
|
128
|
+
```ruby
|
|
129
|
+
validator = JSONSchema::JsonTextValidator.new({ "type" => "object", "required" => ["id"] })
|
|
130
|
+
|
|
131
|
+
validator.valid?('{"id": 1}') # => true
|
|
132
|
+
validator.valid?('{"name": "x"}') # => false
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Text that is not a single JSON document raises `ArgumentError`, and a repeated key keeps its last
|
|
136
|
+
value, as with `JSON.parse`. Custom keywords receive the instance as Ruby objects.
|
|
137
|
+
|
|
120
138
|
### Custom format validators
|
|
121
139
|
|
|
122
|
-
Pass a
|
|
140
|
+
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
141
|
|
|
124
142
|
```ruby
|
|
125
143
|
phone_format = ->(value) { value.match?(/^\+?[1-9]\d{1,14}$/) }
|
|
@@ -131,6 +149,14 @@ validator = JSONSchema.validator_for(
|
|
|
131
149
|
)
|
|
132
150
|
```
|
|
133
151
|
|
|
152
|
+
To check numbers, wrap the callable in `JSONSchema.number_format`; it receives an `Integer`, `Float` or `BigDecimal`:
|
|
153
|
+
|
|
154
|
+
```ruby
|
|
155
|
+
int32 = JSONSchema.number_format(->(number) { number.between?(-(2**31), (2**31) - 1) })
|
|
156
|
+
validator = JSONSchema.validator_for({ "format" => "int32" }, validate_formats: true, formats: { "int32" => int32 })
|
|
157
|
+
validator.valid?(2**31) # => false
|
|
158
|
+
```
|
|
159
|
+
|
|
134
160
|
### Custom keyword validators
|
|
135
161
|
|
|
136
162
|
```ruby
|
|
@@ -298,7 +324,7 @@ Use it to deduplicate schemas that differ only in key order.
|
|
|
298
324
|
|
|
299
325
|
> **Experimental**: the canonicalization API may change in minor releases.
|
|
300
326
|
|
|
301
|
-
`JSONSchema.canonicalize` reduces a schema to a normal form that accepts the same values.
|
|
327
|
+
`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
328
|
|
|
303
329
|
```ruby
|
|
304
330
|
canonical = JSONSchema.canonicalize(
|
|
@@ -308,7 +334,7 @@ canonical.to_json_schema
|
|
|
308
334
|
# => {"$schema"=>"https://json-schema.org/draft/2020-12/schema",
|
|
309
335
|
# "type"=>"integer", "minimum"=>10, "maximum"=>100}
|
|
310
336
|
|
|
311
|
-
#
|
|
337
|
+
# Written differently, these two schemas accept the same values and compare equal
|
|
312
338
|
canonical == JSONSchema.canonicalize({ "type" => "integer", "maximum" => 100, "minimum" => 10 })
|
|
313
339
|
# => true
|
|
314
340
|
|
|
@@ -317,34 +343,34 @@ JSONSchema.canonicalize({ "type" => "integer", "minimum" => 10, "maximum" => 5 }
|
|
|
317
343
|
# => :no, which is JSONSchema::Canonical::Satisfiability::NO
|
|
318
344
|
```
|
|
319
345
|
|
|
320
|
-
A schema the canonical form cannot model exactly comes back unchanged, with `kind == :raw`. Its `view.reason` names
|
|
346
|
+
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
347
|
|
|
322
348
|
Canonical schemas combine like sets of values. Every emitted schema carries `$schema`; the comments below leave it out:
|
|
323
349
|
|
|
324
350
|
```ruby
|
|
325
|
-
|
|
326
|
-
bounded
|
|
351
|
+
non_negative = JSONSchema.canonicalize({ "type" => "integer", "minimum" => 0 })
|
|
352
|
+
bounded = JSONSchema.canonicalize({ "type" => "integer", "maximum" => 100 })
|
|
327
353
|
|
|
328
|
-
# Every value both
|
|
329
|
-
|
|
354
|
+
# Every value both accept
|
|
355
|
+
non_negative.intersect(bounded).to_json_schema
|
|
330
356
|
# => {"type"=>"integer", "minimum"=>0, "maximum"=>100}
|
|
331
357
|
|
|
332
|
-
# Every value either
|
|
333
|
-
|
|
358
|
+
# Every value either accepts
|
|
359
|
+
non_negative.union(bounded).to_json_schema
|
|
334
360
|
# => {"type"=>"integer"}
|
|
335
361
|
|
|
336
|
-
# Every value `
|
|
337
|
-
|
|
362
|
+
# Every value `non_negative` accepts and `bounded` rejects
|
|
363
|
+
non_negative.subtract(bounded).to_json_schema
|
|
338
364
|
# => {"type"=>"integer", "minimum"=>101}
|
|
339
365
|
|
|
340
|
-
# Every value `
|
|
341
|
-
|
|
366
|
+
# Every value `non_negative` rejects: other types, negative integers and non-integer numbers
|
|
367
|
+
non_negative.negate.to_json_schema
|
|
342
368
|
# => {"anyOf"=>[{"type"=>["null", "boolean", "string", "array", "object"]},
|
|
343
369
|
# {"type"=>"integer", "maximum"=>-1},
|
|
344
370
|
# {"type"=>"number", "not"=>{"multipleOf"=>1}}]}
|
|
345
371
|
|
|
346
|
-
|
|
347
|
-
|
|
372
|
+
non_negative.covers(bounded) # => :no: `bounded` accepts negative integers, `non_negative` rejects them
|
|
373
|
+
non_negative.satisfiability # => :yes
|
|
348
374
|
```
|
|
349
375
|
|
|
350
376
|
### Comparing two versions of a schema
|
|
@@ -375,7 +401,7 @@ The direction to check depends on who sends the value:
|
|
|
375
401
|
- `satisfiability`: only `:no` proves a schema accepts nothing. Treat `:unknown` like `:yes`.
|
|
376
402
|
- `a.covers(b)`: only `:yes` proves `a` accepts every value `b` accepts. Treat `:unknown` like `:no`.
|
|
377
403
|
|
|
378
|
-
`
|
|
404
|
+
`Containment`, `Satisfiability`, `Distinctness`, `Kind` and `RawReason` under `JSONSchema::Canonical` hold these symbols as constants, each with an `ALL` list.
|
|
379
405
|
|
|
380
406
|
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
407
|
|
|
@@ -404,7 +430,7 @@ reasons.key?("/properties/name")
|
|
|
404
430
|
# => false
|
|
405
431
|
```
|
|
406
432
|
|
|
407
|
-
A reason is a `LiteralReason` (written as `false`), an `EmptyReason` (one part
|
|
433
|
+
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
434
|
|
|
409
435
|
## Schema Bundling and Dereferencing
|
|
410
436
|
|
|
@@ -573,6 +599,14 @@ validator = JSONSchema.validator_for(
|
|
|
573
599
|
dfa_size_limit: 10240 # Maximum DFA cache size
|
|
574
600
|
)
|
|
575
601
|
)
|
|
602
|
+
|
|
603
|
+
# Patterns in the engine's own syntax instead of ECMA 262:
|
|
604
|
+
# `\d` matches every Unicode decimal digit, as in the Rust `regex` crate
|
|
605
|
+
validator = JSONSchema.validator_for(
|
|
606
|
+
{ "type" => "string", "pattern" => "^\\d+$" },
|
|
607
|
+
pattern_options: JSONSchema::RegexOptions.new(syntax: :engine)
|
|
608
|
+
)
|
|
609
|
+
validator.valid?("٣") # => true
|
|
576
610
|
```
|
|
577
611
|
|
|
578
612
|
- `FancyRegexOptions`: default engine, supports lookaround and backreferences
|
|
@@ -586,6 +620,8 @@ validator = JSONSchema.validator_for(
|
|
|
586
620
|
- `size_limit`: Maximum compiled regex size in bytes
|
|
587
621
|
- `dfa_size_limit`: Maximum DFA cache size in bytes
|
|
588
622
|
|
|
623
|
+
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.
|
|
624
|
+
|
|
589
625
|
If you validate against schemas from untrusted sources, use `RegexOptions`: a crafted pattern cannot make it backtrack.
|
|
590
626
|
|
|
591
627
|
## Email Format Configuration
|
|
@@ -627,7 +663,7 @@ validator = JSONSchema.validator_for(
|
|
|
627
663
|
|
|
628
664
|
## Error Handling
|
|
629
665
|
|
|
630
|
-
A `ValidationError` carries the message,
|
|
666
|
+
A `ValidationError` carries the message, the instance and schema paths, and a `kind` with keyword-specific details:
|
|
631
667
|
|
|
632
668
|
```ruby
|
|
633
669
|
schema = { "type" => "string", "maxLength" => 5 }
|
|
@@ -643,8 +679,8 @@ rescue JSONSchema::ValidationError => error
|
|
|
643
679
|
|
|
644
680
|
# Detailed error information via `kind`
|
|
645
681
|
error.kind.name # => "maxLength"
|
|
646
|
-
error.kind.value # => {
|
|
647
|
-
error.kind.to_h # => {
|
|
682
|
+
error.kind.value # => { limit: 5 }
|
|
683
|
+
error.kind.to_h # => { name: "maxLength", value: { limit: 5 } }
|
|
648
684
|
end
|
|
649
685
|
```
|
|
650
686
|
|
|
@@ -655,8 +691,8 @@ end
|
|
|
655
691
|
```ruby
|
|
656
692
|
JSONSchema.each_error({ "minimum" => 5 }, 3).each do |error|
|
|
657
693
|
error.kind.name # => "minimum"
|
|
658
|
-
error.kind.value # => {
|
|
659
|
-
error.kind.to_h # => {
|
|
694
|
+
error.kind.value # => { limit: 5 }
|
|
695
|
+
error.kind.to_h # => { name: "minimum", value: { limit: 5 } }
|
|
660
696
|
error.kind.to_s # => "minimum"
|
|
661
697
|
end
|
|
662
698
|
```
|
|
@@ -680,16 +716,16 @@ begin
|
|
|
680
716
|
validator.validate!({ "password" => "123", "api_key" => "secret_key_123" })
|
|
681
717
|
rescue JSONSchema::ValidationError => exc
|
|
682
718
|
puts exc.message
|
|
683
|
-
# => '[REDACTED]
|
|
719
|
+
# => '[REDACTED] is shorter than 8 characters'
|
|
684
720
|
puts exc.verbose_message
|
|
685
|
-
# => '[REDACTED]
|
|
721
|
+
# => '[REDACTED] is shorter than 8 characters\n\nFailed validating...\nOn instance["password"]:\n [REDACTED]'
|
|
686
722
|
end
|
|
687
723
|
```
|
|
688
724
|
|
|
689
725
|
### Exception Classes
|
|
690
726
|
|
|
691
727
|
- **`JSONSchema::ValidationError`**: raised on validation failure
|
|
692
|
-
- `message`, `verbose_message`, `instance_path`, `schema_path`, `evaluation_path`, `kind`, `instance`
|
|
728
|
+
- `message`, `verbose_message`, `instance_path`, `schema_path`, `evaluation_path`, `kind`, `instance`, `absolute_keyword_location`
|
|
693
729
|
- JSON Pointer helpers: `instance_path_pointer`, `schema_path_pointer`, `evaluation_path_pointer`
|
|
694
730
|
- **`JSONSchema::ReferencingError`**: raised when a `$ref` cannot be resolved
|
|
695
731
|
|
|
@@ -716,7 +752,7 @@ JSONSchema.valid?(schema, instance,
|
|
|
716
752
|
)
|
|
717
753
|
```
|
|
718
754
|
|
|
719
|
-
`evaluate` accepts the same options except `mask
|
|
755
|
+
`evaluate` accepts the same options except `mask`.
|
|
720
756
|
|
|
721
757
|
`validator_for` accepts the same options except `draft:`. To pin a draft, use a draft-specific class such as `Draft7Validator.new`.
|
|
722
758
|
|
|
@@ -726,9 +762,9 @@ Valid draft symbols: `:draft4`, `:draft6`, `:draft7`, `:draft201909`, `:draft202
|
|
|
726
762
|
|
|
727
763
|
Compared with other Ruby validators:
|
|
728
764
|
|
|
729
|
-
- **96-
|
|
730
|
-
- **987-
|
|
731
|
-
- **25-
|
|
765
|
+
- **96-2,891,549x** faster than `json_schemer`
|
|
766
|
+
- **987-342,162x** faster than `json-schema` where supported
|
|
767
|
+
- **25-1,638,462x** faster than `rj_schema` (RapidJSON/C++) where supported
|
|
732
768
|
|
|
733
769
|
Full results and methodology are in [BENCHMARKS.md](https://github.com/Stranger6667/jsonschema/blob/master/crates/jsonschema-rb/BENCHMARKS.md).
|
|
734
770
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/jsonschema/version.rb
CHANGED
data/sig/jsonschema.rbs
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
# Type
|
|
2
|
-
# High-performance JSON Schema validation for Ruby
|
|
1
|
+
# Type signatures for the jsonschema_rs gem
|
|
3
2
|
|
|
4
3
|
module JSONSchema
|
|
5
4
|
VERSION: String
|
|
6
5
|
|
|
6
|
+
# Draft identifiers that `Resolved#draft` returns.
|
|
7
|
+
Draft4: Integer
|
|
8
|
+
Draft6: Integer
|
|
9
|
+
Draft7: Integer
|
|
10
|
+
Draft201909: Integer
|
|
11
|
+
Draft202012: Integer
|
|
12
|
+
|
|
7
13
|
# Valid draft version symbols
|
|
8
14
|
type draft = :draft4 | :draft6 | :draft7 | :draft201909 | :draft202012
|
|
9
15
|
|
|
@@ -23,15 +29,15 @@ module JSONSchema
|
|
|
23
29
|
# What an array requires of its elements: all distinct, some repeated, or neither.
|
|
24
30
|
type distinctness = :unconstrained | :all_distinct | :some_repeated
|
|
25
31
|
|
|
26
|
-
#
|
|
32
|
+
# Why canonicalization kept a schema verbatim.
|
|
27
33
|
type raw_reason = :unknown_dialect | :unmodeled | :outgrew_intersections
|
|
28
34
|
| :outgrew_cases | :inexact_intersection
|
|
29
35
|
|
|
30
|
-
# Whether one schema
|
|
36
|
+
# Whether one schema accepts every value another does. Only `:yes` proves containment: test
|
|
31
37
|
# for `:yes`, and treat `:unknown` like `:no`.
|
|
32
38
|
type containment = :yes | :no | :unknown
|
|
33
39
|
|
|
34
|
-
# Whether any value satisfies a schema. Only `:no` proves it
|
|
40
|
+
# Whether any value satisfies a schema. Only `:no` proves it accepts nothing: test for `:no`,
|
|
35
41
|
# and treat `:unknown` like `:yes`.
|
|
36
42
|
type satisfiability = :yes | :no | :unknown
|
|
37
43
|
|
|
@@ -109,7 +115,7 @@ module JSONSchema
|
|
|
109
115
|
class UnsupportedResult < CanonicalizationError
|
|
110
116
|
end
|
|
111
117
|
|
|
112
|
-
# A schema reduced to canonical form
|
|
118
|
+
# A schema reduced to canonical form; many schemas accepting the same values share one.
|
|
113
119
|
class CanonicalSchema
|
|
114
120
|
def to_json_schema: () -> untyped
|
|
115
121
|
def draft: () -> JSONSchema::draft
|
|
@@ -129,22 +135,22 @@ module JSONSchema
|
|
|
129
135
|
def hash: () -> Integer
|
|
130
136
|
end
|
|
131
137
|
|
|
132
|
-
#
|
|
138
|
+
# Accepts every value.
|
|
133
139
|
class TrueView
|
|
134
140
|
end
|
|
135
141
|
|
|
136
|
-
#
|
|
142
|
+
# Rejects every value.
|
|
137
143
|
class FalseView
|
|
138
144
|
end
|
|
139
145
|
|
|
140
|
-
#
|
|
146
|
+
# Accepts a value whose JSON type is in `types`.
|
|
141
147
|
class MultiTypeView
|
|
142
148
|
def types: () -> Array[Symbol]
|
|
143
149
|
def inspect: () -> String
|
|
144
150
|
def deconstruct_keys: (untyped keys) -> Hash[Symbol, untyped]
|
|
145
151
|
end
|
|
146
152
|
|
|
147
|
-
#
|
|
153
|
+
# Accepts a value of JSON type `type_name` that `body` accepts.
|
|
148
154
|
class TypedGroupView
|
|
149
155
|
def type_name: () -> Symbol
|
|
150
156
|
def body: () -> CanonicalSchema
|
|
@@ -152,7 +158,7 @@ module JSONSchema
|
|
|
152
158
|
def deconstruct_keys: (untyped keys) -> Hash[Symbol, untyped]
|
|
153
159
|
end
|
|
154
160
|
|
|
155
|
-
# A string
|
|
161
|
+
# A string within `min_length`..`max_length`, matching every listed constraint and none of the excluded ones.
|
|
156
162
|
class StringView
|
|
157
163
|
def min_length: () -> Integer?
|
|
158
164
|
def max_length: () -> Integer?
|
|
@@ -169,28 +175,28 @@ module JSONSchema
|
|
|
169
175
|
|
|
170
176
|
# A number value within a real interval.
|
|
171
177
|
class NumberView
|
|
172
|
-
def minimum: () ->
|
|
178
|
+
def minimum: () -> Numeric?
|
|
173
179
|
def exclusive_minimum: () -> bool
|
|
174
|
-
def maximum: () ->
|
|
180
|
+
def maximum: () -> Numeric?
|
|
175
181
|
def exclusive_maximum: () -> bool
|
|
176
|
-
def multiple_of: () -> Array[
|
|
177
|
-
def not_multiple_of: () -> Array[
|
|
182
|
+
def multiple_of: () -> Array[Numeric]
|
|
183
|
+
def not_multiple_of: () -> Array[Numeric]
|
|
178
184
|
def excludes_integers: () -> bool
|
|
179
185
|
def inspect: () -> String
|
|
180
186
|
def deconstruct_keys: (untyped keys) -> Hash[Symbol, untyped]
|
|
181
187
|
end
|
|
182
188
|
|
|
183
|
-
# An integer
|
|
189
|
+
# An integer within `minimum`..`maximum`, a multiple of every `multiple_of` and of no `not_multiple_of` divisor.
|
|
184
190
|
class IntegerView
|
|
185
191
|
def minimum: () -> Integer?
|
|
186
192
|
def maximum: () -> Integer?
|
|
187
|
-
def multiple_of: () -> Array[
|
|
188
|
-
def not_multiple_of: () -> Array[
|
|
193
|
+
def multiple_of: () -> Array[Numeric]
|
|
194
|
+
def not_multiple_of: () -> Array[Numeric]
|
|
189
195
|
def inspect: () -> String
|
|
190
196
|
def deconstruct_keys: (untyped keys) -> Hash[Symbol, untyped]
|
|
191
197
|
end
|
|
192
198
|
|
|
193
|
-
# An array value
|
|
199
|
+
# An array value's constraints.
|
|
194
200
|
class ArrayView
|
|
195
201
|
def min_items: () -> Integer?
|
|
196
202
|
def max_items: () -> Integer?
|
|
@@ -211,7 +217,7 @@ module JSONSchema
|
|
|
211
217
|
def deconstruct_keys: (untyped keys) -> Hash[Symbol, untyped]
|
|
212
218
|
end
|
|
213
219
|
|
|
214
|
-
# An object value
|
|
220
|
+
# An object value's constraints.
|
|
215
221
|
class ObjectView
|
|
216
222
|
def min_properties: () -> Integer?
|
|
217
223
|
def max_properties: () -> Integer?
|
|
@@ -249,21 +255,21 @@ module JSONSchema
|
|
|
249
255
|
def deconstruct_keys: (untyped keys) -> Hash[Symbol, untyped]
|
|
250
256
|
end
|
|
251
257
|
|
|
252
|
-
#
|
|
258
|
+
# Accepts the values `schema` rejects, keeping the references it names symbolic.
|
|
253
259
|
class NotView
|
|
254
260
|
def schema: () -> CanonicalSchema
|
|
255
261
|
def inspect: () -> String
|
|
256
262
|
def deconstruct_keys: (untyped keys) -> Hash[Symbol, untyped]
|
|
257
263
|
end
|
|
258
264
|
|
|
259
|
-
#
|
|
265
|
+
# Accepts a value every branch accepts.
|
|
260
266
|
class AllOfView
|
|
261
267
|
def branches: () -> Array[CanonicalSchema]
|
|
262
268
|
def inspect: () -> String
|
|
263
269
|
def deconstruct_keys: (untyped keys) -> Hash[Symbol, untyped]
|
|
264
270
|
end
|
|
265
271
|
|
|
266
|
-
#
|
|
272
|
+
# Accepts a value exactly one branch accepts.
|
|
267
273
|
class OneOfView
|
|
268
274
|
def branches: () -> Array[CanonicalSchema]
|
|
269
275
|
def inspect: () -> String
|
|
@@ -277,21 +283,21 @@ module JSONSchema
|
|
|
277
283
|
def deconstruct_keys: (untyped keys) -> Hash[Symbol, untyped]
|
|
278
284
|
end
|
|
279
285
|
|
|
280
|
-
#
|
|
286
|
+
# Accepts a value any branch accepts.
|
|
281
287
|
class AnyOfView
|
|
282
288
|
def branches: () -> Array[CanonicalSchema]
|
|
283
289
|
def inspect: () -> String
|
|
284
290
|
def deconstruct_keys: (untyped keys) -> Hash[Symbol, untyped]
|
|
285
291
|
end
|
|
286
292
|
|
|
287
|
-
# Exactly one
|
|
293
|
+
# Exactly one accepted value.
|
|
288
294
|
class ConstView
|
|
289
295
|
def value: () -> untyped
|
|
290
296
|
def inspect: () -> String
|
|
291
297
|
def deconstruct_keys: (untyped keys) -> Hash[Symbol, untyped]
|
|
292
298
|
end
|
|
293
299
|
|
|
294
|
-
# A sorted, deduplicated finite set of
|
|
300
|
+
# A sorted, deduplicated finite set of accepted values.
|
|
295
301
|
class EnumView
|
|
296
302
|
def values: () -> Array[untyped]
|
|
297
303
|
def inspect: () -> String
|
|
@@ -324,25 +330,24 @@ module JSONSchema
|
|
|
324
330
|
def deconstruct_keys: (untyped keys) -> Hash[Symbol, untyped]
|
|
325
331
|
end
|
|
326
332
|
|
|
327
|
-
# One part
|
|
328
|
-
# of its own under its pointer.
|
|
333
|
+
# One required part accepts no value; a subschema part is also reported under its own pointer.
|
|
329
334
|
class EmptyReason
|
|
330
335
|
def cause: () -> Cause
|
|
331
336
|
def inspect: () -> String
|
|
332
337
|
def deconstruct_keys: (untyped keys) -> Hash[Symbol, untyped]
|
|
333
338
|
end
|
|
334
339
|
|
|
335
|
-
# Each part
|
|
340
|
+
# Each part accepts values; no value satisfies all of them together.
|
|
336
341
|
class ConflictReason
|
|
337
342
|
def causes: () -> Array[Cause]
|
|
338
343
|
def inspect: () -> String
|
|
339
344
|
def deconstruct_keys: (untyped keys) -> Hash[Symbol, untyped]
|
|
340
345
|
end
|
|
341
346
|
|
|
342
|
-
# Why a subschema
|
|
347
|
+
# Why a subschema accepts no value.
|
|
343
348
|
type unsatisfiable_reason = LiteralReason | EmptyReason | ConflictReason
|
|
344
349
|
|
|
345
|
-
# The subschemas that
|
|
350
|
+
# The subschemas that accept no value, keyed by JSON Pointer, with the reason for each.
|
|
346
351
|
#
|
|
347
352
|
# A pointer left out is not proven satisfiable: a document the canonical form does not model
|
|
348
353
|
# reports nothing, as `satisfiability` answers `:unknown`.
|
|
@@ -368,16 +373,14 @@ module JSONSchema
|
|
|
368
373
|
?base_uri: String?
|
|
369
374
|
) -> Canonical::CanonicalSchema
|
|
370
375
|
|
|
376
|
+
# A `format` check that reads numbers, for the `formats` option; other instances pass it.
|
|
377
|
+
def self.number_format: (^(Numeric) -> bool check) -> NumberFormat
|
|
378
|
+
|
|
379
|
+
# A `format` check that reads numbers, made by `JSONSchema.number_format`.
|
|
380
|
+
class NumberFormat
|
|
381
|
+
end
|
|
382
|
+
|
|
371
383
|
# Create a validator with auto-detected draft version.
|
|
372
|
-
#
|
|
373
|
-
# @param schema The JSON Schema (Hash or JSON string)
|
|
374
|
-
# @param validate_formats Enable format validation
|
|
375
|
-
# @param ignore_unknown_formats Ignore unknown formats
|
|
376
|
-
# @param base_uri Base URI for reference resolution
|
|
377
|
-
# @param retriever Custom schema retriever proc
|
|
378
|
-
# @param mask Mask sensitive data in error messages
|
|
379
|
-
# @param formats Custom format validators (Hash of format_name => proc)
|
|
380
|
-
# @param keywords Custom keyword validators (Hash of keyword_name => class)
|
|
381
384
|
def self.validator_for: (
|
|
382
385
|
untyped schema,
|
|
383
386
|
?validate_formats: bool?,
|
|
@@ -386,7 +389,7 @@ module JSONSchema
|
|
|
386
389
|
?base_uri: String?,
|
|
387
390
|
?retriever: (^(String) -> untyped)?,
|
|
388
391
|
?mask: String?,
|
|
389
|
-
?formats: Hash[String, ^(String) -> bool]?,
|
|
392
|
+
?formats: Hash[String, (^(String) -> bool) | NumberFormat]?,
|
|
390
393
|
?keywords: Hash[String, Class]?,
|
|
391
394
|
?registry: Registry?,
|
|
392
395
|
?pattern_options: (RegexOptions | FancyRegexOptions)?,
|
|
@@ -424,6 +427,7 @@ module JSONSchema
|
|
|
424
427
|
?retriever: (^(String) -> untyped)?,
|
|
425
428
|
?registry: Registry?,
|
|
426
429
|
?base_uri: String?,
|
|
430
|
+
?http_options: HttpOptions?,
|
|
427
431
|
?offline: bool?
|
|
428
432
|
) -> Hash[String, untyped]
|
|
429
433
|
|
|
@@ -435,6 +439,7 @@ module JSONSchema
|
|
|
435
439
|
?retriever: (^(String) -> untyped)?,
|
|
436
440
|
?registry: Registry?,
|
|
437
441
|
?base_uri: String?,
|
|
442
|
+
?http_options: HttpOptions?,
|
|
438
443
|
?offline: bool?
|
|
439
444
|
) -> untyped
|
|
440
445
|
|
|
@@ -453,7 +458,7 @@ module JSONSchema
|
|
|
453
458
|
?base_uri: String?,
|
|
454
459
|
?retriever: (^(String) -> untyped)?,
|
|
455
460
|
?mask: String?,
|
|
456
|
-
?formats: Hash[String, ^(String) -> bool]?,
|
|
461
|
+
?formats: Hash[String, (^(String) -> bool) | NumberFormat]?,
|
|
457
462
|
?keywords: Hash[String, Class]?,
|
|
458
463
|
?registry: Registry?,
|
|
459
464
|
?pattern_options: (RegexOptions | FancyRegexOptions)?,
|
|
@@ -473,7 +478,7 @@ module JSONSchema
|
|
|
473
478
|
?base_uri: String?,
|
|
474
479
|
?retriever: (^(String) -> untyped)?,
|
|
475
480
|
?mask: String?,
|
|
476
|
-
?formats: Hash[String, ^(String) -> bool]?,
|
|
481
|
+
?formats: Hash[String, (^(String) -> bool) | NumberFormat]?,
|
|
477
482
|
?keywords: Hash[String, Class]?,
|
|
478
483
|
?registry: Registry?,
|
|
479
484
|
?pattern_options: (RegexOptions | FancyRegexOptions)?,
|
|
@@ -493,7 +498,7 @@ module JSONSchema
|
|
|
493
498
|
?base_uri: String?,
|
|
494
499
|
?retriever: (^(String) -> untyped)?,
|
|
495
500
|
?mask: String?,
|
|
496
|
-
?formats: Hash[String, ^(String) -> bool]?,
|
|
501
|
+
?formats: Hash[String, (^(String) -> bool) | NumberFormat]?,
|
|
497
502
|
?keywords: Hash[String, Class]?,
|
|
498
503
|
?registry: Registry?,
|
|
499
504
|
?pattern_options: (RegexOptions | FancyRegexOptions)?,
|
|
@@ -511,7 +516,7 @@ module JSONSchema
|
|
|
511
516
|
?base_uri: String?,
|
|
512
517
|
?retriever: (^(String) -> untyped)?,
|
|
513
518
|
?mask: String?,
|
|
514
|
-
?formats: Hash[String, ^(String) -> bool]?,
|
|
519
|
+
?formats: Hash[String, (^(String) -> bool) | NumberFormat]?,
|
|
515
520
|
?keywords: Hash[String, Class]?,
|
|
516
521
|
?registry: Registry?,
|
|
517
522
|
?pattern_options: (RegexOptions | FancyRegexOptions)?,
|
|
@@ -530,7 +535,7 @@ module JSONSchema
|
|
|
530
535
|
?vocabularies: Array[String]?,
|
|
531
536
|
?base_uri: String?,
|
|
532
537
|
?retriever: (^(String) -> untyped)?,
|
|
533
|
-
?formats: Hash[String, ^(String) -> bool]?,
|
|
538
|
+
?formats: Hash[String, (^(String) -> bool) | NumberFormat]?,
|
|
534
539
|
?keywords: Hash[String, Class]?,
|
|
535
540
|
?registry: Registry?,
|
|
536
541
|
?pattern_options: (RegexOptions | FancyRegexOptions)?,
|
|
@@ -539,9 +544,27 @@ module JSONSchema
|
|
|
539
544
|
?offline: bool?
|
|
540
545
|
) -> Evaluation
|
|
541
546
|
|
|
542
|
-
# Reusable JSON Schema validator.
|
|
543
547
|
private
|
|
548
|
+
# Reusable JSON Schema validator.
|
|
544
549
|
class Validator
|
|
550
|
+
# The draft classes take the schema and the `validator_for` keyword arguments.
|
|
551
|
+
def initialize: (
|
|
552
|
+
untyped schema,
|
|
553
|
+
?validate_formats: bool?,
|
|
554
|
+
?ignore_unknown_formats: bool?,
|
|
555
|
+
?vocabularies: Array[String]?,
|
|
556
|
+
?base_uri: String?,
|
|
557
|
+
?retriever: (^(String) -> untyped)?,
|
|
558
|
+
?mask: String?,
|
|
559
|
+
?formats: Hash[String, (^(String) -> bool) | NumberFormat]?,
|
|
560
|
+
?keywords: Hash[String, Class]?,
|
|
561
|
+
?registry: Registry?,
|
|
562
|
+
?pattern_options: (RegexOptions | FancyRegexOptions)?,
|
|
563
|
+
?email_options: EmailOptions?,
|
|
564
|
+
?http_options: HttpOptions?,
|
|
565
|
+
?offline: bool?
|
|
566
|
+
) -> void
|
|
567
|
+
|
|
545
568
|
# Fast validation returning boolean.
|
|
546
569
|
def valid?: (untyped instance) -> bool
|
|
547
570
|
|
|
@@ -557,9 +580,45 @@ module JSONSchema
|
|
|
557
580
|
|
|
558
581
|
def inspect: () -> String
|
|
559
582
|
end
|
|
583
|
+
|
|
584
|
+
# Validates instances given as JSON text, without building Ruby objects for them.
|
|
585
|
+
class JsonTextValidator
|
|
586
|
+
def initialize: (
|
|
587
|
+
untyped schema,
|
|
588
|
+
?draft: draft?,
|
|
589
|
+
?validate_formats: bool?,
|
|
590
|
+
?ignore_unknown_formats: bool?,
|
|
591
|
+
?vocabularies: Array[String]?,
|
|
592
|
+
?base_uri: String?,
|
|
593
|
+
?retriever: (^(String) -> untyped)?,
|
|
594
|
+
?mask: String?,
|
|
595
|
+
?formats: Hash[String, (^(String) -> bool) | NumberFormat]?,
|
|
596
|
+
?keywords: Hash[String, Class]?,
|
|
597
|
+
?registry: Registry?,
|
|
598
|
+
?pattern_options: (RegexOptions | FancyRegexOptions)?,
|
|
599
|
+
?email_options: EmailOptions?,
|
|
600
|
+
?http_options: HttpOptions?,
|
|
601
|
+
?offline: bool?
|
|
602
|
+
) -> void
|
|
603
|
+
|
|
604
|
+
# Whether the JSON text holds a valid document.
|
|
605
|
+
def valid?: (String text) -> bool
|
|
606
|
+
|
|
607
|
+
# Raise on the first error of the document in the JSON text.
|
|
608
|
+
def validate!: (String text) -> nil
|
|
609
|
+
|
|
610
|
+
# Iterate validation errors. Returns Array when no block given, nil when block given.
|
|
611
|
+
def each_error: (String text) -> Array[ValidationError]
|
|
612
|
+
| (String text) { (ValidationError) -> void } -> nil
|
|
613
|
+
|
|
614
|
+
# Evaluate the document in the JSON text and return structured output.
|
|
615
|
+
def evaluate: (String text) -> Evaluation
|
|
616
|
+
|
|
617
|
+
def inspect: () -> String
|
|
618
|
+
end
|
|
560
619
|
public
|
|
561
620
|
|
|
562
|
-
#
|
|
621
|
+
# Validators for every subschema, keyed by URI fragment such as `"#/$defs/User"`.
|
|
563
622
|
class ValidatorMap
|
|
564
623
|
def []: (::String pointer) -> Validator?
|
|
565
624
|
def fetch: (::String pointer) -> Validator
|
|
@@ -603,7 +662,6 @@ module JSONSchema
|
|
|
603
662
|
# Path to the failing schema location.
|
|
604
663
|
attr_reader schema_path: Array[String | Integer]
|
|
605
664
|
|
|
606
|
-
# Evaluation path.
|
|
607
665
|
attr_reader evaluation_path: Array[String | Integer]
|
|
608
666
|
|
|
609
667
|
# The specific kind of validation error.
|
|
@@ -612,15 +670,10 @@ module JSONSchema
|
|
|
612
670
|
# The failing instance value.
|
|
613
671
|
attr_reader instance: untyped
|
|
614
672
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
?schema_path: Array[String | Integer],
|
|
620
|
-
?evaluation_path: Array[String | Integer],
|
|
621
|
-
?kind: ValidationErrorKind?,
|
|
622
|
-
?instance: untyped
|
|
623
|
-
) -> void
|
|
673
|
+
# Absolute URI of the failing keyword; nil when its resource has no base URI.
|
|
674
|
+
attr_reader absolute_keyword_location: String?
|
|
675
|
+
|
|
676
|
+
def initialize: (?String message) -> void
|
|
624
677
|
|
|
625
678
|
def to_s: () -> String
|
|
626
679
|
def inspect: () -> String
|
|
@@ -632,13 +685,13 @@ module JSONSchema
|
|
|
632
685
|
# Hash code based on message, schema_path, and instance_path.
|
|
633
686
|
def hash: () -> Integer
|
|
634
687
|
|
|
635
|
-
#
|
|
688
|
+
# `instance_path` as a JSON Pointer (RFC 6901).
|
|
636
689
|
def instance_path_pointer: () -> String
|
|
637
690
|
|
|
638
|
-
#
|
|
691
|
+
# `schema_path` as a JSON Pointer (RFC 6901).
|
|
639
692
|
def schema_path_pointer: () -> String
|
|
640
693
|
|
|
641
|
-
#
|
|
694
|
+
# `evaluation_path` as a JSON Pointer (RFC 6901).
|
|
642
695
|
def evaluation_path_pointer: () -> String
|
|
643
696
|
end
|
|
644
697
|
|
|
@@ -675,7 +728,7 @@ module JSONSchema
|
|
|
675
728
|
def hierarchical: () -> Hash[Symbol, untyped]
|
|
676
729
|
|
|
677
730
|
# Collected annotations from all evaluated nodes.
|
|
678
|
-
# Each entry contains schemaLocation,
|
|
731
|
+
# Each entry contains schemaLocation, absoluteKeywordLocation, instanceLocation and annotations
|
|
679
732
|
def annotations: () -> Array[Hash[Symbol, untyped]]
|
|
680
733
|
|
|
681
734
|
# Collected errors from all evaluated nodes.
|
|
@@ -690,6 +743,7 @@ module JSONSchema
|
|
|
690
743
|
def base_uri: () -> String
|
|
691
744
|
def dynamic_scope: () -> Array[String]
|
|
692
745
|
def lookup: (String reference) -> Resolved
|
|
746
|
+
def lookup_dynamic_ref: (String reference) -> Resolved
|
|
693
747
|
end
|
|
694
748
|
|
|
695
749
|
# Resolved reference containing the dereferenced schema and its context.
|
|
@@ -703,10 +757,13 @@ module JSONSchema
|
|
|
703
757
|
class Registry
|
|
704
758
|
# Create a registry from URI/schema pairs.
|
|
705
759
|
# @param resources Array of [uri, schema] pairs
|
|
706
|
-
# @param draft
|
|
707
|
-
# @param retriever
|
|
760
|
+
# @param draft Default draft symbol, such as :draft7
|
|
761
|
+
# @param retriever Proc that fetches schemas for URIs not in `resources`
|
|
708
762
|
def initialize: (Array[[String, untyped]] resources, ?draft: draft?, ?retriever: (^(String) -> untyped)?) -> void
|
|
709
763
|
|
|
764
|
+
# Resolver for references against `base_uri`.
|
|
765
|
+
def resolver: (String base_uri) -> Resolver
|
|
766
|
+
|
|
710
767
|
def inspect: () -> String
|
|
711
768
|
end
|
|
712
769
|
|
|
@@ -731,7 +788,7 @@ module JSONSchema
|
|
|
731
788
|
# @param require_tld Require top-level domain (default: false)
|
|
732
789
|
# @param allow_domain_literal Allow domain literals like [127.0.0.1] (default: true)
|
|
733
790
|
# @param allow_display_text Allow display names like "Name <email>" (default: true)
|
|
734
|
-
# @param minimum_sub_domains Minimum number of
|
|
791
|
+
# @param minimum_sub_domains Minimum number of domain segments (default: nil)
|
|
735
792
|
def initialize: (
|
|
736
793
|
?require_tld: bool?,
|
|
737
794
|
?allow_domain_literal: bool?,
|
|
@@ -748,7 +805,7 @@ module JSONSchema
|
|
|
748
805
|
# Whether display text is allowed.
|
|
749
806
|
def allow_display_text: () -> bool
|
|
750
807
|
|
|
751
|
-
# Minimum number of
|
|
808
|
+
# Minimum number of domain segments.
|
|
752
809
|
def minimum_sub_domains: () -> Integer?
|
|
753
810
|
|
|
754
811
|
def inspect: () -> String
|
|
@@ -760,7 +817,15 @@ module JSONSchema
|
|
|
760
817
|
# Create regex engine options.
|
|
761
818
|
# @param size_limit Maximum compiled regex size in bytes
|
|
762
819
|
# @param dfa_size_limit Maximum DFA size in bytes
|
|
763
|
-
|
|
820
|
+
# @param syntax :ecma262 translates patterns for the engine, :engine passes them to it unchanged
|
|
821
|
+
def initialize: (
|
|
822
|
+
?size_limit: Integer?,
|
|
823
|
+
?dfa_size_limit: Integer?,
|
|
824
|
+
?syntax: (:ecma262 | :engine)?
|
|
825
|
+
) -> void
|
|
826
|
+
|
|
827
|
+
# Syntax patterns are written in.
|
|
828
|
+
def syntax: () -> (:ecma262 | :engine)
|
|
764
829
|
|
|
765
830
|
# Maximum compiled regex size.
|
|
766
831
|
def size_limit: () -> Integer?
|
|
@@ -772,18 +837,23 @@ module JSONSchema
|
|
|
772
837
|
def to_s: () -> String
|
|
773
838
|
end
|
|
774
839
|
|
|
775
|
-
#
|
|
840
|
+
# fancy-regex engine options: backtracking, with lookaround and backreferences.
|
|
776
841
|
class FancyRegexOptions
|
|
777
842
|
# Create fancy regex engine options.
|
|
778
843
|
# @param backtrack_limit Maximum backtracking steps
|
|
779
844
|
# @param size_limit Maximum compiled regex size
|
|
780
845
|
# @param dfa_size_limit Maximum DFA size
|
|
846
|
+
# @param syntax :ecma262 translates patterns for the engine, :engine passes them to it unchanged
|
|
781
847
|
def initialize: (
|
|
782
848
|
?backtrack_limit: Integer?,
|
|
783
849
|
?size_limit: Integer?,
|
|
784
|
-
?dfa_size_limit: Integer
|
|
850
|
+
?dfa_size_limit: Integer?,
|
|
851
|
+
?syntax: (:ecma262 | :engine)?
|
|
785
852
|
) -> void
|
|
786
853
|
|
|
854
|
+
# Syntax patterns are written in.
|
|
855
|
+
def syntax: () -> (:ecma262 | :engine)
|
|
856
|
+
|
|
787
857
|
# Maximum backtracking steps.
|
|
788
858
|
def backtrack_limit: () -> Integer?
|
|
789
859
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jsonschema_rs
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.63.0
|
|
5
5
|
platform: x86_64-linux
|
|
6
6
|
authors:
|
|
7
7
|
- Dmitry Dygalo
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bigdecimal
|
|
@@ -56,7 +56,7 @@ metadata:
|
|
|
56
56
|
homepage_uri: https://github.com/Stranger6667/jsonschema/tree/master/crates/jsonschema-rb
|
|
57
57
|
source_code_uri: https://github.com/Stranger6667/jsonschema
|
|
58
58
|
changelog_uri: https://github.com/Stranger6667/jsonschema/blob/master/crates/jsonschema-rb/CHANGELOG.md
|
|
59
|
-
documentation_uri: https://github.com/Stranger6667/jsonschema/blob/ruby-v0.
|
|
59
|
+
documentation_uri: https://github.com/Stranger6667/jsonschema/blob/ruby-v0.63.0/crates/jsonschema-rb/README.md
|
|
60
60
|
bug_tracker_uri: https://github.com/Stranger6667/jsonschema/issues
|
|
61
61
|
funding_uri: https://github.com/sponsors/Stranger6667
|
|
62
62
|
rubygems_mfa_required: 'true'
|