json-schema 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -1,11 +1,17 @@
1
1
  h1. Ruby JSON Schema Validator
2
2
 
3
- This library is intended to provide Ruby with an interface for validating JSON objects against a JSON schema conforming to [[JSON Schema Draft 3|http://tools.ietf.org/html/draft-zyp-json-schema-03]]. The project originally started as a fork of [[Constellation's ruby-jsonschema|https://github.com/Constellation/ruby-jsonchema]] project, but differences in the JSON schema draft versions implemented as well as assumptions made by the ruby-jsonschema library forced this to become a new project.
3
+ This library is intended to provide Ruby with an interface for validating JSON objects against a JSON schema conforming to "JSON Schema Draft 3":http://tools.ietf.org/html/draft-zyp-json-schema-03. The project originally started as a fork of "Constellation's ruby-jsonschema":https://github.com/Constellation/ruby-jsonchema project, but differences in the JSON schema draft versions implemented as well as assumptions made by the ruby-jsonschema library forced this to become a new project.
4
4
 
5
5
  This project is far from complete but is in a somewhat usable state...
6
6
 
7
7
  h2. Usage
8
8
 
9
+ Install:
10
+
11
+ <pre>
12
+ gem install json-schema
13
+ </pre>
14
+
9
15
  If downloading the git repo, build the gem and install it:
10
16
 
11
17
  <pre>
@@ -209,7 +209,13 @@ module JSON
209
209
  temp_uri = URI.parse(current_schema.schema['$ref'])
210
210
  if temp_uri.relative?
211
211
  temp_uri = current_schema.uri.clone
212
- temp_uri.path = (Pathname.new(current_schema.uri.path).parent + current_schema.schema['$ref'].split("#")[0]).cleanpath
212
+ # Check for absolute path
213
+ path = current_schema.schema['$ref'].split("#")[0]
214
+ if path[0,1] == "/"
215
+ temp_uri.path = Pathname.new(path).cleanpath
216
+ else
217
+ temp_uri.path = (Pathname.new(current_schema.uri.path).parent + path).cleanpath
218
+ end
213
219
  temp_uri.fragment = current_schema.schema['$ref'].split("#")[1]
214
220
  end
215
221
  temp_uri.fragment = "" if temp_uri.fragment.nil?
@@ -296,7 +302,13 @@ module JSON
296
302
  uri = URI.parse(ref)
297
303
  if uri.relative?
298
304
  uri = parent_schema.uri.clone
299
- uri.path = (Pathname.new(parent_schema.uri.path).parent + ref.split("#")[0]).cleanpath
305
+ # Check for absolute path
306
+ path = ref.split("#")[0]
307
+ if path[0,1] == '/'
308
+ uri.path = Pathname.new(path).cleanpath
309
+ else
310
+ uri.path = (Pathname.new(parent_schema.uri.path).parent + path).cleanpath
311
+ end
300
312
  uri.fragment = nil
301
313
  end
302
314
 
@@ -446,7 +458,14 @@ module JSON
446
458
  begin
447
459
  # Build a uri for it
448
460
  schema_uri = URI.parse(schema)
449
- schema_uri = URI.parse("file://#{Dir.pwd}/#{schema}") if schema_uri.relative?
461
+ if schema_uri.relative?
462
+ # Check for absolute path
463
+ if schema[0,1] == '/'
464
+ schema_uri = URI.parse("file://#{schema}")
465
+ else
466
+ schema_uri = URI.parse("file://#{Dir.pwd}/#{schema}")
467
+ end
468
+ end
450
469
  schema = JSON.parse(open(schema_uri.to_s).read)
451
470
  rescue
452
471
  raise "Invalid schema: #{schema_uri.to_s}"
@@ -466,7 +485,13 @@ module JSON
466
485
  rescue
467
486
  begin
468
487
  json_uri = URI.parse(data)
469
- json_uri = URI.parse("file://#{Dir.pwd}/#{data}") if json_uri.relative?
488
+ if json_uri.relative?
489
+ if data[0,1] == '/'
490
+ schema_uri = URI.parse("file://#{data}")
491
+ else
492
+ schema_uri = URI.parse("file://#{Dir.pwd}/#{data}")
493
+ end
494
+ end
470
495
  data = JSON.parse(open(json_uri.to_s).read)
471
496
  rescue
472
497
  raise "Invalid JSON: #{json_uri.to_s}"
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: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
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: 2010-11-24 00:00:00 -05:00
18
+ date: 2010-11-29 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: "0"
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
- description: A Ruby JSON Schema Validator based on JSON Schema draft 03
35
+ description:
36
36
  email: hoxworth@gmail.com
37
37
  executables: []
38
38
 
@@ -41,12 +41,12 @@ extensions: []
41
41
  extra_rdoc_files:
42
42
  - README.textile
43
43
  files:
44
- - lib/json-schema.rb
45
44
  - lib/json-schema/schema.rb
46
- - lib/json-schema/validator.rb
47
45
  - lib/json-schema/uri/file.rb
48
- - README.textile
46
+ - lib/json-schema/validator.rb
47
+ - lib/json-schema.rb
49
48
  - test/test_jsonschema.rb
49
+ - README.textile
50
50
  has_rdoc: true
51
51
  homepage: http://github.com/hoxworth/json-schema/tree/master
52
52
  licenses: []