Method: Praxis::Docs::OpenApi::ParameterObject.process_parameters

Defined in:
lib/praxis/docs/open_api/parameter_object.rb

.process_parameters(action) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/praxis/docs/open_api/parameter_object.rb', line 43

def self.process_parameters(action)
  output = []
  # An array, with one hash per param inside
  if action.headers
    (action.headers.attributes || {}).each_with_object(output) do |(name, info), out|
      out << ParameterObject.new(location: 'header', name: name, is_required: info.options[:required], info: info).dump
    end
  end

  if action.params
    route_params = \
      if action.route
        action.route.path.named_captures.keys.collect(&:to_sym)
      else
        warn "Warning: No routes defined for action #{action.name}"
        []
      end
    (action.params.attributes || {}).each_with_object(output) do |(name, info), out|
      in_type = route_params.include?(name) ? :path : :query
      is_required = in_type == :path ? true : info.options[:required]
      out << ParameterObject.new(location: in_type, name: name, is_required: is_required, info: info).dump
    end
  end

  output
end