# frozen_string_literal: true module Openapi3Parser module Validation # An immutable collection of Validation::Error objects # @attr_reader [Array] errors class ErrorCollection include Enumerable # Combines ErrorCollection objects or arrays of Validation::Error objects # @param [ErrorCollection, Array] errors # @param [ErrorCollection, Array] other_errors # @return [ErrorCollection] def self.combine(errors, other_errors) new(errors.to_a + other_errors.to_a) end attr_reader :errors alias to_a errors # @param [Array] errors def initialize(errors = []) @errors = errors.freeze end def empty? errors.empty? end def each(&block) errors.each(&block) end # Group errors by those in the same location for the same node # # @return [Array 1) memo[key] = memo.fetch(key, []) + item.errors.map(&:to_s) end end end # @return [String] def inspect "#{self.class.name}(errors: #{to_h})" end LocationTypeGroup = Struct.new(:source_location, :for_type, :errors) do def location_summary(with_type: false) string = source_location.to_s string << " (as #{for_type})" if with_type && !for_type&.empty? string end end end end end