Drop Django 2.0 and DRF 3.7 support
parent
8acab171ea
commit
3a37c4a019
|
|
@ -13,8 +13,8 @@ Generate **real** Swagger/OpenAPI 2.0 specifications from a Django Rest Framewor
|
|||
|
||||
Compatible with
|
||||
|
||||
- **Django Rest Framework**: 3.7.7, 3.8, 3.9
|
||||
- **Django**: 1.11, 2.0, 2.1, 2.2
|
||||
- **Django Rest Framework**: 3.8, 3.9
|
||||
- **Django**: 1.11, 2.1, 2.2
|
||||
- **Python**: 2.7, 3.5, 3.6, 3.7
|
||||
|
||||
Only the latest patch version of each ``major.minor`` series of Python, Django and Django REST Framework is supported.
|
||||
|
|
|
|||
|
|
@ -87,14 +87,14 @@ Where you can use the :func:`@swagger_auto_schema <.swagger_auto_schema>` decora
|
|||
|
||||
* for ``ViewSet``, ``GenericViewSet``, ``ModelViewSet``, because each viewset corresponds to multiple **paths**, you have
|
||||
to decorate the *action methods*, i.e. ``list``, ``create``, ``retrieve``, etc. |br|
|
||||
Additionally, ``@action``\ s, ``@list_route``\ s or ``@detail_route``\ s defined on the viewset, like function based
|
||||
api views, can respond to multiple HTTP methods and thus have multiple operations that must be decorated separately:
|
||||
Additionally, ``@action``\ s defined on the viewset, like function based api views, can respond to multiple HTTP
|
||||
methods and thus have multiple operations that must be decorated separately:
|
||||
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
class ArticleViewSet(viewsets.ModelViewSet):
|
||||
# method or 'methods' can be skipped because the list_route only handles a single method (GET)
|
||||
# method or 'methods' can be skipped because the action only handles a single method (GET)
|
||||
@swagger_auto_schema(operation_description='GET /articles/today/')
|
||||
@action(detail=False, methods=['get'])
|
||||
def today(self, request):
|
||||
|
|
|
|||
|
|
@ -5,5 +5,5 @@ inflection>=0.3.1
|
|||
six>=1.10.0
|
||||
uritemplate>=3.0.0
|
||||
|
||||
djangorestframework>=3.7.7
|
||||
djangorestframework>=3.8
|
||||
Django>=1.11.7
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
python-3.7.1
|
||||
python-3.7.3
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ def swagger_auto_schema(method=None, methods=None, auto_schema=unset, request_bo
|
|||
|
||||
if len(available_http_methods) > 1:
|
||||
assert _methods, \
|
||||
"on multi-method api_view, action, detail_route or list_route, you must specify " \
|
||||
"on multi-method api_view or action, you must specify " \
|
||||
"swagger_auto_schema on a per-method basis using one of the `method` or `methods` arguments"
|
||||
else:
|
||||
# for a single-method view we assume that single method as the decorator target
|
||||
|
|
@ -179,8 +179,8 @@ def swagger_auto_schema(method=None, methods=None, auto_schema=unset, request_bo
|
|||
view_method._swagger_auto_schema = existing_data
|
||||
else:
|
||||
assert not _methods, \
|
||||
"the methods argument should only be specified when decorating an action, detail_route or " \
|
||||
"list_route; you should also ensure that you put the swagger_auto_schema decorator " \
|
||||
"the methods argument should only be specified when decorating an action; " \
|
||||
"you should also ensure that you put the swagger_auto_schema decorator " \
|
||||
"AFTER (above) the _route decorator"
|
||||
assert not existing_data, "swagger_auto_schema applied twice to method"
|
||||
view_method._swagger_auto_schema = data
|
||||
|
|
@ -215,7 +215,7 @@ def is_list_view(path, method, view):
|
|||
:param APIView view: target view
|
||||
:rtype: bool
|
||||
"""
|
||||
# for ViewSets, it could be the default 'list' action, or a list_route
|
||||
# for ViewSets, it could be the default 'list' action, or an @action(detail=False)
|
||||
action = getattr(view, 'action', '')
|
||||
method = getattr(view, action, None) or method
|
||||
detail = getattr(method, 'detail', None)
|
||||
|
|
|
|||
|
|
@ -93,17 +93,10 @@ class ArticleViewSet(viewsets.ModelViewSet):
|
|||
|
||||
swagger_schema = NoTitleAutoSchema
|
||||
|
||||
try:
|
||||
from rest_framework.decorators import action
|
||||
list_route = functools.partial(action, detail=False)
|
||||
detail_route = functools.partial(action, detail=True)
|
||||
except ImportError:
|
||||
# TODO: remove when dropping support for DRF 3.7
|
||||
action = None
|
||||
from rest_framework.decorators import list_route, detail_route
|
||||
from rest_framework.decorators import action
|
||||
|
||||
@swagger_auto_schema(auto_schema=NoPagingAutoSchema, filter_inspectors=[DjangoFilterDescriptionInspector])
|
||||
@list_route(methods=['get'])
|
||||
@action(detail=False, methods=['get'])
|
||||
def today(self, request):
|
||||
today_min = datetime.datetime.combine(datetime.date.today(), datetime.time.min)
|
||||
today_max = datetime.datetime.combine(datetime.date.today(), datetime.time.max)
|
||||
|
|
@ -118,7 +111,7 @@ class ArticleViewSet(viewsets.ModelViewSet):
|
|||
type=openapi.TYPE_INTEGER,
|
||||
description="this should not crash (form parameter on DELETE method)"
|
||||
)])
|
||||
@detail_route(methods=['get', 'post', 'delete'], parser_classes=(MultiPartParser, FileUploadParser))
|
||||
@action(detail=True, methods=['get', 'post', 'delete'], parser_classes=(MultiPartParser, FileUploadParser))
|
||||
def image(self, request, slug=None):
|
||||
"""
|
||||
image method docstring
|
||||
|
|
|
|||
8
tox.ini
8
tox.ini
|
|
@ -6,8 +6,8 @@ isolated_build_env = .package
|
|||
# https://docs.djangoproject.com/en/dev/faq/install/#what-python-version-can-i-use-with-django
|
||||
envlist =
|
||||
py27-django111-drf39-typing,
|
||||
py{27,35,36}-django111-drf{37,38,39},
|
||||
py{35,36,37}-django{20,21,22}-drf{37,38,39},
|
||||
py{27,35,36}-django111-drf{38,39},
|
||||
py{35,36,37}-django{21,22}-drf{38,39},
|
||||
djmaster, lint, docs
|
||||
|
||||
[testenv:.package]
|
||||
|
|
@ -17,12 +17,10 @@ deps =
|
|||
[testenv]
|
||||
deps =
|
||||
django111: Django>=1.11,<2.0
|
||||
django20: Django>=2.0,<2.1
|
||||
django21: Django>=2.1,<2.2
|
||||
django22: Django>=2.2,<2.3
|
||||
|
||||
drf37: djangorestframework>=3.7.7,<3.8
|
||||
drf38: djangorestframework>=3.8.0,<3.9
|
||||
drf38: djangorestframework>=3.8,<3.9
|
||||
drf39: djangorestframework>=3.9,<3.10
|
||||
|
||||
typing: typing>=3.6.6
|
||||
|
|
|
|||
Loading…
Reference in New Issue