class GrapeSwagger::Endpoint::ParamsParser

Attributes

endpoint[R]
params[R]
settings[R]

Public Class Methods

new(params, settings, endpoint) click to toggle source
# File lib/grape-swagger/endpoint/params_parser.rb, line 12
def initialize(params, settings, endpoint)
  @params = params
  @settings = settings
  @endpoint = endpoint
end
parse_request_params(params, settings, endpoint) click to toggle source
# File lib/grape-swagger/endpoint/params_parser.rb, line 8
def self.parse_request_params(params, settings, endpoint)
  new(params, settings, endpoint).parse_request_params
end

Public Instance Methods

parse_request_params() click to toggle source
# File lib/grape-swagger/endpoint/params_parser.rb, line 18
def parse_request_params
  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)
      options[:is_array] = true
      name += '[]' if array_use_braces?
    end

    memo[name] = options
  end
end

Private Instance Methods

array_use_braces?() click to toggle source
# File lib/grape-swagger/endpoint/params_parser.rb, line 35
def array_use_braces?
  @array_use_braces ||= settings[:array_use_braces] && !includes_body_param?
end
includes_body_param?() click to toggle source
# File lib/grape-swagger/endpoint/params_parser.rb, line 69
def includes_body_param?
  params.any? do |_, options|
    options.dig(:documentation, :param_type) == 'body' || options.dig(:documentation, :in) == 'body'
  end
end
param_type_is_array?(param_type) click to toggle source
# File lib/grape-swagger/endpoint/params_parser.rb, line 39
def param_type_is_array?(param_type)
  return false unless param_type
  return true if param_type == 'Array'

  param_types = param_type.match(/\[(.*)\]$/)
  return false unless param_types

  param_types = param_types[0].split(',') if param_types
  param_types.size == 1
end
public_parameter?(param) click to toggle source
# File lib/grape-swagger/endpoint/params_parser.rb, line 54
def public_parameter?(param)
  param_options = param.last
  return true unless param_options.key?(:documentation) && !param_options[:required]

  param_hidden = param_options[:documentation].fetch(:hidden, false)
  if param_hidden.is_a?(Proc)
    param_hidden = if settings[:token_owner]
                     param_hidden.call(endpoint.send(settings[:token_owner].to_sym))
                   else
                     param_hidden.call
                   end
  end
  !param_hidden
end
public_params() click to toggle source
# File lib/grape-swagger/endpoint/params_parser.rb, line 50
def public_params
  params.select { |param| public_parameter?(param) }
end