json-schema 4.0.0 → 4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3685239fb43fca88ffbeb8fe2f220b1b6a53e8ab8b367c51d3bd55526388d75d
4
- data.tar.gz: dcfbf33b0a3f33b0c193e441430d85714f7ffc75deb5ce0d466a32d6dbb91b0a
3
+ metadata.gz: 6b6a5072f20570ae4262df13648a1b637b5db2c02cf881c2728277ea5a203f6d
4
+ data.tar.gz: 4b92633224b1338d58918e7a2d2f5d3e117fee03409455d6f47ea51c8bef7b18
5
5
  SHA512:
6
- metadata.gz: c6e9352ea89263e330481b725e9900fba6a4ae215ce2bc08772626e7282e3c9a279b1590f1d5209825d837a465b034c4128bc8ccbd4d31767e029575eb973ac1
7
- data.tar.gz: 16be5e3ec637f8a7ecfbcdcf984beb862f9ca540a1faac84b9f6b596d3ee0e9b1ff86dc5a6e83f4bf7b3573f052566384491d1d7f7361a37720417cb7a5e91f0
6
+ metadata.gz: 9b5301a03a3fb7d3a43c275858df22d41cface2a465ff2fcfda28c9528f491e6a8f302fbbf52232de68e31d6a32540b9ad8a392fab82ec2b2113980e83119b72
7
+ data.tar.gz: 16f57a870e6b75280f5376d57785ad94500cbfd50bc3ea9ba01df486d0938c36907114780bacfc4860359e73d7adf87ce5c73205ef52ebea1f829b64d7630906
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.1
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