Problem with DRF docs generator
See original GitHub issueI’m using DRF coreapi documentation generator (http://www.django-rest-framework.org/tutorial/7-schemas-and-client-libraries/):
from rest_framework.documentation import include_docs_urls
from rest_framework.schemas import get_schema_view
urlpatterns = [
...
# Documentation
path('docs/', include_docs_urls(title='Pena API',
renderer_classes=[NoneRender])),
path('schema/', get_schema_view(title="Pena API")),
...
]
But Djoser broke my /docs url failing to provide view serializers to coreapi:
Traceback:
File "/Users/roma/.local/share/virtualenvs/pena-Z-V4Ag8c/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
35. response = get_response(request)
File "/Users/roma/.local/share/virtualenvs/pena-Z-V4Ag8c/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
128. response = self.process_exception_by_middleware(e, request)
File "/Users/roma/.local/share/virtualenvs/pena-Z-V4Ag8c/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
126. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/roma/.local/share/virtualenvs/pena-Z-V4Ag8c/lib/python3.6/site-packages/django/views/decorators/csrf.py" in wrapped_view
54. return view_func(*args, **kwargs)
File "/Users/roma/.local/share/virtualenvs/pena-Z-V4Ag8c/lib/python3.6/site-packages/django/views/generic/base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "/Users/roma/.local/share/virtualenvs/pena-Z-V4Ag8c/lib/python3.6/site-packages/rest_framework/views.py" in dispatch
483. response = self.handle_exception(exc)
File "/Users/roma/.local/share/virtualenvs/pena-Z-V4Ag8c/lib/python3.6/site-packages/rest_framework/views.py" in handle_exception
443. self.raise_uncaught_exception(exc)
File "/Users/roma/.local/share/virtualenvs/pena-Z-V4Ag8c/lib/python3.6/site-packages/rest_framework/views.py" in dispatch
480. response = handler(request, *args, **kwargs)
File "/Users/roma/.local/share/virtualenvs/pena-Z-V4Ag8c/lib/python3.6/site-packages/rest_framework/schemas/views.py" in get
31. schema = self.schema_generator.get_schema(request, self.public)
File "/Users/roma/.local/share/virtualenvs/pena-Z-V4Ag8c/lib/python3.6/site-packages/rest_framework/schemas/generators.py" in get_schema
286. links = self.get_links(None if public else request)
File "/Users/roma/.local/share/virtualenvs/pena-Z-V4Ag8c/lib/python3.6/site-packages/rest_framework/schemas/generators.py" in get_links
324. link = view.schema.get_link(path, method, base_url=self.url)
File "/Users/roma/.local/share/virtualenvs/pena-Z-V4Ag8c/lib/python3.6/site-packages/rest_framework/schemas/inspectors.py" in get_link
195. fields += self.get_serializer_fields(path, method)
File "/Users/roma/.local/share/virtualenvs/pena-Z-V4Ag8c/lib/python3.6/site-packages/rest_framework/schemas/inspectors.py" in get_serializer_fields
315. serializer = view.get_serializer()
File "/Users/roma/.local/share/virtualenvs/pena-Z-V4Ag8c/lib/python3.6/site-packages/rest_framework/generics.py" in get_serializer
110. serializer_class = self.get_serializer_class()
File "/Users/roma/.local/share/virtualenvs/pena-Z-V4Ag8c/lib/python3.6/site-packages/djoser/views.py" in get_serializer_class
289. self.action == 'me' and self.request.method == 'DELETE'):
Exception Type: AttributeError at /docs/
Exception Value: 'NoneType' object has no attribute 'method'
The problem - there is no current request while generating schema, so there must be something like None-check here:
elif self.action == 'remove' or (self.action == 'me' and self.request and self.request.method == 'DELETE'):
...
But I’m not sure new logic is correct. What do you think, guys?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
Top Results From Across the Web
Documenting your API - Django REST framework
REST framework provides built-in support for generating OpenAPI schemas, which can be used with tools that allow you to build API documentation.
Read more >Django - ImportError: Could not import 'drf_yasg.generators ...
Original answer. There is an open issue in drf-yasg-(#641) to fix this issue. Unfortunately, the project is no longer maintained given that ...
Read more >Documenting an API implemented with Django Rest Framework
One of the first advantage of basing DjaoDjin's documentation on DRF schema generator was to find a few issues unreported by pylint.
Read more >How to automatically create API Documentation in Django ...
To do so, simply type the following in the terminal. pip install drf-yasg. Now, let's start with the steps. First, create a new...
Read more >drf-spectacular — drf-spectacular documentation
Sane and flexible OpenAPI 3 schema generation for Django REST framework. Documentation is an integral part of API development and OpenAPI 3 is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok, I will work on it over weekend.
Can’t reproduce bug on a new isolated DRF project with djoser 1.3.0, so closing issue. Documentation is rendered fine.