schemurai 2.0.0 → 2.2.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/README.md +40 -2
- data/lib/schemurai/error_message.rb +102 -0
- data/lib/schemurai/evaluation.rb +19 -2
- data/lib/schemurai/evaluator.rb +24 -21
- data/lib/schemurai/schema_domain.rb +27 -19
- data/lib/schemurai/schema_graph.rb +70 -37
- data/lib/schemurai/version.rb +1 -1
- data/lib/schemurai/vm/compiler.rb +166 -129
- data/lib/schemurai/vm/evaluator.rb +523 -221
- data/lib/schemurai.rb +6 -3
- data/sig/schemurai.rbs +157 -0
- metadata +4 -2
data/lib/schemurai.rb
CHANGED
|
@@ -34,10 +34,13 @@ module Schemurai
|
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
#
|
|
37
|
+
# Public value type describing one failed JSON Schema assertion.
|
|
38
38
|
#
|
|
39
|
-
# +
|
|
40
|
-
# to the root instance or schema.
|
|
39
|
+
# +keyword+ identifies the failed keyword. +instance_path+ and +schema_path+
|
|
40
|
+
# are JSON Pointers; an empty string points to the root instance or schema.
|
|
41
|
+
# +message+ is a human-readable String. Its presence and type are public API,
|
|
42
|
+
# but its exact wording is not. Use +keyword+ and the paths for programmatic
|
|
43
|
+
# error handling.
|
|
41
44
|
class ValidationError < Data.define(:keyword, :instance_path, :schema_path, :message)
|
|
42
45
|
# Returns the error fields as a Hash.
|
|
43
46
|
def to_h
|
data/sig/schemurai.rbs
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
module Schemurai
|
|
2
|
+
# A JSON-shaped Ruby value accepted as a schema value or validation instance.
|
|
3
|
+
type json_value =
|
|
4
|
+
nil
|
|
5
|
+
| bool
|
|
6
|
+
| Integer
|
|
7
|
+
| Float
|
|
8
|
+
| String
|
|
9
|
+
| Array[json_value]
|
|
10
|
+
| Hash[String, json_value]
|
|
11
|
+
|
|
12
|
+
# A JSON Schema root.
|
|
13
|
+
type schema = bool | Hash[String, json_value]
|
|
14
|
+
|
|
15
|
+
# External schemas indexed by their absolute URI.
|
|
16
|
+
type schemas = Hash[String, schema]
|
|
17
|
+
|
|
18
|
+
# A resolved evaluator backend.
|
|
19
|
+
type backend = :ruby | :vm
|
|
20
|
+
|
|
21
|
+
# A backend accepted when configuring a validator.
|
|
22
|
+
type backend_selection = backend | :default
|
|
23
|
+
|
|
24
|
+
VERSION: String
|
|
25
|
+
|
|
26
|
+
class Error < StandardError
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class ResolutionError < Error
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
class UnsupportedFormatError < Error
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class InvalidSchemaError < Error
|
|
36
|
+
attr_reader result: Result
|
|
37
|
+
|
|
38
|
+
def initialize: (Result result) -> void
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class ValidationError < Data
|
|
42
|
+
attr_reader keyword: String
|
|
43
|
+
attr_reader instance_path: String
|
|
44
|
+
attr_reader schema_path: String
|
|
45
|
+
attr_reader message: String
|
|
46
|
+
|
|
47
|
+
def self.new: (String keyword, String instance_path, String schema_path, String message) -> ValidationError
|
|
48
|
+
| (keyword: String, instance_path: String, schema_path: String, message: String) -> ValidationError
|
|
49
|
+
|
|
50
|
+
def self.[]: (String keyword, String instance_path, String schema_path, String message) -> ValidationError
|
|
51
|
+
| (keyword: String, instance_path: String, schema_path: String, message: String) -> ValidationError
|
|
52
|
+
|
|
53
|
+
def to_h: () -> {
|
|
54
|
+
keyword: String,
|
|
55
|
+
instance_path: String,
|
|
56
|
+
schema_path: String,
|
|
57
|
+
message: String
|
|
58
|
+
}
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
class Result
|
|
62
|
+
attr_reader errors: Array[ValidationError]
|
|
63
|
+
|
|
64
|
+
def initialize: (Array[ValidationError] errors) -> void
|
|
65
|
+
def valid?: () -> bool
|
|
66
|
+
alias success? valid?
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
interface _Evaluator
|
|
70
|
+
def backend: () -> backend
|
|
71
|
+
def validate: (json_value instance) -> Result
|
|
72
|
+
def valid?: (json_value instance) -> bool
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
class Validator
|
|
76
|
+
def initialize: (_Evaluator evaluator) -> void
|
|
77
|
+
def backend: () -> backend
|
|
78
|
+
def validate: (json_value instance) -> Result
|
|
79
|
+
def valid?: (json_value instance) -> bool
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
class SchemaRegistry
|
|
83
|
+
attr_reader backend: backend
|
|
84
|
+
|
|
85
|
+
def initialize: (
|
|
86
|
+
?schemas: schemas,
|
|
87
|
+
?validate_schema: bool,
|
|
88
|
+
?backend: backend_selection
|
|
89
|
+
) -> void
|
|
90
|
+
|
|
91
|
+
def validate_schema?: () -> bool
|
|
92
|
+
|
|
93
|
+
def compile: (
|
|
94
|
+
schema schema,
|
|
95
|
+
?base_uri: String?,
|
|
96
|
+
?content: bool,
|
|
97
|
+
?format: bool
|
|
98
|
+
) -> Validator
|
|
99
|
+
|
|
100
|
+
def validate_schema: (schema schema) -> Result
|
|
101
|
+
def valid_schema?: (schema schema) -> bool
|
|
102
|
+
def make_shareable: () -> self
|
|
103
|
+
def shareable?: () -> bool
|
|
104
|
+
|
|
105
|
+
def validator_for: (
|
|
106
|
+
String uri,
|
|
107
|
+
?content: bool,
|
|
108
|
+
?format: bool
|
|
109
|
+
) -> Validator
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def self.backend: () -> backend
|
|
113
|
+
|
|
114
|
+
def self.compile: (
|
|
115
|
+
schema schema,
|
|
116
|
+
?schemas: schemas,
|
|
117
|
+
?base_uri: String?,
|
|
118
|
+
?content: bool,
|
|
119
|
+
?format: bool,
|
|
120
|
+
?validate_schema: bool,
|
|
121
|
+
?backend: backend_selection
|
|
122
|
+
) -> Validator
|
|
123
|
+
|
|
124
|
+
def self.validate_schema: (
|
|
125
|
+
schema schema,
|
|
126
|
+
?schemas: schemas,
|
|
127
|
+
?backend: backend_selection
|
|
128
|
+
) -> Result
|
|
129
|
+
|
|
130
|
+
def self.valid_schema?: (
|
|
131
|
+
schema schema,
|
|
132
|
+
?schemas: schemas,
|
|
133
|
+
?backend: backend_selection
|
|
134
|
+
) -> bool
|
|
135
|
+
|
|
136
|
+
def self.validate: (
|
|
137
|
+
schema schema,
|
|
138
|
+
json_value instance,
|
|
139
|
+
?schemas: schemas,
|
|
140
|
+
?base_uri: String?,
|
|
141
|
+
?content: bool,
|
|
142
|
+
?format: bool,
|
|
143
|
+
?validate_schema: bool,
|
|
144
|
+
?backend: backend_selection
|
|
145
|
+
) -> Result
|
|
146
|
+
|
|
147
|
+
def self.valid?: (
|
|
148
|
+
schema schema,
|
|
149
|
+
json_value instance,
|
|
150
|
+
?schemas: schemas,
|
|
151
|
+
?base_uri: String?,
|
|
152
|
+
?content: bool,
|
|
153
|
+
?format: bool,
|
|
154
|
+
?validate_schema: bool,
|
|
155
|
+
?backend: backend_selection
|
|
156
|
+
) -> bool
|
|
157
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: schemurai
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kuya KOHARA (oakcask)
|
|
@@ -42,6 +42,7 @@ files:
|
|
|
42
42
|
- lib/schemurai/dialects/draft2019_09.rb
|
|
43
43
|
- lib/schemurai/dialects/draft2020_12.rb
|
|
44
44
|
- lib/schemurai/dialects/draft7.rb
|
|
45
|
+
- lib/schemurai/error_message.rb
|
|
45
46
|
- lib/schemurai/evaluation.rb
|
|
46
47
|
- lib/schemurai/evaluator.rb
|
|
47
48
|
- lib/schemurai/formats.rb
|
|
@@ -55,13 +56,14 @@ files:
|
|
|
55
56
|
- lib/schemurai/version.rb
|
|
56
57
|
- lib/schemurai/vm/compiler.rb
|
|
57
58
|
- lib/schemurai/vm/evaluator.rb
|
|
59
|
+
- sig/schemurai.rbs
|
|
58
60
|
homepage: https://github.com/oakcask/schemurai
|
|
59
61
|
licenses:
|
|
60
62
|
- MIT
|
|
61
63
|
metadata:
|
|
62
64
|
homepage_uri: https://github.com/oakcask/schemurai
|
|
63
65
|
source_code_uri: https://github.com/oakcask/schemurai/tree/main
|
|
64
|
-
documentation_uri: https://rubydoc.info/gems/schemurai/2.
|
|
66
|
+
documentation_uri: https://rubydoc.info/gems/schemurai/2.2.0
|
|
65
67
|
rubygems_mfa_required: 'true'
|
|
66
68
|
rdoc_options:
|
|
67
69
|
- "--main"
|