lib/grape-swagger/endpoint/params_parser.rb in grape-swagger-0.33.0 vs lib/grape-swagger/endpoint/params_parser.rb in grape-swagger-0.34.0

- old
+ new

@@ -13,41 +13,28 @@ @params = params @settings = settings end def parse_request_params - array_keys = [] public_params.each_with_object({}) do |(name, options), memo| name = name.to_s param_type = options[:type] param_type = param_type.to_s unless param_type.nil? if param_type_is_array?(param_type) - array_keys << name options[:is_array] = true - - name += '[]' if array_use_braces?(options) - else - keys = array_keys.find_all { |key| name.start_with? "#{key}[" } - if keys.any? - options[:is_array] = true - if array_use_braces?(options) - keys.sort.reverse_each do |key| - name = name.sub(key, "#{key}[]") - end - end - end + name += '[]' if array_use_braces? end - memo[name] = options unless %w[Hash Array].include?(param_type) && !options.key?(:documentation) + memo[name] = options end end private - def array_use_braces?(options) - settings[:array_use_braces] && !(options[:documentation] && options[:documentation][:param_type] == 'body') + def array_use_braces? + @array_use_braces ||= settings[:array_use_braces] && !includes_body_param? end def param_type_is_array?(param_type) return false unless param_type return true if param_type == 'Array' @@ -68,9 +55,15 @@ return true unless param_options.key?(:documentation) && !param_options[:required] param_hidden = param_options[:documentation].fetch(:hidden, false) param_hidden = param_hidden.call if param_hidden.is_a?(Proc) !param_hidden + end + + def includes_body_param? + params.any? do |_, options| + options.dig(:documentation, :param_type) == 'body' || options.dig(:documentation, :in) == 'body' + end end end end end