Class: GrapeOAS::ApiModelBuilders::RequestParamsSupport::ParamLocationResolver
- Inherits:
-
Object
- Object
- GrapeOAS::ApiModelBuilders::RequestParamsSupport::ParamLocationResolver
- Defined in:
- lib/grape_oas/api_model_builders/request_params_support/param_location_resolver.rb
Overview
Resolves the location (path, query, body, header) for a parameter.
Class Method Summary collapse
-
.body_param?(spec) ⇒ Boolean
Checks if a parameter should be in the request body.
-
.explicit_non_body_param?(spec) ⇒ Boolean
Checks if a parameter is explicitly marked as NOT a body param.
-
.hidden_parameter?(spec) ⇒ Boolean
Checks if a parameter should be hidden from documentation.
-
.resolve(name:, spec:, route_params:, route:) ⇒ String
Determines the location for a parameter.
Class Method Details
.body_param?(spec) ⇒ Boolean
Checks if a parameter should be in the request body. Supports both ‘param_type: ’body’‘ and `in: ’body’‘ for grape-swagger compatibility.
26 27 28 29 30 31 |
# File 'lib/grape_oas/api_model_builders/request_params_support/param_location_resolver.rb', line 26 def self.body_param?(spec) param_type = spec.dig(:documentation, :param_type)&.to_s&.downcase in_location = spec.dig(:documentation, :in)&.to_s&.downcase param_type == "body" || in_location == "body" || [Hash, "Hash"].include?(spec[:type]) end |
.explicit_non_body_param?(spec) ⇒ Boolean
Checks if a parameter is explicitly marked as NOT a body param. Supports both ‘param_type` and `in` for grape-swagger compatibility.
38 39 40 41 42 43 44 |
# File 'lib/grape_oas/api_model_builders/request_params_support/param_location_resolver.rb', line 38 def self.explicit_non_body_param?(spec) param_type = spec.dig(:documentation, :param_type)&.to_s&.downcase in_location = spec.dig(:documentation, :in)&.to_s&.downcase location = param_type || in_location location && %w[query header path].include?(location) end |
.hidden_parameter?(spec) ⇒ Boolean
Checks if a parameter should be hidden from documentation. Required parameters are never hidden (matching grape-swagger behavior).
51 52 53 54 55 56 57 |
# File 'lib/grape_oas/api_model_builders/request_params_support/param_location_resolver.rb', line 51 def self.hidden_parameter?(spec) return false if spec[:required] hidden = spec.dig(:documentation, :hidden) hidden = hidden.call if hidden.respond_to?(:call) hidden end |
.resolve(name:, spec:, route_params:, route:) ⇒ String
Determines the location for a parameter.
15 16 17 18 19 |
# File 'lib/grape_oas/api_model_builders/request_params_support/param_location_resolver.rb', line 15 def self.resolve(name:, spec:, route_params:, route:) return "path" if route_params.include?(name) extract_from_spec(spec, route) end |