This repository has been archived by the owner on Jan 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use DRF get_schema_view shortcut released in 3.5
- Loading branch information
1 parent
267eeab
commit 0edee4c
Showing
4 changed files
with
26 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,19 @@ | ||
from rest_framework import exceptions | ||
from rest_framework.permissions import AllowAny | ||
from rest_framework import schemas | ||
from rest_framework.renderers import CoreJSONRenderer | ||
from rest_framework.response import Response | ||
from rest_framework.schemas import SchemaGenerator | ||
from rest_framework.views import APIView | ||
|
||
from . import renderers | ||
|
||
|
||
def get_swagger_view(title=None, url=None): | ||
""" | ||
Returns schema view which renders Swagger/OpenAPI. | ||
(Replace with DRF get_schema_view shortcut in 3.5) | ||
""" | ||
class SwaggerSchemaView(APIView): | ||
_ignore_model_permissions = True | ||
exclude_from_schema = True | ||
permission_classes = [AllowAny] | ||
renderer_classes = [ | ||
return schemas.get_schema_view( | ||
title=title, | ||
url=url, | ||
renderer_classes=[ | ||
CoreJSONRenderer, | ||
renderers.OpenAPIRenderer, | ||
renderers.SwaggerUIRenderer | ||
] | ||
|
||
def get(self, request): | ||
generator = SchemaGenerator(title=title, url=url) | ||
schema = generator.get_schema(request=request) | ||
|
||
if not schema: | ||
raise exceptions.ValidationError( | ||
'The schema generator did not return a schema Document' | ||
) | ||
|
||
return Response(schema) | ||
|
||
return SwaggerSchemaView.as_view() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters