json-schema 4.0.0 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3685239fb43fca88ffbeb8fe2f220b1b6a53e8ab8b367c51d3bd55526388d75d
4
- data.tar.gz: dcfbf33b0a3f33b0c193e441430d85714f7ffc75deb5ce0d466a32d6dbb91b0a
3
+ metadata.gz: bc526677f82e629c0fd935d17525e2796385dbf1579f0228e4cdb65c75ff40e2
4
+ data.tar.gz: ac396f2df9fe27c39dd8408afe876aaf84eb9a577ed29635789085707183de9e
5
5
  SHA512:
6
- metadata.gz: c6e9352ea89263e330481b725e9900fba6a4ae215ce2bc08772626e7282e3c9a279b1590f1d5209825d837a465b034c4128bc8ccbd4d31767e029575eb973ac1
7
- data.tar.gz: 16be5e3ec637f8a7ecfbcdcf984beb862f9ca540a1faac84b9f6b596d3ee0e9b1ff86dc5a6e83f4bf7b3573f052566384491d1d7f7361a37720417cb7a5e91f0
6
+ metadata.gz: 7a8726a959df412d10959c9fd8bc8f2c06dd6e299e70781703b229ea00d704986b743365f25bbc51a4ac6d1a0927d08ab326fa25f81cd7d9ffc9bb3dd8ed00d3
7
+ data.tar.gz: 04ccfeb71443b438e9ad7a59c582d5f62e7ed345f20164fa87523d2127a6be38eeb9e3305af6a50b2e77f6e8720f2d420cc6fc424326c3a6f140aeccc12cf52e
data/README.md CHANGED
@@ -241,6 +241,19 @@ JSON::Validator.validate(schema, { "a" => 1 }, :parse_data => false)
241
241
  # => false
242
242
  JSON::Validator.validate(schema, '{ "a": 1 }', :parse_data => false)
243
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
+
244
257
  #
245
258
  # with the `:json` option, the json must be an unparsed json text (not a hash, a uri or a file path)
246
259
  #
@@ -7,6 +7,7 @@ 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
13
  schema = JSON::Schema.new(element, current_schema.uri, validator)
@@ -17,8 +18,9 @@ module JSON
17
18
 
18
19
  begin
19
20
  schema.validate(data, fragments, processor, options)
20
- rescue ValidationError
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 = "The property '#{build_fragment(fragments)}' of type #{type_of_data(data)} did not match all of the required schemas"
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
@@ -4,7 +4,7 @@ module JSON
4
4
  class Schema
5
5
  class PropertiesAttribute < Attribute
6
6
  def self.required?(schema, options)
7
- schema.fetch('required') { options[:strict] }
7
+ schema.fetch('required') { options[:allPropertiesRequired] }
8
8
  end
9
9
 
10
10
  def self.validate(current_schema, data, fragments, processor, validator, options = {})
@@ -33,8 +33,8 @@ module JSON
33
33
  end
34
34
  end
35
35
 
36
- # When strict is true, ensure no undefined properties exist in the data
37
- return unless options[:strict] == true && !schema.key?('additionalProperties')
36
+ # When noAdditionalProperties is true, ensure no undefined properties exist in the data
37
+ return unless options[:noAdditionalProperties] == true && !schema.key?('additionalProperties')
38
38
 
39
39
  diff = data.select do |k, v|
40
40
  k = k.to_s
@@ -6,7 +6,7 @@ module JSON
6
6
  # draft4 relies on its own RequiredAttribute validation at a higher level, rather than
7
7
  # as an attribute of individual properties.
8
8
  def self.required?(schema, options)
9
- options[:strict] == true
9
+ options[:allPropertiesRequired] == true
10
10
  end
11
11
  end
12
12
  end
@@ -27,7 +27,10 @@ module JSON
27
27
  insert_defaults: false,
28
28
  clear_cache: false,
29
29
  strict: false,
30
+ allPropertiesRequired: false,
31
+ noAdditionalProperties: false,
30
32
  parse_data: true,
33
+ parse_integer: true,
31
34
  }
32
35
  @@validators = {}
33
36
  @@default_validator = nil
@@ -45,7 +48,13 @@ module JSON
45
48
 
46
49
  @validation_options = @options[:record_errors] ? { record_errors: true } : {}
47
50
  @validation_options[:insert_defaults] = true if @options[:insert_defaults]
48
- @validation_options[:strict] = true if @options[:strict] == true
51
+ if @options[:strict] == true
52
+ @validation_options[:allPropertiesRequired] = true
53
+ @validation_options[:noAdditionalProperties] = true
54
+ else
55
+ @validation_options[:allPropertiesRequired] = true if @options[:allPropertiesRequired]
56
+ @validation_options[:noAdditionalProperties] = true if @options[:noAdditionalProperties]
57
+ end
49
58
  @validation_options[:clear_cache] = true if !@@cache_schemas || @options[:clear_cache]
50
59
 
51
60
  @@mutex.synchronize { @base_schema = initialize_schema(schema_data, configured_validator) }
@@ -569,7 +578,9 @@ module JSON
569
578
  data = self.class.parse(custom_open(json_uri))
570
579
  elsif data.is_a?(String)
571
580
  begin
572
- data = self.class.parse(data)
581
+ # Check if the string is valid integer
582
+ strict_convert = data.match?(/\A[+-]?\d+\z/) && !@options[:parse_integer]
583
+ data = strict_convert ? data : self.class.parse(data)
573
584
  rescue JSON::Schema::JsonParseError
574
585
  begin
575
586
  json_uri = Util::URI.normalized_uri(data)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenny Hoxworth
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-04-24 00:00:00.000000000 Z
12
+ date: 2023-09-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler