JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Expose JSONAPI::ResourceSerializer#attribute_hash ?
まだ誰も着手していません。
- 主要言語
- Ruby
- スター
- 2.3k
- フォーク
- 546
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
Thanks for all the work on this gem. I've been using it for a new project and I really enjoy it.
For a project I'm currently working on, I have a Song model that has_one :embed. I don't want to expose the Embed model as part of the REST API. I always want to include the attributes of the embed in the response.
The JSON API format document explicitly states that says that attributes "may contain any valid JSON value" and that "complex data structures involving JSON objects and arrays are allowed as attribute values."
I propose that models specified as attributes in a resource should be serialized simply, using #attribute_hash.
For example, this is what my JSON looks like if I simply add :embed as an attribute to my SongResource
"embed": {
"id": 1,
"identifier": "1101",
"site": "youtube",
"art_content_id": 1,
"art_content_type": "Song",
"created_at": "2015-09-04T19:55:41.596Z",
"updated_at": "2015-09-04T19:55:41.596Z"
}
If it was passed through the serializer, this is what I would get. (this is what I want)
"embed": {
"identifier": "1101",
"site": "youtube"
}
Right now, I can do this by manually with code like this in my SongResource
def embed
resource = JSONAPI::Resource.resource_for @model.embed.class.to_s.underscore
serializer = JSONAPI::ResourceSerializer.new resource
serializer.send :attribute_hash, resource.new(@model.embed)
end
If you would be willing to consider a feature like this, I would be happy to put together a pull request for it
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず JSONAPI::ResourceSerializer とその private な attribute_hash エントリーポイントを読み、次に SongResource の属性とリレーションが現在どのようにシリアライズされているかを比較します。埋め込みモデルを、要求された identifier フィールドと site フィールドを含むネストされた属性としてシリアライズでき、Embed を個別のリソースとして公開せずに済むことを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- ruby
- 領域
- api, backend
- issue の種類
- 機能追加
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100