grape-entity
grape-entity copied to clipboard
Params not recognized by grape "declared" method
When using entity documentation as params they don't show whe calling then 'declared' method.
namespace :cdrs do
desc 'Shows all Outbound CDRs.', params: Entities::CdrSearch.documentation
params do
optional :fields, type: String
end
get :out do
authorize!
query_by(Entities::OutboundCdr, permitted_params)
end
end
permitted_params
=> {"fields"=>"asda"}
def permitted_params
@permitted_params ||= declared(params, include_missing: false, include_parent_namespaces: true)
end
Did you expect Entities::CdrSearch.documentation
to carry onto params? This would be a feature request. I do agree that there should be some way of combining probably.
Yes that was the behaviour i expected. That the declared method returned the Entities::CdrSearch.documentation merged with the other params.
Also, another thing to note: fields will appear twice in Swagger since its documented both in params hash and params block.
Any suggested workaround for this? I don't understand why there is a difference in specifying the params be it hash or block.
For anyone else with this issue, here is a quick workaround. Basically it just creates the params block for you from the entity documentation, the params then show up in the declared() method like you'd expect.
params do
Entity::User.documentation.each do |attribute_name, documentation|
eval "#{documentation[:required] ? 'requires' : 'optional' } :#{attribute_name}, type: #{documentation[:type]}"
end
end
This is how I was expecting it to work. I'd be happy to submit a pull request.
It would look something like:
params do
entity Entity::User
end
@wefarrell That would be good!