grape-swagger icon indicating copy to clipboard operation
grape-swagger copied to clipboard

DataType.parse_entity_name() fails with Entity name as String

Open frodrigo opened this issue 9 years ago • 0 comments

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.

frodrigo avatar Jul 26 '16 07:07 frodrigo