json-schema 2.7.0 → 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 +5 -5
- data/README.md +70 -12
- data/lib/json-schema/attribute.rb +10 -0
- data/lib/json-schema/attributes/allof.rb +1 -1
- data/lib/json-schema/attributes/anyof.rb +1 -1
- data/lib/json-schema/attributes/const.rb +15 -0
- data/lib/json-schema/attributes/dependencies.rb +0 -6
- data/lib/json-schema/attributes/dependencies_v4.rb +11 -0
- data/lib/json-schema/attributes/divisibleby.rb +1 -1
- data/lib/json-schema/attributes/formats/custom.rb +1 -1
- data/lib/json-schema/attributes/formats/date.rb +1 -1
- data/lib/json-schema/attributes/formats/date_time.rb +1 -1
- data/lib/json-schema/attributes/formats/date_time_v4.rb +1 -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 +1 -1
- 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/not.rb +1 -1
- data/lib/json-schema/attributes/oneof.rb +2 -2
- data/lib/json-schema/attributes/properties.rb +0 -8
- data/lib/json-schema/attributes/properties_v4.rb +13 -0
- data/lib/json-schema/attributes/ref.rb +1 -17
- data/lib/json-schema/attributes/type.rb +0 -10
- data/lib/json-schema/attributes/type_v4.rb +1 -1
- data/lib/json-schema/schema/reader.rb +1 -1
- data/lib/json-schema/schema/validator.rb +2 -1
- data/lib/json-schema/schema.rb +2 -2
- data/lib/json-schema/util/array_set.rb +4 -4
- data/lib/json-schema/util/uri.rb +42 -0
- data/lib/json-schema/util/uuid.rb +0 -1
- data/lib/json-schema/validator.rb +72 -88
- data/lib/json-schema/validators/draft6.rb +57 -0
- data/lib/json-schema/validators/hyper-draft3.rb +13 -0
- data/lib/json-schema/validators/hyper-draft6.rb +13 -0
- data/lib/json-schema.rb +1 -2
- data/resources/draft-03.json +173 -173
- data/resources/draft-06.json +150 -0
- metadata +31 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
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,8 +1,11 @@
|
|
1
|
-
|
2
|
-
[](https://codeclimate.com/github/ruby-json-schema/json-schema)
|
1
|
+
# Ruby JSON Schema Validator
|
3
2
|
|
4
|
-
|
5
|
-
|
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)
|
6
9
|
|
7
10
|
This library is intended to provide Ruby with an interface for validating JSON
|
8
11
|
objects against a JSON schema conforming to [JSON Schema Draft
|
@@ -16,7 +19,7 @@ Additional Resources
|
|
16
19
|
--------------------
|
17
20
|
|
18
21
|
- [Google Groups](https://groups.google.com/forum/#!forum/ruby-json-schema)
|
19
|
-
- #
|
22
|
+
- #voxpupuli on irc.libera.chat
|
20
23
|
|
21
24
|
Version 2.0.0 Upgrade Notes
|
22
25
|
---------------------------
|
@@ -26,6 +29,14 @@ default**, so schemas that do not declare a validator using the `$schema`
|
|
26
29
|
keyword will use Draft-04 now instead of Draft-03. This is the reason for the
|
27
30
|
major version upgrade.
|
28
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
|
+
|
29
40
|
Installation
|
30
41
|
------------
|
31
42
|
|
@@ -38,8 +49,8 @@ gem install json-schema
|
|
38
49
|
From the git repo:
|
39
50
|
|
40
51
|
```sh
|
41
|
-
|
42
|
-
|
52
|
+
gem build json-schema.gemspec
|
53
|
+
gem install json-schema-*.gem
|
43
54
|
```
|
44
55
|
|
45
56
|
Validation
|
@@ -165,7 +176,7 @@ JSON::Validator.validate(schema, [{"a" => 1}, {"a" => 2}, {"a" => 3}])
|
|
165
176
|
JSON::Validator.fully_validate(schema, { "a" => "taco" }, :errors_as_objects => true)
|
166
177
|
|
167
178
|
#
|
168
|
-
# 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`
|
169
180
|
#
|
170
181
|
|
171
182
|
# => true
|
@@ -290,17 +301,17 @@ class BitwiseAndAttribute < JSON::Schema::Attribute
|
|
290
301
|
def self.validate(current_schema, data, fragments, processor, validator, options = {})
|
291
302
|
if data.is_a?(Integer) && data & current_schema.schema['bitwise-and'].to_i == 0
|
292
303
|
message = "The property '#{build_fragment(fragments)}' did not evaluate to true when bitwise-AND'd with #{current_schema.schema['bitwise-or']}"
|
293
|
-
|
304
|
+
validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
|
294
305
|
end
|
295
306
|
end
|
296
307
|
end
|
297
308
|
|
298
|
-
class ExtendedSchema < JSON::Schema::
|
309
|
+
class ExtendedSchema < JSON::Schema::Draft3
|
299
310
|
def initialize
|
300
311
|
super
|
301
|
-
extend_schema_definition("http://json-schema.org/draft-03/schema#")
|
302
312
|
@attributes["bitwise-and"] = BitwiseAndAttribute
|
303
|
-
@uri = URI.parse("http://test.com/test.json")
|
313
|
+
@uri = JSON::Util::URI.parse("http://test.com/test.json")
|
314
|
+
@names = ["http://test.com/test.json"]
|
304
315
|
end
|
305
316
|
|
306
317
|
JSON::Validator.register_validator(self.new)
|
@@ -374,6 +385,33 @@ schema = {
|
|
374
385
|
errors = JSON::Validator.fully_validate(schema, {"a" => "23"})
|
375
386
|
```
|
376
387
|
|
388
|
+
Validating a JSON Schema
|
389
|
+
------------------------
|
390
|
+
|
391
|
+
To validate that a JSON Schema conforms to the JSON Schema standard,
|
392
|
+
you need to validate your schema against the metaschema for the appropriate
|
393
|
+
JSON Schema Draft. All of the normal validation methods can be used
|
394
|
+
for this. First retrieve the appropriate metaschema from the internal
|
395
|
+
cache (using `JSON::Validator.validator_for_name()` or
|
396
|
+
`JSON::Validator.validator_for_uri()`) and then simply validate your
|
397
|
+
schema against it.
|
398
|
+
|
399
|
+
|
400
|
+
```ruby
|
401
|
+
require "json-schema"
|
402
|
+
|
403
|
+
schema = {
|
404
|
+
"type" => "object",
|
405
|
+
"properties" => {
|
406
|
+
"a" => {"type" => "integer"}
|
407
|
+
}
|
408
|
+
}
|
409
|
+
|
410
|
+
metaschema = JSON::Validator.validator_for_name("draft4").metaschema
|
411
|
+
# => true
|
412
|
+
JSON::Validator.validate(metaschema, schema)
|
413
|
+
```
|
414
|
+
|
377
415
|
Controlling Remote Schema Reading
|
378
416
|
---------------------------------
|
379
417
|
|
@@ -444,3 +482,23 @@ value is of the correct datatype (e.g., an instance value is validated to be an
|
|
444
482
|
integer or a float in the case of 'utc-millisec').
|
445
483
|
|
446
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
|
@@ -38,6 +38,16 @@ module JSON
|
|
38
38
|
valid_classes = TYPE_CLASS_MAPPINGS.fetch(type) { return true }
|
39
39
|
Array(valid_classes).any? { |c| data.is_a?(c) }
|
40
40
|
end
|
41
|
+
|
42
|
+
# Lookup Schema type of given class instance
|
43
|
+
def self.type_of_data(data)
|
44
|
+
type, _ = TYPE_CLASS_MAPPINGS.map { |k,v| [k,v] }.sort_by { |(_, v)|
|
45
|
+
-Array(v).map { |klass| klass.ancestors.size }.max
|
46
|
+
}.find { |(_, v)|
|
47
|
+
Array(v).any? { |klass| data.kind_of?(klass) }
|
48
|
+
}
|
49
|
+
type
|
50
|
+
end
|
41
51
|
end
|
42
52
|
end
|
43
53
|
end
|
@@ -29,7 +29,7 @@ module JSON
|
|
29
29
|
end
|
30
30
|
|
31
31
|
if !valid || !errors.empty?
|
32
|
-
message = "The property '#{build_fragment(fragments)}' of type #{data
|
32
|
+
message = "The property '#{build_fragment(fragments)}' of type #{type_of_data(data)} did not match all of the required schemas"
|
33
33
|
validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
|
34
34
|
validation_errors(processor).last.sub_errors = errors
|
35
35
|
end
|
@@ -37,7 +37,7 @@ module JSON
|
|
37
37
|
end
|
38
38
|
|
39
39
|
if !valid
|
40
|
-
message = "The property '#{build_fragment(fragments)}' of type #{data
|
40
|
+
message = "The property '#{build_fragment(fragments)}' of type #{type_of_data(data)} did not match one or more of the required schemas"
|
41
41
|
validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
|
42
42
|
validation_errors(processor).last.sub_errors = errors
|
43
43
|
end
|
@@ -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
|
@@ -34,11 +34,5 @@ module JSON
|
|
34
34
|
value.is_a?(String) || value.is_a?(Array) || value.is_a?(Hash)
|
35
35
|
end
|
36
36
|
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
37
|
end
|
44
38
|
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
|
@@ -48,132 +48,5 @@ module JSON
|
|
48
48
|
raise NotImplementedError
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
52
|
-
class MinLengthAttribute < LimitAttribute
|
53
|
-
def self.acceptable_type
|
54
|
-
String
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.limit_name
|
58
|
-
'minLength'
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.error_message(schema)
|
62
|
-
"was not of a minimum string length of #{limit(schema)}"
|
63
|
-
end
|
64
|
-
|
65
|
-
def self.value(data)
|
66
|
-
data.length
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
class MaxLengthAttribute < MinLengthAttribute
|
71
|
-
def self.limit_name
|
72
|
-
'maxLength'
|
73
|
-
end
|
74
|
-
|
75
|
-
def self.error_message(schema)
|
76
|
-
"was not of a maximum string length of #{limit(schema)}"
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
class MinItemsAttribute < LimitAttribute
|
81
|
-
def self.acceptable_type
|
82
|
-
Array
|
83
|
-
end
|
84
|
-
|
85
|
-
def self.value(data)
|
86
|
-
data.length
|
87
|
-
end
|
88
|
-
|
89
|
-
def self.limit_name
|
90
|
-
'minItems'
|
91
|
-
end
|
92
|
-
|
93
|
-
def self.error_message(schema)
|
94
|
-
"did not contain a minimum number of items #{limit(schema)}"
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
class MaxItemsAttribute < MinItemsAttribute
|
99
|
-
def self.limit_name
|
100
|
-
'maxItems'
|
101
|
-
end
|
102
|
-
|
103
|
-
def self.error_message(schema)
|
104
|
-
"had more items than the allowed #{limit(schema)}"
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
class MinPropertiesAttribute < LimitAttribute
|
109
|
-
def self.acceptable_type
|
110
|
-
Hash
|
111
|
-
end
|
112
|
-
|
113
|
-
def self.value(data)
|
114
|
-
data.size
|
115
|
-
end
|
116
|
-
|
117
|
-
def self.limit_name
|
118
|
-
'minProperties'
|
119
|
-
end
|
120
|
-
|
121
|
-
def self.error_message(schema)
|
122
|
-
"did not contain a minimum number of properties #{limit(schema)}"
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
class MaxPropertiesAttribute < MinPropertiesAttribute
|
127
|
-
def self.limit_name
|
128
|
-
'maxProperties'
|
129
|
-
end
|
130
|
-
|
131
|
-
def self.error_message(schema)
|
132
|
-
"had more properties than the allowed #{limit(schema)}"
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
class NumericLimitAttribute < LimitAttribute
|
137
|
-
def self.acceptable_type
|
138
|
-
Numeric
|
139
|
-
end
|
140
|
-
|
141
|
-
def self.error_message(schema)
|
142
|
-
exclusivity = exclusive?(schema) ? 'exclusively' : 'inclusively'
|
143
|
-
format("did not have a %s value of %s, %s", limit_name, limit(schema), exclusivity)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
class MaximumAttribute < NumericLimitAttribute
|
148
|
-
def self.limit_name
|
149
|
-
'maximum'
|
150
|
-
end
|
151
|
-
|
152
|
-
def self.exclusive?(schema)
|
153
|
-
schema['exclusiveMaximum']
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
class MaximumInclusiveAttribute < MaximumAttribute
|
158
|
-
def self.exclusive?(schema)
|
159
|
-
schema['maximumCanEqual'] == false
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
class MinimumAttribute < NumericLimitAttribute
|
164
|
-
def self.limit_name
|
165
|
-
'minimum'
|
166
|
-
end
|
167
|
-
|
168
|
-
def self.exclusive?(schema)
|
169
|
-
schema['exclusiveMinimum']
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
class MinimumInclusiveAttribute < MinimumAttribute
|
174
|
-
def self.exclusive?(schema)
|
175
|
-
schema['minimumCanEqual'] == false
|
176
|
-
end
|
177
|
-
end
|
178
51
|
end
|
179
52
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'json-schema/attributes/limits/items'
|
2
|
+
|
3
|
+
module JSON
|
4
|
+
class Schema
|
5
|
+
class MaxItemsAttribute < ItemsLimitAttribute
|
6
|
+
def self.limit_name
|
7
|
+
'maxItems'
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.error_message(schema)
|
11
|
+
"had more items than the allowed #{limit(schema)}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'json-schema/attributes/limits/length'
|
2
|
+
|
3
|
+
module JSON
|
4
|
+
class Schema
|
5
|
+
class MaxLengthAttribute < LengthLimitAttribute
|
6
|
+
def self.limit_name
|
7
|
+
'maxLength'
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.error_message(schema)
|
11
|
+
"was not of a maximum string length of #{limit(schema)}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'json-schema/attributes/limits/properties'
|
2
|
+
|
3
|
+
module JSON
|
4
|
+
class Schema
|
5
|
+
class MaxPropertiesAttribute < PropertiesLimitAttribute
|
6
|
+
def self.limit_name
|
7
|
+
'maxProperties'
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.error_message(schema)
|
11
|
+
"had more properties than the allowed #{limit(schema)}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'json-schema/attributes/limits/numeric'
|
2
|
+
|
3
|
+
module JSON
|
4
|
+
class Schema
|
5
|
+
class MaximumAttribute < NumericLimitAttribute
|
6
|
+
def self.limit_name
|
7
|
+
'maximum'
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.exclusive?(schema)
|
11
|
+
schema['exclusiveMaximum']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'json-schema/attributes/limits/items'
|
2
|
+
|
3
|
+
module JSON
|
4
|
+
class Schema
|
5
|
+
class MinItemsAttribute < ItemsLimitAttribute
|
6
|
+
def self.limit_name
|
7
|
+
'minItems'
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.error_message(schema)
|
11
|
+
"did not contain a minimum number of items #{limit(schema)}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'json-schema/attributes/limits/length'
|
2
|
+
|
3
|
+
module JSON
|
4
|
+
class Schema
|
5
|
+
class MinLengthAttribute < LengthLimitAttribute
|
6
|
+
def self.limit_name
|
7
|
+
'minLength'
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.error_message(schema)
|
11
|
+
"was not of a minimum string length of #{limit(schema)}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'json-schema/attributes/limits/properties'
|
2
|
+
|
3
|
+
module JSON
|
4
|
+
class Schema
|
5
|
+
class MinPropertiesAttribute < PropertiesLimitAttribute
|
6
|
+
def self.limit_name
|
7
|
+
'minProperties'
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.error_message(schema)
|
11
|
+
"did not contain a minimum number of properties #{limit(schema)}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'json-schema/attributes/limits/numeric'
|
2
|
+
|
3
|
+
module JSON
|
4
|
+
class Schema
|
5
|
+
class MinimumAttribute < NumericLimitAttribute
|
6
|
+
def self.limit_name
|
7
|
+
'minimum'
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.exclusive?(schema)
|
11
|
+
schema['exclusiveMinimum']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'json-schema/attributes/limit'
|
2
|
+
|
3
|
+
module JSON
|
4
|
+
class Schema
|
5
|
+
class NumericLimitAttribute < LimitAttribute
|
6
|
+
def self.acceptable_type
|
7
|
+
Numeric
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.error_message(schema)
|
11
|
+
exclusivity = exclusive?(schema) ? 'exclusively' : 'inclusively'
|
12
|
+
format("did not have a %s value of %s, %s", limit_name, limit(schema), exclusivity)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -14,7 +14,7 @@ module JSON
|
|
14
14
|
if options[:record_errors] && errors_copy.length != processor.validation_errors.length
|
15
15
|
processor.validation_errors.replace(errors_copy)
|
16
16
|
else
|
17
|
-
message = "The property '#{build_fragment(fragments)}' of type #{data
|
17
|
+
message = "The property '#{build_fragment(fragments)}' of type #{type_of_data(data)} matched the disallowed schema"
|
18
18
|
failed = false
|
19
19
|
end
|
20
20
|
rescue ValidationError
|