reprah/grape-raketasks

Filter mounted APIs

Closed this issue · 4 comments

Example:

class Base < Grape::API
  mount Mounted
end

Seems like I cannot use rake grape_raketasks:routes GRAPE_API=mounted =>
You don't have any Grape routes defined!

Sorry about that! I made some heavy assumptions about how people name their Grape APIs and filtered according to them. The task was looking for a Grape API called Mounted::API. This will have to change.

My first approach for a fix will be to check if the filter (what GRAPE_API gets set to), turned into a class name, is a subclass of Grape::API. If it is, I'll return the routes belonging to that API. I will also have to consider the case where two APIs have the same name but are nested within different modules.

I'll keep you updated. Thanks!

@dm1try, what happens now after doing a bundle update/gem update for grape-raketasks and running rake grape_raketasks:routes API=Mounted or API=Base::Mounted? Does it filter correctly?

Thanks!

@reprah , after update I have some error.
Run bundle exec rake grape_raketasks:routes and get

rake aborted!
LoadError: Expected ...projects/.../app/api/helpers/session_helper.rb to define SessionHelper

Sorry 😊

Btw, already fixed, I checked on the same project.
Not sure maybe it was my fault :)