jschema 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jschema/json_reference.rb +20 -14
- data/lib/jschema/schema.rb +7 -8
- data/lib/jschema/simple_validator.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32ddf45ff9ed3c8f8922bd23962d932ec921d42c
|
4
|
+
data.tar.gz: ec0efce314be4969803f3cdec809099011af6495
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eee310162f1b3484ecd1541e80cfc40b3f837f6d2fc56d88bdb3d3446ce0cf4ed271685845e7357bae000b073a4192d8af9f89db0fb756ceb1f31141797ba4ce
|
7
|
+
data.tar.gz: 3cff14eacb201b794b15372d62abd997dcbba14659a7332e9c0a6d44e38aacd1a435856e24acd5cab2c504993f8cf6e12ed0862f06e26204d8e710c773f95515
|
@@ -65,8 +65,8 @@ module JSchema
|
|
65
65
|
schema_data = JSON.parse download_schema(uri)
|
66
66
|
parent_schema = schema && schema.parent
|
67
67
|
Schema.build(schema_data, parent_schema, uri.to_s)
|
68
|
-
rescue JSON::ParserError, Timeout::Error, Errno::ECONNREFUSED
|
69
|
-
raise InvalidSchema, "Failed to download external schema
|
68
|
+
rescue JSON::ParserError, Timeout::Error, Errno::ECONNREFUSED, Net::HTTPBadResponse => e
|
69
|
+
raise InvalidSchema, "Failed to download external schema #{uri}. #{e.class}: #{e.message}"
|
70
70
|
end
|
71
71
|
|
72
72
|
def valid_external_uri?(uri)
|
@@ -74,24 +74,30 @@ module JSchema
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def download_schema(uri)
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
77
|
+
3.times do
|
78
|
+
request = Net::HTTP::Get.new(uri.to_s)
|
79
|
+
request['Accept'] = 'application/json+schema'
|
80
|
+
|
81
|
+
http = Net::HTTP.new(uri.hostname, uri.port)
|
82
|
+
http.read_timeout = 3
|
83
|
+
http.open_timeout = 2
|
84
|
+
http.continue_timeout = 1
|
85
|
+
response = http.request(request)
|
86
|
+
if ["301", "302"].include?(response.code)
|
87
|
+
uri = URI.parse(response.header['location'])
|
88
|
+
else
|
89
|
+
return response.body
|
90
|
+
end
|
91
|
+
end
|
92
|
+
raise Net::HTTPBadResponse, "Too many redirects -- last location header was #{uri}"
|
86
93
|
end
|
87
94
|
|
88
95
|
def key(uri, schema)
|
89
96
|
if schema
|
90
97
|
root_schema = root(schema)
|
91
|
-
"#{root_schema.object_id}:#{uri}"
|
92
|
-
else
|
93
|
-
uri.to_s
|
98
|
+
return "#{root_schema.object_id}:#{uri}"
|
94
99
|
end
|
100
|
+
uri.to_s
|
95
101
|
end
|
96
102
|
|
97
103
|
def root(schema)
|
data/lib/jschema/schema.rb
CHANGED
@@ -42,6 +42,13 @@ module JSchema
|
|
42
42
|
|
43
43
|
attr_reader :uri, :parent
|
44
44
|
|
45
|
+
def initialize(schema, uri, parent)
|
46
|
+
@uri = uri
|
47
|
+
@parent = parent
|
48
|
+
@schema = schema
|
49
|
+
@validators = Validator.build(schema, self)
|
50
|
+
end
|
51
|
+
|
45
52
|
def valid?(instance)
|
46
53
|
validate(instance).empty?
|
47
54
|
end
|
@@ -59,13 +66,5 @@ module JSchema
|
|
59
66
|
def to_s
|
60
67
|
uri.to_s
|
61
68
|
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def initialize(schema, uri, parent)
|
66
|
-
@uri = uri
|
67
|
-
@parent = parent
|
68
|
-
@validators = Validator.build(schema, self)
|
69
|
-
end
|
70
69
|
end
|
71
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jschema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Papkovskiy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Implementation of JSON Schema Draft 4
|
14
14
|
email: konstantin@papkovskiy.com
|
@@ -47,7 +47,7 @@ files:
|
|
47
47
|
- lib/jschema/validator/required.rb
|
48
48
|
- lib/jschema/validator/type.rb
|
49
49
|
- lib/jschema/validator/unique_items.rb
|
50
|
-
homepage:
|
50
|
+
homepage: https://github.com/Soylent/jschema
|
51
51
|
licenses:
|
52
52
|
- MIT
|
53
53
|
metadata: {}
|
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
67
|
version: '0'
|
68
68
|
requirements: []
|
69
69
|
rubyforge_project:
|
70
|
-
rubygems_version: 2.
|
70
|
+
rubygems_version: 2.6.8
|
71
71
|
signing_key:
|
72
72
|
specification_version: 4
|
73
73
|
summary: JSON Schema implementation
|