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

Changing root to model class name #998

Merged

Conversation

joaomdmoura
Copy link
Member

As I mentioned on #986

Another change I might do is to define the root key based on the model name and not on the serializer one.

This basically changes the default root used on Json Adapter to be the resource class name instead of the serializer's name.

This is also a prerequisite to other PRs.

example:

This serializer:

class FooBarCommentSerializer < ActiveModel::Serializer
  attributes :content
end

resulted on this response (using json aadapter):

{
  foo_bar_comment: {
    content: 'ZOMG a comment'
  }
}

now it results:

{
  comment: {
    content: 'ZOMG a comment'
  }
}

@bf4
Copy link
Member

bf4 commented Jul 14, 2015

I'm somewhat concerned that this appears to be a breaking change in that many tests needed to be changed. However, I've lost track of if this is a 0.10 issue, so maybe it's ok in the rc?

@joaomdmoura
Copy link
Member Author

@bf4 yeap, this is might impact some ppl updating to 0.10.x, but we already know that upgrading from older version won't be easy, there a lot of other breaking changes, and use the resource class name seems the right thing, it helps user to keep a pattern. Do you have any thoughts about it? 😄

@bf4
Copy link
Member

bf4 commented Jul 14, 2015

I guess I'd like to see some kind of changelog or doc for how the same resource will be rendered given different ams versions (and adapters), but not sure how practical that is.

@bf4
Copy link
Member

bf4 commented Jul 14, 2015

That said, I suppose, that in all the changed tests, the new expectation appears more correct and less surprising from a hypermedia point of view. e.g. PostWithComments should still have a root key of post(s), not 'post(s)_with_comments'

@joaomdmoura
Copy link
Member Author

totally agree @bf4, I think the new doc structure I'm about to merge (the one we have being working on at #994) will be the right place to do it, after we merge it.

The new expectation appears more correct and less surprising from a hypermedia point of view

Awesome! 😄

@joaomdmoura joaomdmoura force-pushed the changing_root_to_model_class_name branch from ec5a3cf to bf24c16 Compare July 23, 2015 06:10
@joaomdmoura joaomdmoura force-pushed the changing_root_to_model_class_name branch from bf24c16 to 9817a5b Compare July 23, 2015 06:11
@joaomdmoura
Copy link
Member Author

Taking into account that:

I and also after talk to @spastorino and @bf4, that fell comfortable about this, I'm merging it.

joaomdmoura added a commit that referenced this pull request Jul 23, 2015
@joaomdmoura joaomdmoura merged commit e1c25e8 into rails-api:master Jul 23, 2015
@bf4
Copy link
Member

bf4 commented Jul 23, 2015

👍 🎆

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

Successfully merging this pull request may close these issues.

5 participants