Sha256: 65aaa109b2535175a35cceb091146f57e72e790562e4962f3af2ee6e59fa2614

Contents?: true

Size: 899 Bytes

Versions: 7

Compression:

Stored size: 899 Bytes

Contents

# frozen_string_literal: true

module Openapi3Parser
  module Validators
    class DuplicateParameters
      def self.call(resolved_input)
        new.call(resolved_input)
      end

      def call(resolved_input)
        dupes = duplicate_names_by_in(resolved_input)
        message(dupes) unless dupes.empty?
      end

      private

      def duplicate_names_by_in(resolved_input)
        potential_items = resolved_input.reject do |item|
          next true unless item.respond_to?(:keys)

          item["name"].nil? || item["in"].nil?
        end

        potential_items.group_by { |item| [item["name"], item["in"]] }
                       .delete_if { |_, group| group.size < 2 }
                       .keys
      end

      def message(dupes)
        grouped = dupes.map { |d| "#{d.first} in #{d.last}" }.join(", ")
        "Duplicate parameters: #{grouped}"
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
openapi3_parser-0.9.2 lib/openapi3_parser/validators/duplicate_parameters.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/openapi3_parser-0.9.1/lib/openapi3_parser/validators/duplicate_parameters.rb
openapi3_parser-0.9.1 lib/openapi3_parser/validators/duplicate_parameters.rb
openapi3_parser-0.9.0 lib/openapi3_parser/validators/duplicate_parameters.rb
openapi3_parser-0.8.2 lib/openapi3_parser/validators/duplicate_parameters.rb
openapi3_parser-0.8.1 lib/openapi3_parser/validators/duplicate_parameters.rb
openapi3_parser-0.8.0 lib/openapi3_parser/validators/duplicate_parameters.rb