Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grape DSL: Return different entities #1513

Open
Razer6 opened this issue Oct 27, 2016 · 2 comments
Open

Grape DSL: Return different entities #1513

Razer6 opened this issue Oct 27, 2016 · 2 comments

Comments

@Razer6
Copy link
Contributor

Razer6 commented Oct 27, 2016

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
@dblock
Copy link
Member

dblock commented Oct 28, 2016

Generally I don't recommend APIs that return two different things. But I think this should be possible - give it a try, if not it should be a feature request.

@LeFnord
Copy link
Member

LeFnord commented Oct 28, 2016

short answer: actual it isn't possible, and it isn't recommended
longer answer: it should not be possible

why not?
have in mind what this means …
a logic would be implemented for this feature, ok
but this logic must also be handled on the consumer and documentation side,
cause it is common sense to expect one resource and changes,
which removes common behaviour are breaking changes,
means exactly: please make also feature request for:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants