{"action":"closed","number":60,"pull_request":{"url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/pulls/60","id":64251135,"html_url":"https://github.com/fotinakis/jsonapi-serializers/pull/60","diff_url":"https://github.com/fotinakis/jsonapi-serializers/pull/60.diff","patch_url":"https://github.com/fotinakis/jsonapi-serializers/pull/60.patch","issue_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/issues/60","number":60,"state":"closed","locked":false,"title":"Sparse fieldsets","user":{"login":"smackesey","id":1531373,"avatar_url":"https://avatars.githubusercontent.com/u/1531373?v=3","gravatar_id":"","url":"https://api.github.com/users/smackesey","html_url":"https://github.com/smackesey","followers_url":"https://api.github.com/users/smackesey/followers","following_url":"https://api.github.com/users/smackesey/following{/other_user}","gists_url":"https://api.github.com/users/smackesey/gists{/gist_id}","starred_url":"https://api.github.com/users/smackesey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smackesey/subscriptions","organizations_url":"https://api.github.com/users/smackesey/orgs","repos_url":"https://api.github.com/users/smackesey/repos","events_url":"https://api.github.com/users/smackesey/events{/privacy}","received_events_url":"https://api.github.com/users/smackesey/received_events","type":"User","site_admin":false},"body":"### Problem: Sparse Fieldsets\r\n\r\n- the JSON API spec declares that access to [sparse fieldsets](http://jsonapi.org/format/#fetching-sparse-fieldsets) must be supported\r\n\r\n### Pre-Change Behavior\r\n\r\n- sparse fieldsets are not officially supported; that is, when a resource is rendered, all of its attributes/relationships are rendered unless :unless/:if hacks are declared at the Serializer class level\r\n\r\n### Post-Change Behavior\r\n\r\n- sparse fieldsets are now supported via a new option to `Serializer::serialize`: `:fields`\r\n- `:fields` should be a hash with keys corresponding to type names and values as arrays of fields (attributes and/or relationships) of that type\r\n- if the `fields` hash contains an entry for a given type, when a resource of that type (primary or sideloaded) is rendered, only attributes or relatioships that appear in the field list are included\r\n- if no `fields` hash is provided, then behavior is the same as pre-change\r\n\r\n##### Implementation\r\n\r\n- new `:fields` option for `Serializer::serialize`; default value is nil\r\n- `fields` is normalized in the same location and manner as includes, except that the fields are mapped to symbols so they can be compared with attribute names. For each key-value pair:\r\n    - if value is a `String`, split it on commas\r\n    - if value is an `Array`, convert to strings\r\n- `fields` is passed through to both the primary data `Serializer` and the `Serializer`s for any sideloaded records\r\n- `Serializer::InstanceMethods#initialize` now takes an option `:fields` (which it receives from `serialize_primary`) and sets it as an instance variable\r\n- the `@fields` instance variable is referenced in `Serializer::InstanceMethods#should_include_attr?`\r\n    - if `@fields` contains an entry (an `Array`) for `type`, it is checked for the target attribute/relationship, which is included only if it is in the `Array`\r\n    - this required adding a new argument `attr_name` to `#should_include_attr?`, so that `@fields[type]` can be checked for the name\r\n    - adding the argument required slight modifications to `#attributes`, `#has_many_relationships`, and `#has_one_relationships`, which call `#should_include_attr?`\r\n\r\n### Notes/Questions\r\n\r\n- what tests should I add?\r\n- will rebase to master when finalized\r\n- will update README when finalized\r\n- the interaction of `fields` and includes `includes` is potentially confusing: [this page](http://jsonapi.org/examples/#sparse-fieldsets) shows the proper behavior; I believe my implementation is consistent with this\r\n","created_at":"2016-03-26T22:37:00Z","updated_at":"2016-09-22T16:29:45Z","closed_at":"2016-09-22T16:29:45Z","merged_at":null,"merge_commit_sha":"64d805102fd5b6cebb656c338d4c5ec05f763dc4","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/pulls/60/commits","review_comments_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/pulls/60/comments","review_comment_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/pulls/comments{/number}","comments_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/issues/60/comments","statuses_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/statuses/61fc18421ae2b54beba053467e2289856c350d9a","head":{"label":"smackesey:sparse-fieldsets","ref":"sparse-fieldsets","sha":"61fc18421ae2b54beba053467e2289856c350d9a","user":{"login":"smackesey","id":1531373,"avatar_url":"https://avatars.githubusercontent.com/u/1531373?v=3","gravatar_id":"","url":"https://api.github.com/users/smackesey","html_url":"https://github.com/smackesey","followers_url":"https://api.github.com/users/smackesey/followers","following_url":"https://api.github.com/users/smackesey/following{/other_user}","gists_url":"https://api.github.com/users/smackesey/gists{/gist_id}","starred_url":"https://api.github.com/users/smackesey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smackesey/subscriptions","organizations_url":"https://api.github.com/users/smackesey/orgs","repos_url":"https://api.github.com/users/smackesey/repos","events_url":"https://api.github.com/users/smackesey/events{/privacy}","received_events_url":"https://api.github.com/users/smackesey/received_events","type":"User","site_admin":false},"repo":{"id":54798343,"name":"jsonapi-serializers","full_name":"smackesey/jsonapi-serializers","owner":{"login":"smackesey","id":1531373,"avatar_url":"https://avatars.githubusercontent.com/u/1531373?v=3","gravatar_id":"","url":"https://api.github.com/users/smackesey","html_url":"https://github.com/smackesey","followers_url":"https://api.github.com/users/smackesey/followers","following_url":"https://api.github.com/users/smackesey/following{/other_user}","gists_url":"https://api.github.com/users/smackesey/gists{/gist_id}","starred_url":"https://api.github.com/users/smackesey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smackesey/subscriptions","organizations_url":"https://api.github.com/users/smackesey/orgs","repos_url":"https://api.github.com/users/smackesey/repos","events_url":"https://api.github.com/users/smackesey/events{/privacy}","received_events_url":"https://api.github.com/users/smackesey/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/smackesey/jsonapi-serializers","description":"Pure Ruby readonly serializers for the JSON:API spec.","fork":true,"url":"https://api.github.com/repos/smackesey/jsonapi-serializers","forks_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/forks","keys_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/keys{/key_id}","collaborators_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/teams","hooks_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/hooks","issue_events_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/issues/events{/number}","events_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/events","assignees_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/assignees{/user}","branches_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/branches{/branch}","tags_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/tags","blobs_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/git/refs{/sha}","trees_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/git/trees{/sha}","statuses_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/statuses/{sha}","languages_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/languages","stargazers_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/stargazers","contributors_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/contributors","subscribers_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/subscribers","subscription_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/subscription","commits_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/commits{/sha}","git_commits_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/git/commits{/sha}","comments_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/comments{/number}","issue_comment_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/issues/comments{/number}","contents_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/contents/{+path}","compare_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/compare/{base}...{head}","merges_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/merges","archive_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/downloads","issues_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/issues{/number}","pulls_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/pulls{/number}","milestones_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/milestones{/number}","notifications_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/labels{/name}","releases_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/releases{/id}","deployments_url":"https://api.github.com/repos/smackesey/jsonapi-serializers/deployments","created_at":"2016-03-26T20:33:13Z","updated_at":"2016-03-26T20:33:14Z","pushed_at":"2016-03-27T01:51:37Z","git_url":"git://github.com/smackesey/jsonapi-serializers.git","ssh_url":"git@github.com:smackesey/jsonapi-serializers.git","clone_url":"https://github.com/smackesey/jsonapi-serializers.git","svn_url":"https://github.com/smackesey/jsonapi-serializers","homepage":"","size":162,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"fotinakis:master","ref":"master","sha":"1034e6fac9f925db7248e20b140bfe82dcde91db","user":{"login":"fotinakis","id":75300,"avatar_url":"https://avatars.githubusercontent.com/u/75300?v=3","gravatar_id":"","url":"https://api.github.com/users/fotinakis","html_url":"https://github.com/fotinakis","followers_url":"https://api.github.com/users/fotinakis/followers","following_url":"https://api.github.com/users/fotinakis/following{/other_user}","gists_url":"https://api.github.com/users/fotinakis/gists{/gist_id}","starred_url":"https://api.github.com/users/fotinakis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fotinakis/subscriptions","organizations_url":"https://api.github.com/users/fotinakis/orgs","repos_url":"https://api.github.com/users/fotinakis/repos","events_url":"https://api.github.com/users/fotinakis/events{/privacy}","received_events_url":"https://api.github.com/users/fotinakis/received_events","type":"User","site_admin":false},"repo":{"id":35304294,"name":"jsonapi-serializers","full_name":"fotinakis/jsonapi-serializers","owner":{"login":"fotinakis","id":75300,"avatar_url":"https://avatars.githubusercontent.com/u/75300?v=3","gravatar_id":"","url":"https://api.github.com/users/fotinakis","html_url":"https://github.com/fotinakis","followers_url":"https://api.github.com/users/fotinakis/followers","following_url":"https://api.github.com/users/fotinakis/following{/other_user}","gists_url":"https://api.github.com/users/fotinakis/gists{/gist_id}","starred_url":"https://api.github.com/users/fotinakis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fotinakis/subscriptions","organizations_url":"https://api.github.com/users/fotinakis/orgs","repos_url":"https://api.github.com/users/fotinakis/repos","events_url":"https://api.github.com/users/fotinakis/events{/privacy}","received_events_url":"https://api.github.com/users/fotinakis/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fotinakis/jsonapi-serializers","description":"Pure Ruby readonly serializers for the JSON:API spec.","fork":false,"url":"https://api.github.com/repos/fotinakis/jsonapi-serializers","forks_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/forks","keys_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/teams","hooks_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/hooks","issue_events_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/issues/events{/number}","events_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/events","assignees_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/assignees{/user}","branches_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/branches{/branch}","tags_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/tags","blobs_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/git/refs{/sha}","trees_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/statuses/{sha}","languages_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/languages","stargazers_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/stargazers","contributors_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/contributors","subscribers_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/subscribers","subscription_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/subscription","commits_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/commits{/sha}","git_commits_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/git/commits{/sha}","comments_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/comments{/number}","issue_comment_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/issues/comments{/number}","contents_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/contents/{+path}","compare_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/merges","archive_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/downloads","issues_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/issues{/number}","pulls_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/pulls{/number}","milestones_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/milestones{/number}","notifications_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/labels{/name}","releases_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/releases{/id}","deployments_url":"https://api.github.com/repos/fotinakis/jsonapi-serializers/deployments","created_at":"2015-05-08T22:14:47Z","updated_at":"2016-09-21T14:40:55Z","pushed_at":"2016-09-02T19:17:40Z","git_url":"git://github.com/fotinakis/jsonapi-serializers.git","ssh_url":"git@github.com:fotinakis/jsonapi-serializers.git","clone_url":"https://github.com/fotinakis/jsonapi-serializers.git","svn_url":"https://github.com/fotinakis/jsonapi-serializers","homepage":"","size":289,"stargazers_count":240,"watchers_count":240,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":52,"mirror_url":null,"open_issues_count":9,"forks":52,"open_issues":9,"watchers":240,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/fotinakis/jsonapi-serializers/pulls/60"},"html":{"href":"https://github.com/fotinakis/jsonapi-serializers/pull/60"},"issue":{"href":"https://api.github.com/repos/fotinakis/jsonapi-serializers/issues/60"},"comments":{"href":"https://api.github.com/repos/fotinakis/jsonapi-serializers/issues/60/comments"},"review_comments":{"href":"https://api.github.com/repos/fotinakis/jsonapi-serializers/pulls/60/comments"},"review_comment":{"href":"https://api.github.com/repos/fotinakis/jsonapi-serializers/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/fotinakis/jsonapi-serializers/pulls/60/commits"},"statuses":{"href":"https://api.github.com/repos/fotinakis/jsonapi-serializers/statuses/61fc18421ae2b54beba053467e2289856c350d9a"}},"merged":false,"mergeable":false,"mergeable_state":"dirty","merged_by":null,"comments":6,"review_comments":1,"commits":4,"additions":30,"deletions":19,"changed_files":2}}
{"actor":{"display_login":"fotinakis"}}