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

Model routes should be dasherized, not camelized #308

Open
drauschenbach opened this issue Dec 23, 2017 · 5 comments
Open

Model routes should be dasherized, not camelized #308

drauschenbach opened this issue Dec 23, 2017 · 5 comments

Comments

@drauschenbach
Copy link

When the NewAPI().AddResource() mechanism is used to register a model with a name such as MyStruct, the route that is registered should be the dasherized my-struct. Instead, the route that is registered is the camelized myStruct. This isn't compatible with Ember Data. And in fact, Ember does not even have a convenient pathForType widget to camelize and pluralize a dasherized route, which makes this a pesky interop issue that requires hacking.

@drauschenbach
Copy link
Author

drauschenbach commented Dec 23, 2017

The JSONAPISerializer expects the backend to return a JSON API Document that follows the JSON API specification and the conventions of the examples found on http://jsonapi.org/format. This means all type names should be pluralized and attribute and relationship names should be dash-cased.

(from Ember 2.17.0 customizing-serializers)

Reading through #15 and trying to figure out where this discrepancy crept in.

@wwwdata
Copy link
Member

wwwdata commented Dec 24, 2017

You're right. But in the meantime, it is still possible to give all the fields in your structs custom names. So you could do it like in our example and give dasherized names to your fields, see:

type User struct {
ID string `json:"-"`
//rename the username field to user-name.
Username string `json:"user-name"`
PasswordHash string `json:"-"`
Chocolates []*Chocolate `json:"-"`
ChocolatesIDs []string `json:"-"`
exists bool
}

Maybe we should make this a configurable option whether people want to use the standard dasherized or camel version.

@drauschenbach
Copy link
Author

Agreed -- I'm already using dasherized field names and that is working great. This issue is specifically about the parent struct name and how it's converted to a URL/route name.

@drauschenbach
Copy link
Author

drauschenbach commented Jan 8, 2018

My colleague just pointed out EntityNamer, which looks like a way to work around this on the server side.

@xomaczar
Copy link

xomaczar commented Aug 30, 2018

If you are using ember-data, I would suggest not to dasherize your fieldNames and types, as you are adding more work for ember-data serializer - specifically to normalize your response. Ember data internally stores data in json:api format, where fieldNames are camelCase and types are singular. Ember-data Serializer was meant to be a stop gap for you to align your API, if you have control over it, which sounds like you do.

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