class Openapi3Parser::Validation::ErrorCollection
An immutable collection of Validation::Error
objects @attr_reader [Array<Validation::Error>] errors
Constants
- LocationTypeGroup
Attributes
errors[R]
to_a[R]
Public Class Methods
combine(errors, other_errors)
click to toggle source
Combines ErrorCollection
objects or arrays of Validation::Error
objects @param [ErrorCollection, Array<Validation::Error>] errors @param [ErrorCollection, Array<Validation::Error>] other_errors @return [ErrorCollection]
# File lib/openapi3_parser/validation/error_collection.rb, line 14 def self.combine(errors, other_errors) new(errors.to_a + other_errors.to_a) end
new(errors = [])
click to toggle source
@param [Array<Validation::Error>] errors
# File lib/openapi3_parser/validation/error_collection.rb, line 22 def initialize(errors = []) @errors = errors.freeze end
Public Instance Methods
each(&block)
click to toggle source
# File lib/openapi3_parser/validation/error_collection.rb, line 30 def each(&block) errors.each(&block) end
empty?()
click to toggle source
# File lib/openapi3_parser/validation/error_collection.rb, line 26 def empty? errors.empty? end
group_errors()
click to toggle source
Group errors by those in the same location for the same node
@return [Array<LocationTypeGroup]
# File lib/openapi3_parser/validation/error_collection.rb, line 37 def group_errors grouped = group_by do |e| [e.source_location.to_s, e.for_type] end grouped.map do |_, errors| LocationTypeGroup.new(errors[0].source_location, errors[0].for_type, errors) end end
inspect()
click to toggle source
@return [String]
# File lib/openapi3_parser/validation/error_collection.rb, line 65 def inspect "#{self.class.name}(errors: #{to_h})" end
to_h()
click to toggle source
Return a hash structure where the location is key and the errors are values
@return [Hash]
# File lib/openapi3_parser/validation/error_collection.rb, line 53 def to_h grouped = group_errors.group_by { |g| g.source_location.to_s } grouped.each_with_object({}) do |(_, items), memo| items.each do |item| key = item.location_summary(with_type: items.count > 1) memo[key] = memo.fetch(key, []) + item.errors.map(&:to_s) end end end