json-schema 4.3.0 → 5.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c79ea15e07caea8f225d40184c80f17922f8d97fdf65c340905d198c43ee5cc1
4
- data.tar.gz: d6c157775d369763d985517fa038c5403dec213e38454052c1bfa2bc6ebaf32f
3
+ metadata.gz: c42ecb537bfb46692249a301cd3c0f6d8ad0a37588d572e2daaa7591a172bb5a
4
+ data.tar.gz: 304974463c21a8e456099e10b37dee2ab2f0936cea8f1a34b06143da0e1d84d0
5
5
  SHA512:
6
- metadata.gz: feda7027308b7452ffb12719f32af4c8abd32ab049435006e8a54e4456e21dc41c2d7c730a2e53da7c0b355c0b2a361ec10b33a80b612b3f31f9240be76b67f5
7
- data.tar.gz: f31f5be8f6f75ec75fe54313a3cd0b3008b2163c7969fd947f487f68ac058d33cd89ef2c9e093da8636537fb39b6569e46b0885ba2f5b4bfe849240da9187ae5
6
+ metadata.gz: eb9b26e1e7251258d4af08666bad83904a362239f2dabecf4aaec3b3280a6d17d9aa7285faa47e84fa854504fe75b21a2a7ac607381bd047113ea1041fdef1ba
7
+ data.tar.gz: b17404fd2a367a562995aadb9882d3527098168a9e1689d2b231bf4f8e7b59b79aeba79f8525ceadffcd7fbe3d9a87297d23b7f6854f7c8fde29b59cda9867c0
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
@@ -5,6 +5,7 @@ require 'digest/sha1'
5
5
  require 'date'
6
6
  require 'thread'
7
7
  require 'timeout'
8
+ require 'stringio'
8
9
  require 'yaml'
9
10
 
10
11
  require 'json-schema/schema/reader'
@@ -299,7 +300,6 @@ module JSON
299
300
 
300
301
  def clear_cache
301
302
  @@schemas = {}
302
- JSON::Util::URI.clear_cache
303
303
  end
304
304
 
305
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.0
4
+ version: 5.0.0
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-03-26 00:00:00.000000000 Z
12
+ date: 2024-08-19 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.26
197
+ rubygems_version: 3.5.11
199
198
  signing_key:
200
199
  specification_version: 4
201
200
  summary: Ruby JSON Schema Validator