beam-community / jsonapi

JSON:API Serializer and Query Handler for Elixir
https://hex.pm/packages/jsonapi
MIT License
495 stars 78 forks source link

Add options to transform field keys non-recursively (#132) #310

Closed protestContest closed 7 months ago

protestContest commented 7 months ago

Following up on this discussion.

This adds two new values for the config option transform_fields:

Some users may have views with fields that are maps, and don't want the map's keys dasherized or camelized. The new config values allow these users to use the transform_fields option to transform only the field names, but not the values.

Feedback is requested. I don't really like the config value names—preferably we can think of something better. If this seems like the right direction, I'll continue to update the documentation.

mattpolzin commented 7 months ago

I'm not opposed to the current naming, but since you are interested in alternative ideas: "shallow" is an alright word for what you're doing here.

mattpolzin commented 7 months ago

This seems like a good direction to go in. I'll do a more in-depth look at your implementation of expand_fields_once after you've wrapped up your first draft.

protestContest commented 7 months ago

Ok, I've updated the config values to :camelize_shallow and :dasherize_shallow and updated the docs around this config option. I also included a couple minor unrelated fixes to appease the linter.

protestContest commented 7 months ago

Totally. What do you think of expand_keys? That sounds more descriptive to me.

mattpolzin commented 7 months ago

expand_root_keys? I'm good with expand_keys too since it no longer sounds like it is as closely related to expand_fields, but expand_keys would need some code-documentation explaining that it only looks at keys in the root of the map (perhaps that documentation is useful regardless of the name).

protestContest commented 7 months ago

expand_root_keys sounds good to me, I'll update that and add some docs.

mattpolzin commented 7 months ago

I'll cut a new release shortly. https://github.com/beam-community/jsonapi/pull/311