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
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`.
|
|
@@ -369,15 +374,6 @@ module JSONSchema
|
|
|
369
374
|
) -> Canonical::CanonicalSchema
|
|
370
375
|
|
|
371
376
|
# 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
377
|
def self.validator_for: (
|
|
382
378
|
untyped schema,
|
|
383
379
|
?validate_formats: bool?,
|
|
@@ -424,6 +420,7 @@ module JSONSchema
|
|
|
424
420
|
?retriever: (^(String) -> untyped)?,
|
|
425
421
|
?registry: Registry?,
|
|
426
422
|
?base_uri: String?,
|
|
423
|
+
?http_options: HttpOptions?,
|
|
427
424
|
?offline: bool?
|
|
428
425
|
) -> Hash[String, untyped]
|
|
429
426
|
|
|
@@ -435,6 +432,7 @@ module JSONSchema
|
|
|
435
432
|
?retriever: (^(String) -> untyped)?,
|
|
436
433
|
?registry: Registry?,
|
|
437
434
|
?base_uri: String?,
|
|
435
|
+
?http_options: HttpOptions?,
|
|
438
436
|
?offline: bool?
|
|
439
437
|
) -> untyped
|
|
440
438
|
|
|
@@ -539,9 +537,27 @@ module JSONSchema
|
|
|
539
537
|
?offline: bool?
|
|
540
538
|
) -> Evaluation
|
|
541
539
|
|
|
542
|
-
# Reusable JSON Schema validator.
|
|
543
540
|
private
|
|
541
|
+
# Reusable JSON Schema validator.
|
|
544
542
|
class Validator
|
|
543
|
+
# The draft classes take the schema and the `validator_for` keyword arguments.
|
|
544
|
+
def initialize: (
|
|
545
|
+
untyped schema,
|
|
546
|
+
?validate_formats: bool?,
|
|
547
|
+
?ignore_unknown_formats: bool?,
|
|
548
|
+
?vocabularies: Array[String]?,
|
|
549
|
+
?base_uri: String?,
|
|
550
|
+
?retriever: (^(String) -> untyped)?,
|
|
551
|
+
?mask: String?,
|
|
552
|
+
?formats: Hash[String, ^(String) -> bool]?,
|
|
553
|
+
?keywords: Hash[String, Class]?,
|
|
554
|
+
?registry: Registry?,
|
|
555
|
+
?pattern_options: (RegexOptions | FancyRegexOptions)?,
|
|
556
|
+
?email_options: EmailOptions?,
|
|
557
|
+
?http_options: HttpOptions?,
|
|
558
|
+
?offline: bool?
|
|
559
|
+
) -> void
|
|
560
|
+
|
|
545
561
|
# Fast validation returning boolean.
|
|
546
562
|
def valid?: (untyped instance) -> bool
|
|
547
563
|
|
|
@@ -559,7 +575,7 @@ module JSONSchema
|
|
|
559
575
|
end
|
|
560
576
|
public
|
|
561
577
|
|
|
562
|
-
#
|
|
578
|
+
# Validators for every subschema, keyed by URI fragment such as `"#/$defs/User"`.
|
|
563
579
|
class ValidatorMap
|
|
564
580
|
def []: (::String pointer) -> Validator?
|
|
565
581
|
def fetch: (::String pointer) -> Validator
|
|
@@ -603,7 +619,6 @@ module JSONSchema
|
|
|
603
619
|
# Path to the failing schema location.
|
|
604
620
|
attr_reader schema_path: Array[String | Integer]
|
|
605
621
|
|
|
606
|
-
# Evaluation path.
|
|
607
622
|
attr_reader evaluation_path: Array[String | Integer]
|
|
608
623
|
|
|
609
624
|
# The specific kind of validation error.
|
|
@@ -612,15 +627,10 @@ module JSONSchema
|
|
|
612
627
|
# The failing instance value.
|
|
613
628
|
attr_reader instance: untyped
|
|
614
629
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
?schema_path: Array[String | Integer],
|
|
620
|
-
?evaluation_path: Array[String | Integer],
|
|
621
|
-
?kind: ValidationErrorKind?,
|
|
622
|
-
?instance: untyped
|
|
623
|
-
) -> void
|
|
630
|
+
# Absolute URI of the failing keyword; nil when its resource has no base URI.
|
|
631
|
+
attr_reader absolute_keyword_location: String?
|
|
632
|
+
|
|
633
|
+
def initialize: (?String message) -> void
|
|
624
634
|
|
|
625
635
|
def to_s: () -> String
|
|
626
636
|
def inspect: () -> String
|
|
@@ -632,13 +642,13 @@ module JSONSchema
|
|
|
632
642
|
# Hash code based on message, schema_path, and instance_path.
|
|
633
643
|
def hash: () -> Integer
|
|
634
644
|
|
|
635
|
-
#
|
|
645
|
+
# `instance_path` as a JSON Pointer (RFC 6901).
|
|
636
646
|
def instance_path_pointer: () -> String
|
|
637
647
|
|
|
638
|
-
#
|
|
648
|
+
# `schema_path` as a JSON Pointer (RFC 6901).
|
|
639
649
|
def schema_path_pointer: () -> String
|
|
640
650
|
|
|
641
|
-
#
|
|
651
|
+
# `evaluation_path` as a JSON Pointer (RFC 6901).
|
|
642
652
|
def evaluation_path_pointer: () -> String
|
|
643
653
|
end
|
|
644
654
|
|
|
@@ -675,7 +685,7 @@ module JSONSchema
|
|
|
675
685
|
def hierarchical: () -> Hash[Symbol, untyped]
|
|
676
686
|
|
|
677
687
|
# Collected annotations from all evaluated nodes.
|
|
678
|
-
# Each entry contains schemaLocation,
|
|
688
|
+
# Each entry contains schemaLocation, absoluteKeywordLocation, instanceLocation and annotations
|
|
679
689
|
def annotations: () -> Array[Hash[Symbol, untyped]]
|
|
680
690
|
|
|
681
691
|
# Collected errors from all evaluated nodes.
|
|
@@ -690,6 +700,7 @@ module JSONSchema
|
|
|
690
700
|
def base_uri: () -> String
|
|
691
701
|
def dynamic_scope: () -> Array[String]
|
|
692
702
|
def lookup: (String reference) -> Resolved
|
|
703
|
+
def lookup_dynamic_ref: (String reference) -> Resolved
|
|
693
704
|
end
|
|
694
705
|
|
|
695
706
|
# Resolved reference containing the dereferenced schema and its context.
|
|
@@ -703,10 +714,13 @@ module JSONSchema
|
|
|
703
714
|
class Registry
|
|
704
715
|
# Create a registry from URI/schema pairs.
|
|
705
716
|
# @param resources Array of [uri, schema] pairs
|
|
706
|
-
# @param draft
|
|
707
|
-
# @param retriever
|
|
717
|
+
# @param draft Default draft symbol, such as :draft7
|
|
718
|
+
# @param retriever Proc that fetches schemas for URIs not in `resources`
|
|
708
719
|
def initialize: (Array[[String, untyped]] resources, ?draft: draft?, ?retriever: (^(String) -> untyped)?) -> void
|
|
709
720
|
|
|
721
|
+
# Resolver for references against `base_uri`.
|
|
722
|
+
def resolver: (String base_uri) -> Resolver
|
|
723
|
+
|
|
710
724
|
def inspect: () -> String
|
|
711
725
|
end
|
|
712
726
|
|
|
@@ -731,7 +745,7 @@ module JSONSchema
|
|
|
731
745
|
# @param require_tld Require top-level domain (default: false)
|
|
732
746
|
# @param allow_domain_literal Allow domain literals like [127.0.0.1] (default: true)
|
|
733
747
|
# @param allow_display_text Allow display names like "Name <email>" (default: true)
|
|
734
|
-
# @param minimum_sub_domains Minimum number of
|
|
748
|
+
# @param minimum_sub_domains Minimum number of domain segments (default: nil)
|
|
735
749
|
def initialize: (
|
|
736
750
|
?require_tld: bool?,
|
|
737
751
|
?allow_domain_literal: bool?,
|
|
@@ -748,7 +762,7 @@ module JSONSchema
|
|
|
748
762
|
# Whether display text is allowed.
|
|
749
763
|
def allow_display_text: () -> bool
|
|
750
764
|
|
|
751
|
-
# Minimum number of
|
|
765
|
+
# Minimum number of domain segments.
|
|
752
766
|
def minimum_sub_domains: () -> Integer?
|
|
753
767
|
|
|
754
768
|
def inspect: () -> String
|
|
@@ -760,7 +774,15 @@ module JSONSchema
|
|
|
760
774
|
# Create regex engine options.
|
|
761
775
|
# @param size_limit Maximum compiled regex size in bytes
|
|
762
776
|
# @param dfa_size_limit Maximum DFA size in bytes
|
|
763
|
-
|
|
777
|
+
# @param syntax :ecma262 translates patterns for the engine, :engine passes them to it unchanged
|
|
778
|
+
def initialize: (
|
|
779
|
+
?size_limit: Integer?,
|
|
780
|
+
?dfa_size_limit: Integer?,
|
|
781
|
+
?syntax: (:ecma262 | :engine)?
|
|
782
|
+
) -> void
|
|
783
|
+
|
|
784
|
+
# Syntax patterns are written in.
|
|
785
|
+
def syntax: () -> (:ecma262 | :engine)
|
|
764
786
|
|
|
765
787
|
# Maximum compiled regex size.
|
|
766
788
|
def size_limit: () -> Integer?
|
|
@@ -772,18 +794,23 @@ module JSONSchema
|
|
|
772
794
|
def to_s: () -> String
|
|
773
795
|
end
|
|
774
796
|
|
|
775
|
-
#
|
|
797
|
+
# fancy-regex engine options: backtracking, with lookaround and backreferences.
|
|
776
798
|
class FancyRegexOptions
|
|
777
799
|
# Create fancy regex engine options.
|
|
778
800
|
# @param backtrack_limit Maximum backtracking steps
|
|
779
801
|
# @param size_limit Maximum compiled regex size
|
|
780
802
|
# @param dfa_size_limit Maximum DFA size
|
|
803
|
+
# @param syntax :ecma262 translates patterns for the engine, :engine passes them to it unchanged
|
|
781
804
|
def initialize: (
|
|
782
805
|
?backtrack_limit: Integer?,
|
|
783
806
|
?size_limit: Integer?,
|
|
784
|
-
?dfa_size_limit: Integer
|
|
807
|
+
?dfa_size_limit: Integer?,
|
|
808
|
+
?syntax: (:ecma262 | :engine)?
|
|
785
809
|
) -> void
|
|
786
810
|
|
|
811
|
+
# Syntax patterns are written in.
|
|
812
|
+
def syntax: () -> (:ecma262 | :engine)
|
|
813
|
+
|
|
787
814
|
# Maximum backtracking steps.
|
|
788
815
|
def backtrack_limit: () -> Integer?
|
|
789
816
|
|
data/src/canonical.rs
CHANGED
|
@@ -343,7 +343,7 @@ impl RawView {
|
|
|
343
343
|
}
|
|
344
344
|
}
|
|
345
345
|
|
|
346
|
-
///
|
|
346
|
+
/// Accepts every value.
|
|
347
347
|
#[derive(magnus::TypedData)]
|
|
348
348
|
#[magnus(class = "JSONSchema::Canonical::TrueView", free_immediately)]
|
|
349
349
|
pub struct TrueView;
|
|
@@ -356,7 +356,7 @@ impl TrueView {
|
|
|
356
356
|
|
|
357
357
|
impl DataTypeFunctions for TrueView {}
|
|
358
358
|
|
|
359
|
-
///
|
|
359
|
+
/// Rejects every value.
|
|
360
360
|
#[derive(magnus::TypedData)]
|
|
361
361
|
#[magnus(class = "JSONSchema::Canonical::FalseView", free_immediately)]
|
|
362
362
|
pub struct FalseView;
|
|
@@ -369,7 +369,7 @@ impl FalseView {
|
|
|
369
369
|
|
|
370
370
|
impl DataTypeFunctions for FalseView {}
|
|
371
371
|
|
|
372
|
-
///
|
|
372
|
+
/// Accepts a value whose JSON type is in `types`.
|
|
373
373
|
#[derive(magnus::TypedData)]
|
|
374
374
|
#[magnus(class = "JSONSchema::Canonical::MultiTypeView", free_immediately)]
|
|
375
375
|
pub struct MultiTypeView {
|
|
@@ -401,7 +401,7 @@ impl MultiTypeView {
|
|
|
401
401
|
}
|
|
402
402
|
}
|
|
403
403
|
|
|
404
|
-
///
|
|
404
|
+
/// Accepts a value of JSON type `type_name` that `body` accepts.
|
|
405
405
|
#[derive(magnus::TypedData)]
|
|
406
406
|
#[magnus(class = "JSONSchema::Canonical::TypedGroupView", free_immediately)]
|
|
407
407
|
pub struct TypedGroupView {
|
|
@@ -465,7 +465,8 @@ fn strings_to_ruby(ruby: &Ruby, values: &[String]) -> Result<Value, Error> {
|
|
|
465
465
|
Ok(array.as_value())
|
|
466
466
|
}
|
|
467
467
|
|
|
468
|
-
/// A string
|
|
468
|
+
/// A string within `min_length`..`max_length`, matching every listed constraint and none of the
|
|
469
|
+
/// excluded ones.
|
|
469
470
|
#[derive(magnus::TypedData)]
|
|
470
471
|
#[magnus(class = "JSONSchema::Canonical::StringView", free_immediately)]
|
|
471
472
|
pub struct StringView {
|
|
@@ -646,7 +647,8 @@ impl NumberView {
|
|
|
646
647
|
}
|
|
647
648
|
}
|
|
648
649
|
|
|
649
|
-
/// An integer
|
|
650
|
+
/// An integer within `minimum`..`maximum`, a multiple of every `multiple_of` and of no
|
|
651
|
+
/// `not_multiple_of` divisor.
|
|
650
652
|
#[derive(magnus::TypedData)]
|
|
651
653
|
#[magnus(class = "JSONSchema::Canonical::IntegerView", free_immediately)]
|
|
652
654
|
pub struct IntegerView {
|
|
@@ -850,8 +852,6 @@ impl ContainsView {
|
|
|
850
852
|
}
|
|
851
853
|
}
|
|
852
854
|
|
|
853
|
-
// The violation list needs the same lazy Ruby-object conversion `ContainsView::from_core` does,
|
|
854
|
-
// so this stays a free function rather than a method on either violation view class.
|
|
855
855
|
fn object_violation_to_ruby(ruby: &Ruby, violation: &CoreObjectViolationView) -> Value {
|
|
856
856
|
match violation {
|
|
857
857
|
CoreObjectViolationView::NameFails(schema) => ruby
|
|
@@ -1133,7 +1133,7 @@ impl ObjectView {
|
|
|
1133
1133
|
}
|
|
1134
1134
|
}
|
|
1135
1135
|
|
|
1136
|
-
///
|
|
1136
|
+
/// Accepts a value any branch accepts.
|
|
1137
1137
|
#[derive(magnus::TypedData)]
|
|
1138
1138
|
#[magnus(class = "JSONSchema::Canonical::AnyOfView", free_immediately)]
|
|
1139
1139
|
pub struct AnyOfView {
|
|
@@ -1174,7 +1174,7 @@ impl AnyOfView {
|
|
|
1174
1174
|
}
|
|
1175
1175
|
}
|
|
1176
1176
|
|
|
1177
|
-
///
|
|
1177
|
+
/// Accepts a value exactly one branch accepts.
|
|
1178
1178
|
#[derive(magnus::TypedData)]
|
|
1179
1179
|
#[magnus(class = "JSONSchema::Canonical::OneOfView", free_immediately)]
|
|
1180
1180
|
pub struct OneOfView {
|
|
@@ -1215,7 +1215,7 @@ impl OneOfView {
|
|
|
1215
1215
|
}
|
|
1216
1216
|
}
|
|
1217
1217
|
|
|
1218
|
-
///
|
|
1218
|
+
/// Accepts a value every branch accepts.
|
|
1219
1219
|
#[derive(magnus::TypedData)]
|
|
1220
1220
|
#[magnus(class = "JSONSchema::Canonical::AllOfView", free_immediately)]
|
|
1221
1221
|
pub struct AllOfView {
|
|
@@ -1256,7 +1256,7 @@ impl AllOfView {
|
|
|
1256
1256
|
}
|
|
1257
1257
|
}
|
|
1258
1258
|
|
|
1259
|
-
///
|
|
1259
|
+
/// Accepts the values `schema` rejects, keeping the references it names symbolic.
|
|
1260
1260
|
#[derive(magnus::TypedData)]
|
|
1261
1261
|
#[magnus(class = "JSONSchema::Canonical::NotView", free_immediately)]
|
|
1262
1262
|
pub struct NotView {
|
|
@@ -1315,7 +1315,7 @@ impl ReferenceView {
|
|
|
1315
1315
|
}
|
|
1316
1316
|
}
|
|
1317
1317
|
|
|
1318
|
-
/// Exactly one
|
|
1318
|
+
/// Exactly one accepted value.
|
|
1319
1319
|
#[derive(magnus::TypedData)]
|
|
1320
1320
|
#[magnus(class = "JSONSchema::Canonical::ConstView", free_immediately)]
|
|
1321
1321
|
pub struct ConstView {
|
|
@@ -1343,7 +1343,7 @@ impl ConstView {
|
|
|
1343
1343
|
}
|
|
1344
1344
|
}
|
|
1345
1345
|
|
|
1346
|
-
/// A sorted, deduplicated finite set of
|
|
1346
|
+
/// A sorted, deduplicated finite set of accepted values.
|
|
1347
1347
|
#[derive(magnus::TypedData)]
|
|
1348
1348
|
#[magnus(class = "JSONSchema::Canonical::EnumView", free_immediately)]
|
|
1349
1349
|
pub struct EnumView {
|
|
@@ -1375,7 +1375,7 @@ impl EnumView {
|
|
|
1375
1375
|
}
|
|
1376
1376
|
}
|
|
1377
1377
|
|
|
1378
|
-
///
|
|
1378
|
+
/// A schema location and the keywords there that a reason names.
|
|
1379
1379
|
#[derive(magnus::TypedData)]
|
|
1380
1380
|
#[magnus(class = "JSONSchema::Canonical::Cause", free_immediately)]
|
|
1381
1381
|
pub struct Cause {
|
|
@@ -1438,8 +1438,7 @@ impl LiteralReason {
|
|
|
1438
1438
|
}
|
|
1439
1439
|
}
|
|
1440
1440
|
|
|
1441
|
-
/// One part
|
|
1442
|
-
/// its own under its pointer.
|
|
1441
|
+
/// One required part accepts no value; a subschema part is also reported under its own pointer.
|
|
1443
1442
|
#[derive(magnus::TypedData)]
|
|
1444
1443
|
#[magnus(class = "JSONSchema::Canonical::EmptyReason", free_immediately)]
|
|
1445
1444
|
pub struct EmptyReason {
|
|
@@ -1467,7 +1466,7 @@ impl EmptyReason {
|
|
|
1467
1466
|
}
|
|
1468
1467
|
}
|
|
1469
1468
|
|
|
1470
|
-
/// Each part
|
|
1469
|
+
/// Each part accepts values; no value satisfies all of them together.
|
|
1471
1470
|
#[derive(magnus::TypedData)]
|
|
1472
1471
|
#[magnus(class = "JSONSchema::Canonical::ConflictReason", free_immediately)]
|
|
1473
1472
|
pub struct ConflictReason {
|
|
@@ -1583,7 +1582,8 @@ fn with_canonical_options<R>(
|
|
|
1583
1582
|
call(options.with_registry(registry.inner.as_ref()))
|
|
1584
1583
|
}
|
|
1585
1584
|
|
|
1586
|
-
/// The subschemas of `schema` that
|
|
1585
|
+
/// The subschemas of `schema` that accept no value, keyed by JSON Pointer, with the reason for
|
|
1586
|
+
/// each.
|
|
1587
1587
|
fn find_unsatisfiable(ruby: &Ruby, args: &[Value]) -> Result<Value, Error> {
|
|
1588
1588
|
let parsed = scan_args::<(Value,), (), (), (), _, ()>(args)?;
|
|
1589
1589
|
let (schema_arg,) = parsed.required;
|
data/src/error_kind.rs
CHANGED
|
@@ -164,7 +164,7 @@ impl ValidationErrorKind {
|
|
|
164
164
|
ID_CONTENT_MEDIA_TYPE.to_symbol(),
|
|
165
165
|
ruby.into_value(content_media_type.as_str()),
|
|
166
166
|
)?,
|
|
167
|
-
K::Custom { message, .. }
|
|
167
|
+
K::Custom { message, .. } => rb_hash1(
|
|
168
168
|
ruby,
|
|
169
169
|
ID_MESSAGE.to_symbol(),
|
|
170
170
|
ruby.into_value(message.as_str()),
|
|
@@ -188,9 +188,11 @@ impl ValidationErrorKind {
|
|
|
188
188
|
ID_ERROR.to_symbol(),
|
|
189
189
|
ruby.into_value(error.to_string().as_str()),
|
|
190
190
|
)?,
|
|
191
|
-
K::
|
|
191
|
+
K::MaxContains { limit }
|
|
192
|
+
| K::MaxItems { limit }
|
|
192
193
|
| K::MaxLength { limit }
|
|
193
194
|
| K::MaxProperties { limit }
|
|
195
|
+
| K::MinContains { limit }
|
|
194
196
|
| K::MinItems { limit }
|
|
195
197
|
| K::MinLength { limit }
|
|
196
198
|
| K::MinProperties { limit } => rb_hash1(
|
data/src/evaluation.rs
CHANGED
|
@@ -4,10 +4,7 @@
|
|
|
4
4
|
use jsonschema::{output::ErrorDescription, OutputUnit};
|
|
5
5
|
use magnus::{method, prelude::*, Error, RArray, RHash, RModule, Ruby, Value};
|
|
6
6
|
|
|
7
|
-
use crate::{
|
|
8
|
-
ser::{serialize_to_ruby, value_to_ruby},
|
|
9
|
-
static_id::define_rb_intern,
|
|
10
|
-
};
|
|
7
|
+
use crate::{ser::value_to_ruby, static_id::define_rb_intern};
|
|
11
8
|
|
|
12
9
|
define_rb_intern!(static ID_SCHEMA_LOCATION: "schemaLocation");
|
|
13
10
|
define_rb_intern!(static ID_ABSOLUTE_KEYWORD_LOCATION: "absoluteKeywordLocation");
|
|
@@ -111,7 +108,7 @@ impl Evaluation {
|
|
|
111
108
|
// Builds an output unit straight into a Ruby Hash, with the keys and order the serialized
|
|
112
109
|
// output has.
|
|
113
110
|
fn unit_to_ruby(ruby: &Ruby, unit: OutputUnit<'_>, nested: bool) -> Result<RHash, Error> {
|
|
114
|
-
//
|
|
111
|
+
// Inserted with one `bulk_insert` call.
|
|
115
112
|
let mut pairs = [ruby.qnil().as_value(); 16];
|
|
116
113
|
let mut len = 0;
|
|
117
114
|
let mut push = |key: Value, value: Value| {
|
|
@@ -138,13 +135,13 @@ fn unit_to_ruby(ruby: &Ruby, unit: OutputUnit<'_>, nested: bool) -> Result<RHash
|
|
|
138
135
|
if let Some(annotations) = unit.annotations() {
|
|
139
136
|
push(
|
|
140
137
|
ID_ANNOTATIONS.to_symbol().as_value(),
|
|
141
|
-
|
|
138
|
+
value_to_ruby(ruby, annotations.value())?,
|
|
142
139
|
);
|
|
143
140
|
}
|
|
144
141
|
if let Some(annotations) = unit.dropped_annotations() {
|
|
145
142
|
push(
|
|
146
143
|
ID_DROPPED_ANNOTATIONS.to_symbol().as_value(),
|
|
147
|
-
|
|
144
|
+
value_to_ruby(ruby, annotations.value())?,
|
|
148
145
|
);
|
|
149
146
|
}
|
|
150
147
|
if !unit.errors().is_empty() {
|
|
@@ -179,7 +176,6 @@ fn list_units(ruby: &Ruby, unit: OutputUnit<'_>, out: RArray) -> Result<(), Erro
|
|
|
179
176
|
/// Messages grouped by keyword in first-seen order: one message as a String, several as an Array.
|
|
180
177
|
fn errors_to_ruby(ruby: &Ruby, errors: &[ErrorDescription]) -> Result<RHash, Error> {
|
|
181
178
|
let hash = ruby.hash_new();
|
|
182
|
-
// ponytail: quadratic in a unit's errors, which hold about one per keyword.
|
|
183
179
|
for (index, error) in errors.iter().enumerate() {
|
|
184
180
|
let keyword = error.keyword();
|
|
185
181
|
if errors[..index].iter().any(|seen| seen.keyword() == keyword) {
|