question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Configurable camelizing type values

See original GitHub issue

As was discovered in PR https://github.com/yury-dymov/json-api-normalizer/pull/33 there is potential issue with camelizing type’s values inside relationships data objects.

Despite camelizing option explicitly called: camelizeKeys: true it’s affecting type values too. It will be great to have separate configurable option to camelize type values.

Input:

const json = {
  data: [
    {
      type: 'post',
      relationships: {
        'rel1-to-camelize': {
          data: [
            {
              id: 4,
              type: 'type1-to-camelize',
            },
          ],
        },
      },
      id: 2620,
    },
  ],
};

Output:

const output = {
  post: {
    2620: {
      type: 'post',
      id: 2620,
      relationships: {
        rel1ToCamelize: {
          data: [
            {
              id: 4,
              type: 'type1ToCamelize',
            },
          ],
        },
      },
    },
  },
};

In my point of view this should work by this way:

result = normalize(json, {
    camelizeKeys: true,
    camelizeTypeValues: true,
});

And camelizeTypeValues should be in false state by default.

This is breaking change

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
yury-dymovcommented, Feb 15, 2018

Thank you for the help 😃

0reactions
antonkomarevcommented, Feb 15, 2018

I agree that consistency is important. And additionally there could be case when you need to compare type value with the resources stored in your local repository by their type key. And since they are both camelized by default this will be easier then.

Read more comments on GitHub >

github_iconTop Results From Across the Web

camelize - MuleSoft Documentation
camelize (text: String): String. Returns a string in camel case based on underscores in the string. All underscores are deleted, including any underscores...
Read more >
Phoenix.Naming — Phoenix v1.6.15 - HexDocs
Functions ; camelize(value). Converts a string to camel case. ; camelize(value, atom) ; humanize(atom). Converts an attribute/form field into its humanize version.
Read more >
Don't camelize field names by default · Issue #1707 - GitHub
When migrating from v1.7 syntax to v1.8 class syntax I discovered that the name attribute on an instance of Field was being camelized....
Read more >
String - Rails API
By default, camelize converts strings to UpperCamelCase. If the argument to camelize is set to :lower then camelize produces lowerCamelCase.
Read more >
Rails - Serialize Model to JSON with camelize - Stack Overflow
Put it in values = hash.map do |key, value| Minor change, just thought I'd mention it. – joshfindit. Jun 1, 2016 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found