Exception: JsonSchemaRails::ValidationError

Inherits:
Error
  • Object
show all
Defined in:
lib/json_schema_rails/errors.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, schema = nil, errors = nil) ⇒ ValidationError

Returns a new instance of ValidationError.



23
24
25
26
27
# File 'lib/json_schema_rails/errors.rb', line 23

def initialize(message, schema = nil, errors = nil)
  super(message)
  @schema = schema
  @errors = errors
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



21
22
23
# File 'lib/json_schema_rails/errors.rb', line 21

def errors
  @errors
end

#schemaObject (readonly)

Returns the value of attribute schema.



20
21
22
# File 'lib/json_schema_rails/errors.rb', line 20

def schema
  @schema
end

Class Method Details

.from_errors(errors, schema = nil, schema_name = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/json_schema_rails/errors.rb', line 29

def self.from_errors(errors, schema = nil, schema_name = nil)
  message = "Validation error"
  message << " for schema #{schema_name}" if schema_name

  errors.each do |err|
    if err.is_a?(JsonSchema::ValidationError)
      message << "\n- #{err.pointer}: failed schema #{err.schema.pointer}: #{err.message}"
    else
      message << "\n- #{err.schema.pointer}: #{err.message}"
    end
  end

  new(message, schema, errors)
end