Repository: django-json-api/django-rest-framework-json-api

Issue:
Error raised when sending OPTIONS request to relationship view
Hi.
I'm trying to send an OPTIONS request to a relationship view and the server raises a `RuntimeError` saying `ResourceIdentifierObjectsSerializer must be initialized with a model class`. I took a look in the code and I don't see how `RelationshipView` may specify the model class explicitly or implicitly. I don't have too much experience with the package itself so could someone please take a look at this?


Discussion:
See [the declaration of ResourceIdentifierObjectSerializer](https://github.com/django-json-api/django-rest-framework-json-api/blob/master/rest_framework_json_api/serializers.py#L30-L34) where it looks like the `model_class` and `instance` have to be provided as an optional argument. In the debugger, neither is set. I'm not quite sure where that is supposed to happen. Will try to find it.

The is based on iterating through a RelationShipView's fields which was happening because I was
trying to use coreapi `rest_framework.schemas.get_schema_view`.

The relevant call tree is:

[rest_framework.GenericAPIView.get_serializer](https://github.com/encode/django-rest-framework/blob/master/rest_framework/generics.py#L105)
[rest_framework.AutoSchema.get_serializer_fields](https://github.com/encode/django-rest-framework/blob/master/rest_framework/schemas/inspectors.py#L301)



I added a serializer_class and this appears to have fixed it:
```python
class WidgetRelationshipView(RelationshipView):
    queryset = Widget.objects
    serializer_class = WidgetSerializer # <<<--- add this
    self_link_view_name = 'widget-relationships'
```
But the response for coreapi and swagger are both based on application/json and not application/vnd.api+json so it's the coreapi schema, not jsonapi's.

Resolving patch:
diff --git a/rest_framework_json_api/serializers.py b/rest_framework_json_api/serializers.py
--- a/rest_framework_json_api/serializers.py
+++ b/rest_framework_json_api/serializers.py
@@ -29,10 +29,8 @@ class ResourceIdentifierObjectSerializer(BaseSerializer):
 
     def __init__(self, *args, **kwargs):
         self.model_class = kwargs.pop('model_class', self.model_class)
-        if 'instance' not in kwargs and not self.model_class:
-            raise RuntimeError(
-                'ResourceIdentifierObjectsSerializer must be initialized with a model class.'
-            )
+        # this has no fields but assumptions are made elsewhere that self.fields exists.
+        self.fields = {}
         super(ResourceIdentifierObjectSerializer, self).__init__(*args, **kwargs)
 
     def to_representation(self, instance):


Test patch:
diff --git a/example/tests/test_views.py b/example/tests/test_views.py
--- a/example/tests/test_views.py
+++ b/example/tests/test_views.py
@@ -274,6 +274,39 @@ def test_new_comment_data_patch_to_many_relationship(self):
 
         assert Comment.objects.filter(id=self.second_comment.id).exists()
 
+    def test_options_entry_relationship_blog(self):
+        url = reverse(
+            'entry-relationships', kwargs={'pk': self.first_entry.id, 'related_field': 'blog'}
+        )
+        response = self.client.options(url)
+        expected_data = {
+            "data": {
+                "name": "Entry Relationship",
+                "description": "",
+                "renders": [
+                    "application/vnd.api+json",
+                    "text/html"
+                ],
+                "parses": [
+                    "application/vnd.api+json",
+                    "application/x-www-form-urlencoded",
+                    "multipart/form-data"
+                ],
+                "allowed_methods": [
+                    "GET",
+                    "POST",
+                    "PATCH",
+                    "DELETE",
+                    "HEAD",
+                    "OPTIONS"
+                ],
+                "actions": {
+                    "POST": {}
+                }
+            }
+        }
+        assert response.json() == expected_data
+
 
 class TestRelatedMixin(APITestCase):