json_schemer 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -1
- data/json_schemer.gemspec +1 -0
- data/lib/json_schemer/schema/base.rb +18 -2
- data/lib/json_schemer/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 382a4fe7c0bfaba4ac319cc29289337490b69440217d6725034e516efe5a9f97
|
4
|
+
data.tar.gz: 59abe27c6052f6f7a210a0c1a51c08ffbb231f6dfe0f5f10d1021a9ccb05b0ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59328690e27ae9ef6fe1a2c82bca000d99ea1678a39de8f81e01e5f58ffa6cb1254adfb2163ba738b784bff3067c51d429ae6eb61da83da755ca72982b704669
|
7
|
+
data.tar.gz: 003be8eb68f6f57a70aeaa1014a0e2f26f63252eddb7599b44270c15850d5195acc7a60042927714cfb2e406d0a4af6d5d5c2c4a66c905460b20fb2323e1b82c
|
data/Gemfile.lock
CHANGED
data/json_schemer.gemspec
CHANGED
@@ -34,4 +34,5 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_runtime_dependency "ecma-re-validator", "~> 0.1.2"
|
35
35
|
spec.add_runtime_dependency "hana", "~> 1.3.3"
|
36
36
|
spec.add_runtime_dependency "uri_template", "~> 0.7.0"
|
37
|
+
spec.add_runtime_dependency "regexp_parser", "~> 0.5.0"
|
37
38
|
end
|
@@ -29,6 +29,13 @@ module JSONSchemer
|
|
29
29
|
NET_HTTP_REF_RESOLVER = proc { |uri| JSON.parse(Net::HTTP.get(uri)) }.freeze
|
30
30
|
BOOLEANS = Set[true, false].freeze
|
31
31
|
|
32
|
+
RUBY_REGEX_ANCHORS_TO_ECMA_262 = {
|
33
|
+
:bos => 'A',
|
34
|
+
:eos => 'z',
|
35
|
+
:bol => '\A',
|
36
|
+
:eol => '\z'
|
37
|
+
}.freeze
|
38
|
+
|
32
39
|
def initialize(
|
33
40
|
schema,
|
34
41
|
format: true,
|
@@ -332,7 +339,7 @@ module JSONSchemer
|
|
332
339
|
|
333
340
|
yield error(instance, 'maxLength') if max_length && data.size > max_length
|
334
341
|
yield error(instance, 'minLength') if min_length && data.size < min_length
|
335
|
-
yield error(instance, 'pattern') if pattern &&
|
342
|
+
yield error(instance, 'pattern') if pattern && ecma_262_regex(pattern) !~ data
|
336
343
|
yield error(instance, 'format') if format? && spec_format?(format) && !valid_spec_format?(data, format)
|
337
344
|
|
338
345
|
if content_encoding || content_media_type
|
@@ -474,7 +481,7 @@ module JSONSchemer
|
|
474
481
|
|
475
482
|
if pattern_properties
|
476
483
|
regex_pattern_properties ||= pattern_properties.map do |pattern, property_schema|
|
477
|
-
[pattern,
|
484
|
+
[pattern, ecma_262_regex(pattern), property_schema]
|
478
485
|
end
|
479
486
|
regex_pattern_properties.each do |pattern, regex, property_schema|
|
480
487
|
if regex =~ key
|
@@ -513,6 +520,15 @@ module JSONSchemer
|
|
513
520
|
end
|
514
521
|
end
|
515
522
|
|
523
|
+
def ecma_262_regex(pattern)
|
524
|
+
@ecma_262_regex ||= {}
|
525
|
+
@ecma_262_regex[pattern] ||= Regexp.new(
|
526
|
+
Regexp::Scanner.scan(pattern).map do |type, token, text|
|
527
|
+
type == :anchor ? RUBY_REGEX_ANCHORS_TO_ECMA_262.fetch(token, text) : text
|
528
|
+
end.join
|
529
|
+
)
|
530
|
+
end
|
531
|
+
|
516
532
|
def join_uri(a, b)
|
517
533
|
if a && b
|
518
534
|
URI.join(a, b)
|
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.7
|
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-08-
|
11
|
+
date: 2018-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 0.7.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: regexp_parser
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.5.0
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.5.0
|
97
111
|
description:
|
98
112
|
email:
|
99
113
|
- davishmcclurg@gmail.com
|