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.
- checksums.yaml +4 -4
- data/README.md +55 -11
- data/lib/json-schema/attribute.rb +15 -16
- data/lib/json-schema/attributes/additionalitems.rb +1 -0
- data/lib/json-schema/attributes/additionalproperties.rb +4 -7
- data/lib/json-schema/attributes/allof.rb +33 -6
- data/lib/json-schema/attributes/anyof.rb +4 -4
- data/lib/json-schema/attributes/const.rb +15 -0
- data/lib/json-schema/attributes/dependencies.rb +1 -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 +3 -3
- data/lib/json-schema/attributes/extends.rb +10 -8
- data/lib/json-schema/attributes/format.rb +2 -1
- data/lib/json-schema/attributes/formats/custom.rb +5 -7
- data/lib/json-schema/attributes/formats/date.rb +2 -1
- data/lib/json-schema/attributes/formats/date_time.rb +4 -3
- data/lib/json-schema/attributes/formats/date_time_v4.rb +2 -1
- data/lib/json-schema/attributes/formats/ip.rb +3 -3
- 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 +2 -2
- data/lib/json-schema/attributes/limits/numeric.rb +1 -1
- data/lib/json-schema/attributes/maxdecimal.rb +2 -2
- data/lib/json-schema/attributes/not.rb +2 -2
- data/lib/json-schema/attributes/oneof.rb +9 -11
- data/lib/json-schema/attributes/pattern.rb +1 -1
- data/lib/json-schema/attributes/patternproperties.rb +2 -1
- data/lib/json-schema/attributes/properties.rb +10 -10
- data/lib/json-schema/attributes/properties_v4.rb +2 -2
- data/lib/json-schema/attributes/propertynames.rb +23 -0
- data/lib/json-schema/attributes/ref.rb +19 -18
- data/lib/json-schema/attributes/required.rb +6 -5
- data/lib/json-schema/attributes/type.rb +11 -10
- data/lib/json-schema/attributes/type_v4.rb +3 -3
- data/lib/json-schema/attributes/uniqueitems.rb +1 -1
- data/lib/json-schema/errors/validation_error.rb +10 -10
- data/lib/json-schema/schema/reader.rb +4 -2
- data/lib/json-schema/schema/validator.rb +4 -4
- data/lib/json-schema/schema.rb +13 -14
- data/lib/json-schema/util/array_set.rb +2 -4
- data/lib/json-schema/util/uri.rb +100 -77
- data/lib/json-schema/util/uuid.rb +204 -226
- data/lib/json-schema/validator.rb +173 -156
- 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 +3 -3
- data/resources/draft-06.json +12 -12
- metadata +60 -32
data/lib/json-schema/util/uri.rb
CHANGED
|
@@ -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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
# @param uri [String, Addressable::URI
|
|
29
|
+
# @return [String]
|
|
30
|
+
def unescaped_path(uri)
|
|
31
|
+
parse(uri).unescaped_path
|
|
32
|
+
end
|
|
39
33
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
55
|
-
|
|
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
|
-
|
|
56
|
+
def absolutize_ref(ref, base)
|
|
57
|
+
parse(ref).absolutize_ref(base)
|
|
58
58
|
end
|
|
59
|
+
end
|
|
59
60
|
|
|
60
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
90
|
+
self
|
|
85
91
|
end
|
|
86
92
|
end
|
|
87
93
|
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
92
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
end
|
|
112
|
+
self.fragment = fragment
|
|
113
|
+
end
|
|
97
114
|
|
|
98
|
-
|
|
99
|
-
|
|
115
|
+
self.fragment = '' if self.fragment.nil? || self.fragment.empty?
|
|
116
|
+
end
|
|
100
117
|
|
|
101
|
-
|
|
118
|
+
self
|
|
102
119
|
end
|
|
103
120
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|