ruby-grape/grape · error · Grape::Exceptions::MissingGroupType
group type is required
Error message
group type is required
What it means
`requires :name do ... end` creates a subordinate ParamsScope via new_scope, and for a required element Grape must know the group's container type to coerce and validate it. When `type:` is nil (and the scope is not optional), new_scope raises Grape::Exceptions::MissingGroupType ('group type is required') while the endpoint is being defined.
Source
Thrown at lib/grape/validations/params_scope.rb:282
end
def validate_attributes(attrs, **opts, &block)
opts[:type] ||= Array if block
validates(attrs, opts)
end
# Returns a new parameter scope, subordinate to the current one and nested
# under the given element.
# @param element [Symbol] the parameter name under which this scope is nested
# @param type [Class] the type governing this scope
# @param as [Symbol, nil] optional renamed name for the element
# @param optional [Boolean] whether the parameter this scope is nested under
# is optional or not (and hence, whether this block's params will be).
# @yield parameter scope
def new_scope(element, type:, as:, optional: false, &)
# if required params are grouped and no type or unsupported type is provided, raise an error
if element && !optional
raise Grape::Exceptions::MissingGroupType if type.nil?
raise Grape::Exceptions::UnsupportedGroupType unless Grape::Validations::Types.group?(type)
end
self.class.new(
api: @api,
element:,
element_renamed: as,
parent: self,
optional:,
type: type || Array,
group: @group,
&
)
end
# Returns a new parameter scope, not nested under any current-level param
# but instead at the same level as the current scope.
# @param dependent_on [Symbol] if given, specifies that this scope shouldView on GitHub (pinned to 22d7975629)
Solutions
- Add `type: Hash` for a single nested object: `requires :address, type: Hash do ... end`.
- Use `type: Array` (or JSON / Array[JSON]) for list-shaped groups.
- If the parameter is genuinely optional, switch to `optional :name, type: Hash do ... end`.
Example fix
# before requires :address do requires :street, type: String end # raises MissingGroupType # after requires :address, type: Hash do requires :street, type: String end
Defensive patterns
Strategy: validation
Validate before calling
# Every `requires :x do ... end` must read `requires :x, type: Hash|Array|JSON|Array[JSON] do ... end` # Lint: flag any (optional|requires) ... do block lacking type: in params declarations
Prevention
- Treat `type:` as mandatory whenever a block follows requires/optional.
- Provide base-class macros (e.g. `requires_hash :address`) so groups are always typed.
- Boot-time smoke specs per route catch MissingGroupType in CI.
When it happens
Trigger: `requires :address do requires :street, type: String end` without a type. Nesting groups where an inner `requires :items do ... end` lost its `type: Array`. Shared param macros that forward blocks but drop the type option.
Common situations: Writing nested params for the first time (flat attributes need no type, groups do). Refactoring that removes the type option while keeping the block. Reusing documented examples that predate strict group typing.
Related errors
- group type is required
- group type must be Array, Hash, JSON or Array[JSON]
- group type must be Array, Hash, JSON or Array[JSON]
- type #{type} should support coercion via `[]`
- #declared is not available prior to parameter validation
AI-assisted analysis of ruby-grape/grape@22d7975629 (2026-08-21).
Data as JSON: /api/errors/28fc24ddc3a2157c.
Report an issue: GitHub.