Class: GrapeOAS::ApiModelBuilders::RequestParams
- Inherits:
-
Object
- Object
- GrapeOAS::ApiModelBuilders::RequestParams
- Defined in:
- lib/grape_oas/api_model_builders/request_params.rb
Constant Summary collapse
- ROUTE_PARAM_REGEX =
/(?<=:)\w+/
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
-
#path_param_name_map ⇒ Object
readonly
Returns the value of attribute path_param_name_map.
-
#route ⇒ Object
readonly
Returns the value of attribute route.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(api:, route:, path_param_name_map: nil) ⇒ RequestParams
constructor
A new instance of RequestParams.
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
#api ⇒ Object (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_map ⇒ Object (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 |
#route ⇒ Object (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
#build ⇒ Object
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.[: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 |