ruby-grape / ruby-grape/grape

Still having issues with helper inheritance

Open
#1,820 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug?
Dominant language
Ruby
Stars
10k
Forks
1.2k
Avg merge
14h 38m
Merged PRs (30d)
92

Description

I thought this was supposed to be fixed with #1665, but I am still having issues with it. I have a few classes inheriting from Grape::API and I want to avoid having to include the helpers in every endpoint class:

require "#{Rails.root}/app/api/v2/helpers/authentication_helper.rb"

module API
  module V2
    
    class Base < Grape::API
      prefix 'v2'
      format :json
    end
      
    class AuthenticatedBase < Base
       helpers ApiHelpers::AuthenticationHelper
       before { authenticate! }
    end
  
    class AdminBase < Base
      # other things in here for higher security routes
    end
    
  end
end

However, when I go to make my end point class inherit, I can't use the AuthenticationHelper methods like current_user, for example.

require "#{Rails.root}/app/api/v2/base_classes.rb"

module API
	module V2
		
		class Sensors < AuthenticatedBase

		  desc 'End-points for Sensors'
      
		  namespace :sensors do

...

Is this intended? What am I missing?

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 with app/api/v2/base_classes.rb and app/api/v2/helpers/authentication_helper.rb, then inspect the API::V2::Sensors entry point and reproduce access to current_user through AuthenticatedBase. Done means the intended inheritance behavior is established and the endpoint either receives the helper methods as expected or the missing behavior is clearly documented with coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.