json-schema 2.1.8 → 2.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +1 -1
- data/lib/json-schema/validator.rb +14 -15
- data/test/test_bad_schema_ref.rb +33 -0
- metadata +4 -2
data/README.textile
CHANGED
@@ -112,7 +112,8 @@ module JSON
|
|
112
112
|
:validate_schema => false,
|
113
113
|
:record_errors => false,
|
114
114
|
:errors_as_objects => false,
|
115
|
-
:insert_defaults => false
|
115
|
+
:insert_defaults => false,
|
116
|
+
:clear_cache => true
|
116
117
|
}
|
117
118
|
@@validators = {}
|
118
119
|
@@default_validator = nil
|
@@ -168,7 +169,8 @@ module JSON
|
|
168
169
|
if @base_schema.schema["$schema"]
|
169
170
|
version_string = @options[:version] = self.class.version_string_for(@base_schema.schema["$schema"])
|
170
171
|
end
|
171
|
-
|
172
|
+
# Don't clear the cache during metaschema validation!
|
173
|
+
meta_validator = JSON::Validator.new(self.class.metaschema_for(version_string), @base_schema.schema, {:clear_cache => false})
|
172
174
|
meta_validator.validate
|
173
175
|
rescue JSON::Schema::ValidationError, JSON::Schema::SchemaError
|
174
176
|
raise $!
|
@@ -219,14 +221,18 @@ module JSON
|
|
219
221
|
def validate()
|
220
222
|
begin
|
221
223
|
@base_schema.validate(@data,[],self,@validation_options)
|
222
|
-
|
224
|
+
if @validation_options[:clear_cache] == true
|
225
|
+
Validator.clear_cache
|
226
|
+
end
|
223
227
|
if @options[:errors_as_objects]
|
224
228
|
return @errors.map{|e| e.to_hash}
|
225
229
|
else
|
226
230
|
return @errors.map{|e| e.to_string}
|
227
231
|
end
|
228
232
|
rescue JSON::Schema::ValidationError
|
229
|
-
|
233
|
+
if @validation_options[:clear_cache] == true
|
234
|
+
Validator.clear_cache
|
235
|
+
end
|
230
236
|
raise $!
|
231
237
|
end
|
232
238
|
end
|
@@ -254,17 +260,9 @@ module JSON
|
|
254
260
|
end
|
255
261
|
|
256
262
|
if Validator.schemas[uri.to_s].nil?
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
build_schemas(schema)
|
261
|
-
rescue JSON::ParserError
|
262
|
-
# Don't rescue this error, we want JSON formatting issues to bubble up
|
263
|
-
raise $!
|
264
|
-
rescue Exception
|
265
|
-
# Failures will occur when this URI cannot be referenced yet. Don't worry about it,
|
266
|
-
# the proper error will fall out if the ref isn't ever defined
|
267
|
-
end
|
263
|
+
schema = JSON::Schema.new(JSON::Validator.parse(open(uri.to_s).read), uri, @options[:version])
|
264
|
+
Validator.add_schema(schema)
|
265
|
+
build_schemas(schema)
|
268
266
|
end
|
269
267
|
end
|
270
268
|
|
@@ -439,6 +437,7 @@ module JSON
|
|
439
437
|
end
|
440
438
|
|
441
439
|
def cache_schemas=(val)
|
440
|
+
warn "[DEPRECATION NOTICE] Schema caching is now a validation option. Schemas will still be cached if this is set to true, but this method will be removed in version >= 3. Please use the :clear_cache validation option instead."
|
442
441
|
@@cache_schemas = val == true ? true : false
|
443
442
|
end
|
444
443
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'socket'
|
3
|
+
require File.dirname(__FILE__) + '/../lib/json-schema'
|
4
|
+
|
5
|
+
class BadSchemaRefTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_bad_uri_ref
|
8
|
+
schema = {
|
9
|
+
"$schema" => "http://json-schema.org/draft-04/schema#",
|
10
|
+
"type" => "array",
|
11
|
+
"items" => { "$ref" => "../google.json"}
|
12
|
+
}
|
13
|
+
|
14
|
+
data = [1,2,3]
|
15
|
+
assert_raise(URI::BadURIError) do
|
16
|
+
JSON::Validator.validate(schema,data)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_bad_host_ref
|
21
|
+
schema = {
|
22
|
+
"$schema" => "http://json-schema.org/draft-04/schema#",
|
23
|
+
"type" => "array",
|
24
|
+
"items" => { "$ref" => "http://ppcheesecheseunicornnuuuurrrrr.com/json.schema"}
|
25
|
+
}
|
26
|
+
|
27
|
+
data = [1,2,3]
|
28
|
+
assert_raise(SocketError) do
|
29
|
+
JSON::Validator.validate(schema,data)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
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: 2.1.
|
4
|
+
version: 2.1.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
12
|
+
date: 2014-01-05 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email: hoxworth@gmail.com
|
@@ -74,6 +74,7 @@ files:
|
|
74
74
|
- LICENSE.md
|
75
75
|
- test/test_all_of_ref_schema.rb
|
76
76
|
- test/test_any_of_ref_schema.rb
|
77
|
+
- test/test_bad_schema_ref.rb
|
77
78
|
- test/test_extended_schema.rb
|
78
79
|
- test/test_extends_and_additionalProperties.rb
|
79
80
|
- test/test_files_v3.rb
|
@@ -138,6 +139,7 @@ summary: Ruby JSON Schema Validator
|
|
138
139
|
test_files:
|
139
140
|
- test/test_all_of_ref_schema.rb
|
140
141
|
- test/test_any_of_ref_schema.rb
|
142
|
+
- test/test_bad_schema_ref.rb
|
141
143
|
- test/test_extended_schema.rb
|
142
144
|
- test/test_extends_and_additionalProperties.rb
|
143
145
|
- test/test_files_v3.rb
|