{"action":"created","issue":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1338","labels_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1338/labels{/name}","comments_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1338/comments","events_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1338/events","html_url":"https://github.com/rails-api/active_model_serializers/pull/1338","id":117938846,"number":1338,"title":"Namespaced serializers","user":{"login":"bdmac","id":47326,"avatar_url":"https://avatars.githubusercontent.com/u/47326?v=3","gravatar_id":"","url":"https://api.github.com/users/bdmac","html_url":"https://github.com/bdmac","followers_url":"https://api.github.com/users/bdmac/followers","following_url":"https://api.github.com/users/bdmac/following{/other_user}","gists_url":"https://api.github.com/users/bdmac/gists{/gist_id}","starred_url":"https://api.github.com/users/bdmac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bdmac/subscriptions","organizations_url":"https://api.github.com/users/bdmac/orgs","repos_url":"https://api.github.com/users/bdmac/repos","events_url":"https://api.github.com/users/bdmac/events{/privacy}","received_events_url":"https://api.github.com/users/bdmac/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-11-20T00:18:57Z","updated_at":"2015-11-23T12:54:14Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/1338","html_url":"https://github.com/rails-api/active_model_serializers/pull/1338","diff_url":"https://github.com/rails-api/active_model_serializers/pull/1338.diff","patch_url":"https://github.com/rails-api/active_model_serializers/pull/1338.patch"},"body":"Adds support for finding serializers based on the \"current\" serializers\r\nnamespace to support things like serializer versioning. Without this you\r\nhave to be explicit in naming which serializer to use in all of your\r\nserializer associations. That's OK usually (albeit annoying) but it\r\nbreaks polymorphism since you can't really specify the right serializer\r\nahead of time.\r\n\r\nI came across a bunch of PRs such as #1225 that talk about different\r\nversions of namespacing based on modules or controllers or whatever and\r\nsome of them even talk about supporting serializer namespaces but I have\r\nbeen unable to find one that actually does this part of it. If there is\r\nalready work being done for this, feel free to ignore this PR but we\r\nneeded this for our current work.\r\n\r\nThis PR builds on top of the work done by @beauby in #1225 to add\r\nsupport for namespaced serializer lookups. @beauby's work only allowed\r\nfor actual nesting of serializers withing a namespaced serializer (e.g.\r\nfor overrides) but did not actually walk up the tree to siblings or\r\nserializers farther up the inheritance/namespace tree.\r\n\r\nIt simply modifies `Serializer#serializer_lookup_chain_for` to add all\r\nof the possible levels of namespaces based on the current serializer.\r\nWith this patch for example if we have:\r\n```ruby\r\nclass Public::V1::PostSerializer\r\n  belongs_to :author\r\nend\r\n\r\nclass Public::V1::AuthorSerializer\r\nend\r\n```\r\nwe will wind up with the following items in the lookup chain for an\r\nauthor when serializing a Post with Public::V1::PostSerializer:\r\n```ruby\r\n['Public::V1::PostSerializer::AuthorSerializer',\r\n'Public::V1::AuthorSerializer', 'Public::AuthorSerializer',\r\n'::AuthorSerializer']\r\n```"},"comment":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/comments/158926053","html_url":"https://github.com/rails-api/active_model_serializers/pull/1338#issuecomment-158926053","issue_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1338","id":158926053,"user":{"login":"beauby","id":2215778,"avatar_url":"https://avatars.githubusercontent.com/u/2215778?v=3","gravatar_id":"","url":"https://api.github.com/users/beauby","html_url":"https://github.com/beauby","followers_url":"https://api.github.com/users/beauby/followers","following_url":"https://api.github.com/users/beauby/following{/other_user}","gists_url":"https://api.github.com/users/beauby/gists{/gist_id}","starred_url":"https://api.github.com/users/beauby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beauby/subscriptions","organizations_url":"https://api.github.com/users/beauby/orgs","repos_url":"https://api.github.com/users/beauby/repos","events_url":"https://api.github.com/users/beauby/events{/privacy}","received_events_url":"https://api.github.com/users/beauby/received_events","type":"User","site_admin":false},"created_at":"2015-11-23T12:54:14Z","updated_at":"2015-11-23T12:54:14Z","body":"Two possible solutions (for which I issued PRs at some point but they ended up in limbo):\r\n 1. Hit the controller's namespace (will be really easy to do with the whole `context` thing)\r\n 2. Hit the \"root serializer\"'s namespace, that is the one that was specified/inferred for the actual render call"}}