ruby-grape / grape-swagger

Add OAPI/swagger v2.0 compliant documentation to your grape API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

enhancemnt to "add_root" feature

urkle opened this issue · comments

The new add_root feature is extremely nice and something I've been waiting for in this gem for a while.

One small issue with it is that the way it handles dynamically building the 'root' name is solely based on the response model class name. Where as, ideally what would be nice is to "detect" if said response model is a grape-entity class and query the "Root" configuration from that class.

I have several GrapeEntity classes that change the "root" to be someone slightly different than the internal class name (e.g. OrganizationMember -> 'members'/'member') so having the swagger gem consult the entity class. (e.g. simply calling OrganizationMember.root_element(root_type) where root_type is :collection_root or :root ).

This has further been made harder with the upgrade to Grape swagger 1.1.0 as now the full class-name hierarchy is used as the entity name, thus if I have things in V2::Entities::MyModel the resulting calculated "root" is v2/entities/my_model which is very incorrect. I'll be making a PR to try and see how I can best inject querying the entity model for the "root" and see how that goes.

@LeFnord Do you have any thoughts on the best way to address this issue? Initial looking at the code shows that the method that determine this doesn't have the entity class but rather only the resulting string from the entity_name calculation. So to allow my proposal here would require some refactoring of the internals to pass enough context around.