Skip to content

DataType.parse_entity_name() fails with Entity name as String #480

Open
@frodrigo

Description

@frodrigo

On this code raw_data_type can be a String setup by Grape itself from entity class name. The underlying parse_entity_name fails as it expects a model class.

          case raw_data_type.to_s
          when 'Boolean', 'Date', 'Integer', 'String', 'Float', 'JSON', 'Array'
            raw_data_type.to_s.downcase
          when 'Hash'
            'object'
          when 'Rack::Multipart::UploadedFile', 'File'
            'file'
          when 'Virtus::Attribute::Boolean'
            'boolean'
          when 'BigDecimal'
            'double'
          when 'DateTime', 'Time'
            'dateTime'
          when 'Numeric'
            'long'
          when 'Symbol'
            'string'
          else
            parse_entity_name(raw_data_type) # HERE ####################
          end
        end

I found a work around, but not sure that is the right way to fix it: if the model is a String then switch back to Class.

          if model.is_a?(String)
            begin
              model = model.split('::').reduce(Module, :const_get)
            rescue NameError
            end
          end

Problem come from params like this:

params {
    optional(:points, type: RequestPoint, documentation: {param_type: 'form'})
}

The problem is present in branch 0.1x and 0.2x.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions