Exception: JSON::Schema::ValidationError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/json-schema/validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, fragments, failed_attribute, schema) ⇒ ValidationError

Returns a new instance of ValidationError.



15
16
17
18
19
20
21
22
# File 'lib/json-schema/validator.rb', line 15

def initialize(message, fragments, failed_attribute, schema)
  @fragments = fragments.clone
  @schema = schema
  @sub_errors = []
  @failed_attribute = failed_attribute
  message = "#{message} in schema #{schema.uri}"
  super(message)
end

Instance Attribute Details

#failed_attributeObject

Returns the value of attribute failed_attribute.



13
14
15
# File 'lib/json-schema/validator.rb', line 13

def failed_attribute
  @failed_attribute
end

#fragmentsObject

Returns the value of attribute fragments.



13
14
15
# File 'lib/json-schema/validator.rb', line 13

def fragments
  @fragments
end

#schemaObject

Returns the value of attribute schema.



13
14
15
# File 'lib/json-schema/validator.rb', line 13

def schema
  @schema
end

#sub_errorsObject

Returns the value of attribute sub_errors.



13
14
15
# File 'lib/json-schema/validator.rb', line 13

def sub_errors
  @sub_errors
end

Instance Method Details

#to_hashObject



34
35
36
37
38
39
40
# File 'lib/json-schema/validator.rb', line 34

def to_hash
  base = {:schema => @schema.uri, :fragment => ::JSON::Schema::Attribute.build_fragment(fragments), :message => message, :failed_attribute => @failed_attribute.to_s.split(":").last.split("Attribute").first}
  if !@sub_errors.empty?
    base[:errors] = @sub_errors.map{|e| e.to_hash}
  end
  base
end

#to_stringObject



24
25
26
27
28
29
30
31
32
# File 'lib/json-schema/validator.rb', line 24

def to_string
  if @sub_errors.empty?
    message
  else
    full_message = message + "\n The schema specific errors were:\n"
    @sub_errors.each{|e| full_message = full_message + " - " + e.to_string + "\n"}
    full_message
  end
end