Make the library compatible with drf-yasg library
See original GitHub issuehttps://github.com/axnsan12/drf-yasg is the best swagger generator out there by far.
Unfortunately, it is not possible to integrate with wagtail due to the current API design.
The error when generating swagger schema:
Traceback (most recent call last):
File "/home/code/swehq/newgifiter/gifiter/blog/venv/lib/python3.6/site-packages/drf_yasg/inspectors/view.py", line 94, in get_view_serializer
return self.view.get_serializer()
File "/home/code/swehq/newgifiter/gifiter/blog/venv/lib/python3.6/site-packages/rest_framework/generics.py", line 110, in get_serializer
serializer_class = self.get_serializer_class()
File "/home/code/swehq/newgifiter/gifiter/blog/venv/lib/python3.6/site-packages/wagtail/api/v2/endpoints.py", line 300, in get_serializer_class
model = type(self.get_object())
File "/home/code/swehq/newgifiter/gifiter/blog/venv/lib/python3.6/site-packages/wagtail/api/v2/endpoints.py", line 437, in get_object
base = super().get_object()
File "/home/code/swehq/newgifiter/gifiter/blog/venv/lib/python3.6/site-packages/rest_framework/generics.py", line 94, in get_object
(self.__class__.__name__, lookup_url_kwarg)
AssertionError: Expected view PagesAdminAPIEndpoint to be called with a URL keyword argument named "pk". Fix your URL conf, or set the `.lookup_field` attribute on the view correctly.
Internal Server Error: /swagger/
Traceback (most recent call last):
File "/home/code/swehq/newgifiter/gifiter/blog/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
response = get_response(request)
File "/home/code/swehq/newgifiter/gifiter/blog/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 158, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/code/swehq/newgifiter/gifiter/blog/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 156, in _get_response
response = response.render()
File "/home/code/swehq/newgifiter/gifiter/blog/venv/lib/python3.6/site-packages/django/template/response.py", line 106, in render
self.content = self.rendered_content
File "/home/code/swehq/newgifiter/gifiter/blog/venv/lib/python3.6/site-packages/rest_framework/response.py", line 72, in rendered_content
ret = renderer.render(self.data, accepted_media_type, context)
File "/home/code/swehq/newgifiter/gifiter/blog/venv/lib/python3.6/site-packages/drf_yasg/renderers.py", line 34, in render
return codec.encode(data)
File "/home/code/swehq/newgifiter/gifiter/blog/venv/lib/python3.6/site-packages/drf_yasg/codecs.py", line 73, in encode
raise SwaggerValidationError("spec validation failed", errors, spec, self)
drf_yasg.errors.SwaggerValidationError: spec validation failed
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
drf-yasg - PyPI
Generate real Swagger/OpenAPI 2.0 specifications from a Django Rest Framework API. Compatible with. Django Rest Framework: 3.10, 3.11, 3.12.
Read more >drf-yasg Documentation - Read the Docs
Generate real Swagger/OpenAPI 2.0 specifications from a Django Rest Framework API. Compatible with. • Django Rest Framework: 3.10, 3.11, ...
Read more >Django - ImportError: Could not import 'drf_yasg.generators ...
I'm trying to add https://github.com/axnsan12/drf-yasg this library to our django ...
Read more >How to Create More Understandable APIs in Python
The first step to create APIs in Python is to set up the environment to explore how to use drf-yasg: 1. Install the...
Read more >Documenting an API implemented with Django Rest Framework
We followed the instruction to get started with drf-yasg and browsed ... by redoc or swagger-ui, both Javascript libraries, in the browser ...
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
This is a bit finicky to achieve, but can be done with a polymorphic serialiser, and generally bypasses wagtail’s API to use DRF out of the box, relying on Wagtail serializers and fields. Example here, showing different page schema on the /pages_read endpoint (see the different response samples for HomePage, AboutPage, etc).
I’m still getting StreamField to work, though.
@jasonHav If folks are interested and can raise money to sponsor for a couple of weeks’ work for me (I have a couple of weeks spare at end of april / early may) I could tidy what I’ve done as a package on pypi (
drf-wagtail
, maybe) with a couple of examples.Based on validation from @lingster (below), we will close this issue as it appears to be resolved. If this still is a problem for some specific scenario it would be good for a new bug to be raised with exact steps to reproduce.