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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6f1555ed0ddacfa334c2a2635b4cce09c532aae3121539c28086e27ddf3c22fe
4
- data.tar.gz: 5e49a8c68c44f40ac3ac9b3766b49f8f1c5d21ff5560dd1e2dd8f3d994183655
3
+ metadata.gz: ddb07f2bbccb28d21477a4514b460b385363ff5a3c7d1b981c538408228ae796
4
+ data.tar.gz: 374a24a40fd3c6714a24be1ef248a79143cb36121d60996017ac4cd2858b5dbb
5
5
  SHA512:
6
- metadata.gz: e5e79032c18e1e4f9ba1a21be3d7b6afc48a7decdd37f7b2f9d4a9984b85684b1b115e2b16a4497955ec0d0d696d082dcd346f0443b3494f415718323f3beb86
7
- data.tar.gz: 229375ee9837355c3225080db7b88eed7dce26a3fb608ded003453b9765de4a3d1546d3ea0eb6e7649698fcbe8ba58b49157cab7817f6a71ae66963abb5f45a4
6
+ metadata.gz: 0e34958d512ef4093d360a9596cd15ec51a90ea30d4b346453379c2d749496b83be9d237e34c332d225302a6fecf5fc156785d3aae4fe2be95f47fa00ee1e1e4
7
+ data.tar.gz: fa555c0ed341eae0bcd861c4be770eca06e8aa136dfcb4b4d4bad83661b9042dcfdc5dcc76ed5c59b40946cd2930323710153740ef315f32587105f252caa88b
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /.ruby-version
data/.gitmodules CHANGED
@@ -1,3 +1,4 @@
1
1
  [submodule "JSON-Schema-Test-Suite"]
2
2
  path = JSON-Schema-Test-Suite
3
3
  url = https://github.com/json-schema-org/JSON-Schema-Test-Suite
4
+ branch = master
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- json_schemer (0.1.4)
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.3)
14
+ hana (1.3.4)
15
15
  minitest (5.11.1)
16
16
  rake (10.5.0)
17
- regexp_parser (0.4.9)
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.1
30
+ 1.16.2
@@ -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 valid_format?(data, format)
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
- validate_format(data, schema, pointer, format, &Proc.new) if format && format?
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 validate_format(data, schema, pointer, format)
205
- valid = if formats && formats.key?(format)
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
@@ -10,7 +10,8 @@ module JSONSchemer
10
10
  'hostname',
11
11
  'ipv4',
12
12
  'ipv6',
13
- 'uri'
13
+ 'uri',
14
+ 'regex'
14
15
  ].freeze
15
16
 
16
17
  private
@@ -12,7 +12,8 @@ module JSONSchemer
12
12
  'uri',
13
13
  'uri-reference',
14
14
  'uri-template',
15
- 'json-pointer'
15
+ 'json-pointer',
16
+ 'regex'
16
17
  ].freeze
17
18
 
18
19
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JSONSchemer
4
- VERSION = '0.1.4'
4
+ VERSION = '0.1.5'
5
5
  end
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
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-01-30 00:00:00.000000000 Z
11
+ date: 2018-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler