json-schema 2.8.1 → 6.1.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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +55 -11
  3. data/lib/json-schema/attribute.rb +15 -16
  4. data/lib/json-schema/attributes/additionalitems.rb +1 -0
  5. data/lib/json-schema/attributes/additionalproperties.rb +4 -7
  6. data/lib/json-schema/attributes/allof.rb +33 -6
  7. data/lib/json-schema/attributes/anyof.rb +4 -4
  8. data/lib/json-schema/attributes/const.rb +15 -0
  9. data/lib/json-schema/attributes/dependencies.rb +1 -0
  10. data/lib/json-schema/attributes/disallow.rb +2 -1
  11. data/lib/json-schema/attributes/divisibleby.rb +1 -1
  12. data/lib/json-schema/attributes/enum.rb +3 -3
  13. data/lib/json-schema/attributes/extends.rb +10 -8
  14. data/lib/json-schema/attributes/format.rb +2 -1
  15. data/lib/json-schema/attributes/formats/custom.rb +5 -7
  16. data/lib/json-schema/attributes/formats/date.rb +2 -1
  17. data/lib/json-schema/attributes/formats/date_time.rb +4 -3
  18. data/lib/json-schema/attributes/formats/date_time_v4.rb +2 -1
  19. data/lib/json-schema/attributes/formats/ip.rb +3 -3
  20. data/lib/json-schema/attributes/formats/time.rb +1 -1
  21. data/lib/json-schema/attributes/formats/uri.rb +2 -1
  22. data/lib/json-schema/attributes/items.rb +1 -0
  23. data/lib/json-schema/attributes/limit.rb +2 -2
  24. data/lib/json-schema/attributes/limits/numeric.rb +1 -1
  25. data/lib/json-schema/attributes/maxdecimal.rb +2 -2
  26. data/lib/json-schema/attributes/not.rb +2 -2
  27. data/lib/json-schema/attributes/oneof.rb +9 -11
  28. data/lib/json-schema/attributes/pattern.rb +1 -1
  29. data/lib/json-schema/attributes/patternproperties.rb +2 -1
  30. data/lib/json-schema/attributes/properties.rb +10 -10
  31. data/lib/json-schema/attributes/properties_v4.rb +2 -2
  32. data/lib/json-schema/attributes/propertynames.rb +23 -0
  33. data/lib/json-schema/attributes/ref.rb +19 -18
  34. data/lib/json-schema/attributes/required.rb +6 -5
  35. data/lib/json-schema/attributes/type.rb +11 -10
  36. data/lib/json-schema/attributes/type_v4.rb +3 -3
  37. data/lib/json-schema/attributes/uniqueitems.rb +1 -1
  38. data/lib/json-schema/errors/validation_error.rb +10 -10
  39. data/lib/json-schema/schema/reader.rb +4 -2
  40. data/lib/json-schema/schema/validator.rb +4 -4
  41. data/lib/json-schema/schema.rb +13 -14
  42. data/lib/json-schema/util/array_set.rb +2 -4
  43. data/lib/json-schema/util/uri.rb +100 -77
  44. data/lib/json-schema/util/uuid.rb +204 -226
  45. data/lib/json-schema/validator.rb +173 -156
  46. data/lib/json-schema/validators/draft1.rb +21 -23
  47. data/lib/json-schema/validators/draft2.rb +22 -24
  48. data/lib/json-schema/validators/draft3.rb +26 -28
  49. data/lib/json-schema/validators/draft4.rb +34 -36
  50. data/lib/json-schema/validators/draft6.rb +36 -36
  51. data/lib/json-schema/validators/hyper-draft1.rb +2 -3
  52. data/lib/json-schema/validators/hyper-draft2.rb +2 -3
  53. data/lib/json-schema/validators/hyper-draft3.rb +2 -3
  54. data/lib/json-schema/validators/hyper-draft4.rb +2 -3
  55. data/lib/json-schema/validators/hyper-draft6.rb +2 -3
  56. data/lib/json-schema.rb +3 -3
  57. data/resources/draft-06.json +12 -12
  58. metadata +60 -32
