json-schema 4.3.1 → 5.0.1

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: 0dbe37dbd0d05f133ae0158ff0c721f9baeca5b0c99bd7a7f449fee1dd86cc34
4
- data.tar.gz: 68d4ffcaed1df4925aafe8eef95d346fa4707fb3452b8baef14f340eb7f63687
3
+ metadata.gz: 665bf8bb88916db0ab988db716c12977298a2a1d0f67a04d47f04bb472a8554c
4
+ data.tar.gz: 355cbd6c8cc3ad538ea43e27a54763207f37c67953d069b50cac69fff6cfdadd
5
5
  SHA512:
6
- metadata.gz: 28f033e814cd2c139f0630b677b22f6bce0fdcfa06109f4827e3ad798bd24af3394c8ecf56b0a25ca8f58a2d0069ddefb7d6777929368bf3ce8d3d27e10f4a73
7
- data.tar.gz: 87c9ff71b0f5c34adda4affe416603a1340e15b3ae7e9b7fb8172eb99d6fc185dfda920375fe4b4990263459ff6986888d4a8184313f824a487984f53731141f
6
+ metadata.gz: bd9a37445ddcf4bb8484088f674bce6d7ce14395fbd2abf205ffdad97e67deb28816361b9327fa915b56f661c39c0e6c0ff68cca93f0ea5018239dbaef2b5af2
7
+ data.tar.gz: 173546de58f345e6fff077dfac84c4a7911afec48f3dc991551ae9d2f2df8b5ebfcdc2c00950a70ce54a835517ae8349d4200cef6d5ae8c2f7815dbed2bc9f1c
data/README.md CHANGED
@@ -80,7 +80,7 @@ that the `$schema` attribute takes precedence over the `:version` option during
80
80
  parsing and validation.
81
81
 
82
82
  For further information on json schema itself refer to <a
83
- href="http://spacetelescope.github.io/understanding-json-schema/">Understanding
83
+ href="https://json-schema.org/understanding-json-schema">Understanding
84
84
  JSON Schema</a>.
85
85
 
86
86
  Basic Usage
@@ -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
7
+ # @api private
8
+ class URI < Addressable::URI
6
9
  SUPPORTED_PROTOCOLS = %w(http https ftp tftp sftp ssh svn+ssh telnet nntp gopher wais ldap prospero)
7
10
 
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
21
- end
22
-
23
- normalized_uri
24
- end
11
+ class << self
12
+ alias unescape_uri unescape
25
13
 
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?
14
+ # @param uri [String, Addressable::URI]
15
+ # @return [Addressable::URI, nil]
16
+ def parse(uri)
17
+ super(uri)
18
+ rescue Addressable::URI::InvalidURIError => e
19
+ raise JSON::Schema::UriError, e.message
20
+ end
31
21
 
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
- 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, 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
@@ -36,8 +36,7 @@ module JSON
36
36
  private_class_method :new
37
37
 
38
38
  class << self
39
- # :nodoc
40
- def mask19 v, str
39
+ def mask v, str
41
40
  nstr = str.bytes.to_a
42
41
  version = [0, 16, 32, 48, 64, 80][v]
43
42
  nstr[6] &= 0b00001111
@@ -51,26 +50,7 @@ module JSON
51
50
  str
52
51
  end
53
52
 
54
- # :nodoc
55
- def mask18 v, str
56
- version = [0, 16, 32, 48, 64, 80][v]
57
- str[6] &= 0b00001111
58
- str[6] |= version
59
- # str[7] &= 0b00001111
60
- # str[7] |= 0b01010000
61
- str[8] &= 0b00111111
62
- str[8] |= 0b10000000
63
- str
64
- end
65
-
66
- def mask v, str
67
- if RUBY_VERSION >= '1.9.0'
68
- mask19 v, str
69
- else
70
- mask18 v, str
71
- end
72
- end
73
- private :mask, :mask18, :mask19
53
+ private :mask
74
54
 
75
55
  # UUID generation using SHA1. Recommended over create_md5.
76
56
  # Namespace object is another UUID, some of them are pre-defined below.
@@ -153,14 +133,10 @@ module JSON
153
133
  str = sha1.digest
154
134
  r = rand 14 # 20-6
155
135
  node = str[r, 6] || str
156
- if RUBY_VERSION >= '1.9.0'
157
- nnode = node.bytes.to_a
158
- nnode[0] |= 0x01
159
- node = ''
160
- nnode.each { |s| node << s.chr }
161
- else
162
- node[0] |= 0x01 # multicast bit
163
- end
136
+ nnode = node.bytes.to_a
137
+ nnode[0] |= 0x01
138
+ node = ''
139
+ nnode.each { |s| node << s.chr }
164
140
  k = rand 0x40000
165
141
  open STATE_FILE, 'w' do |fp|
166
142
  fp.flock IO::LOCK_EX
@@ -300,7 +300,6 @@ module JSON
300
300
 
301
301
  def clear_cache
302
302
  @@schemas = {}
303
- JSON::Util::URI.clear_cache
304
303
  end
305
304
 
306
305
  def schemas
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.3.1
4
+ version: 5.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenny Hoxworth
@@ -9,76 +9,76 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-07-12 00:00:00.000000000 Z
12
+ date: 2024-10-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: bundler
15
+ name: minitest
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '0'
20
+ version: '5.0'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ">="
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '0'
27
+ version: '5.0'
28
28
  - !ruby/object:Gem::Dependency
29
- name: minitest
29
+ name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '5.0'
34
+ version: '13.0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '5.0'
41
+ version: '13.0'
42
42
  - !ruby/object:Gem::Dependency
43
- name: rake
43
+ name: voxpupuli-rubocop
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">="
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '0'
48
+ version: 2.8.0
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ">="
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '0'
55
+ version: 2.8.0
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: webmock
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ">="
60
+ - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '0'
62
+ version: '3.23'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ">="
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '0'
69
+ version: '3.23'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: addressable
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - ">="
74
+ - - "~>"
75
75
  - !ruby/object:Gem::Version
76
76
  version: '2.8'
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - ">="
81
+ - - "~>"
82
82
  - !ruby/object:Gem::Version
83
83
  version: '2.8'
84
84
  description:
@@ -178,7 +178,6 @@ licenses:
178
178
  metadata:
179
179
  source_code_uri: https://github.com/voxpupuli/json-schema/
180
180
  changelog_uri: https://github.com/voxpupuli/json-schema//blob/master/CHANGELOG.md
181
- homepage_uri: https://github.com/voxpupuli/json-schema/
182
181
  bug_tracker_uri: https://github.com/voxpupuli/json-schema//issues
183
182
  post_install_message:
184
183
  rdoc_options: []
@@ -188,14 +187,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
188
187
  requirements:
189
188
  - - ">="
190
189
  - !ruby/object:Gem::Version
191
- version: '2.5'
190
+ version: '2.7'
192
191
  required_rubygems_version: !ruby/object:Gem::Requirement
193
192
  requirements:
194
193
  - - ">="
195
194
  - !ruby/object:Gem::Version
196
- version: '2.5'
195
+ version: '0'
197
196
  requirements: []
198
- rubygems_version: 3.3.27
197
+ rubygems_version: 3.5.16
199
198
  signing_key:
200
199
  specification_version: 4
201
200
  summary: Ruby JSON Schema Validator