active_model_serializers icon indicating copy to clipboard operation
active_model_serializers copied to clipboard

Preserve path when string is camelized

Open sineed opened this issue 9 years ago • 2 comments
trafficstars

Purpose

In my project I have some cases when I need to make a POST request with nested data. The following data may be provided:

{
  "data": {
    "type": "offers",
    "attributes": {
      "bid": { "amount": 1.12, "currency": "USD" }
    }
  }
}

Bid attribute may have validation errors so the response should provide this information:

{
  "errors": [
    { "source": { "pointer": "/data/attributes/bid/amount" }, "detail": "too_low" }
  ]
}

But when I use camel key transformation I receive /data/attributes/bid::Amount instead of /data/attributes/bid/amount

This PR fixes this behavior for camel and camel_lower key transformations

Changes

In camel and camel_lower key transformations

Caveats

I saw work at https://github.com/rails-api/active_model_serializers/pull/1928 and introduction of case_transform. I can make PR to this gem also.

Related GitHub issues

#1928

Additional helpful information

sineed avatar Nov 22 '16 08:11 sineed

@sineed, thanks for your PR! By analyzing the history of the files in this pull request, we identified @remear, @dubadub and @iancanderson to be potential reviewers.

mention-bot avatar Nov 22 '16 08:11 mention-bot

So the value is being transformed? that doesn't seem right

bf4 avatar May 01 '17 05:05 bf4