@@ -1,109 +1,132 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'addressable/uri'
2
4
 
3
5
  module JSON
4
6
  module Util
5
- module URI
6
- SUPPORTED_PROTOCOLS = %w(http https ftp tftp sftp ssh svn+ssh telnet nntp gopher wais ldap prospero)
7
-
8
- def self.normalized_uri(uri, base_path = Dir.pwd)
9
- @normalize_cache ||= {}
10
- normalized_uri = @normalize_cache[uri]
11
-
12
- if !normalized_uri
13
- normalized_uri = parse(uri)
14
- # Check for absolute path
15
- if normalized_uri.relative?
16
- data = normalized_uri
17
- data = File.join(base_path, data) if data.path[0,1] != "/"
18
- normalized_uri = file_uri(data)
19
- end
20
- @normalize_cache[uri] = normalized_uri.freeze
7
+ # @api private
8
+ class URI < Addressable::URI
9
+ SUPPORTED_PROTOCOLS = %w[http https ftp tftp sftp ssh svn+ssh telnet nntp gopher wais ldap prospero]
10
+
11
+ class << self
12
+ alias unescape_uri unescape
13
+
14
+ # @param uri [String, Addressable::URI]
15
+ # @return [Addressable::URI, nil]
16
+ def parse(uri)
17
+ super
18
+ rescue Addressable::URI::InvalidURIError => e
19
+ raise JSON::Schema::UriError, e.message
21
20
  end
22
21
 
23
- normalized_uri
24
- end
25
-
26
- def self.absolutize_ref(ref, base)
27
- ref_uri = strip_fragment(ref.dup)
28
-
29
- return ref_uri if ref_uri.absolute?
30
- return parse(base) if ref_uri.path.empty?
31
-
32
- uri = strip_fragment(base.dup).join(ref_uri.path)
33
- normalized_uri(uri)
34
- end
22
+ # @param uri [String, Addressable::URI]
23
+ # @return [Addressable::URI, nil]
24
+ def file_uri(uri)
25
+ convert_path(parse(uri).path)
26
+ end
35
27
 
36
- def self.normalize_ref(ref, base)
37
- ref_uri = parse(ref)
38
- base_uri = parse(base)
28
+ # @param uri [String, Addressable::URI
29
+ # @return [String]
30
+ def unescaped_path(uri)
31
+ parse(uri).unescaped_path
32
+ end
39
33
 
40
- ref_uri.defer_validation do
41
- if ref_uri.relative?
42
- ref_uri.merge!(base_uri)
34
+ # Strips the fragment from the URI.
35
+ # @param uri [String, Addressable::URI]
36
+ # @return [Addressable::URI]
37
+ def strip_fragment(uri)
38
+ parse(uri).strip_fragment
39
+ end
43
40
 
44
- # Check for absolute path
45
- path, fragment = ref.to_s.split("#")
46
- if path.nil? || path == ''
47
- ref_uri.path = base_uri.path
48
- elsif path[0,1] == "/"
49
- ref_uri.path = Pathname.new(path).cleanpath.to_s
50
- else
51
- ref_uri.join!(path)
52
- end
41
+ # @param uri [String, Addressable::URI]
42
+ # @return [Addressable::URI]
43
+ def normalized_uri(uri, base_path = Dir.pwd)
44
+ parse(uri).normalized_uri(base_path)
45
+ end
53
46
 
54
- ref_uri.fragment = fragment
55
- end
47
+ # Normalizes the reference URI based on the provided base URI
48
+ #
49
+ # @param ref [String, Addressable::URI]
50
+ # @param base [String, Addressable::URI]
51
+ # @return [Addressable::URI]
52
+ def normalize_ref(ref, base)
53
+ parse(ref).normalize_ref(base)
54
+ end
56
55
 
