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

Nested exposure double-exposes a field #57

Closed
Nerian opened this issue Feb 14, 2014 · 3 comments
Closed

Nested exposure double-exposes a field #57

Nerian opened this issue Feb 14, 2014 · 3 comments
Labels

Comments

@Nerian
Copy link
Contributor

Nerian commented Feb 14, 2014

Hi,

class Thing
  def something
    'hello'
  end
end

class Thing::Entity < Grape::Entity
  expose :fields do
    expose :something
  end
end

returns: 

{
  "thing": {
    "fields": {
      "something": "hello"
    },
    "something": "hello"
  }
}

I would expect:

{
  "thing": {
    "fields": {
      "something": "hello"
    },
  }
}

Is this the expected behaviour? How can I get what I want?

I am using master

@dblock
Copy link
Member

dblock commented Feb 16, 2014

It should do what you expect. Can you please share code that reproduces the problem?

@dblock dblock added the bug? label Feb 16, 2014
@Nerian
Copy link
Contributor Author

Nerian commented Feb 16, 2014

Sure here it is:

  example  gem list | grep grape       
grape (0.6.1)
grape-entity (0.4.1)

#config.ru

require 'grape'
require 'grape-entity'

class Thing
  def something
    'hello'
  end
end

class Thing::Entity < Grape::Entity
  expose :fields do
    expose :something
  end
end

module Twitter
  class App < Grape::API

    get :some_action do
      present :thing, Thing.new
    end

  end
end

run Twitter::App

Do rackup and go to http://localhost:9292/some_action.json

You should see:

{
  "thing":
  {
    "fields": { "something":"hello" },
    "something":"hello"
  }
}

@dblock
Copy link
Member

dblock commented Feb 16, 2014

Unless I am missing something, I think it's most definitely a bug with nested exposures. If you want to be helpful, write a test within grape-entity for this. Maybe you can also fix it :)

@dblock dblock added bug and removed bug? labels Feb 16, 2014
Nerian added a commit to Nerian/grape-entity that referenced this issue Feb 17, 2014
Nerian added a commit to Nerian/grape-entity that referenced this issue Feb 17, 2014
Nerian added a commit to Nerian/grape-entity that referenced this issue Feb 17, 2014
@dblock dblock closed this as completed in a7f459f Mar 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants