Class: GrapeOAS::ApiModelBuilders::RequestParams

Inherits:
Object
  • Object
show all
Defined in:
lib/grape_oas/api_model_builders/request_params.rb

Constant Summary collapse

ROUTE_PARAM_REGEX =
/(?<=:)\w+/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api:, route:, path_param_name_map: nil) ⇒ RequestParams

Returns a new instance of RequestParams.



10
11
12
13
14
# File 'lib/grape_oas/api_model_builders/request_params.rb', line 10

def initialize(api:, route:, path_param_name_map: nil)
  @api = api
  @route = route
  @path_param_name_map = path_param_name_map || {}
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



8
9
10
# File 'lib/grape_oas/api_model_builders/request_params.rb', line 8

def api
  @api
end

#path_param_name_mapObject (readonly)

Returns the value of attribute path_param_name_map.



8
9
10
# File 'lib/grape_oas/api_model_builders/request_params.rb', line 8

def path_param_name_map
  @path_param_name_map
end

#routeObject (readonly)

Returns the value of attribute route.



8
9
10
# File 'lib/grape_oas/api_model_builders/request_params.rb', line 8

def route
  @route
end

Instance Method Details

#buildObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/grape_oas/api_model_builders/request_params.rb', line 16

def build
  route_params = route.path.scan(ROUTE_PARAM_REGEX)
  all_params = route.options[:params] || {}

  # Check if we have nested params (bracket notation)
  has_nested = all_params.keys.any? { |k| k.include?("[") }

  if has_nested
    build_with_nested_params(all_params, route_params)
  else
    build_flat_params(all_params, route_params)
  end
end