57
- ref_uri.fragment = "" if ref_uri.fragment.nil? || ref_uri.fragment.empty?
56
+ def absolutize_ref(ref, base)
57
+ parse(ref).absolutize_ref(base)
58
58
  end
59
+ end
59
60
 
60
- ref_uri
61
+ # Unencodes any percent encoded characters within a path component.
62
+ #
63
+ # @return [String]
64
+ def unescaped_path
65
+ self.class.unescape_component(path)
61
66
  end
62
67
 
63
- def self.parse(uri)
64
- if uri.is_a?(Addressable::URI)
65
- return uri.dup
68
+ # Strips the fragment from the URI.
69
+ # @return [Addressable::URI] a new instance of URI without a fragment
70
+ def strip_fragment
71
+ if fragment.nil? || fragment.empty?
72
+ self
66
73
  else
67
- @parse_cache ||= {}
68
- parsed_uri = @parse_cache[uri]
69
- if parsed_uri
70
- parsed_uri.dup
71
- else
72
- @parse_cache[uri] = Addressable::URI.parse(uri)
73
- end
74
+ merge(fragment: '')
74
75
  end
75
- rescue Addressable::URI::InvalidURIError => e
76
- raise JSON::Schema::UriError.new(e.message)
77
76
  end
78
77
 
79
- def self.strip_fragment(uri)
80
- parsed_uri = parse(uri)
81
- if parsed_uri.fragment.nil? || parsed_uri.fragment.empty?
82
- parsed_uri
78
+ # Normalizes the URI based on the provided base path.
79
+ #
80
+ # @param base_path [String] the base path to use for relative URIs. Defaults to the current working directory.
81
+ # @return [Addressable::URI] the normalized URI or nil
82
+ def normalized_uri(base_path = Dir.pwd)
83
+ if relative?
84
+ if path[0, 1] == '/'
85
+ self.class.file_uri(self)
86
+ else
87
+ self.class.file_uri(File.join(base_path, self))
88
+ end
83
89
  else
84
- parsed_uri.merge(:fragment => "")
90
+ self
85
91
  end
86
92
  end
87
93
 
88
- def self.file_uri(uri)
89
- parsed_uri = parse(uri)
94
+ # @param base [Addressable::URI, String]
95
+ # @return [Addressable::URI]
96
+ def normalize_ref(base)
97
+ base_uri = self.class.parse(base)
98
+ defer_validation do
99
+ if relative?
100
+ # Check for absolute path
101
+ path, fragment = to_s.split('#')
102
+ merge!(base_uri)
90
103
 
91
- Addressable::URI.convert_path(parsed_uri.path)
92
- end
104
+ if path.nil? || path == ''
105
+ self.path = base_uri.path
106
+ elsif path[0, 1] == '/'
107
+ self.path = Pathname.new(path).cleanpath.to_s
108
+ else
109
+ join!(path)
110
+ end
93
111
 
94
- def self.unescape_uri(uri)
95
- Addressable::URI.unescape(uri)
96
- end
112
+ self.fragment = fragment
113
+ end
97
114
 
98
- def self.unescaped_path(uri)
99
- parsed_uri = parse(uri)
115
+ self.fragment = '' if self.fragment.nil? || self.fragment.empty?
116
+ end
100
117
 
101
- Addressable::URI.unescape(parsed_uri.path)
118
+ self
102
119
  end
103
120
 
104
- def self.clear_cache
105
- @parse_cache = {}
106
- @normalize_cache = {}
121
+ # @param base [Addressable::URI, String]
122
+ # @return [Addressable::URI]
123
+ def absolutize_ref(base)
124
+ ref = strip_fragment
125
+ if ref.absolute?
126
+ ref
127
+ else
128
+ self.class.strip_fragment(base).join(ref.path).normalized_uri
129
+ end
107
130
  end
108
131
  end
109
132
  end