json-schema 2.8.1 → 3.0.0
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/README.md +39 -9
- data/lib/json-schema/attributes/const.rb +15 -0
- data/lib/json-schema/attributes/formats/ip.rb +1 -1
- data/lib/json-schema/schema/reader.rb +1 -1
- data/lib/json-schema/validator.rb +26 -34
- data/lib/json-schema/validators/draft6.rb +1 -0
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab17ffc9133c3115ad9bb2f4b37338ee71d1994bf62849e7557b7e41a9d1d8e9
|
4
|
+
data.tar.gz: 3c44c431d8997fa255613bd6235fdd82b3c7c15ecc9e1077a1d41ff33b31c69b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 999689f22f02b64395c78b537ee86f6f0390e9cb2dc57e14293d310999bf11b5633b2fe16f1ca4c773bedb90e002452617f3df6926ff955deb84cca5446381ce
|
7
|
+
data.tar.gz: 71f12207a56541aab4ba1157d74e988295aff34e181daeb8937ed1e8bdc7a81025baaad536a0634da49527d63c71d341d433832cb56672b60f7fd920dcecda1a
|
data/README.md
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
|
2
|
-
[](https://travis-ci.org/ruby-json-schema/json-schema)
|
3
|
-
[](https://codeclimate.com/github/ruby-json-schema/json-schema)
|
1
|
+
# Ruby JSON Schema Validator
|
4
2
|
|
5
|
-
|
6
|
-
|
3
|
+
[](https://github.com/voxpupuli/json-schema/blob/master/LICENSE)
|
4
|
+
[](https://github.com/voxpupuli/json-schema/actions/workflows/test.yml)
|
5
|
+
[](https://github.com/voxpupuli/json-schema/actions/workflows/release.yml)
|
6
|
+
[](https://rubygems.org/gems/json-schema)
|
7
|
+
[](https://rubygems.org/gems/json-schema)
|
8
|
+
[](#transfer-notice)
|
7
9
|
|
8
10
|
This library is intended to provide Ruby with an interface for validating JSON
|
9
11
|
objects against a JSON schema conforming to [JSON Schema Draft
|
@@ -17,7 +19,7 @@ Additional Resources
|
|
17
19
|
--------------------
|
18
20
|
|
19
21
|
- [Google Groups](https://groups.google.com/forum/#!forum/ruby-json-schema)
|
20
|
-
- #
|
22
|
+
- #voxpupuli on irc.libera.chat
|
21
23
|
|
22
24
|
Version 2.0.0 Upgrade Notes
|
23
25
|
---------------------------
|
@@ -27,6 +29,14 @@ default**, so schemas that do not declare a validator using the `$schema`
|
|
27
29
|
keyword will use Draft-04 now instead of Draft-03. This is the reason for the
|
28
30
|
major version upgrade.
|
29
31
|
|
32
|
+
Version 3.0.0 Upgrade Notes
|
33
|
+
---------------------------
|
34
|
+
|
35
|
+
All individual changes are documented in the CHANGELOG.md. The biggest change
|
36
|
+
is that the new version only supports Ruby 2.5 and newer. Take a look into the
|
37
|
+
gemspec file to see the currently supported Ruby version and also
|
38
|
+
`.github/workflows/test.yml` to see the Ruby versions we test on.
|
39
|
+
|
30
40
|
Installation
|
31
41
|
------------
|
32
42
|
|
@@ -39,8 +49,8 @@ gem install json-schema
|
|
39
49
|
From the git repo:
|
40
50
|
|
41
51
|
```sh
|
42
|
-
|
43
|
-
|
52
|
+
gem build json-schema.gemspec
|
53
|
+
gem install json-schema-*.gem
|
44
54
|
```
|
45
55
|
|
46
56
|
Validation
|
@@ -166,7 +176,7 @@ JSON::Validator.validate(schema, [{"a" => 1}, {"a" => 2}, {"a" => 3}])
|
|
166
176
|
JSON::Validator.fully_validate(schema, { "a" => "taco" }, :errors_as_objects => true)
|
167
177
|
|
168
178
|
#
|
169
|
-
# with the `:strict` option, all properties are
|
179
|
+
# with the `:strict` option, all properties are considered to have `"required": true` and all objects `"additionalProperties": false`
|
170
180
|
#
|
171
181
|
|
172
182
|
# => true
|
@@ -472,3 +482,23 @@ value is of the correct datatype (e.g., an instance value is validated to be an
|
|
472
482
|
integer or a float in the case of 'utc-millisec').
|
473
483
|
|
474
484
|
Additionally, JSON::Validator does not handle any json hyperschema attributes.
|
485
|
+
|
486
|
+
# Transfer Notice
|
487
|
+
|
488
|
+
This plugin was originally authored by [Iain Beeston](https://github.com/iainbeeston).
|
489
|
+
The maintainer preferred that [Vox Pupuli](https://voxpupuli.org/) take ownership of the module for future improvement and maintenance.
|
490
|
+
Existing pull requests and issues were transferred, please fork and continue to contribute [here](https://github.com/voxpupuli/json-schema).
|
491
|
+
|
492
|
+
# License
|
493
|
+
|
494
|
+
This gem is licensed unter the [MIT license](LICENSE.md).
|
495
|
+
|
496
|
+
## Release information
|
497
|
+
|
498
|
+
To make a new release, please do:
|
499
|
+
* update the version in VERSION.yml
|
500
|
+
* Install gems with `bundle install --with release --path .vendor`
|
501
|
+
* generate the changelog with `bundle exec rake changelog`
|
502
|
+
* Check if the new version matches the closed issues/PRs in the changelog
|
503
|
+
* Create a PR with it
|
504
|
+
* After it got merged, push a tag. GitHub actions will do the actual release to rubygems and GitHub Packages
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'json-schema/attribute'
|
2
|
+
|
3
|
+
module JSON
|
4
|
+
class Schema
|
5
|
+
class ConstAttribute < Attribute
|
6
|
+
def self.validate(current_schema, data, fragments, processor, validator, options = {})
|
7
|
+
const_value = current_schema.schema['const']
|
8
|
+
unless const_value == data
|
9
|
+
message = "The property '#{build_fragment(fragments)}' value #{data.inspect} did not match constant '#{const_value}'"
|
10
|
+
validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -4,6 +4,7 @@ require 'bigdecimal'
|
|
4
4
|
require 'digest/sha1'
|
5
5
|
require 'date'
|
6
6
|
require 'thread'
|
7
|
+
require 'timeout'
|
7
8
|
require 'yaml'
|
8
9
|
|
9
10
|
require 'json-schema/schema/reader'
|
@@ -41,8 +42,7 @@ module JSON
|
|
41
42
|
@options = @@default_opts.clone.merge(opts)
|
42
43
|
@errors = []
|
43
44
|
|
44
|
-
|
45
|
-
@options[:version] = validator
|
45
|
+
configured_validator = self.class.validator_for_name(@options[:version])
|
46
46
|
@options[:schema_reader] ||= self.class.schema_reader
|
47
47
|
|
48
48
|
@validation_options = @options[:record_errors] ? {:record_errors => true} : {}
|
@@ -50,19 +50,16 @@ module JSON
|
|
50
50
|
@validation_options[:strict] = true if @options[:strict] == true
|
51
51
|
@validation_options[:clear_cache] = true if !@@cache_schemas || @options[:clear_cache]
|
52
52
|
|
53
|
-
@@mutex.synchronize { @base_schema = initialize_schema(schema_data) }
|
53
|
+
@@mutex.synchronize { @base_schema = initialize_schema(schema_data, configured_validator) }
|
54
54
|
@original_data = data
|
55
55
|
@data = initialize_data(data)
|
56
56
|
@@mutex.synchronize { build_schemas(@base_schema) }
|
57
57
|
|
58
58
|
# validate the schema, if requested
|
59
59
|
if @options[:validate_schema]
|
60
|
-
if @base_schema.schema["$schema"]
|
61
|
-
base_validator = self.class.validator_for_name(@base_schema.schema["$schema"])
|
62
|
-
end
|
63
|
-
metaschema = base_validator ? base_validator.metaschema : validator.metaschema
|
64
60
|
# Don't clear the cache during metaschema validation!
|
65
|
-
self.class.
|
61
|
+
meta_validator = self.class.new(@base_schema.validator.metaschema, @base_schema.schema, {:clear_cache => false})
|
62
|
+
meta_validator.validate
|
66
63
|
end
|
67
64
|
|
68
65
|
# If the :fragment option is set, try and validate against the fragment
|
@@ -73,40 +70,35 @@ module JSON
|
|
73
70
|
|
74
71
|
def schema_from_fragment(base_schema, fragment)
|
75
72
|
schema_uri = base_schema.uri
|
76
|
-
fragments = fragment.split("/")
|
73
|
+
fragments = fragment.split("/").map { |f| f.gsub('~0', '~').gsub('~1', '/') }
|
77
74
|
|
78
75
|
# ensure the first element was a hash, per the fragment spec
|
79
76
|
if fragments.shift != "#"
|
80
77
|
raise JSON::Schema::SchemaError.new("Invalid fragment syntax in :fragment option")
|
81
78
|
end
|
82
79
|
|
80
|
+
schema_fragment = base_schema.schema
|
83
81
|
fragments.each do |f|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
elsif base_schema.is_a?(Hash)
|
90
|
-
if !base_schema.has_key?(f)
|
91
|
-
raise JSON::Schema::SchemaError.new("Invalid fragment resolution for :fragment option")
|
92
|
-
end
|
93
|
-
base_schema = JSON::Schema.new(base_schema[f],schema_uri,@options[:version])
|
94
|
-
elsif base_schema.is_a?(Array)
|
95
|
-
if base_schema[f.to_i].nil?
|
96
|
-
raise JSON::Schema::SchemaError.new("Invalid fragment resolution for :fragment option")
|
97
|
-
end
|
98
|
-
base_schema = JSON::Schema.new(base_schema[f.to_i],schema_uri,@options[:version])
|
99
|
-
else
|
100
|
-
raise JSON::Schema::SchemaError.new("Invalid schema encountered when resolving :fragment option")
|
82
|
+
case schema_fragment
|
83
|
+
when Hash
|
84
|
+
schema_fragment = schema_fragment[f]
|
85
|
+
when Array
|
86
|
+
schema_fragment = schema_fragment[f.to_i]
|
101
87
|
end
|
102
88
|
end
|
103
89
|
|
90
|
+
unless schema_fragment.is_a?(Hash)
|
91
|
+
raise JSON::Schema::SchemaError.new("Invalid fragment resolution for :fragment option")
|
92
|
+
end
|
93
|
+
|
94
|
+
schema = JSON::Schema.new(schema_fragment, schema_uri, base_schema.validator)
|
95
|
+
|
104
96
|
if @options[:list]
|
105
|
-
|
106
|
-
elsif
|
107
|
-
JSON::Schema.new(
|
97
|
+
schema.to_array_schema
|
98
|
+
elsif schema.is_a?(Hash)
|
99
|
+
JSON::Schema.new(schema, schema_uri, @options[:version])
|
108
100
|
else
|
109
|
-
|
101
|
+
schema
|
110
102
|
end
|
111
103
|
end
|
112
104
|
|
@@ -519,12 +511,12 @@ module JSON
|
|
519
511
|
@@fake_uuid_generator.call(schema)
|
520
512
|
end
|
521
513
|
|
522
|
-
def initialize_schema(schema)
|
514
|
+
def initialize_schema(schema, default_validator)
|
523
515
|
if schema.is_a?(String)
|
524
516
|
begin
|
525
517
|
# Build a fake URI for this
|
526
518
|
schema_uri = JSON::Util::URI.parse(fake_uuid(schema))
|
527
|
-
schema = JSON::Schema.new(
|
519
|
+
schema = JSON::Schema.new(JSON::Validator.parse(schema), schema_uri, default_validator)
|
528
520
|
if @options[:list] && @options[:fragment].nil?
|
529
521
|
schema = schema.to_array_schema
|
530
522
|
end
|
@@ -554,7 +546,7 @@ module JSON
|
|
554
546
|
elsif schema.is_a?(Hash)
|
555
547
|
schema_uri = JSON::Util::URI.parse(fake_uuid(serialize(schema)))
|
556
548
|
schema = JSON::Schema.stringify(schema)
|
557
|
-
schema = JSON::Schema.new(schema, schema_uri,
|
549
|
+
schema = JSON::Schema.new(schema, schema_uri, default_validator)
|
558
550
|
if @options[:list] && @options[:fragment].nil?
|
559
551
|
schema = schema.to_array_schema
|
560
552
|
end
|
@@ -593,7 +585,7 @@ module JSON
|
|
593
585
|
uri = Util::URI.normalized_uri(uri) if uri.is_a?(String)
|
594
586
|
if uri.absolute? && Util::URI::SUPPORTED_PROTOCOLS.include?(uri.scheme)
|
595
587
|
begin
|
596
|
-
open(uri.to_s).read
|
588
|
+
URI.open(uri.to_s).read
|
597
589
|
rescue OpenURI::HTTPError, Timeout::Error => e
|
598
590
|
raise JSON::Schema::JsonLoadError, e.message
|
599
591
|
end
|
@@ -34,6 +34,7 @@ module JSON
|
|
34
34
|
"additionalItems" => JSON::Schema::AdditionalItemsAttribute,
|
35
35
|
"dependencies" => JSON::Schema::DependenciesV4Attribute,
|
36
36
|
"extends" => JSON::Schema::ExtendsAttribute,
|
37
|
+
"const" => JSON::Schema::ConstAttribute,
|
37
38
|
"$ref" => JSON::Schema::RefAttribute
|
38
39
|
}
|
39
40
|
@default_formats = {
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json-schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenny Hoxworth
|
8
|
+
- Vox Pupuli
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2022-05-03 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rake
|
@@ -72,16 +73,16 @@ dependencies:
|
|
72
73
|
requirements:
|
73
74
|
- - ">="
|
74
75
|
- !ruby/object:Gem::Version
|
75
|
-
version: '2.
|
76
|
+
version: '2.8'
|
76
77
|
type: :runtime
|
77
78
|
prerelease: false
|
78
79
|
version_requirements: !ruby/object:Gem::Requirement
|
79
80
|
requirements:
|
80
81
|
- - ">="
|
81
82
|
- !ruby/object:Gem::Version
|
82
|
-
version: '2.
|
83
|
+
version: '2.8'
|
83
84
|
description:
|
84
|
-
email:
|
85
|
+
email: voxpupuli@groups.io
|
85
86
|
executables: []
|
86
87
|
extensions: []
|
87
88
|
extra_rdoc_files:
|
@@ -96,6 +97,7 @@ files:
|
|
96
97
|
- lib/json-schema/attributes/additionalproperties.rb
|
97
98
|
- lib/json-schema/attributes/allof.rb
|
98
99
|
- lib/json-schema/attributes/anyof.rb
|
100
|
+
- lib/json-schema/attributes/const.rb
|
99
101
|
- lib/json-schema/attributes/dependencies.rb
|
100
102
|
- lib/json-schema/attributes/dependencies_v4.rb
|
101
103
|
- lib/json-schema/attributes/disallow.rb
|
@@ -169,7 +171,7 @@ files:
|
|
169
171
|
- resources/draft-03.json
|
170
172
|
- resources/draft-04.json
|
171
173
|
- resources/draft-06.json
|
172
|
-
homepage: http://github.com/
|
174
|
+
homepage: http://github.com/voxpupuli/json-schema/
|
173
175
|
licenses:
|
174
176
|
- MIT
|
175
177
|
metadata: {}
|
@@ -181,15 +183,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
181
183
|
requirements:
|
182
184
|
- - ">="
|
183
185
|
- !ruby/object:Gem::Version
|
184
|
-
version: '
|
186
|
+
version: '2.5'
|
185
187
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
188
|
requirements:
|
187
189
|
- - ">="
|
188
190
|
- !ruby/object:Gem::Version
|
189
|
-
version: '
|
191
|
+
version: '2.5'
|
190
192
|
requirements: []
|
191
|
-
|
192
|
-
rubygems_version: 2.7.6
|
193
|
+
rubygems_version: 3.3.7
|
193
194
|
signing_key:
|
194
195
|
specification_version: 4
|
195
196
|
summary: Ruby JSON Schema Validator
|