json_schemer 0.2.10 → 0.2.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +3 -9
- data/Gemfile.lock +6 -6
- data/json_schemer.gemspec +1 -1
- data/lib/json_schemer.rb +2 -0
- data/lib/json_schemer/errors.rb +31 -0
- data/lib/json_schemer/format.rb +1 -1
- data/lib/json_schemer/schema/base.rb +13 -16
- data/lib/json_schemer/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14785b9586c0f152587eedbdea3da0a37f8a766b21db28821ffa374fef6d6235
|
4
|
+
data.tar.gz: fe50adb42c6b0da48fc43b7c8ebee40e61a42f4ccfa3d87de6723551388b223c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e23c122d31d6a9c38326c90c1ac9af35148ce0b13ff1a576f2fb9bfff7cfdd289d2122b73d5b8b20330d8323e8ec98b11452ec0b70ccd339a26e6dba4d7f33b5
|
7
|
+
data.tar.gz: a4be1485304ae45f125e6b73494c5a1a5cf98d092c66b25dd2ff81fed0a74833165d8655abc46799faa97af0372d9d3f06e4a5e30554b0c31260b01699aa76be
|
data/.github/workflows/ci.yml
CHANGED
@@ -4,19 +4,13 @@ jobs:
|
|
4
4
|
ruby:
|
5
5
|
strategy:
|
6
6
|
matrix:
|
7
|
-
ruby: [2.4
|
7
|
+
ruby: [2.4, 2.5, 2.6, 2.7, truffleruby-head]
|
8
8
|
runs-on: ubuntu-latest
|
9
9
|
steps:
|
10
|
-
- uses: actions/checkout@
|
11
|
-
- uses:
|
10
|
+
- uses: actions/checkout@v2
|
11
|
+
- uses: ruby/setup-ruby@v1
|
12
12
|
with:
|
13
13
|
ruby-version: ${{ matrix.ruby }}
|
14
|
-
- uses: actions/setup-python@v1
|
15
|
-
with:
|
16
|
-
python-version: 3.x
|
17
14
|
- run: |
|
18
|
-
pip install --user Flask
|
19
|
-
./JSON-Schema-Test-Suite/bin/jsonschema_suite serve &
|
20
|
-
gem install bundler
|
21
15
|
bundle install
|
22
16
|
bundle exec rake test
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
json_schemer (0.2.
|
4
|
+
json_schemer (0.2.15)
|
5
5
|
ecma-re-validator (~> 0.2)
|
6
6
|
hana (~> 1.3)
|
7
7
|
regexp_parser (~> 1.5)
|
@@ -10,12 +10,12 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
ecma-re-validator (0.2.
|
13
|
+
ecma-re-validator (0.2.1)
|
14
14
|
regexp_parser (~> 1.2)
|
15
|
-
hana (1.3.
|
15
|
+
hana (1.3.6)
|
16
16
|
minitest (5.11.3)
|
17
|
-
rake (
|
18
|
-
regexp_parser (1.
|
17
|
+
rake (13.0.1)
|
18
|
+
regexp_parser (1.8.1)
|
19
19
|
uri_template (0.7.0)
|
20
20
|
|
21
21
|
PLATFORMS
|
@@ -25,7 +25,7 @@ DEPENDENCIES
|
|
25
25
|
bundler (~> 2.0)
|
26
26
|
json_schemer!
|
27
27
|
minitest (~> 5.0)
|
28
|
-
rake (~>
|
28
|
+
rake (~> 13.0)
|
29
29
|
|
30
30
|
BUNDLED WITH
|
31
31
|
2.1.4
|
data/json_schemer.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.required_ruby_version = '~> 2.4'
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 2.0"
|
26
|
-
spec.add_development_dependency "rake", "~>
|
26
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
27
27
|
spec.add_development_dependency "minitest", "~> 5.0"
|
28
28
|
|
29
29
|
# spec.add_development_dependency "benchmark-ips", "~> 2.7.2"
|
data/lib/json_schemer.rb
CHANGED
@@ -14,6 +14,7 @@ require 'uri_template'
|
|
14
14
|
|
15
15
|
require 'json_schemer/version'
|
16
16
|
require 'json_schemer/format'
|
17
|
+
require 'json_schemer/errors'
|
17
18
|
require 'json_schemer/cached_ref_resolver'
|
18
19
|
require 'json_schemer/schema/base'
|
19
20
|
require 'json_schemer/schema/draft4'
|
@@ -28,6 +29,7 @@ module JSONSchemer
|
|
28
29
|
class InvalidSymbolKey < StandardError; end
|
29
30
|
|
30
31
|
DRAFT_CLASS_BY_META_SCHEMA = {
|
32
|
+
'http://json-schema.org/schema#' => Schema::Draft4, # Version-less $schema deprecated after Draft 4
|
31
33
|
'http://json-schema.org/draft-04/schema#' => Schema::Draft4,
|
32
34
|
'http://json-schema.org/draft-06/schema#' => Schema::Draft6,
|
33
35
|
'http://json-schema.org/draft-07/schema#' => Schema::Draft7
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Based on code from @robacarp found in issue 48:
|
2
|
+
# https://github.com/davishmcclurg/json_schemer/issues/48
|
3
|
+
#
|
4
|
+
module JSONSchemer
|
5
|
+
module Errors
|
6
|
+
class << self
|
7
|
+
def pretty(error)
|
8
|
+
data_pointer, type, schema = error.values_at('data_pointer', 'type', 'schema')
|
9
|
+
location = data_pointer.empty? ? 'root' : "property '#{data_pointer}'"
|
10
|
+
|
11
|
+
case type
|
12
|
+
when 'required'
|
13
|
+
keys = error.fetch('details').fetch('missing_keys').join(', ')
|
14
|
+
"#{location} is missing required keys: #{keys}"
|
15
|
+
when 'null', 'string', 'boolean', 'integer', 'number', 'array', 'object'
|
16
|
+
"#{location} is not of type: #{type}"
|
17
|
+
when 'pattern'
|
18
|
+
"#{location} does not match pattern: #{schema.fetch('pattern')}"
|
19
|
+
when 'format'
|
20
|
+
"#{location} does not match format: #{schema.fetch('format')}"
|
21
|
+
when 'const'
|
22
|
+
"#{location} is not: #{schema.fetch('const').inspect}"
|
23
|
+
when 'enum'
|
24
|
+
"#{location} is not one of: #{schema.fetch('enum')}"
|
25
|
+
else
|
26
|
+
"#{location} is invalid: error_type=#{type}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/json_schemer/format.rb
CHANGED
@@ -3,7 +3,7 @@ module JSONSchemer
|
|
3
3
|
module Format
|
4
4
|
# this is no good
|
5
5
|
EMAIL_REGEX = /\A[^@\s]+@([\p{L}\d-]+\.)+[\p{L}\d\-]{2,}\z/i.freeze
|
6
|
-
LABEL_REGEX_STRING = '\p{L}([\p{L}\p{N}\-]*[\p{L}\p{N}])?'
|
6
|
+
LABEL_REGEX_STRING = '[\p{L}\p{N}]([\p{L}\p{N}\-]*[\p{L}\p{N}])?'
|
7
7
|
HOSTNAME_REGEX = /\A(#{LABEL_REGEX_STRING}\.)*#{LABEL_REGEX_STRING}\z/i.freeze
|
8
8
|
JSON_POINTER_REGEX_STRING = '(\/([^~\/]|~[01])*)*'
|
9
9
|
JSON_POINTER_REGEX = /\A#{JSON_POINTER_REGEX_STRING}\z/.freeze
|
@@ -568,12 +568,10 @@ module JSONSchemer
|
|
568
568
|
end
|
569
569
|
|
570
570
|
def safe_strict_decode64(data)
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
nil
|
576
|
-
end
|
571
|
+
Base64.strict_decode64(data)
|
572
|
+
rescue ArgumentError => e
|
573
|
+
raise e unless e.message == 'invalid base64'
|
574
|
+
nil
|
577
575
|
end
|
578
576
|
|
579
577
|
def ecma_262_regex(pattern)
|
@@ -615,16 +613,15 @@ module JSONSchemer
|
|
615
613
|
if schema.is_a?(Array)
|
616
614
|
schema.each_with_index { |subschema, index| resolve_ids(subschema, ids, parent_uri, "#{pointer}/#{index}") }
|
617
615
|
elsif schema.is_a?(Hash)
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
definitions.each { |key, subschema| resolve_ids(subschema, ids, uri, "#{pointer}/definitions/#{key}") }
|
616
|
+
uri = join_uri(parent_uri, schema[id_keyword])
|
617
|
+
schema.each do |key, value|
|
618
|
+
if key == id_keyword && uri != parent_uri
|
619
|
+
ids[uri.to_s] = {
|
620
|
+
schema: schema,
|
621
|
+
pointer: pointer
|
622
|
+
}
|
623
|
+
end
|
624
|
+
resolve_ids(value, ids, uri, "#{pointer}/#{key}")
|
628
625
|
end
|
629
626
|
end
|
630
627
|
ids
|
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.2.
|
4
|
+
version: 0.2.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Harsha
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '13.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- json_schemer.gemspec
|
128
128
|
- lib/json_schemer.rb
|
129
129
|
- lib/json_schemer/cached_ref_resolver.rb
|
130
|
+
- lib/json_schemer/errors.rb
|
130
131
|
- lib/json_schemer/format.rb
|
131
132
|
- lib/json_schemer/schema/base.rb
|
132
133
|
- lib/json_schemer/schema/draft4.rb
|
@@ -152,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
153
|
- !ruby/object:Gem::Version
|
153
154
|
version: '0'
|
154
155
|
requirements: []
|
155
|
-
rubygems_version: 3.
|
156
|
+
rubygems_version: 3.1.2
|
156
157
|
signing_key:
|
157
158
|
specification_version: 4
|
158
159
|
summary: JSON Schema validator. Supports drafts 4, 6, and 7.
|