Class: JTD::ValidationError

Inherits:
Struct
  • Object
show all
Defined in:
lib/jtd/validate.rb

Overview

Represents a single JSON Type Definition validation error.

ValidationError does not extend StandardError; it is not a Ruby exception. It is a plain old Ruby object.

Every ValidationError has two attributes:

  • instance_path is an array of strings. It represents the path to the part of the instance passed to JTD::validate that was rejected.

  • schema_path is an array of strings. It represents the path to the part of the schema passed to JTD::validate that rejected the instance at instance_path.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#instance_pathObject

Returns the value of attribute instance_path

Returns:

  • (Object)

    the current value of instance_path



96
97
98
# File 'lib/jtd/validate.rb', line 96

def instance_path
  @instance_path
end

#schema_pathObject

Returns the value of attribute schema_path

Returns:

  • (Object)

    the current value of schema_path



96
97
98
# File 'lib/jtd/validate.rb', line 96

def schema_path
  @schema_path
end

Class Method Details

.from_hash(hash) ⇒ Object

Constructs a new ValidationError from the standard JSON representation of a validation error in JSON Type Definition.



100
101
102
103
104
105
# File 'lib/jtd/validate.rb', line 100

def self.from_hash(hash)
  instance_path = hash['instancePath']
  schema_path = hash['schemaPath']

  ValidationError.new(instance_path, schema_path)
end