Closed npatmaja closed 8 years ago
The kebab case was a default of the jsonapi-serializer, we now by default don't change the casing, since there is no prefered casing expressed by the JSONAPI standard.
If you want this to be your default, you could do:
const ChangeCase = require('change-case');
const Mapper = require('jsonapi-mapper');
const URL = 'http://localhost:3000';
// Mapper instance
const mapper = new Mapper.Bookshelf(URL, { keyForAttribute: ChangeCase.paramCase });
@jamesdixon, what do you think of this? Should kebab / param case be the default or doing nothing is the right thing here?
@chamini2 the JSON API spec doesn't specify one way or the other, but all of their examples use kebab-case. It's also the serializer default. My suggestion is that we do nothing here and as you've shown, allow users to make their own decisions in this regard.
@npatmaja I just noticed that you said that your fields changed from kebab-case to snake_case in beta7. Just wanted to double check that your wording was correct? If that truly is the case, there might be an issue, but as @chamini2 mentioned, we don't tamper with the casing -- we leave that up to the user to specify.
@jamesdixon yes, I have tests that asserts the resulting object to contain correct attributes, which uses kebab-case. However, when I updated to beta 7 today, my tests failed and it turned out the attributes were in snake_case, but when I downgraded it to beta 6 again, the tests passed, without changing any code (except package.json)
As @chamini2 mentioned, an option to select a case will work if this behaviour is intentional.
@npatmaja thanks for the follow up.
@chamini2 not sure if that was an intentional change or not?
It wasn't intentional, to be honest, but it makes sense to let it as a user's decision. Maybe we could use that new Mapper.Bookshelf
options object as default behaviours to be passed by the user, and then they can overwrite a default behaviour by passing the same option in the .map
options object?
@chamini2 I believe that makes a lot of sense.
@jamesdixon @chamini2 :+1: I think we can close this issue now
Hi, I just updated to beta 7 and I notice that the attributes fields changed from kebab case to snake case, which broke my project. For example my table column is
transaction_status
and in beta 6 and prior it is mapped totransaction-status
but in beta 7 it is mapped totransaction_status
. Is this behavior intentional?