Class: GrapeOAS::ApiModelBuilders::RequestParamsSupport::NestedParamsBuilder
- Inherits:
-
Object
- Object
- GrapeOAS::ApiModelBuilders::RequestParamsSupport::NestedParamsBuilder
- Defined in:
- lib/grape_oas/api_model_builders/request_params_support/nested_params_builder.rb
Overview
Constant Summary collapse
- BRACKET_PATTERN =
/\[([^\]]+)\]/- MAX_NESTING_DEPTH =
10
Instance Method Summary collapse
-
#build(flat_params, path_params: []) ⇒ ApiModel::Schema
Builds a nested schema from flat bracket-notation params.
-
#initialize(schema_builder:) ⇒ NestedParamsBuilder
constructor
A new instance of NestedParamsBuilder.
Constructor Details
#initialize(schema_builder:) ⇒ NestedParamsBuilder
Returns a new instance of NestedParamsBuilder.
13 14 15 |
# File 'lib/grape_oas/api_model_builders/request_params_support/nested_params_builder.rb', line 13 def initialize(schema_builder:) @schema_builder = schema_builder end |
Instance Method Details
#build(flat_params, path_params: []) ⇒ ApiModel::Schema
Builds a nested schema from flat bracket-notation params.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/grape_oas/api_model_builders/request_params_support/nested_params_builder.rb', line 22 def build(flat_params, path_params: []) schema = ApiModel::Schema.new(type: Constants::SchemaTypes::OBJECT) # Separate top-level params from nested bracket params top_level, nested = partition_params(flat_params) # Group nested params by their root key nested_groups = group_nested_params(nested) top_level.each do |name, spec| next if path_params.include?(name) next if ParamLocationResolver.explicit_non_body_param?(spec) next if ParamLocationResolver.hidden_parameter?(spec) child_schema = @schema_builder.build(spec) # Check if this param has nested children if nested_groups.key?(name) nested_children = nested_groups[name] child_schema = build_nested_children(spec, nested_children, depth: 0) end required = spec[:required] || false schema.add_property(name, child_schema, required: required) end schema end |