{"action":"created","issue":{"url":"https://api.github.com/repos/marcgibbons/django-rest-swagger/issues/194","labels_url":"https://api.github.com/repos/marcgibbons/django-rest-swagger/issues/194/labels{/name}","comments_url":"https://api.github.com/repos/marcgibbons/django-rest-swagger/issues/194/comments","events_url":"https://api.github.com/repos/marcgibbons/django-rest-swagger/issues/194/events","html_url":"https://github.com/marcgibbons/django-rest-swagger/issues/194","id":54985759,"number":194,"title":"problem of using swagger when I use the get_serializer_class() for dynamic serializer based on the URL's charges","user":{"login":"gufeisun","id":1175602,"avatar_url":"https://avatars.githubusercontent.com/u/1175602?v=3","gravatar_id":"","url":"https://api.github.com/users/gufeisun","html_url":"https://github.com/gufeisun","followers_url":"https://api.github.com/users/gufeisun/followers","following_url":"https://api.github.com/users/gufeisun/following{/other_user}","gists_url":"https://api.github.com/users/gufeisun/gists{/gist_id}","starred_url":"https://api.github.com/users/gufeisun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gufeisun/subscriptions","organizations_url":"https://api.github.com/users/gufeisun/orgs","repos_url":"https://api.github.com/users/gufeisun/repos","events_url":"https://api.github.com/users/gufeisun/events{/privacy}","received_events_url":"https://api.github.com/users/gufeisun/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2015-01-21T07:16:23Z","updated_at":"2015-03-17T09:25:10Z","closed_at":null,"body":"I am using django-rest-swagger for api doc generation. I would like to return different user the different part of models. So I used the `get_serializer_class()` function to use different serializer for different users by checking the `kwargs['pk']` on the url.\r\n\r\n\r\nThe `urls.py` is:\r\n\r\n    url(r'^api/users/$', views.UserEnum.as_view()),\r\n    url(r'^api/users/(?P<pk>[0-9]+)/$', views.UserDetail.as_view()),\r\n\r\nThe view that I am using is:\r\n\r\n    #List all the users or create a new user\r\n    class UserEnum(generics.ListCreateAPIView):\r\n        queryset = User.objects.all()\r\n        serializer_class = UserSerializer\r\n        permission_classes = (IsAuthenticated, IsAdminUser,)\r\n    \r\n    class UserDetail(generics.RetrieveUpdateDestroyAPIView):\r\n        queryset = User.objects.all()\r\n        #serializer_class = UserSerializer #TODO: Problem with Swagger\r\n        permission_classes = (IsAuthenticated, IsOwnerAdminOrReadOnly,)\r\n    \r\n        def get_serializer_class(self):\r\n            #swagger crash here.\r\n            user_id = int(self.kwargs['pk'])\r\n            if self.request.user.id == user_id or self.request.user.is_superuser:\r\n                serializer_class = UserSerializer\r\n            else:\r\n                serializer_class = UserProfileSerializer\r\n            return serializer_class\r\n    \r\n        def get_object(self, *args, **kwargs):\r\n            user_id = int(self.kwargs['pk'])\r\n    \r\n            if self.request.user.id == user_id or self.request.user.is_superuser:\r\n                return User.objects.get(id=user_id)\r\n            else:\r\n                return UserProfile.objects.get(user=user_id)\r\n\r\n**The above two urls work successfully without problems.** But when I type the `http://127.0.0.1:8000/api/` for generate api docs, it return the below error:\r\n\r\n    `Unable to read api 'users' from path http://127.0.0.1:8000/api/api-docs/api/users (server returned Internal Server Error)`\r\n\r\n\r\n    File \"/Users/Scofield/anaconda/lib/python2.7/site-packages/rest_framework_swagger/introspectors.py\" in ask_for_serializer_class\r\n      179.                 return view.get_serializer_class()\r\n    File \"/Users/Scofield/Dropbox/My Projects/Angels&Demons/src/doWishSites/doWishCore/views.py\" in get_serializer_class\r\n      27.         user_id = int(self.kwargs['pk'])\r\n\r\n    Exception Type: KeyError at /api/api-docs/api/users\r\n    Exception Value: 'pk'"},"comment":{"url":"https://api.github.com/repos/marcgibbons/django-rest-swagger/issues/comments/82234675","html_url":"https://github.com/marcgibbons/django-rest-swagger/issues/194#issuecomment-82234675","issue_url":"https://api.github.com/repos/marcgibbons/django-rest-swagger/issues/194","id":82234675,"user":{"login":"mcgeeco","id":5881581,"avatar_url":"https://avatars.githubusercontent.com/u/5881581?v=3","gravatar_id":"","url":"https://api.github.com/users/mcgeeco","html_url":"https://github.com/mcgeeco","followers_url":"https://api.github.com/users/mcgeeco/followers","following_url":"https://api.github.com/users/mcgeeco/following{/other_user}","gists_url":"https://api.github.com/users/mcgeeco/gists{/gist_id}","starred_url":"https://api.github.com/users/mcgeeco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcgeeco/subscriptions","organizations_url":"https://api.github.com/users/mcgeeco/orgs","repos_url":"https://api.github.com/users/mcgeeco/repos","events_url":"https://api.github.com/users/mcgeeco/events{/privacy}","received_events_url":"https://api.github.com/users/mcgeeco/received_events","type":"User","site_admin":false},"created_at":"2015-03-17T09:25:10Z","updated_at":"2015-03-17T09:25:10Z","body":"I'll be back in work tomorrow, I can show you the code then, if you like."}}