json-schema 2.1.7 → 2.1.8

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.
data/README.textile CHANGED
@@ -22,7 +22,7 @@ From the git repo:
22
22
 
23
23
  <pre>
24
24
  $ gem build json-schema.gemspec
25
- $ gem install json-schema-2.1.7.gem
25
+ $ gem install json-schema-2.1.8.gem
26
26
  </pre>
27
27
 
28
28
 
@@ -1,3 +1,5 @@
1
+ require 'uri'
2
+
1
3
  module JSON
2
4
  class Schema
3
5
  class FormatAttribute < Attribute
@@ -8,7 +10,6 @@ module JSON
8
10
  when 'date-time'
9
11
  if data.is_a?(String)
10
12
  error_message = "The property '#{build_fragment(fragments)}' must be a date/time in the ISO-8601 format of YYYY-MM-DDThh:mm:ssZ or YYYY-MM-DDThh:mm:ss.ssZ"
11
- validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors]) and return if !data.is_a?(String)
12
13
  r = Regexp.new('^\d\d\d\d-\d\d-\d\dT(\d\d):(\d\d):(\d\d)([\.,]\d+)?(Z|[+-](\d\d)(:?\d\d)?)?$')
13
14
  if (m = r.match(data))
14
15
  parts = data.split("T")
@@ -31,12 +32,10 @@ module JSON
31
32
  return
32
33
  end
33
34
  end
34
-
35
35
  # Date in the format of YYYY-MM-DD
36
36
  when 'date'
37
37
  if data.is_a?(String)
38
38
  error_message = "The property '#{build_fragment(fragments)}' must be a date in the format of YYYY-MM-DD"
39
- validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors]) and return if !data.is_a?(String)
40
39
  r = Regexp.new('^\d\d\d\d-\d\d-\d\d$')
41
40
  if (m = r.match(data))
42
41
  begin
@@ -55,7 +54,6 @@ module JSON
55
54
  when 'time'
56
55
  if data.is_a?(String)
57
56
  error_message = "The property '#{build_fragment(fragments)}' must be a time in the format of hh:mm:ss"
58
- validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors]) and return if !data.is_a?(String)
59
57
  r = Regexp.new('^(\d\d):(\d\d):(\d\d)$')
60
58
  if (m = r.match(data))
61
59
  validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors]) and return if m[1].to_i > 23
@@ -71,7 +69,6 @@ module JSON
71
69
  when 'ip-address', 'ipv4'
72
70
  if data.is_a?(String)
73
71
  error_message = "The property '#{build_fragment(fragments)}' must be a valid IPv4 address"
74
- validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors]) and return if !data.is_a?(String)
75
72
  r = Regexp.new('^(\d+){1,3}\.(\d+){1,3}\.(\d+){1,3}\.(\d+){1,3}$')
76
73
  if (m = r.match(data))
77
74
  1.upto(4) do |x|
@@ -87,7 +84,6 @@ module JSON
87
84
  when 'ipv6'
88
85
  if data.is_a?(String)
89
86
  error_message = "The property '#{build_fragment(fragments)}' must be a valid IPv6 address"
90
- validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors]) and return if !data.is_a?(String)
91
87
  r = Regexp.new('^[a-f0-9:]+$')
92
88
  if (m = r.match(data))
93
89
  # All characters are valid, now validate structure
@@ -106,8 +102,22 @@ module JSON
106
102
  return
107
103
  end
108
104
  end
105
+
106
+ when 'uri'
107
+ if data.is_a?(String)
108
+ error_message = "The property '#{build_fragment(fragments)}' must be a valid URI"
109
+ begin
110
+ URI.parse(data)
111
+ rescue URI::InvalidURIError
112
+ validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors])
113
+ end
114
+ end
115
+
116
+ when 'hostname'
117
+
118
+ when 'email'
109
119
  end
110
120
  end
111
121
  end
112
122
  end
113
- end
123
+ end
@@ -1006,8 +1006,22 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
1006
1006
  "type" => "object",
1007
1007
  "properties" => { "a" => {"type" => ["string","null"], "format" => "ip-address"}}
1008
1008
  }
