jsonschema 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Rakefile +1 -1
  2. data/lib/jsonschema.rb +21 -21
  3. metadata +4 -15
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ require 'rake/rdoctask'
9
9
  require 'rake/contrib/rubyforgepublisher'
10
10
  require 'rake/contrib/sshpublisher'
11
11
  require 'fileutils'
12
- require 'lib/jsonschema'
12
+ require './lib/jsonschema'
13
13
  include FileUtils
14
14
 
15
15
  $version = JSON::Schema::VERSION
@@ -2,7 +2,7 @@
2
2
 
3
3
  module JSON
4
4
  class Schema
5
- VERSION = '2.0.0'
5
+ VERSION = '2.0.1'
6
6
  class ValueError < Exception;end
7
7
  class Undefined;end
8
8
  TypesMap = {
@@ -37,7 +37,7 @@ module JSON
37
37
 
38
38
  if value == Undefined
39
39
  unless schema['optional']
40
- raise ValueError, "#{key} is missing and it is not optional"
40
+ raise ValueError, "#{key}: is missing and it is not optional"
41
41
  end
42
42
 
43
43
  # default
@@ -61,7 +61,7 @@ module JSON
61
61
  rescue ValueError
62
62
  flag = false
63
63
  end
64
- raise ValueError, "disallowed value was matched" if flag
64
+ raise ValueError, "#{key}: disallowed value was matched" if flag
65
65
  end
66
66
 
67
67
  unless value.nil?
@@ -75,7 +75,7 @@ module JSON
75
75
  additional = schema['additionalProperties']
76
76
  if additional.instance_of?(FalseClass)
77
77
  if schema['items'].size < value.size
78
- raise ValueError, "There are more values in the array than are allowed by the items and additionalProperties restrictions."
78
+ raise ValueError, "#{key}: There are more values in the array than are allowed by the items and additionalProperties restrictions."
79
79
  end
80
80
  else
81
81
  value.each_with_index {|val, index|
@@ -90,10 +90,10 @@ module JSON
90
90
  end
91
91
  end
92
92
  if schema['minItems'] && value.size < schema['minItems']
93
- raise ValueError, "There must be a minimum of #{schema['minItems']} in the array"
93
+ raise ValueError, "#{key}: There must be a minimum of #{schema['minItems']} in the array"
94
94
  end
95
95
  if schema['maxItems'] && value.size > schema['maxItems']
96
- raise ValueError, "There must be a maximum of #{schema['maxItems']} in the array"
96
+ raise ValueError, "#{key}: There must be a maximum of #{schema['maxItems']} in the array"
97
97
  end
98
98
  elsif schema['properties']
99
99
  check_object(value, schema['properties'], schema['additionalProperties'])
@@ -104,13 +104,13 @@ module JSON
104
104
  properties = {}
105
105
  value.each {|k, val|
106
106
  if additional.instance_of?(FalseClass)
107
- raise ValueError, "Additional properties not defined by 'properties' are not allowed in field '#{k}'"
107
+ raise ValueError, "#{key}: Additional properties not defined by 'properties' are not allowed in field '#{k}'"
108
108
  else
109
109
  check_property(val, schema['additionalProperties'], k, value)
110
110
  end
111
111
  }
112
112
  else
113
- raise ValueError, "additionalProperties schema definition for field '#{}' is not an object"
113
+ raise ValueError, "#{key}: additionalProperties schema definition for field '#{}' is not an object"
114
114
  end
115
115
  end
116
116
  end
@@ -118,18 +118,18 @@ module JSON
118
118
  if value.instance_of?(String)
119
119
  # pattern
120
120
  if schema['pattern'] && !(value =~ Regexp.new(schema['pattern']))
121
- raise ValueError, "does not match the regex pattern #{schema['pattern']}"
121
+ raise ValueError, "#{key}: does not match the regex pattern #{schema['pattern']}"
122
122
  end
123
123
 
124
124
  strlen = value.split(//).size
125
125
  # maxLength
126
126
  if schema['maxLength'] && strlen > schema['maxLength']
127
- raise ValueError, "may only be #{schema['maxLength']} characters long"
127
+ raise ValueError, "#{key}: may only be #{schema['maxLength']} characters long"
128
128
  end
129
129
 
130
130
  # minLength
131
131
  if schema['minLength'] && strlen < schema['minLength']
132
- raise ValueError, "must be at least #{schema['minLength']} characters long"
132
+ raise ValueError, "#{key}: must be at least #{schema['minLength']} characters long"
133
133
  end
134
134
  end
135
135
 
@@ -140,11 +140,11 @@ module JSON
140
140
  minimumCanEqual = schema.fetch('minimumCanEqual', Undefined)
141
141
  if minimumCanEqual == Undefined || minimumCanEqual
142
142
  if value < schema['minimum']
143
- raise ValueError, "must have a minimum value of #{schema['minimum']}"
143
+ raise ValueError, "#{key}: must have a minimum value of #{schema['minimum']}"
144
144
  end
145
145
  else
146
146
  if value <= schema['minimum']
147
- raise ValueError, "must have a minimum value of #{schema['minimum']}"
147
+ raise ValueError, "#{key}: must have a minimum value of #{schema['minimum']}"
148
148
  end
149
149
  end
150
150
  end
@@ -154,11 +154,11 @@ module JSON
154
154
  maximumCanEqual = schema.fetch('maximumCanEqual', Undefined)
155
155
  if maximumCanEqual == Undefined || maximumCanEqual
156
156
  if value > schema['maximum']
157
- raise ValueError, "must have a maximum value of #{schema['maximum']}"
157
+ raise ValueError, "#{key}: must have a maximum value of #{schema['maximum']}"
158
158
  end
159
159
  else
160
160
  if value >= schema['maximum']
161
- raise ValueError, "must have a maximum value of #{schema['maximum']}"
161
+ raise ValueError, "#{key}: must have a maximum value of #{schema['maximum']}"
162
162
  end
163
163
  end
164
164
  end
@@ -166,7 +166,7 @@ module JSON
166
166
  # maxDecimal
167
167
  if schema['maxDecimal'] && schema['maxDecimal'].kind_of?(Numeric)
168
168
  if value.to_s =~ /\.\d{#{schema['maxDecimal']+1},}/
169
- raise ValueError, "may only have #{schema['maxDecimal']} digits of decimal places"
169
+ raise ValueError, "#{key}: may only have #{schema['maxDecimal']} digits of decimal places"
170
170
  end
171
171
  end
172
172
 
@@ -175,18 +175,18 @@ module JSON
175
175
  # enum
176
176
  if schema['enum']
177
177
  unless(schema['enum'].detect{|enum| enum == value })
178
- raise ValueError, "does not have a value in the enumeration #{schema['enum'].join(", ")}"
178
+ raise ValueError, "#{key}: does not have a value in the enumeration #{schema['enum'].join(", ")}"
179
179
  end
180
180
  end
181
181
 
182
182
  # description
183
183
  if schema['description'] && !schema['description'].instance_of?(String)
184
- raise ValueError, "The description for field '#{value}' must be a string"
184
+ raise ValueError, "#{key}: The description for field '#{value}' must be a string"
185
185
  end
186
186
 
187
187
  # title
188
188
  if schema['title'] && !schema['title'].instance_of?(String)
189
- raise ValueError, "The title for field '#{value}' must be a string"
189
+ raise ValueError, "#{key}: The title for field '#{value}' must be a string"
190
190
  end
191
191
 
192
192
  # format
@@ -242,13 +242,13 @@ module JSON
242
242
  end
243
243
  end
244
244
  unless datavalid
245
- raise ValueError, "#{value.class} value found, but a #{type} is required"
245
+ raise ValueError, "#{key}: #{value.class} value found, but a #{type} is required"
246
246
  end
247
247
  elsif converted_fieldtype.instance_of? Hash
248
248
  check_property(value, type, key, parent)
249
249
  else
250
250
  unless value.instance_of? converted_fieldtype
251
- raise ValueError, "#{value.class} value found, but a #{type} is required"
251
+ raise ValueError, "#{key}: #{value.class} value found, but a #{type} is required"
252
252
  end
253
253
  end
254
254
  end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonschema
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
5
- prerelease: false
6
- segments:
7
- - 2
8
- - 0
9
- - 0
10
- version: 2.0.0
4
+ prerelease:
5
+ version: 2.0.1
11
6
  platform: ruby
12
7
  authors:
13
8
  - Constellation
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2010-08-23 00:00:00 +09:00
13
+ date: 2011-03-02 00:00:00 +09:00
19
14
  default_executable:
20
15
  dependencies: []
21
16
 
@@ -51,23 +46,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
46
  requirements:
52
47
  - - ">="
53
48
  - !ruby/object:Gem::Version
54
- hash: 3
55
- segments:
56
- - 0
57
49
  version: "0"
58
50
  required_rubygems_version: !ruby/object:Gem::Requirement
59
51
  none: false
60
52
  requirements:
61
53
  - - ">="
62
54
  - !ruby/object:Gem::Version
63
- hash: 3
64
- segments:
65
- - 0
66
55
  version: "0"
67
56
  requirements: []
68
57
 
69
58
  rubyforge_project: jsonschema
70
- rubygems_version: 1.3.7
59
+ rubygems_version: 1.5.0
71
60
  signing_key:
72
61
  specification_version: 3
73
62
  summary: json schema library ruby porting from http://code.google.com/p/jsonschema/