json-schema 2.8.0 → 5.1.1
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 +5 -5
- data/README.md +82 -11
- data/lib/json-schema/attribute.rb +13 -14
- data/lib/json-schema/attributes/additionalitems.rb +1 -0
- data/lib/json-schema/attributes/additionalproperties.rb +3 -6
- data/lib/json-schema/attributes/allof.rb +6 -4
- data/lib/json-schema/attributes/anyof.rb +2 -2
- data/lib/json-schema/attributes/const.rb +15 -0
- data/lib/json-schema/attributes/dependencies.rb +1 -6
- data/lib/json-schema/attributes/dependencies_v4.rb +11 -0
- data/lib/json-schema/attributes/disallow.rb +2 -1
- data/lib/json-schema/attributes/divisibleby.rb +1 -1
- data/lib/json-schema/attributes/enum.rb +2 -2
- data/lib/json-schema/attributes/extends.rb +7 -7
- data/lib/json-schema/attributes/format.rb +2 -1
- data/lib/json-schema/attributes/formats/custom.rb +1 -1
- data/lib/json-schema/attributes/formats/date.rb +2 -1
- data/lib/json-schema/attributes/formats/date_time.rb +3 -2
- data/lib/json-schema/attributes/formats/date_time_v4.rb +2 -1
- data/lib/json-schema/attributes/formats/ip.rb +1 -1
- data/lib/json-schema/attributes/formats/time.rb +1 -1
- data/lib/json-schema/attributes/formats/uri.rb +2 -1
- data/lib/json-schema/attributes/items.rb +1 -0
- data/lib/json-schema/attributes/limit.rb +0 -127
- data/lib/json-schema/attributes/limits/items.rb +15 -0
- data/lib/json-schema/attributes/limits/length.rb +15 -0
- data/lib/json-schema/attributes/limits/max_items.rb +15 -0
- data/lib/json-schema/attributes/limits/max_length.rb +15 -0
- data/lib/json-schema/attributes/limits/max_properties.rb +15 -0
- data/lib/json-schema/attributes/limits/maximum.rb +15 -0
- data/lib/json-schema/attributes/limits/maximum_inclusive.rb +11 -0
- data/lib/json-schema/attributes/limits/min_items.rb +15 -0
- data/lib/json-schema/attributes/limits/min_length.rb +15 -0
- data/lib/json-schema/attributes/limits/min_properties.rb +15 -0
- data/lib/json-schema/attributes/limits/minimum.rb +15 -0
- data/lib/json-schema/attributes/limits/minimum_inclusive.rb +11 -0
- data/lib/json-schema/attributes/limits/numeric.rb +16 -0
- data/lib/json-schema/attributes/limits/properties.rb +15 -0
- data/lib/json-schema/attributes/maxdecimal.rb +1 -1
- data/lib/json-schema/attributes/not.rb +2 -2
- data/lib/json-schema/attributes/oneof.rb +2 -4
- data/lib/json-schema/attributes/patternproperties.rb +2 -1
- data/lib/json-schema/attributes/properties.rb +9 -17
- data/lib/json-schema/attributes/properties_v4.rb +13 -0
- data/lib/json-schema/attributes/propertynames.rb +23 -0
- data/lib/json-schema/attributes/ref.rb +8 -8
- data/lib/json-schema/attributes/required.rb +4 -3
- data/lib/json-schema/attributes/type.rb +3 -2
- data/lib/json-schema/attributes/type_v4.rb +1 -1
- data/lib/json-schema/errors/validation_error.rb +5 -6
- data/lib/json-schema/schema/reader.rb +3 -1
- data/lib/json-schema/schema/validator.rb +3 -3
- data/lib/json-schema/schema.rb +3 -4
- data/lib/json-schema/util/array_set.rb +1 -1
- data/lib/json-schema/util/uri.rb +98 -75
- data/lib/json-schema/util/uuid.rb +203 -226
- data/lib/json-schema/validator.rb +122 -115
- data/lib/json-schema/validators/draft1.rb +21 -23
- data/lib/json-schema/validators/draft2.rb +22 -24
- data/lib/json-schema/validators/draft3.rb +26 -28
- data/lib/json-schema/validators/draft4.rb +34 -36
- data/lib/json-schema/validators/draft6.rb +36 -36
- data/lib/json-schema/validators/hyper-draft1.rb +2 -3
- data/lib/json-schema/validators/hyper-draft2.rb +2 -3
- data/lib/json-schema/validators/hyper-draft3.rb +2 -3
- data/lib/json-schema/validators/hyper-draft4.rb +2 -3
- data/lib/json-schema/validators/hyper-draft6.rb +2 -3
- data/lib/json-schema.rb +2 -3
- data/resources/draft-06.json +41 -41
- metadata +67 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9c842fa3f98c7ebbdde9ebdbceb44bb1eab1f282f6a5c6c0008e0aac0eca92b6
|
4
|
+
data.tar.gz: d6f98215e98ce89c007d158594078d7135574543c10a82e953dcb3feed6dc9fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f744aa3ddcf37191afd16c7424b97d4e610f5da6f0c5ccbdad8fdcc10ee95f1d130f165142da95394ea09a758907b6bf6157343a1796477ed75a340c17217b65
|
7
|
+
data.tar.gz: 1a0d01bfb3595f4286603e9c31d3c578aff55b4abc37952c41e448d02a7ea22c37a7ba5bc8cbb85809f4395992b0da8c73ec79109e6d15338b8802cf96465dbb
|
data/README.md
CHANGED
@@ -1,13 +1,16 @@
|
|
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.md)
|
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
|
10
|
-
|
12
|
+
6](https://tools.ietf.org/html/draft-wright-json-schema-01). Legacy support for
|
13
|
+
[JSON Schema Draft 4](http://tools.ietf.org/html/draft-zyp-json-schema-04),
|
11
14
|
[JSON Schema Draft 3](http://tools.ietf.org/html/draft-zyp-json-schema-03),
|
12
15
|
[JSON Schema Draft 2](http://tools.ietf.org/html/draft-zyp-json-schema-02), and
|
13
16
|
[JSON Schema Draft 1](http://tools.ietf.org/html/draft-zyp-json-schema-01) is
|
@@ -17,7 +20,7 @@ Additional Resources
|
|
17
20
|
--------------------
|
18
21
|
|
19
22
|
- [Google Groups](https://groups.google.com/forum/#!forum/ruby-json-schema)
|
20
|
-
- #
|
23
|
+
- #voxpupuli on irc.libera.chat
|
21
24
|
|
22
25
|
Version 2.0.0 Upgrade Notes
|
23
26
|
---------------------------
|
@@ -27,6 +30,14 @@ default**, so schemas that do not declare a validator using the `$schema`
|
|
27
30
|
keyword will use Draft-04 now instead of Draft-03. This is the reason for the
|
28
31
|
major version upgrade.
|
29
32
|
|
33
|
+
Version 3.0.0 Upgrade Notes
|
34
|
+
---------------------------
|
35
|
+
|
36
|
+
All individual changes are documented in the CHANGELOG.md. The biggest change
|
37
|
+
is that the new version only supports Ruby 2.5 and newer. Take a look into the
|
38
|
+
gemspec file to see the currently supported Ruby version and also
|
39
|
+
`.github/workflows/test.yml` to see the Ruby versions we test on.
|
40
|
+
|
30
41
|
Installation
|
31
42
|
------------
|
32
43
|
|
@@ -39,8 +50,8 @@ gem install json-schema
|
|
39
50
|
From the git repo:
|
40
51
|
|
41
52
|
```sh
|
42
|
-
|
43
|
-
|
53
|
+
gem build json-schema.gemspec
|
54
|
+
gem install json-schema-*.gem
|
44
55
|
```
|
45
56
|
|
46
57
|
Validation
|
@@ -69,7 +80,7 @@ that the `$schema` attribute takes precedence over the `:version` option during
|
|
69
80
|
parsing and validation.
|
70
81
|
|
71
82
|
For further information on json schema itself refer to <a
|
72
|
-
href="
|
83
|
+
href="https://json-schema.org/understanding-json-schema">Understanding
|
73
84
|
JSON Schema</a>.
|
74
85
|
|
75
86
|
Basic Usage
|
@@ -166,7 +177,7 @@ JSON::Validator.validate(schema, [{"a" => 1}, {"a" => 2}, {"a" => 3}])
|
|
166
177
|
JSON::Validator.fully_validate(schema, { "a" => "taco" }, :errors_as_objects => true)
|
167
178
|
|
168
179
|
#
|
169
|
-
# with the `:strict` option, all properties are
|
180
|
+
# with the `:strict` option, all properties are considered to have `"required": true` and all objects `"additionalProperties": false`
|
170
181
|
#
|
171
182
|
|
172
183
|
# => true
|
@@ -230,6 +241,19 @@ JSON::Validator.validate(schema, { "a" => 1 }, :parse_data => false)
|
|
230
241
|
# => false
|
231
242
|
JSON::Validator.validate(schema, '{ "a": 1 }', :parse_data => false)
|
232
243
|
|
244
|
+
#
|
245
|
+
# with the `:parse_integer` option set to false, the integer value given as string will not be parsed.
|
246
|
+
#
|
247
|
+
|
248
|
+
# => true
|
249
|
+
JSON::Validator.validate({type: "integer"}, "23")
|
250
|
+
# => false
|
251
|
+
JSON::Validator.validate({type: "integer"}, "23", parse_integer: false)
|
252
|
+
# => true
|
253
|
+
JSON::Validator.validate({type: "string"}, "123", parse_integer: false)
|
254
|
+
# => false
|
255
|
+
JSON::Validator.validate({type: "string"}, "123")
|
256
|
+
|
233
257
|
#
|
234
258
|
# with the `:json` option, the json must be an unparsed json text (not a hash, a uri or a file path)
|
235
259
|
#
|
@@ -375,6 +399,33 @@ schema = {
|
|
375
399
|
errors = JSON::Validator.fully_validate(schema, {"a" => "23"})
|
376
400
|
```
|
377
401
|
|
402
|
+
Validating a JSON Schema
|
403
|
+
------------------------
|
404
|
+
|
405
|
+
To validate that a JSON Schema conforms to the JSON Schema standard,
|
406
|
+
you need to validate your schema against the metaschema for the appropriate
|
407
|
+
JSON Schema Draft. All of the normal validation methods can be used
|
408
|
+
for this. First retrieve the appropriate metaschema from the internal
|
409
|
+
cache (using `JSON::Validator.validator_for_name()` or
|
410
|
+
`JSON::Validator.validator_for_uri()`) and then simply validate your
|
411
|
+
schema against it.
|
412
|
+
|
413
|
+
|
414
|
+
```ruby
|
415
|
+
require "json-schema"
|
416
|
+
|
417
|
+
schema = {
|
418
|
+
"type" => "object",
|
419
|
+
"properties" => {
|
420
|
+
"a" => {"type" => "integer"}
|
421
|
+
}
|
422
|
+
}
|
423
|
+
|
424
|
+
metaschema = JSON::Validator.validator_for_name("draft4").metaschema
|
425
|
+
# => true
|
426
|
+
JSON::Validator.validate(metaschema, schema)
|
427
|
+
```
|
428
|
+
|
378
429
|
Controlling Remote Schema Reading
|
379
430
|
---------------------------------
|
380
431
|
|
@@ -445,3 +496,23 @@ value is of the correct datatype (e.g., an instance value is validated to be an
|
|
445
496
|
integer or a float in the case of 'utc-millisec').
|
446
497
|
|
447
498
|
Additionally, JSON::Validator does not handle any json hyperschema attributes.
|
499
|
+
|
500
|
+
# Transfer Notice
|
501
|
+
|
502
|
+
This plugin was originally authored by [Iain Beeston](https://github.com/iainbeeston).
|
503
|
+
The maintainer preferred that [Vox Pupuli](https://voxpupuli.org/) take ownership of the module for future improvement and maintenance.
|
504
|
+
Existing pull requests and issues were transferred, please fork and continue to contribute [here](https://github.com/voxpupuli/json-schema).
|
505
|
+
|
506
|
+
# License
|
507
|
+
|
508
|
+
This gem is licensed under the [MIT license](LICENSE.md).
|
509
|
+
|
510
|
+
## Release information
|
511
|
+
|
512
|
+
To make a new release, please do:
|
513
|
+
* update the version in VERSION.yml
|
514
|
+
* Install gems with `bundle install --with release --path .vendor`
|
515
|
+
* generate the changelog with `bundle exec rake changelog`
|
516
|
+
* Check if the new version matches the closed issues/PRs in the changelog
|
517
|
+
* Create a PR with it
|
518
|
+
* After it got merged, push a tag. GitHub actions will do the actual release to rubygems and GitHub Packages
|
@@ -3,8 +3,7 @@ require 'json-schema/errors/validation_error'
|
|
3
3
|
module JSON
|
4
4
|
class Schema
|
5
5
|
class Attribute
|
6
|
-
def self.validate(current_schema, data, fragments, processor, validator, options = {})
|
7
|
-
end
|
6
|
+
def self.validate(current_schema, data, fragments, processor, validator, options = {}); end
|
8
7
|
|
9
8
|
def self.build_fragment(fragments)
|
10
9
|
"#/#{fragments.join('/')}"
|
@@ -24,14 +23,14 @@ module JSON
|
|
24
23
|
end
|
25
24
|
|
26
25
|
TYPE_CLASS_MAPPINGS = {
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
26
|
+
'string' => String,
|
27
|
+
'number' => Numeric,
|
28
|
+
'integer' => Integer,
|
29
|
+
'boolean' => [TrueClass, FalseClass],
|
30
|
+
'object' => Hash,
|
31
|
+
'array' => Array,
|
32
|
+
'null' => NilClass,
|
33
|
+
'any' => Object,
|
35
34
|
}
|
36
35
|
|
37
36
|
def self.data_valid_for_type?(data, type)
|
@@ -41,11 +40,11 @@ module JSON
|
|
41
40
|
|
42
41
|
# Lookup Schema type of given class instance
|
43
42
|
def self.type_of_data(data)
|
44
|
-
type,
|
43
|
+
type, = TYPE_CLASS_MAPPINGS.map { |k, v| [k, v] }.sort_by do |(_, v)|
|
45
44
|
-Array(v).map { |klass| klass.ancestors.size }.max
|
46
|
-
|
47
|
-
Array(v).any? { |klass| data.
|
48
|
-
|
45
|
+
end.find do |(_, v)|
|
46
|
+
Array(v).any? { |klass| data.is_a?(klass) }
|
47
|
+
end
|
49
48
|
type
|
50
49
|
end
|
51
50
|
end
|
@@ -19,6 +19,7 @@ module JSON
|
|
19
19
|
additional_items_schema = JSON::Schema.new(schema['additionalItems'], current_schema.uri, validator)
|
20
20
|
data.each_with_index do |item, i|
|
21
21
|
next if i < schema['items'].length
|
22
|
+
|
22
23
|
additional_items_schema.validate(item, fragments + [i.to_s], processor, options)
|
23
24
|
end
|
24
25
|
end
|
@@ -33,11 +33,9 @@ module JSON
|
|
33
33
|
extra_properties = extra_properties - schema['properties'].keys
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
extra_properties.reject! { |prop| regexp.match(prop) }
|
40
|
-
end
|
36
|
+
schema['patternProperties']&.each_key do |key|
|
37
|
+
regexp = Regexp.new(key)
|
38
|
+
extra_properties.reject! { |prop| regexp.match(prop) }
|
41
39
|
end
|
42
40
|
|
43
41
|
if extended_schemas = schema['extends']
|
@@ -52,7 +50,6 @@ module JSON
|
|
52
50
|
|
53
51
|
extra_properties
|
54
52
|
end
|
55
|
-
|
56
53
|
end
|
57
54
|
end
|
58
55
|
end
|
@@ -7,18 +7,20 @@ module JSON
|
|
7
7
|
# Create an hash to hold errors that are generated during validation
|
8
8
|
errors = Hash.new { |hsh, k| hsh[k] = [] }
|
9
9
|
valid = true
|
10
|
+
message = nil
|
10
11
|
|
11
12
|
current_schema.schema['allOf'].each_with_index do |element, schema_index|
|
12
|
-
schema = JSON::Schema.new(element,current_schema.uri,validator)
|
13
|
+
schema = JSON::Schema.new(element, current_schema.uri, validator)
|
13
14
|
|
14
15
|
# We're going to add a little cruft here to try and maintain any validation errors that occur in the allOf
|
15
16
|
# We'll handle this by keeping an error count before and after validation, extracting those errors and pushing them onto an error array
|
16
17
|
pre_validation_error_count = validation_errors(processor).count
|
17
18
|
|
18
19
|
begin
|
19
|
-
schema.validate(data,fragments,processor,options)
|
20
|
-
rescue ValidationError
|
20
|
+
schema.validate(data, fragments, processor, options)
|
21
|
+
rescue ValidationError => e
|
21
22
|
valid = false
|
23
|
+
message = e.message
|
22
24
|
end
|
23
25
|
|
24
26
|
diff = validation_errors(processor).count - pre_validation_error_count
|
@@ -29,7 +31,7 @@ module JSON
|
|
29
31
|
end
|
30
32
|
|
31
33
|
if !valid || !errors.empty?
|
32
|
-
message
|
34
|
+
message ||= "The property '#{build_fragment(fragments)}' of type #{type_of_data(data)} did not match all of the required schemas"
|
33
35
|
validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
|
34
36
|
validation_errors(processor).last.sub_errors = errors
|
35
37
|
end
|
@@ -11,14 +11,14 @@ module JSON
|
|
11
11
|
original_data = data.is_a?(Hash) ? data.clone : data
|
12
12
|
|
13
13
|
current_schema.schema['anyOf'].each_with_index do |element, schema_index|
|
14
|
-
schema = JSON::Schema.new(element,current_schema.uri,validator)
|
14
|
+
schema = JSON::Schema.new(element, current_schema.uri, validator)
|
15
15
|
|
16
16
|
# We're going to add a little cruft here to try and maintain any validation errors that occur in the anyOf
|
17
17
|
# We'll handle this by keeping an error count before and after validation, extracting those errors and pushing them onto a union error
|
18
18
|
pre_validation_error_count = validation_errors(processor).count
|
19
19
|
|
20
20
|
begin
|
21
|
-
schema.validate(data,fragments,processor,options)
|
21
|
+
schema.validate(data, fragments, processor, options)
|
22
22
|
valid = true
|
23
23
|
rescue ValidationError
|
24
24
|
# We don't care that these schemas don't validate - we only care that one validated
|
@@ -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
|
@@ -26,6 +26,7 @@ module JSON
|
|
26
26
|
|
27
27
|
def self.validate_dependency(schema, data, property, value, fragments, processor, attribute, options)
|
28
28
|
return if data.key?(value.to_s)
|
29
|
+
|
29
30
|
message = "The property '#{build_fragment(fragments)}' has a property '#{property}' that depends on a missing property '#{value}'"
|
30
31
|
validation_error(processor, message, fragments, schema, attribute, options[:record_errors])
|
31
32
|
end
|
@@ -34,11 +35,5 @@ module JSON
|
|
34
35
|
value.is_a?(String) || value.is_a?(Array) || value.is_a?(Hash)
|
35
36
|
end
|
36
37
|
end
|
37
|
-
|
38
|
-
class DependenciesV4Attribute < DependenciesAttribute
|
39
|
-
def self.accept_value?(value)
|
40
|
-
value.is_a?(Array) || value.is_a?(Hash)
|
41
|
-
end
|
42
|
-
end
|
43
38
|
end
|
44
39
|
end
|
@@ -5,7 +5,8 @@ module JSON
|
|
5
5
|
class DisallowAttribute < Attribute
|
6
6
|
def self.validate(current_schema, data, fragments, processor, validator, options = {})
|
7
7
|
return unless type = validator.attributes['type']
|
8
|
-
|
8
|
+
|
9
|
+
type.validate(current_schema, data, fragments, processor, validator, options.merge(disallow: true))
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end
|
@@ -12,7 +12,7 @@ module JSON
|
|
12
12
|
|
13
13
|
factor = current_schema.schema[keyword]
|
14
14
|
|
15
|
-
if factor == 0 || factor == 0.0 || (BigDecimal
|
15
|
+
if factor == 0 || factor == 0.0 || (BigDecimal(data.to_s) % BigDecimal(factor.to_s)).to_f != 0
|
16
16
|
message = "The property '#{build_fragment(fragments)}' was not divisible by #{factor}"
|
17
17
|
validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
|
18
18
|
end
|
@@ -7,14 +7,14 @@ module JSON
|
|
7
7
|
enum = current_schema.schema['enum']
|
8
8
|
return if enum.include?(data)
|
9
9
|
|
10
|
-
values = enum.map
|
10
|
+
values = enum.map do |val|
|
11
11
|
case val
|
12
12
|
when nil then 'null'
|
13
13
|
when Array then 'array'
|
14
14
|
when Hash then 'object'
|
15
15
|
else val.to_s
|
16
16
|
end
|
17
|
-
|
17
|
+
end.join(', ')
|
18
18
|
|
19
19
|
message = "The property '#{build_fragment(fragments)}' value #{data.inspect} did not match one of the following values: #{values}"
|
20
20
|
validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
|
@@ -8,11 +8,11 @@ module JSON
|
|
8
8
|
schemas = current_schema.schema['extends']
|
9
9
|
schemas = [schemas] if !schemas.is_a?(Array)
|
10
10
|
schemas.each do |s|
|
11
|
-
uri,schema = get_extended_uri_and_schema(s, current_schema, validator)
|
11
|
+
uri, schema = get_extended_uri_and_schema(s, current_schema, validator)
|
12
12
|
if schema
|
13
13
|
schema.validate(data, fragments, processor, options)
|
14
14
|
elsif uri
|
15
|
-
message = "The extended schema '#{uri
|
15
|
+
message = "The extended schema '#{uri}' cannot be found"
|
16
16
|
validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
|
17
17
|
else
|
18
18
|
message = "The property '#{build_fragment(fragments)}' was not a valid schema"
|
@@ -22,15 +22,15 @@ module JSON
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def self.get_extended_uri_and_schema(s, current_schema, validator)
|
25
|
-
uri,schema = nil,nil
|
25
|
+
uri, schema = nil, nil
|
26
26
|
|
27
27
|
if s.is_a?(Hash)
|
28
28
|
uri = current_schema.uri
|
29
29
|
if s['$ref']
|
30
|
-
ref_uri,ref_schema = JSON::Schema::RefAttribute.get_referenced_uri_and_schema(s, current_schema, validator)
|
30
|
+
ref_uri, ref_schema = JSON::Schema::RefAttribute.get_referenced_uri_and_schema(s, current_schema, validator)
|
31
31
|
if ref_schema
|
32
32
|
if s.size == 1 # Check if anything else apart from $ref
|
33
|
-
uri,schema = ref_uri,ref_schema
|
33
|
+
uri, schema = ref_uri, ref_schema
|
34
34
|
else
|
35
35
|
s = s.dup
|
36
36
|
s.delete '$ref'
|
@@ -38,10 +38,10 @@ module JSON
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
41
|
-
schema ||= JSON::Schema.new(s,uri,validator)
|
41
|
+
schema ||= JSON::Schema.new(s, uri, validator)
|
42
42
|
end
|
43
43
|
|
44
|
-
[uri,schema]
|
44
|
+
[uri, schema]
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -5,9 +5,10 @@ module JSON
|
|
5
5
|
class FormatAttribute < Attribute
|
6
6
|
def self.validate(current_schema, data, fragments, processor, validator, options = {})
|
7
7
|
return unless data_valid_for_type?(data, current_schema.schema['type'])
|
8
|
+
|
8
9
|
format = current_schema.schema['format'].to_s
|
9
10
|
validator = validator.formats[format]
|
10
|
-
validator
|
11
|
+
validator&.validate(current_schema, data, fragments, processor, validator, options)
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'json-schema/
|
1
|
+
require 'json-schema/attributes/format'
|
2
2
|
|
3
3
|
module JSON
|
4
4
|
class Schema
|
@@ -13,6 +13,7 @@ module JSON
|
|
13
13
|
Date.parse(data)
|
14
14
|
rescue ArgumentError => e
|
15
15
|
raise e unless e.message == 'invalid date'
|
16
|
+
|
16
17
|
validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors])
|
17
18
|
end
|
18
19
|
else
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'json-schema/
|
1
|
+
require 'json-schema/attributes/format'
|
2
2
|
|
3
3
|
module JSON
|
4
4
|
class Schema
|
@@ -10,12 +10,13 @@ module JSON
|
|
10
10
|
if data.is_a?(String)
|
11
11
|
error_message = "The property '#{build_fragment(fragments)}' must be a date/time in the ISO-8601 format of YYYY-MM-DDThh:mm:ssZ or YYYY-MM-DDThh:mm:ss.ssZ"
|
12
12
|
if (m = REGEXP.match(data))
|
13
|
-
parts = data.split(
|
13
|
+
parts = data.split('T')
|
14
14
|
|
15
15
|
begin
|
16
16
|
Date.parse(parts[0])
|
17
17
|
rescue ArgumentError => e
|
18
18
|
raise e unless e.message == 'invalid date'
|
19
|
+
|
19
20
|
validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors])
|
20
21
|
return
|
21
22
|
end
|
@@ -1,10 +1,11 @@
|
|
1
|
-
require 'json-schema/
|
1
|
+
require 'json-schema/attributes/format'
|
2
2
|
|
3
3
|
module JSON
|
4
4
|
class Schema
|
5
5
|
class DateTimeV4Format < FormatAttribute
|
6
6
|
def self.validate(current_schema, data, fragments, processor, validator, options = {})
|
7
7
|
return unless data.is_a?(String)
|
8
|
+
|
8
9
|
DateTime.rfc3339(data)
|
9
10
|
rescue ArgumentError
|
10
11
|
error_message = "The property '#{build_fragment(fragments)}' must be a valid RFC3339 date/time string"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'json-schema/
|
1
|
+
require 'json-schema/attributes/format'
|
2
2
|
require 'json-schema/errors/uri_error'
|
3
3
|
|
4
4
|
module JSON
|
@@ -6,6 +6,7 @@ module JSON
|
|
6
6
|
class UriFormat < FormatAttribute
|
7
7
|
def self.validate(current_schema, data, fragments, processor, validator, options = {})
|
8
8
|
return unless data.is_a?(String)
|
9
|
+
|
9
10
|
error_message = "The property '#{build_fragment(fragments)}' must be a valid URI"
|
10
11
|
begin
|
11
12
|
JSON::Util::URI.parse(data)
|