json-schema 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
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.0.gem
25
+ $ gem install json-schema-2.1.1.gem
26
26
  </pre>
27
27
 
28
28
 
@@ -124,9 +124,9 @@ module JSON
124
124
  # I'm not a fan of this, but it's quick and dirty to get it working for now
125
125
  return "draft-04" unless version
126
126
  case version.to_s
127
- when "draft4"
127
+ when "draft4", "http://json-schema.org/draft-04/schema#"
128
128
  "draft-04"
129
- when "draft3"
129
+ when "draft3", "http://json-schema.org/draft-03/schema#"
130
130
  "draft-03"
131
131
  when "draft2"
132
132
  "draft-02"
@@ -157,20 +157,23 @@ module JSON
157
157
  @validation_options = @options[:record_errors] ? {:record_errors => true} : {}
158
158
  @validation_options[:insert_defaults] = true if @options[:insert_defaults]
159
159
 
160
+ @@mutex.synchronize { @base_schema = initialize_schema(schema_data) }
161
+ @data = initialize_data(data)
162
+ @@mutex.synchronize { build_schemas(@base_schema) }
163
+
160
164
  # validate the schema, if requested
161
165
  if @options[:validate_schema]
162
166
  begin
163
- meta_validator = JSON::Validator.new(self.class.metaschema_for(version_string), schema_data)
167
+ if @base_schema.schema["$schema"]
168
+ version_string = @options[:version] = self.class.version_string_for(@base_schema.schema["$schema"])
169
+ end
170
+ meta_validator = JSON::Validator.new(self.class.metaschema_for(version_string), @base_schema.schema)
164
171
  meta_validator.validate
165
172
  rescue JSON::Schema::ValidationError, JSON::Schema::SchemaError
166
173
  raise $!
167
174
  end
168
175
  end
169
176
 
170
- @@mutex.synchronize { @base_schema = initialize_schema(schema_data) }
171
- @data = initialize_data(data)
172
- @@mutex.synchronize { build_schemas(@base_schema) }
173
-
174
177
  # If the :fragment option is set, try and validate against the fragment
175
178
  if opts[:fragment]
176
179
  @base_schema = schema_from_fragment(@base_schema, opts[:fragment])
@@ -76,4 +76,10 @@ class JSONSchemaValidation < Test::Unit::TestCase
76
76
  assert_equal 1, errors.size
77
77
  assert_match /the property .*required.*did not match/i, errors.first
78
78
  end
79
+
80
+ def test_validate_schema_3_without_version_option
81
+ data = {"b" => {"a" => 5}}
82
+ assert(JSON::Validator.validate(valid_schema_v3,data,:validate_schema => true))
83
+ assert(!JSON::Validator.validate(invalid_schema_v3,data,:validate_schema => true))
84
+ end
79
85
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: