Repository: encode/django-rest-framework

Issue:
Schema generator ignores detail_route and list_route overrides of serializer_class 
## Checklist
- [x] I have verified that that issue exists against the `master` branch of Django REST framework.
- [x] I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
- [x] This is not a usage question. (Those should be directed to the [discussion group](https://groups.google.com/forum/#!forum/django-rest-framework) instead.)
- [x] This cannot be dealt with as a third party library. (We prefer new functionality to be [in the form of third party libraries](http://www.django-rest-framework.org/topics/third-party-resources/#about-third-party-packages) where possible.)
- [x] I have reduced the issue to the simplest possible case.
- [x] I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)
## Steps to reproduce

``` python
class ExampleSerializer(serializers.Serializer):
    a = serializers.CharField(required=True)
    b = serializers.CharField(required=False)

class AnotherSerializer(serializers.Serializer):
    c = serializers.CharField(required=True)
    d = serializers.CharField(required=False)

class ExampleViewSet(ModelViewSet):
    serializer_class = ExampleSerializer

    @detail_route(methods=['post'], serializer_class=AnotherSerializer)
    def custom_action(self, request, pk):
        return super(ExampleSerializer, self).retrieve(self, request)
```
## Expected behavior

Fields `c` and `d` from `AnotherSerializer` in generated schema.
## Actual behavior

Fields `a` and `b` from `ExampleSerializer` - serializer of viewset itself.



Discussion:

Resolving patch:
diff --git a/rest_framework/schemas.py b/rest_framework/schemas.py
--- a/rest_framework/schemas.py
+++ b/rest_framework/schemas.py
@@ -195,6 +195,8 @@ def get_link(self, path, method, callback):
         Return a `coreapi.Link` instance for the given endpoint.
         """
         view = callback.cls()
+        for attr, val in getattr(callback, 'initkwargs', {}).items():
+            setattr(view, attr, val)
 
         fields = self.get_path_fields(path, method, callback, view)
         fields += self.get_serializer_fields(path, method, callback, view)
diff --git a/rest_framework/viewsets.py b/rest_framework/viewsets.py
--- a/rest_framework/viewsets.py
+++ b/rest_framework/viewsets.py
@@ -97,6 +97,7 @@ def view(request, *args, **kwargs):
         # generation can pick out these bits of information from a
         # resolved URL.
         view.cls = cls
+        view.initkwargs = initkwargs
         view.suffix = initkwargs.get('suffix', None)
         view.actions = actions
         return csrf_exempt(view)


Test patch:
diff --git a/tests/test_schemas.py b/tests/test_schemas.py
--- a/tests/test_schemas.py
+++ b/tests/test_schemas.py
@@ -5,6 +5,7 @@
 
 from rest_framework import filters, pagination, permissions, serializers
 from rest_framework.compat import coreapi
+from rest_framework.decorators import detail_route
 from rest_framework.response import Response
 from rest_framework.routers import DefaultRouter
 from rest_framework.schemas import SchemaGenerator
@@ -27,12 +28,21 @@ class ExampleSerializer(serializers.Serializer):
     b = serializers.CharField(required=False)
 
 
+class AnotherSerializer(serializers.Serializer):
+    c = serializers.CharField(required=True)
+    d = serializers.CharField(required=False)
+
+
 class ExampleViewSet(ModelViewSet):
     pagination_class = ExamplePagination
     permission_classes = [permissions.IsAuthenticatedOrReadOnly]
     filter_backends = [filters.OrderingFilter]
     serializer_class = ExampleSerializer
 
+    @detail_route(methods=['post'], serializer_class=AnotherSerializer)
+    def custom_action(self, request, pk):
+        return super(ExampleSerializer, self).retrieve(self, request)
+
 
 class ExampleView(APIView):
     permission_classes = [permissions.IsAuthenticatedOrReadOnly]
@@ -120,6 +130,16 @@ def test_authenticated_request(self):
                             coreapi.Field('pk', required=True, location='path')
                         ]
                     ),
+                    'custom_action': coreapi.Link(
+                        url='/example/{pk}/custom_action/',
+                        action='post',
+                        encoding='application/json',
+                        fields=[
+                            coreapi.Field('pk', required=True, location='path'),
+                            coreapi.Field('c', required=True, location='form'),
+                            coreapi.Field('d', required=False, location='form'),
+                        ]
+                    ),
                     'update': coreapi.Link(
                         url='/example/{pk}/',
                         action='put',