Skip to content

Commit

Permalink
Added a SchemaError exception that is currently only fired when an in…
Browse files Browse the repository at this point in the history
…valid fragment is referenced. I guess I should start performing other schema checks... don't really want to validate every loaded schema against the core meta schema every time, however...
  • Loading branch information
hoxworth committed Dec 18, 2010
1 parent 3796268 commit 356564c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/json-schema/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def initialize(message, fragments, schema)
super(message)
end
end

class SchemaError < Exception
end

class Validator

Expand Down Expand Up @@ -472,13 +475,18 @@ def validate_ref(current_schema, data, fragments)
# Perform fragment resolution to retrieve the appropriate level for the schema
target_schema = ref_schema.schema
fragments = temp_uri.fragment.split("/")
fragment_path = ''
fragments.each do |fragment|
if fragment && fragment != ''
if target_schema.is_a?(Array)
target_schema = target_schema[fragment.to_i]
else
target_schema = target_schema[fragment]
end
fragment_path = fragment_path + "/#{fragment}"
if target_schema.nil?
raise SchemaError.new("The fragment '#{fragment_path}' does not exist on schema #{ref_schema.uri.to_s}")
end
end
end

Expand Down

0 comments on commit 356564c

Please sign in to comment.