{"record":{"id":"662d8e9f4d5ce0cc","repo":"ruby-grape/grape","slug":"group-type-must-be-array-hash-json-or-array-json-662d8e","errorCode":null,"errorMessage":"group type must be Array, Hash, JSON or Array[JSON]","messagePattern":"group type must be Array, Hash, JSON or Array\\[JSON\\]","errorType":"exception","errorClass":"Grape::Exceptions::UnsupportedGroupType","httpStatus":null,"severity":"error","filePath":"lib/grape/validations/params_scope.rb","lineNumber":283,"sourceCode":"\n      def validate_attributes(attrs, **opts, &block)\n        opts[:type] ||= Array if block\n        validates(attrs, opts)\n      end\n\n      # Returns a new parameter scope, subordinate to the current one and nested\n      # under the given element.\n      # @param element [Symbol] the parameter name under which this scope is nested\n      # @param type [Class] the type governing this scope\n      # @param as [Symbol, nil] optional renamed name for the element\n      # @param optional [Boolean] whether the parameter this scope is nested under\n      #   is optional or not (and hence, whether this block's params will be).\n      # @yield parameter scope\n      def new_scope(element, type:, as:, optional: false, &)\n        # if required params are grouped and no type or unsupported type is provided, raise an error\n        if element && !optional\n          raise Grape::Exceptions::MissingGroupType if type.nil?\n          raise Grape::Exceptions::UnsupportedGroupType unless Grape::Validations::Types.group?(type)\n        end\n\n        self.class.new(\n          api: @api,\n          element:,\n          element_renamed: as,\n          parent: self,\n          optional:,\n          type: type || Array,\n          group: @group,\n          &\n        )\n      end\n\n      # Returns a new parameter scope, not nested under any current-level param\n      # but instead at the same level as the current scope.\n      # @param dependent_on [Symbol] if given, specifies that this scope should\n      #   only validate if this parameter from the above scope is present","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/ruby-grape/grape/blob/22d7975629846a3c0c7bd2b34e140a7a1b4af8f6/lib/grape/validations/params_scope.rb#L265-L301","documentation":"For a required parameter group, new_scope validates the declared type with Grape::Validations::Types.group? - only Array, Hash, JSON, and Array[JSON] can govern a block scope. Any other type (String, Integer, a custom class) raises Grape::Exceptions::UnsupportedGroupType ('group type must be Array, Hash, JSON or Array[JSON]') because Grape cannot interpret the block's members inside that container.","triggerScenarios":"`requires :tags, type: String do ... end`. `requires :items, type: Integer do ... end`. `requires :meta, type: SomeCustomClass do ... end` where the class is not one of the four group types.","commonSituations":"Changing a scalar parameter into a nested group but keeping the old scalar type. Mixing up `type: Array[String]` (valid only without a block) with block-based member declarations. Adapting examples with the wrong container type.","solutions":["Use a group type: `type: Hash`, `type: Array`, `type: JSON`, or `type: Array[JSON]`.","Remove the block if the parameter is a scalar or scalar array: `requires :tags, type: Array[String]`.","For JSON payloads use `type: JSON` and declare members in the block."],"exampleFix":"# before\nrequires :tags, type: String do\n  requires :name, type: String\nend # raises UnsupportedGroupType\n\n# after\nrequires :tags, type: Array do\n  requires :name, type: String\nend\n\n# scalar array without a block\nrequires :tags, type: Array[String]","handlingStrategy":"type-guard","validationCode":"def group_type_ok?(type) = Grape::Validations::Types.group?(type)\n\nraise ArgumentError, 'block params need Array, Hash, JSON or Array[JSON]' unless group_type_ok?(declared_type)","typeGuard":"def group_type?(type) = Grape::Validations::Types.group?(type)","tryCatchPattern":null,"preventionTips":["Blocks only with group types; scalars and Array[Scalar] without blocks.","When converting a scalar param to a group, change the type in the same edit.","Boot specs per endpoint catch UnsupportedGroupType early."],"tags":["grape","params","requires","group-type","type-declaration"],"backgroundTag":"unsupported-group-type","analyzedSha":"22d7975629846a3c0c7bd2b34e140a7a1b4af8f6","analyzedAt":"2026-08-21T17:03:54.627Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}