Skip to content

Commit 02b4290

Browse files
committed
dereference the fragment before validating the schema - validating the schema of the root is incorrect; it is correct to validate the schema located at the fragment.
1 parent 89f05e2 commit 02b4290

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/json-schema/validator.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ def initialize(schema_data, data, opts={})
5555
@data = initialize_data(data)
5656
@@mutex.synchronize { build_schemas(@base_schema) }
5757

58+
# If the :fragment option is set, try and validate against the fragment
59+
if opts[:fragment]
60+
@base_schema = schema_from_fragment(@base_schema, opts[:fragment])
61+
end
62+
5863
# validate the schema, if requested
5964
if @options[:validate_schema]
6065
if @base_schema.schema["$schema"]
@@ -64,11 +69,6 @@ def initialize(schema_data, data, opts={})
6469
# Don't clear the cache during metaschema validation!
6570
self.class.validate!(metaschema, @base_schema.schema, {:clear_cache => false})
6671
end
67-
68-
# If the :fragment option is set, try and validate against the fragment
69-
if opts[:fragment]
70-
@base_schema = schema_from_fragment(@base_schema, opts[:fragment])
71-
end
7272
end
7373

7474
def schema_from_fragment(base_schema, fragment)

0 commit comments

Comments
 (0)