json_schemer 0.1.4 → 0.1.5
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/.gitignore +1 -0
- data/.gitmodules +1 -0
- data/Gemfile.lock +4 -4
- data/lib/json_schemer/format.rb +1 -1
- data/lib/json_schemer/schema/base.rb +15 -9
- data/lib/json_schemer/schema/draft4.rb +2 -1
- data/lib/json_schemer/schema/draft6.rb +2 -1
- data/lib/json_schemer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddb07f2bbccb28d21477a4514b460b385363ff5a3c7d1b981c538408228ae796
|
4
|
+
data.tar.gz: 374a24a40fd3c6714a24be1ef248a79143cb36121d60996017ac4cd2858b5dbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e34958d512ef4093d360a9596cd15ec51a90ea30d4b346453379c2d749496b83be9d237e34c332d225302a6fecf5fc156785d3aae4fe2be95f47fa00ee1e1e4
|
7
|
+
data.tar.gz: fa555c0ed341eae0bcd861c4be770eca06e8aa136dfcb4b4d4bad83661b9042dcfdc5dcc76ed5c59b40946cd2930323710153740ef315f32587105f252caa88b
|
data/.gitignore
CHANGED
data/.gitmodules
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
json_schemer (0.1.
|
4
|
+
json_schemer (0.1.5)
|
5
5
|
ecma-re-validator (~> 0.1.2)
|
6
6
|
hana (~> 1.3.3)
|
7
7
|
uri_template (~> 0.7.0)
|
@@ -11,10 +11,10 @@ GEM
|
|
11
11
|
specs:
|
12
12
|
ecma-re-validator (0.1.2)
|
13
13
|
regexp_parser (~> 0.2)
|
14
|
-
hana (1.3.
|
14
|
+
hana (1.3.4)
|
15
15
|
minitest (5.11.1)
|
16
16
|
rake (10.5.0)
|
17
|
-
regexp_parser (0.
|
17
|
+
regexp_parser (0.5.0)
|
18
18
|
uri_template (0.7.0)
|
19
19
|
|
20
20
|
PLATFORMS
|
@@ -27,4 +27,4 @@ DEPENDENCIES
|
|
27
27
|
rake (~> 10.0)
|
28
28
|
|
29
29
|
BUNDLED WITH
|
30
|
-
1.16.
|
30
|
+
1.16.2
|
data/lib/json_schemer/format.rb
CHANGED
@@ -66,7 +66,7 @@ module JSONSchemer
|
|
66
66
|
IHIER_PART = Regexp.compile("(?:(?://#{IAUTHORITY}#{IPATH_ABEMPTY})|(?:#{IPATH_ABSOLUTE})|(?:#{IPATH_ROOTLESS})|(?:#{IPATH_EMPTY}))").freeze
|
67
67
|
IRI = Regexp.compile("^#{SCHEME}:(?:#{IHIER_PART})(?:\\?#{IQUERY})?(?:\\##{IFRAGMENT})?$").freeze
|
68
68
|
|
69
|
-
def
|
69
|
+
def valid_spec_format?(data, format)
|
70
70
|
case format
|
71
71
|
when 'date-time'
|
72
72
|
valid_date_time?(data)
|
@@ -66,7 +66,9 @@ module JSONSchemer
|
|
66
66
|
return
|
67
67
|
end
|
68
68
|
|
69
|
-
|
69
|
+
if format? && custom_format?(format)
|
70
|
+
validate_custom_format(data, schema, pointer, formats.fetch(format), &Proc.new)
|
71
|
+
end
|
70
72
|
|
71
73
|
if keywords
|
72
74
|
keywords.each do |keyword, callable|
|
@@ -127,6 +129,14 @@ module JSONSchemer
|
|
127
129
|
!!@format
|
128
130
|
end
|
129
131
|
|
132
|
+
def custom_format?(format)
|
133
|
+
!!(formats && formats.key?(format))
|
134
|
+
end
|
135
|
+
|
136
|
+
def spec_format?(format)
|
137
|
+
!custom_format?(format) && supported_format?(format)
|
138
|
+
end
|
139
|
+
|
130
140
|
def child(schema)
|
131
141
|
JSONSchemer.schema(
|
132
142
|
schema,
|
@@ -201,14 +211,8 @@ module JSONSchemer
|
|
201
211
|
end
|
202
212
|
end
|
203
213
|
|
204
|
-
def
|
205
|
-
|
206
|
-
format_option = formats[format]
|
207
|
-
format_option == false || format_option.call(data, schema)
|
208
|
-
elsif supported_format?(format)
|
209
|
-
valid_format?(data, format)
|
210
|
-
end
|
211
|
-
yield error(data, schema, pointer, 'format') unless valid
|
214
|
+
def validate_custom_format(data, schema, pointer, custom_format)
|
215
|
+
yield error(data, schema, pointer, 'format') if custom_format != false && !custom_format.call(data, schema)
|
212
216
|
end
|
213
217
|
|
214
218
|
def validate_exclusive_maximum(data, schema, pointer, exclusive_maximum, maximum)
|
@@ -265,12 +269,14 @@ module JSONSchemer
|
|
265
269
|
max_length = schema['maxLength']
|
266
270
|
min_length = schema['minLength']
|
267
271
|
pattern = schema['pattern']
|
272
|
+
format = schema['format']
|
268
273
|
content_encoding = schema['contentEncoding']
|
269
274
|
content_media_type = schema['contentMediaType']
|
270
275
|
|
271
276
|
yield error(data, schema, pointer, 'maxLength') if max_length && data.size > max_length
|
272
277
|
yield error(data, schema, pointer, 'minLength') if min_length && data.size < min_length
|
273
278
|
yield error(data, schema, pointer, 'pattern') if pattern && Regexp.new(pattern) !~ data
|
279
|
+
yield error(data, schema, pointer, 'format') if format? && spec_format?(format) && !valid_spec_format?(data, format)
|
274
280
|
|
275
281
|
if content_encoding || content_media_type
|
276
282
|
decoded_data = data
|
data/lib/json_schemer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_schemer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Harsha
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|