Skip to content

Commit 1d7675e

Browse files
committed
improve error message when a schema that is not a hash is passed to Schema#initialize, use #to_hash
1 parent e4d3499 commit 1d7675e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/json-schema/schema.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ class Schema
66
attr_accessor :schema, :uri, :validator
77

88
def initialize(schema,uri,parent_validator=nil)
9-
@schema = schema
9+
unless schema.respond_to?(:to_hash)
10+
raise ArgumentError, "schema must be a hash; got: #{schema.inspect}"
11+
end
12+
13+
@schema = schema.to_hash
1014
@uri = uri
1115

1216
# If there is an ID on this schema, use it to generate the URI

0 commit comments

Comments
 (0)