Class: Openapi3Parser::Validation::Error

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/openapi3_parser/validation/error.rb

Overview

Represents a validation error for an OpenAPI document

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, context, factory_class = nil) ⇒ Error

Returns a new instance of Error.

Parameters:

  • message (String)
  • context (Context)
  • factory_class (Class, nil) (defaults to: nil)


28
29
30
31
32
# File 'lib/openapi3_parser/validation/error.rb', line 28

def initialize(message, context, factory_class = nil)
  @message = message
  @context = context
  @factory_class = factory_class
end

Instance Attribute Details

#contextContext (readonly)

The context where this was validated

Returns:

  • (Context)

    the current value of context



13
14
15
# File 'lib/openapi3_parser/validation/error.rb', line 13

def context
  @context
end

#factory_classClass? (readonly)

The NodeFactory that was being created when this error was found

Returns:

  • (Class, nil)

    the current value of factory_class



13
14
15
# File 'lib/openapi3_parser/validation/error.rb', line 13

def factory_class
  @factory_class
end

#messageString (readonly) Also known as: to_s

The error message

Returns:

  • (String)

    the current value of message



13
14
15
# File 'lib/openapi3_parser/validation/error.rb', line 13

def message
  @message
end

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
55
# File 'lib/openapi3_parser/validation/error.rb', line 49

def ==(other)
  return false unless other.instance_of?(self.class)

  message == other.message &&
    context == other.context &&
    factory_class == other.factory_class
end

#for_typeString?

Returns:

  • (String, nil)


35
36
37
38
39
40
# File 'lib/openapi3_parser/validation/error.rb', line 35

def for_type
  return unless factory_class
  return "(anonymous)" unless factory_class.name

  factory_class.name.split("::").last
end

#inspectString

Returns:

  • (String)


43
44
45
46
# File 'lib/openapi3_parser/validation/error.rb', line 43

def inspect
  "#{self.class.name}(message: #{message}, context: #{context}, " \
    "for_type: #{for_type})"
end

#source_locationContext::Location

The source file and pointer for where this error occurred

Returns:

  • (Context::Location)


21
# File 'lib/openapi3_parser/validation/error.rb', line 21

def_delegator :context, :source_location