Grape DSL: Return different entities
Open
Nobody has claimed this yet.
feature request
needs info
- Dominant language
- Ruby
- Stars
- 10k
- Forks
- 1.2k
- Avg merge
- 14h 38m
- Merged PRs (30d)
- 92
Description
Consider an API endpoint which returns a different entity depending on the current user. Is it possible to specify those different return entities in Grape DSL? Something like the following?
desc 'Return user details' do
success Entities::BasicUser, Entities::FullUser
end
get 'users' do
if is_admin
present users, with: Entities::FullUser
else
present users, with: Entities::BasicUser
end
end
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the Grape DSL handling for success declarations and the entity selection used by present. Compare how the example's Entities::BasicUser and Entities::FullUser would be represented for one endpoint. Done means determining and documenting or implementing a supported way to declare different return entities based on the current user.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100