# Buggy code
def get_serializer_fields(self, path, method, callback, view):
    """
    Return a list of `coreapi.Field` instances corresponding to any
    request body input, as determined by the serializer class.
    """
    if method not in ("PUT", "PATCH", "POST"):
        return []

    fields = []

    serializer_class = view.get_serializer_class()
    serializer = serializer_class()

    if isinstance(serializer, serializers.ListSerializer):
        return coreapi.Field(name="data", location="body", required=True)

    if not isinstance(serializer, serializers.Serializer):
        return []

    for field in serializer.fields.values():
        if field.read_only:
            continue
        required = field.required and method != "PATCH"
        field = coreapi.Field(name=field.source, location="form", required=required)
        fields.append(field)

    return fields


# Traceback (AttributeError)
Traceback (most recent call last):
File "/home/ashish/Env/backend/lib/python3.4/site-packages/django/core/handlers/base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "/home/ashish/Env/backend/lib/python3.4/site-packages/django/core/handlers/base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/ashish/Env/backend/lib/python3.4/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/home/ashish/Env/backend/lib/python3.4/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/home/ashish/Env/backend/lib/python3.4/site-packages/rest_framework/views.py", line 466, in dispatch
response = self.handle_exception(exc)
File "/home/ashish/Env/backend/lib/python3.4/site-packages/rest_framework/views.py", line 463, in dispatch
response = handler(request, *args, **kwargs)
File "/home/ashish/Env/backend/lib/python3.4/site-packages/rest_framework/decorators.py", line 52, in handler
return func(*args, **kwargs)
File "/home/ashish/Projects/backend/oyster/config/swagger.py", line 7, in schema_view
generator = schemas.SchemaGenerator(title='Bookings API')
File "/home/ashish/Env/backend/lib/python3.4/site-packages/rest_framework/schemas.py", line 74, in __init__
self.endpoints = self.get_api_endpoints(patterns)
File "/home/ashish/Env/backend/lib/python3.4/site-packages/rest_framework/schemas.py", line 128, in get_api_endpoints
prefix=path_regex
File "/home/ashish/Env/backend/lib/python3.4/site-packages/rest_framework/schemas.py", line 121, in get_api_endpoints
link = self.get_link(path, method, callback)
File "/home/ashish/Env/backend/lib/python3.4/site-packages/rest_framework/schemas.py", line 196, in get_link
fields += self.get_serializer_fields(path, method, callback, view)
File "/home/ashish/Env/backend/lib/python3.4/site-packages/rest_framework/schemas.py", line 256, in get_serializer_fields
serializer_class = view.get_serializer_class()
AttributeError: 'LogoutView' object has no attribute 'get_serializer_class'

# Fixed code
def get_serializer_fields(self, path, method, callback, view):
    """
    Return a list of `coreapi.Field` instances corresponding to any
    request body input, as determined by the serializer class.
    """
    if method not in ("PUT", "PATCH", "POST"):
        return []

    fields = []

    if not (
        hasattr(view, "get_serializer_class")
        and callable(getattr(view, "get_serializer_class"))
    ):
        return []

    serializer_class = view.get_serializer_class()
    serializer = serializer_class()

    if isinstance(serializer, serializers.ListSerializer):
        return coreapi.Field(name="data", location="body", required=True)

    if not isinstance(serializer, serializers.Serializer):
        return []

    for field in serializer.fields.values():
        if field.read_only:
            continue
        required = field.required and method != "PATCH"
        field = coreapi.Field(name=field.source, location="form", required=required)
        fields.append(field)

    return fields