ruby-grape / ruby-grape/grape-swagger

DataType.parse_entity_name() fails with Entity name as String

Open
#480 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug?
Dominant language
Ruby
Stars
1.1k
Forks
479
Avg merge
2d 14h
Merged PRs (30d)
6

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at DataType.parse_entity_name and reproduce the failure with the RequestPoint parameter example, where the entity name is supplied as a String. Trace how String and model-class inputs are handled, then verify that String entity names parse correctly without regressing the listed primitive and file types.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api, documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.