json-schema 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,6 +6,10 @@ h2. Dependencies
6
6
 
7
7
  The JSON::Schema library has no dependencies if the validation methods are called using Ruby objects. However, either the <code>json</code> or the <code>yajl-ruby</code> gem needs to be installed to validate JSON strings or files containing JSON data.
8
8
 
9
+ h2. 0.9.3 Notes
10
+
11
+ For those upgrading to version 0.9.3 and above and use external file references, the library changed how files are referenced. The JSON Schema spec clearly states that relative URIs are to be referenced against the parent schema's URI, and not the parent schema's 'parent' URI, as the library previously assumed.
12
+
9
13
  h2. Installation
10
14
 
11
15
  From rubygems.org:
@@ -18,7 +22,7 @@ From the git repo:
18
22
 
19
23
  <pre>
20
24
  $ gem build json-schema.gemspec
21
- $ gem install json-schema-0.9.1.gem
25
+ $ gem install json-schema-0.9.3.gem
22
26
  </pre>
23
27
 
24
28
 
@@ -12,14 +12,15 @@ module JSON
12
12
  elsif path[0,1] == "/"
13
13
  temp_uri.path = Pathname.new(path).cleanpath.to_s
14
14
  else
15
- temp_uri.path = (Pathname.new(current_schema.uri.path).parent + path).cleanpath.to_s
15
+ temp_uri.path = (Pathname.new(current_schema.uri.path) + path).cleanpath.to_s
16
16
  end
17
17
  temp_uri.fragment = current_schema.schema['$ref'].split("#")[1]
18
18
  end
19
19
  temp_uri.fragment = "" if temp_uri.fragment.nil?
20
20
 
21
21
  # Grab the parent schema from the schema list
22
- schema_key = temp_uri.to_s.split("#")[0]
22
+ schema_key = temp_uri.to_s.split("#")[0] + "#"
23
+
23
24
  ref_schema = JSON::Validator.schemas[schema_key]
24
25
 
25
26
  if ref_schema
@@ -13,12 +13,12 @@ module JSON
13
13
  if @schema['id']
14
14
  temp_uri = URI.parse(@schema['id'])
15
15
  if temp_uri.relative?
16
- uri.path = (Pathname.new(uri.path).parent + @schema['id']).cleanpath.to_s
16
+ uri.path = (Pathname.new(uri.path) + @schema['id']).cleanpath.to_s
17
17
  temp_uri = uri
18
18
  end
19
19
  @uri = temp_uri
20
20
  end
21
- @uri.fragment = nil
21
+ @uri.fragment = ''
22
22
 
23
23
  # If there is a $schema on this schema, use it to determine which validator to use
24
24
  if @schema['$schema']
@@ -134,9 +134,9 @@ module JSON
134
134
  if path && path[0,1] == '/'
135
135
  uri.path = Pathname.new(path).cleanpath.to_s
136
136
  else
137
- uri.path = (Pathname.new(parent_schema.uri.path).parent + path).cleanpath.to_s
137
+ uri.path = (Pathname.new(parent_schema.uri.path) + path).cleanpath.to_s
138
138
  end
139
- uri.fragment = nil
139
+ uri.fragment = ''
140
140
  end
141
141
 
142
142
  if Validator.schemas[uri.to_s].nil?
@@ -156,7 +156,12 @@ module JSON
156
156
 
157
157
 
158
158
  # Build all schemas with IDs, mapping out the namespace
159
- def build_schemas(parent_schema)
159
+ def build_schemas(parent_schema)
160
+ # Build ref schemas if they exist
161
+ if parent_schema.schema["$ref"]
162
+ load_ref_schema(parent_schema, parent_schema.schema["$ref"])
163
+ end
164
+
160
165
  # Check for schemas in union types
161
166
  ["type", "disallow"].each do |key|
162
167
  if parent_schema.schema[key] && parent_schema.schema[key].is_a?(Array)
@@ -199,16 +204,12 @@ module JSON
199
204
 
200
205
  # Either load a reference schema or create a new schema
201
206
  def handle_schema(parent_schema, obj)
202
- if obj['$ref']
203
- load_ref_schema(parent_schema, obj['$ref'])
204
- else
205
- schema_uri = parent_schema.uri.clone
206
- schema = JSON::Schema.new(obj,schema_uri,@options[:version])
207
- if obj['id']
208
- Validator.add_schema(schema)
209
- end
210
- build_schemas(schema)
211
- end
207
+ schema_uri = parent_schema.uri.clone
208
+ schema = JSON::Schema.new(obj,schema_uri,@options[:version])
209
+ if obj['id']
210
+ Validator.add_schema(schema)
211
+ end
212
+ build_schemas(schema)
212
213
  end
213
214
 
214
215
 
@@ -226,6 +227,7 @@ module JSON
226
227
  def validate!(schema, data,opts={})
227
228
  validator = JSON::Validator.new(schema, data, opts)
228
229
  validator.validate
230
+ return true
229
231
  end
230
232
  alias_method 'validate2', 'validate!'
231
233
 
@@ -267,7 +269,7 @@ module JSON
267
269
 
268
270
  def json_backend=(backend)
269
271
  backend = backend.to_s
270
- if @@available_json_backend.include?(backend)
272
+ if @@available_json_backends.include?(backend)
271
273
  @@json_backend = backend
272
274
  else
273
275
  raise JSON::Schema::JsonParseError.new("The JSON backend '#{backend}' could not be found.")
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-schema
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 61
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 2
10
- version: 0.9.2
9
+ - 3
10
+ version: 0.9.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kenny Hoxworth
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-30 00:00:00 -04:00
18
+ date: 2011-04-21 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21