simple_json_schema 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +4 -0
- data/Gemfile.lock +2 -2
- data/README.md +3 -3
- data/draft-07-schema +270 -0
- data/lib/simple_json_schema.rb +6 -2
- data/lib/simple_json_schema/checker.rb +2 -2
- data/lib/simple_json_schema/custom_draft7.rb +207 -0
- data/lib/simple_json_schema/scope.rb +2 -2
- data/lib/simple_json_schema/validator.rb +4 -4
- data/lib/simple_json_schema/validators/integer.rb +1 -1
- data/lib/simple_json_schema/validators/number.rb +1 -1
- data/lib/simple_json_schema/validators/string.rb +1 -1
- data/lib/simple_json_schema/version.rb +1 -1
- data/update_draft7_schema +9 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddf8b00b377c44e276b281a67ee6daf52bb254dec9cea0f2ef277e835cb5c7e1
|
4
|
+
data.tar.gz: b8bd835175f4559692c4858ba4735c74afca34dd39c2aa609e9a2a05c5a36ed4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 454cdba35466ad60e6177c1e621c789776d2080b9780b7133cb355c99124f4d7f779f61e178bddf7c73bcf2db4da3b754d414630d726796f26189c2115f725e9
|
7
|
+
data.tar.gz: 6d4e0d386ab1aae6147f1fd8ce278b421b2f18da7c58ff5d07a1d55c323b1edc9d79b32f193e9426295349d903a16e35921e2b89e179961bb2d7b650474e9d50
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
simple_json_schema (0.1.
|
4
|
+
simple_json_schema (0.1.6)
|
5
5
|
activesupport (~> 6.0)
|
6
6
|
addressable (~> 2.7)
|
7
7
|
ecma-re-validator (~> 0.3)
|
@@ -26,7 +26,7 @@ GEM
|
|
26
26
|
docile (1.3.3)
|
27
27
|
ecma-re-validator (0.3.0)
|
28
28
|
regexp_parser (~> 2.0)
|
29
|
-
i18n (1.8.
|
29
|
+
i18n (1.8.7)
|
30
30
|
concurrent-ruby (~> 1.0)
|
31
31
|
method_source (1.0.0)
|
32
32
|
minitest (5.14.2)
|
data/README.md
CHANGED
@@ -73,9 +73,9 @@ Some extra implementations on types (THIS IS NOT ON THE DRAFT7 DEFINITION!)
|
|
73
73
|
|
74
74
|
| Type | Attribute | Description | Allowed values |
|
75
75
|
| ---- | --------- | ----------- | -------------- |
|
76
|
-
| string |
|
77
|
-
| integer |
|
78
|
-
| number |
|
76
|
+
| string | not_blank | Will evaluate the `blank?` concept on the string | true/false |
|
77
|
+
| integer | not_zero | Will enforce value != 0 | true/false |
|
78
|
+
| number | not_zero | Will enforce value != 0.0 | true/false |
|
79
79
|
|
80
80
|
## Development
|
81
81
|
|
data/draft-07-schema
ADDED
@@ -0,0 +1,270 @@
|
|
1
|
+
{
|
2
|
+
"$schema": "https://gitlab.com/vliper/simple_json_schema/-/raw/master/draft-07-schema#",
|
3
|
+
"$id": "https://gitlab.com/vliper/simple_json_schema/-/raw/master/draft-07-schema#",
|
4
|
+
"title": "Simple JSON Schema meta-schema",
|
5
|
+
"definitions": {
|
6
|
+
"schemaArray": {
|
7
|
+
"type": "array",
|
8
|
+
"minItems": 1,
|
9
|
+
"items": {
|
10
|
+
"$ref": "#"
|
11
|
+
}
|
12
|
+
},
|
13
|
+
"nonNegativeInteger": {
|
14
|
+
"type": "integer",
|
15
|
+
"minimum": 0
|
16
|
+
},
|
17
|
+
"nonNegativeIntegerDefault0": {
|
18
|
+
"allOf": [
|
19
|
+
{
|
20
|
+
"$ref": "#/definitions/nonNegativeInteger"
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"default": 0
|
24
|
+
}
|
25
|
+
]
|
26
|
+
},
|
27
|
+
"simpleTypes": {
|
28
|
+
"enum": [
|
29
|
+
"array",
|
30
|
+
"boolean",
|
31
|
+
"integer",
|
32
|
+
"null",
|
33
|
+
"number",
|
34
|
+
"object",
|
35
|
+
"string"
|
36
|
+
]
|
37
|
+
},
|
38
|
+
"stringArray": {
|
39
|
+
"type": "array",
|
40
|
+
"items": {
|
41
|
+
"type": "string"
|
42
|
+
},
|
43
|
+
"uniqueItems": true,
|
44
|
+
"default": [
|
45
|
+
|
46
|
+
]
|
47
|
+
}
|
48
|
+
},
|
49
|
+
"type": [
|
50
|
+
"object",
|
51
|
+
"boolean"
|
52
|
+
],
|
53
|
+
"properties": {
|
54
|
+
"$id": {
|
55
|
+
"type": "string",
|
56
|
+
"format": "uri-reference"
|
57
|
+
},
|
58
|
+
"$schema": {
|
59
|
+
"type": "string",
|
60
|
+
"format": "uri"
|
61
|
+
},
|
62
|
+
"$ref": {
|
63
|
+
"type": "string",
|
64
|
+
"format": "uri-reference"
|
65
|
+
},
|
66
|
+
"$comment": {
|
67
|
+
"type": "string"
|
68
|
+
},
|
69
|
+
"title": {
|
70
|
+
"type": "string"
|
71
|
+
},
|
72
|
+
"description": {
|
73
|
+
"type": "string"
|
74
|
+
},
|
75
|
+
"default": true,
|
76
|
+
"readOnly": {
|
77
|
+
"type": "boolean",
|
78
|
+
"default": false
|
79
|
+
},
|
80
|
+
"writeOnly": {
|
81
|
+
"type": "boolean",
|
82
|
+
"default": false
|
83
|
+
},
|
84
|
+
"examples": {
|
85
|
+
"type": "array",
|
86
|
+
"items": true
|
87
|
+
},
|
88
|
+
"multipleOf": {
|
89
|
+
"type": "number",
|
90
|
+
"exclusiveMinimum": 0
|
91
|
+
},
|
92
|
+
"maximum": {
|
93
|
+
"type": "number"
|
94
|
+
},
|
95
|
+
"exclusiveMaximum": {
|
96
|
+
"type": "number"
|
97
|
+
},
|
98
|
+
"minimum": {
|
99
|
+
"type": "number"
|
100
|
+
},
|
101
|
+
"exclusiveMinimum": {
|
102
|
+
"type": "number"
|
103
|
+
},
|
104
|
+
"maxLength": {
|
105
|
+
"$ref": "#/definitions/nonNegativeInteger"
|
106
|
+
},
|
107
|
+
"minLength": {
|
108
|
+
"$ref": "#/definitions/nonNegativeIntegerDefault0"
|
109
|
+
},
|
110
|
+
"pattern": {
|
111
|
+
"type": "string",
|
112
|
+
"format": "regex"
|
113
|
+
},
|
114
|
+
"additionalItems": {
|
115
|
+
"$ref": "#"
|
116
|
+
},
|
117
|
+
"items": {
|
118
|
+
"anyOf": [
|
119
|
+
{
|
120
|
+
"$ref": "#"
|
121
|
+
},
|
122
|
+
{
|
123
|
+
"$ref": "#/definitions/schemaArray"
|
124
|
+
}
|
125
|
+
],
|
126
|
+
"default": true
|
127
|
+
},
|
128
|
+
"maxItems": {
|
129
|
+
"$ref": "#/definitions/nonNegativeInteger"
|
130
|
+
},
|
131
|
+
"minItems": {
|
132
|
+
"$ref": "#/definitions/nonNegativeIntegerDefault0"
|
133
|
+
},
|
134
|
+
"uniqueItems": {
|
135
|
+
"type": "boolean",
|
136
|
+
"default": false
|
137
|
+
},
|
138
|
+
"contains": {
|
139
|
+
"$ref": "#"
|
140
|
+
},
|
141
|
+
"maxProperties": {
|
142
|
+
"$ref": "#/definitions/nonNegativeInteger"
|
143
|
+
},
|
144
|
+
"minProperties": {
|
145
|
+
"$ref": "#/definitions/nonNegativeIntegerDefault0"
|
146
|
+
},
|
147
|
+
"required": {
|
148
|
+
"$ref": "#/definitions/stringArray"
|
149
|
+
},
|
150
|
+
"additionalProperties": {
|
151
|
+
"$ref": "#"
|
152
|
+
},
|
153
|
+
"definitions": {
|
154
|
+
"type": "object",
|
155
|
+
"additionalProperties": {
|
156
|
+
"$ref": "#"
|
157
|
+
},
|
158
|
+
"default": {
|
159
|
+
}
|
160
|
+
},
|
161
|
+
"properties": {
|
162
|
+
"type": "object",
|
163
|
+
"additionalProperties": {
|
164
|
+
"$ref": "#"
|
165
|
+
},
|
166
|
+
"default": {
|
167
|
+
}
|
168
|
+
},
|
169
|
+
"patternProperties": {
|
170
|
+
"type": "object",
|
171
|
+
"additionalProperties": {
|
172
|
+
"$ref": "#"
|
173
|
+
},
|
174
|
+
"propertyNames": {
|
175
|
+
"format": "regex"
|
176
|
+
},
|
177
|
+
"default": {
|
178
|
+
}
|
179
|
+
},
|
180
|
+
"dependencies": {
|
181
|
+
"type": "object",
|
182
|
+
"additionalProperties": {
|
183
|
+
"anyOf": [
|
184
|
+
{
|
185
|
+
"$ref": "#"
|
186
|
+
},
|
187
|
+
{
|
188
|
+
"$ref": "#/definitions/stringArray"
|
189
|
+
}
|
190
|
+
]
|
191
|
+
}
|
192
|
+
},
|
193
|
+
"propertyNames": {
|
194
|
+
"$ref": "#"
|
195
|
+
},
|
196
|
+
"const": true,
|
197
|
+
"enum": {
|
198
|
+
"type": "array",
|
199
|
+
"items": true,
|
200
|
+
"minItems": 1,
|
201
|
+
"uniqueItems": true
|
202
|
+
},
|
203
|
+
"type": {
|
204
|
+
"anyOf": [
|
205
|
+
{
|
206
|
+
"$ref": "#/definitions/simpleTypes"
|
207
|
+
},
|
208
|
+
{
|
209
|
+
"type": "array",
|
210
|
+
"items": {
|
211
|
+
"$ref": "#/definitions/simpleTypes"
|
212
|
+
},
|
213
|
+
"minItems": 1,
|
214
|
+
"uniqueItems": true
|
215
|
+
}
|
216
|
+
]
|
217
|
+
},
|
218
|
+
"format": {
|
219
|
+
"type": "string",
|
220
|
+
"enum": [
|
221
|
+
"date-time",
|
222
|
+
"date",
|
223
|
+
"time",
|
224
|
+
"email",
|
225
|
+
"idn-email",
|
226
|
+
"hostname",
|
227
|
+
"idn-hostname",
|
228
|
+
"ipv4",
|
229
|
+
"ipv6",
|
230
|
+
"uri",
|
231
|
+
"uri-reference",
|
232
|
+
"iri",
|
233
|
+
"iri-reference",
|
234
|
+
"json-pointer",
|
235
|
+
"relative-json-pointer",
|
236
|
+
"regex"
|
237
|
+
]
|
238
|
+
},
|
239
|
+
"if": {
|
240
|
+
"$ref": "#"
|
241
|
+
},
|
242
|
+
"then": {
|
243
|
+
"$ref": "#"
|
244
|
+
},
|
245
|
+
"else": {
|
246
|
+
"$ref": "#"
|
247
|
+
},
|
248
|
+
"allOf": {
|
249
|
+
"$ref": "#/definitions/schemaArray"
|
250
|
+
},
|
251
|
+
"anyOf": {
|
252
|
+
"$ref": "#/definitions/schemaArray"
|
253
|
+
},
|
254
|
+
"oneOf": {
|
255
|
+
"$ref": "#/definitions/schemaArray"
|
256
|
+
},
|
257
|
+
"not": {
|
258
|
+
"$ref": "#"
|
259
|
+
},
|
260
|
+
"not_blank": {
|
261
|
+
"type": "boolean",
|
262
|
+
"default": false
|
263
|
+
},
|
264
|
+
"not_zero": {
|
265
|
+
"type": "boolean",
|
266
|
+
"default": false
|
267
|
+
}
|
268
|
+
},
|
269
|
+
"default": true
|
270
|
+
}
|
data/lib/simple_json_schema.rb
CHANGED
@@ -28,16 +28,18 @@ require 'simple_json_schema/regex_helper'
|
|
28
28
|
require 'simple_json_schema/ref_helper'
|
29
29
|
require 'simple_json_schema/scope'
|
30
30
|
require 'simple_json_schema/validator'
|
31
|
+
require 'simple_json_schema/custom_draft7'
|
31
32
|
|
32
33
|
module SimpleJSONSchema
|
33
34
|
class UnsupportedMetaSchema < StandardError; end
|
34
35
|
|
36
|
+
DEFAULT_SCHEMA = 'https://gitlab.com/vliper/simple_json_schema/-/raw/master/draft-07-schema#'
|
35
37
|
DRAFT_BY_SCHEMA = {
|
36
|
-
|
38
|
+
DEFAULT_SCHEMA => :draft7,
|
39
|
+
'http://json-schema.org/draft-07/schema#' => :draft
|
37
40
|
}.freeze
|
38
41
|
|
39
42
|
NET_HTTP_REF_RESOLVER = proc { |uri| JSON.parse(Net::HTTP.get(uri)) }
|
40
|
-
DEFAULT_SCHEMA = 'http://json-schema.org/draft-07/schema#'
|
41
43
|
|
42
44
|
class << self
|
43
45
|
def valid?(data, schema, options = nil)
|
@@ -51,6 +53,8 @@ module SimpleJSONSchema
|
|
51
53
|
options ||= schema.delete(:options)
|
52
54
|
end
|
53
55
|
|
56
|
+
options = options.with_indifferent_access if options.is_a?(Hash)
|
57
|
+
|
54
58
|
scope = Scope.new(data: data, schema: schema, draft: draft_class(schema), options: options)
|
55
59
|
Validator.validate(scope)
|
56
60
|
scope.errors
|
@@ -9,12 +9,12 @@ module SimpleJSONSchema
|
|
9
9
|
class << self
|
10
10
|
def at_value(scope, check, operation)
|
11
11
|
over = scope[check]
|
12
|
-
scope.error(check,
|
12
|
+
scope.error(check, count: over) if over && scope.value&.public_send(operation, over)
|
13
13
|
end
|
14
14
|
|
15
15
|
def at_size(scope, check, operation)
|
16
16
|
over = scope[check]
|
17
|
-
scope.error(check,
|
17
|
+
scope.error(check, count: over) if over && scope.value&.size&.public_send(operation, over)
|
18
18
|
end
|
19
19
|
|
20
20
|
def required_keys(scope)
|
@@ -0,0 +1,207 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SimpleJSONSchema
|
4
|
+
# Draft-7 whit custom settings.
|
5
|
+
CUSTOM_DRAFT7 = {
|
6
|
+
'$schema' => 'https://gitlab.com/vliper/simple_json_schema/-/raw/master/draft-07-schema#',
|
7
|
+
'$id' => 'https://gitlab.com/vliper/simple_json_schema/-/raw/master/draft-07-schema#',
|
8
|
+
'title' => 'Simple JSON Schema meta-schema',
|
9
|
+
'definitions' => {
|
10
|
+
'schemaArray' => {
|
11
|
+
'type' => 'array',
|
12
|
+
'minItems' => 1,
|
13
|
+
'items' => { '$ref' => '#' }
|
14
|
+
},
|
15
|
+
'nonNegativeInteger' => {
|
16
|
+
'type' => 'integer',
|
17
|
+
'minimum' => 0
|
18
|
+
},
|
19
|
+
'nonNegativeIntegerDefault0' => {
|
20
|
+
'allOf' => [
|
21
|
+
{ '$ref' => '#/definitions/nonNegativeInteger' },
|
22
|
+
{ 'default' => 0 }
|
23
|
+
]
|
24
|
+
},
|
25
|
+
'simpleTypes' => {
|
26
|
+
'enum' => %w[
|
27
|
+
array
|
28
|
+
boolean
|
29
|
+
integer
|
30
|
+
null
|
31
|
+
number
|
32
|
+
object
|
33
|
+
string
|
34
|
+
]
|
35
|
+
},
|
36
|
+
'stringArray' => {
|
37
|
+
'type' => 'array',
|
38
|
+
'items' => { 'type' => 'string' },
|
39
|
+
'uniqueItems' => true,
|
40
|
+
'default' => []
|
41
|
+
}
|
42
|
+
},
|
43
|
+
'type' => %w[object boolean],
|
44
|
+
'properties' => {
|
45
|
+
'$id' => {
|
46
|
+
'type' => 'string',
|
47
|
+
'format' => 'uri-reference'
|
48
|
+
},
|
49
|
+
'$schema' => {
|
50
|
+
'type' => 'string',
|
51
|
+
'format' => 'uri'
|
52
|
+
},
|
53
|
+
'$ref' => {
|
54
|
+
'type' => 'string',
|
55
|
+
'format' => 'uri-reference'
|
56
|
+
},
|
57
|
+
'$comment' => {
|
58
|
+
'type' => 'string'
|
59
|
+
},
|
60
|
+
'title' => {
|
61
|
+
'type' => 'string'
|
62
|
+
},
|
63
|
+
'description' => {
|
64
|
+
'type' => 'string'
|
65
|
+
},
|
66
|
+
'default' => true,
|
67
|
+
'readOnly' => {
|
68
|
+
'type' => 'boolean',
|
69
|
+
'default' => false
|
70
|
+
},
|
71
|
+
'writeOnly' => {
|
72
|
+
'type' => 'boolean',
|
73
|
+
'default' => false
|
74
|
+
},
|
75
|
+
'examples' => {
|
76
|
+
'type' => 'array',
|
77
|
+
'items' => true
|
78
|
+
},
|
79
|
+
'multipleOf' => {
|
80
|
+
'type' => 'number',
|
81
|
+
'exclusiveMinimum' => 0
|
82
|
+
},
|
83
|
+
'maximum' => {
|
84
|
+
'type' => 'number'
|
85
|
+
},
|
86
|
+
'exclusiveMaximum' => {
|
87
|
+
'type' => 'number'
|
88
|
+
},
|
89
|
+
'minimum' => {
|
90
|
+
'type' => 'number'
|
91
|
+
},
|
92
|
+
'exclusiveMinimum' => {
|
93
|
+
'type' => 'number'
|
94
|
+
},
|
95
|
+
'maxLength' => { '$ref' => '#/definitions/nonNegativeInteger' },
|
96
|
+
'minLength' => { '$ref' => '#/definitions/nonNegativeIntegerDefault0' },
|
97
|
+
'pattern' => {
|
98
|
+
'type' => 'string',
|
99
|
+
'format' => 'regex'
|
100
|
+
},
|
101
|
+
'additionalItems' => { '$ref' => '#' },
|
102
|
+
'items' => {
|
103
|
+
'anyOf' => [
|
104
|
+
{ '$ref' => '#' },
|
105
|
+
{ '$ref' => '#/definitions/schemaArray' }
|
106
|
+
],
|
107
|
+
'default' => true
|
108
|
+
},
|
109
|
+
'maxItems' => { '$ref' => '#/definitions/nonNegativeInteger' },
|
110
|
+
'minItems' => { '$ref' => '#/definitions/nonNegativeIntegerDefault0' },
|
111
|
+
'uniqueItems' => {
|
112
|
+
'type' => 'boolean',
|
113
|
+
'default' => false
|
114
|
+
},
|
115
|
+
'contains' => { '$ref' => '#' },
|
116
|
+
'maxProperties' => { '$ref' => '#/definitions/nonNegativeInteger' },
|
117
|
+
'minProperties' => { '$ref' => '#/definitions/nonNegativeIntegerDefault0' },
|
118
|
+
'required' => { '$ref' => '#/definitions/stringArray' },
|
119
|
+
'additionalProperties' => { '$ref' => '#' },
|
120
|
+
'definitions' => {
|
121
|
+
'type' => 'object',
|
122
|
+
'additionalProperties' => { '$ref' => '#' },
|
123
|
+
'default' => {}
|
124
|
+
},
|
125
|
+
'properties' => {
|
126
|
+
'type' => 'object',
|
127
|
+
'additionalProperties' => { '$ref' => '#' },
|
128
|
+
'default' => {}
|
129
|
+
},
|
130
|
+
'patternProperties' => {
|
131
|
+
'type' => 'object',
|
132
|
+
'additionalProperties' => { '$ref' => '#' },
|
133
|
+
'propertyNames' => { 'format' => 'regex' },
|
134
|
+
'default' => {}
|
135
|
+
},
|
136
|
+
'dependencies' => {
|
137
|
+
'type' => 'object',
|
138
|
+
'additionalProperties' => {
|
139
|
+
'anyOf' => [
|
140
|
+
{ '$ref' => '#' },
|
141
|
+
{ '$ref' => '#/definitions/stringArray' }
|
142
|
+
]
|
143
|
+
}
|
144
|
+
},
|
145
|
+
'propertyNames' => { '$ref' => '#' },
|
146
|
+
'const' => true,
|
147
|
+
'enum' => {
|
148
|
+
'type' => 'array',
|
149
|
+
'items' => true,
|
150
|
+
'minItems' => 1,
|
151
|
+
'uniqueItems' => true
|
152
|
+
},
|
153
|
+
'type' => {
|
154
|
+
'anyOf' => [
|
155
|
+
{ '$ref' => '#/definitions/simpleTypes' },
|
156
|
+
{
|
157
|
+
'type' => 'array',
|
158
|
+
'items' => { '$ref' => '#/definitions/simpleTypes' },
|
159
|
+
'minItems' => 1,
|
160
|
+
'uniqueItems' => true
|
161
|
+
}
|
162
|
+
]
|
163
|
+
},
|
164
|
+
'format' => {
|
165
|
+
'type' => 'string',
|
166
|
+
# uri-template, was removed from `enum` to not be supported
|
167
|
+
'enum' => %w[
|
168
|
+
date-time
|
169
|
+
date
|
170
|
+
time
|
171
|
+
email
|
172
|
+
idn-email
|
173
|
+
hostname
|
174
|
+
idn-hostname
|
175
|
+
ipv4
|
176
|
+
ipv6
|
177
|
+
uri
|
178
|
+
uri-reference
|
179
|
+
iri
|
180
|
+
iri-reference
|
181
|
+
json-pointer
|
182
|
+
relative-json-pointer
|
183
|
+
regex
|
184
|
+
]
|
185
|
+
},
|
186
|
+
# 'contentMediaType' => { 'type' => 'string' }, # not supported
|
187
|
+
# 'contentEncoding' => { 'type' => 'string' }, # not supported
|
188
|
+
'if' => { '$ref' => '#' },
|
189
|
+
'then' => { '$ref' => '#' },
|
190
|
+
'else' => { '$ref' => '#' },
|
191
|
+
'allOf' => { '$ref' => '#/definitions/schemaArray' },
|
192
|
+
'anyOf' => { '$ref' => '#/definitions/schemaArray' },
|
193
|
+
'oneOf' => { '$ref' => '#/definitions/schemaArray' },
|
194
|
+
'not' => { '$ref' => '#' },
|
195
|
+
# Custom.
|
196
|
+
'not_blank' => {
|
197
|
+
'type' => 'boolean',
|
198
|
+
'default' => false
|
199
|
+
},
|
200
|
+
'not_zero' => {
|
201
|
+
'type' => 'boolean',
|
202
|
+
'default' => false
|
203
|
+
}
|
204
|
+
},
|
205
|
+
'default' => true
|
206
|
+
}.freeze
|
207
|
+
end
|
@@ -27,7 +27,7 @@ module SimpleJSONSchema
|
|
27
27
|
def validate?(scope)
|
28
28
|
scope.errors = []
|
29
29
|
|
30
|
-
validate(scope.
|
30
|
+
validate(scope.no_hooks)
|
31
31
|
scope.errors.none?
|
32
32
|
end
|
33
33
|
|
@@ -51,7 +51,7 @@ module SimpleJSONSchema
|
|
51
51
|
|
52
52
|
def validate_all_of(scope)
|
53
53
|
scope[:allOf]&.each_index do |index|
|
54
|
-
validate(scope.path_to(schema_path: [:allOf, index]).
|
54
|
+
validate(scope.path_to(schema_path: [:allOf, index]).no_hooks)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -60,7 +60,7 @@ module SimpleJSONSchema
|
|
60
60
|
return if any_of.nil?
|
61
61
|
return if any_of.each_index.any? { |index| validate?(scope.path_to(schema_path: [:anyOf, index])) }
|
62
62
|
|
63
|
-
any_of.each_index { |index| validate(scope.path_to(schema_path: [:anyOf, index]).
|
63
|
+
any_of.each_index { |index| validate(scope.path_to(schema_path: [:anyOf, index]).no_hooks) }
|
64
64
|
end
|
65
65
|
|
66
66
|
def validate_one_of(scope)
|
@@ -72,7 +72,7 @@ module SimpleJSONSchema
|
|
72
72
|
if valid_count > 1
|
73
73
|
scope.error(:oneOf)
|
74
74
|
elsif valid_count.zero?
|
75
|
-
one_of.each_index { |index| validate(scope.path_to(schema_path: [:oneOf, index]).
|
75
|
+
one_of.each_index { |index| validate(scope.path_to(schema_path: [:oneOf, index]).no_hooks) }
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -9,7 +9,7 @@ module SimpleJSONSchema
|
|
9
9
|
value = scope.value
|
10
10
|
|
11
11
|
return scope.error(:integer) if !value.is_a?(::Numeric) || (!value.is_a?(::Integer) && value.floor != value)
|
12
|
-
return scope.error(:zero_not_allowed) if scope[:
|
12
|
+
return scope.error(:zero_not_allowed) if scope[:not_zero] == true && value.zero?
|
13
13
|
|
14
14
|
super
|
15
15
|
end
|
@@ -9,7 +9,7 @@ module SimpleJSONSchema
|
|
9
9
|
value = scope.value
|
10
10
|
|
11
11
|
return scope.error(:number) unless value.is_a?(::Numeric)
|
12
|
-
return scope.error(:zero_not_allowed) if scope[:
|
12
|
+
return scope.error(:zero_not_allowed) if scope[:not_zero] == true && value.zero?
|
13
13
|
|
14
14
|
super
|
15
15
|
end
|
@@ -9,7 +9,7 @@ module SimpleJSONSchema
|
|
9
9
|
value = scope.value
|
10
10
|
|
11
11
|
return scope.error(:string) unless value.is_a?(::String)
|
12
|
-
return scope.error(:blank) if scope[:
|
12
|
+
return scope.error(:blank) if scope[:not_blank] == true && value.blank?
|
13
13
|
|
14
14
|
Checker.at_size(scope, :maxLength, :>)
|
15
15
|
Checker.at_size(scope, :minLength, :<)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_json_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Georgeo Rocco
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -188,10 +188,12 @@ files:
|
|
188
188
|
- bin/console
|
189
189
|
- bin/setup
|
190
190
|
- bin/simple_json_schema
|
191
|
+
- draft-07-schema
|
191
192
|
- lib/simple_json_schema.rb
|
192
193
|
- lib/simple_json_schema/cache.rb
|
193
194
|
- lib/simple_json_schema/checker.rb
|
194
195
|
- lib/simple_json_schema/concerns/hash_acessor.rb
|
196
|
+
- lib/simple_json_schema/custom_draft7.rb
|
195
197
|
- lib/simple_json_schema/items_helper.rb
|
196
198
|
- lib/simple_json_schema/properties_helper.rb
|
197
199
|
- lib/simple_json_schema/ref_helper.rb
|
@@ -209,6 +211,7 @@ files:
|
|
209
211
|
- lib/simple_json_schema/validators/string.rb
|
210
212
|
- lib/simple_json_schema/version.rb
|
211
213
|
- simple_json_schema.gemspec
|
214
|
+
- update_draft7_schema
|
212
215
|
homepage: https://gitlab.com/vliper/simple_json_schema
|
213
216
|
licenses:
|
214
217
|
- MIT
|