1009
- assert(!JSON::Validator.validate(schema,data1,:version => :draft3))
1010
- assert(JSON::Validator.validate(schema,data2,:version => :draft3))
1009
+ assert(!JSON::Validator.validate(schema,data1))
1010
+ assert(JSON::Validator.validate(schema,data2))
1011
+ end
1012
+
1013
+ def test_format_uri
1014
+ data1 = {"a" => "http://gitbuh.com"}
1015
+ data2 = {"a" => "::boo"}
1016
+
1017
+ schema = {
1018
+ "$schema" => "http://json-schema.org/draft-03/schema#",
1019
+ "type" => "object",
1020
+ "properties" => { "a" => {"type" => "string", "format" => "uri"}}
1021
+ }
1022
+
1023
+ assert(JSON::Validator.validate(schema,data1))
1024
+ assert(!JSON::Validator.validate(schema,data2))
1011
1025
  end
1012
1026
 
1013
1027
 
@@ -930,6 +930,20 @@ class JSONSchemaDraft4Test < Test::Unit::TestCase
930
930
  assert(!JSON::Validator.validate(schema,data))
931
931
  end
932
932
 
933
+ def test_format_uri
934
+ data1 = {"a" => "http://gitbuh.com"}
935
+ data2 = {"a" => "::boo"}
936
+
937
+ schema = {
938
+ "$schema" => "http://json-schema.org/draft-04/schema#",
939
+ "type" => "object",
940
+ "properties" => { "a" => {"type" => "string", "format" => "uri"}}
941
+ }
942
+
943
+ assert(JSON::Validator.validate(schema,data1))
944
+ assert(!JSON::Validator.validate(schema,data2))
945
+ end
946
+
933
947
 
934
948
  def test_format_union
935
949
  data1 = {"a" => "boo"}
@@ -940,8 +954,8 @@ class JSONSchemaDraft4Test < Test::Unit::TestCase
940
954
  "type" => "object",
941
955
  "properties" => { "a" => {"type" => ["string","null"], "format" => "ip-address"}}
942
956
  }
943
- assert(!JSON::Validator.validate(schema,data1,:version => :draft3))
944
- assert(JSON::Validator.validate(schema,data2,:version => :draft3))
957
+ assert(!JSON::Validator.validate(schema,data1))
958
+ assert(JSON::Validator.validate(schema,data2))
945
959
  end
946
960
 
947
961
 
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.7
4
+ version: 2.1.8
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Kenny Hoxworth
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-01-03 00:00:00.000000000 Z
12
+ date: 2014-01-04 00:00:00.000000000 Z
12
13
  dependencies: []
13
14
  description:
14
15
  email: hoxworth@gmail.com
@@ -112,26 +113,27 @@ files:
112
113
  homepage: http://github.com/hoxworth/json-schema/tree/master
113
114
  licenses:
114
115
  - MIT
115
- metadata: {}
116
116
  post_install_message:
117
117
  rdoc_options: []
118
118
  require_paths:
119
119
  - lib
120
120
  required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
121
122
  requirements:
122
123
  - - ! '>='
123
124
  - !ruby/object:Gem::Version
124
125
  version: '0'
125
126
  required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
126
128
  requirements:
127
129
  - - ! '>='
128
130
  - !ruby/object:Gem::Version
129
131
  version: '0'
130
132
  requirements: []
131
133
  rubyforge_project:
132
- rubygems_version: 2.0.7
134
+ rubygems_version: 1.8.23
133
135
  signing_key:
134
- specification_version: 4
136
+ specification_version: 3
135
137
  summary: Ruby JSON Schema Validator
136
138
  test_files:
137
139
  - test/test_all_of_ref_schema.rb
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MDk3NjY1MWJhZWMwMDk0MGFjMWZlNzNmNzNmYzE5MWM4Y2I4MWYyNg==
5
- data.tar.gz: !binary |-
6
- YTUyMTAyNTdiZmE3YWI0YzM0Y2ZmYmQ5YTZjMTdiYjYzZWNjMWEzNg==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- ZDNjOTI5ZWNlYmVlYWI4MTQ0ZTdhOWFlMjlmODZmZmZhMGI4NTZjNTkwMjg3
10
- NGQ0MjQ4NWMyYjdiNzc0ZmZiZGQ1MDQzMjQzNDMwNmZiZDk2ZTQwZTY0NDdi
11
- NGM1ODA4NTEzNjE1N2JlNWQyMTdlODA2ZjdkMGZlOGExZjA3NmE=
12
- data.tar.gz: !binary |-
13
- NDVkY2E4MWM0NGZlYjgyNTEwOGM0ZDIzNDIzYWNmMzMzZTMxMDhhMGQ4NDk0
14
- MzI3ZWY1NjJlNzIxNDc3N2IyZWJlMWYyYTkwODA5YjAwMmM5NGYyYTUwOGE4
15
- ZDA0ZDhhMTZmODU1YmRmODBkNWNlZjhmYTQyYjI5YzRlM2Y1NTM=