json-schema 2.1.0 → 2.1.1
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 +1 -1
- data/lib/json-schema/validator.rb +10 -7
- data/test/test_schema_validation.rb +6 -0
- metadata +1 -1
data/README.textile
CHANGED
@@ -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
|
-
|
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
|