Rails is so magical that I need help from someone who knows a little better than I do.
Since I have a lot of crud API basic endpoints repeated over and over I decided to automate their creations (see my final post in the following github issue).
For the sake of having some basic valid swagger documentation I automated also the creation of the Grape::Entities by adding some custom code to my ApplicationRecord (see github SOLUTION snippet added to this question: Inheriting class definition from parent class).
With the above 2 customizations I can create API endpoint by simply doing:
V1::Base.show Book
The above method will create an endpoint and it will use the automagically created Entity like so that it gets automagically documented with default values that can be overridden later on if needed in the Book model class:
Book::Entity
There is 1 exception when the above code seems to break: it seems that whenever I interact in an early state during the bootstrap of my Rails application (initializers for example), when I call V1::Base.show Book
(to create the api endpoint) which calls Book::Entity
the following error is returned:
NameError: uninitialized constant Book::Entity
Could anybody give me a hint on what it could be? the early interaction with the model can be a simple Book.all, it smells like a thread issue.