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 599
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #570 from marcgibbons/feature/upgrade-reqs
2.1.0: Make DRF 3.5 minimum version, use get_schema_view shortcut
- Loading branch information
Showing
9 changed files
with
46 additions
and
109 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
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
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 +1 @@ | ||
__version__ = '2.0.7' | ||
__version__ = '2.1.0' |
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
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