-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Namespace separator fix for type field in jsonapi adapter #1216
Conversation
@@ -212,7 +212,7 @@ def test_underscore_model_namespace_for_linked_resource_type | |||
expected = { | |||
related: { | |||
data: [{ | |||
type: 'spam_unrelated_links', | |||
type: 'unrelated_links', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did the expectation change here?
aside, the type should probably be spam:unrelated_links' or
spam-unrelated_links`
json-api/json-api#850 (the issue I made that the jsonapi forum references )
(aside, why is there a just confusing naming)related=
writer on Post that is important?
The idea was to reject namespace by default:
So my idea was to cut namespace by default, but type directive will be there to set it explicitly. |
For #1029 I would stick with |
@youroff agree about it's up to us, and we can create the ruby convention right here. |
After giving it a thought, I tend to agree with @bf4. A user that uses namespaces should know what they are doing, and overriding the type with |
Honestly, BTW, not related to this one, but I discovered recently while playing with ember, that by default it generates attribute names dasherized, and not underscored for payload. Not sure if it's explicitly stated in standard, but the point is that when we use ams with ember the keys are transferred differently encoded for inbound and outbound packets. And the payload for server doesn't seem to be ready for rails because of that, so I got a thought — are there deserializers for AR? Could AMS solve this issue be providing some wrapper for strong parameters? |
@youroff Let's comply with JSON API for now. If they change the spec, we can always change AMS then. Considering deserializers, it's a WIP, it's kinda almost ready, but we need to discuss a few things before rebasing/pushing it. |
See linked issue, ember is 'wrong' |
You mean that it doesn't convert |
No, that ember uses |
Does ember support namespaced models or it uses it somehow else? |
Btw, what if we add setting for separator? So that anyone will be able to change it to |
legit.. new global config |
Looks like we lost sight of this. Is a good PR. @youroff Would you like to rebase and we'll finish it up? |
Sorry, missed that on holidays... Sure, will take a look at it soon. What's the final decision on how we deal with namespaces? |
|
Well, in our app we use the same model in the different ways. For example, there is a User -> Membership -> Dealership relation. And Membership reflects into two different Ember models: one ProfileMembership — is a light version to be attachable to profile (and loadable with). So it's something used throughout the site to adjust current user's experience, and another Memebership is manageable by dealership Admin. It contains various additional fields, which are used on the backend. Currently I use type directive to set type explicitly inside of different serializers and having option to derive type name from the name of serializer would make the code a bit cleaner. So I believe it's not that unique a use case and having an option (with taking type from the model as a default) wouldn't hurt anyone, what do you think? And it's pretty easy to implement, I believe I've done some sketch of it already. So for namespace, we'll have a setting for separator with '--' as default, right? Btw, what's the way of using namespaces on the side of Ember? If you have some example in mind, could you point out? |
Here's more generic example... Let's say we have Post model. It may have title, intro, body, lots of metadata. Though in a news feed we only need title and intro. So that would be PostPreview on ember's end. And when user wants to read whole article it would load Post model. Sure we could implement fields parameter, but the approach seems cleaner. Also, not sure about now, but when ember was about version 1-something, it would take record from the store by default, so once loaded reduced record, it wouldn't reload it when called with findRecord. |
I think we need to wait for the JSON API spec to decide on what to do about namespaces, yeah? |
In 1.0 it is up to us. See linked issue I made re 'kebab' case in the json api repo |
Can we make a decision on this? |
Actually, I would commit some time to fix that if we have a decission. Just ran into the need of namespace separator compatible with Ember. @bf4? |
I'm late to this conversation, but I'm fine with either |
I think all agree that we need some global setting for json-api adapter and the last question is what would be the default. |
Closing in favor of #16009 |
This PR removes namespace from automatically generated
type
field.Discussion's going on here:
http://discuss.jsonapi.org/t/convention-for-namespacing-type/99