Closed
Description
Hi.
Thanks for this library. It works great.
I'm trying to get it to work with Django Rest Swagger but error message Exception Value: ResourceIdentifierObjectsSerializer must be initialized with a model class.
keeps coming up. You'll find the traceback below.
This is happening at this piece of code:
class SwaggerSchemaView(APIView):
"""
Configuration view to generate API documentation using the
django-rest-swagger library.
"""
permission_classes = [IsAuthenticated]
renderer_classes = [
renderers.OpenAPIRenderer,
renderers.SwaggerUIRenderer
]
def get(self, request):
generator = SchemaGenerator(title='Condo API')
schema = generator.get_schema(request=request) # <--- Error happens here
return Response(schema)
Important points:
- Django Rest Swagger is working fine when not rendering views where DJA is used;
- I'm using the
url
trick as pointed out in DJA documentation to show the self URL. - I'm also using ResourceRelatedField to render related resources link.
Can anyone help shed some light into this?
EDIT:
After taking out the RelationshipView
s from the api url patterns, it worked. So, it would seem the RelationshipView
is where incompatibility with Django Rest Swagger resides. Keeping the url
field does not result in an exception.
Traceback:
File "/opt/conda/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
39. response = get_response(request)
File "/opt/conda/lib/python3.5/site-packages/django/core/handlers/base.py" in _legacy_get_response
249. response = self._get_response(request)
File "/opt/conda/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "/opt/conda/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/conda/lib/python3.5/site-packages/django/views/decorators/csrf.py" in wrapped_view
58. return view_func(*args, **kwargs)
File "/opt/conda/lib/python3.5/site-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/opt/conda/lib/python3.5/site-packages/rest_framework/views.py" in dispatch
477. response = self.handle_exception(exc)
File "/opt/conda/lib/python3.5/site-packages/rest_framework/views.py" in handle_exception
437. self.raise_uncaught_exception(exc)
File "/opt/conda/lib/python3.5/site-packages/rest_framework/views.py" in dispatch
474. response = handler(request, *args, **kwargs)
File "/usr/src/app/src/config/views.py" in get
21. schema = generator.get_schema(request=request)
File "/opt/conda/lib/python3.5/site-packages/rest_framework/schemas.py" in get_schema
242. links = self.get_links(request)
File "/opt/conda/lib/python3.5/site-packages/rest_framework/schemas.py" in get_links
273. link = self.get_link(path, method, view)
File "/opt/conda/lib/python3.5/site-packages/rest_framework/schemas.py" in get_link
372. fields += self.get_serializer_fields(path, method, view)
File "/opt/conda/lib/python3.5/site-packages/rest_framework/schemas.py" in get_serializer_fields
472. serializer = view.get_serializer()
File "/opt/conda/lib/python3.5/site-packages/rest_framework/generics.py" in get_serializer
111. return serializer_class(*args, **kwargs)
File "/opt/conda/lib/python3.5/site-packages/rest_framework_json_api/serializers.py" in __init__
24. raise RuntimeError('ResourceIdentifierObjectsSerializer must be initialized with a model class.')
Exception Type: RuntimeError at /api/
Exception Value: ResourceIdentifierObjectsSerializer must be initialized with a model class.
Request information:
USER: admin@email.com [1]
GET: No GET data
POST: No POST data
FILES: No FILES data
Thanks