JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Meta key_format setting

Open
#825 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
2.3k
Forks
546
PR merge metrics
No merged PRs in 30d

Description

Right now (in 0.8.0-beta2) we can use the configuration option of json_key_format to change the style of the attribute key names (dasherized, camelized, etc) but there is no way to do so for meta data!

I am suggesting we add a similar configuration option for formatting the key names of meta data. Something along the lines of json_meta_key_format.


Here is an example:

# using: config.json_key_format = :camelized_key

class UserResource < JSONAPI::Resource
  attributes :first_name, :last_name

  def meta(_options = {})
    {
      formal_name: "#{@model.last_name}, #{@model.first_name}"
    }
  end
end

Will return something like this currently:

"data": {
  "attributes": {
    "firstName": "foo",
    "lastName": "bar"
  },
  "meta": {
    "formal_name": "bar, foo"
  },
  ...
}

What I propose is a json_meta_key_format configuration, which, for example sake would return with the following when using config.json_meta_key_format = :camelized_key:

"data": {
  "attributes": {
    "firstName": "foo",
    "lastName": "bar"
  },
  "meta": {
    "formalName": "bar, foo"
  },
  ...
}

(Notice formalName instead of formal_name)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the existing json_key_format configuration and the resource meta method shown in the issue, then trace where metadata keys are serialized. Add the proposed json_meta_key_format behavior so formal_name can become formalName, and verify the generated JSON matches the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.