diff --git a/drf_spectacular/contrib/django_oauth_toolkit.py b/drf_spectacular/contrib/django_oauth_toolkit.py index 25985aaf..58486ef8 100644 --- a/drf_spectacular/contrib/django_oauth_toolkit.py +++ b/drf_spectacular/contrib/django_oauth_toolkit.py @@ -6,11 +6,12 @@ class DjangoOAuthToolkitScheme(OpenApiAuthenticationExtension): name = 'oauth2' def get_security_requirement(self, auto_schema): - from oauth2_provider.contrib.rest_framework import ( - TokenHasScope, TokenMatchesOASRequirements, IsAuthenticatedOrTokenHasScope - ) # TODO generalize (will also be used in versioning) from collections import namedtuple + + from oauth2_provider.contrib.rest_framework import ( + IsAuthenticatedOrTokenHasScope, TokenHasScope, TokenMatchesOASRequirements, + ) Request = namedtuple('Request', ['method']) view = auto_schema.view @@ -26,9 +27,10 @@ def get_security_requirement(self, auto_schema): return {self.name: permission.get_scopes(request, view)} def get_security_definition(self, auto_schema): - from drf_spectacular.settings import spectacular_settings from oauth2_provider.settings import oauth2_settings + from drf_spectacular.settings import spectacular_settings + flows = {} for flow_type in spectacular_settings.OAUTH2_FLOWS: flows[flow_type] = {} diff --git a/drf_spectacular/contrib/rest_framework_simplejwt.py b/drf_spectacular/contrib/rest_framework_simplejwt.py index deb266f8..caf399ed 100644 --- a/drf_spectacular/contrib/rest_framework_simplejwt.py +++ b/drf_spectacular/contrib/rest_framework_simplejwt.py @@ -7,6 +7,7 @@ class SimpleJWTScheme(OpenApiAuthenticationExtension): def get_security_definition(self, auto_schema): from rest_framework_simplejwt.settings import api_settings + from drf_spectacular.plumbing import warn if len(api_settings.AUTH_HEADER_TYPES) > 1: diff --git a/drf_spectacular/plumbing.py b/drf_spectacular/plumbing.py index 58ed2730..2b6f7116 100644 --- a/drf_spectacular/plumbing.py +++ b/drf_spectacular/plumbing.py @@ -135,7 +135,7 @@ def get_lib_doc_excludes(): # do not import on package level due to potential import recursion when loading # extensions as recommended: USER's settings.py -> USER EXTENSIONS -> extensions.py # -> plumbing.py -> DRF views -> DRF DefaultSchema -> openapi.py - plumbing.py -> Loop - from rest_framework import generics, viewsets, views + from rest_framework import generics, views, viewsets return [ views.APIView, *[getattr(serializers, c) for c in dir(serializers) if c.endswith('Serializer')], diff --git a/requirements/testing.txt b/requirements/testing.txt index 53f9a073..17f104b7 100644 --- a/requirements/testing.txt +++ b/requirements/testing.txt @@ -4,4 +4,4 @@ pytest-cov>=2.8.1 flake8>=3.7.9 mypy>=0.770 djangorestframework-stubs>=1.1.0 -isort>=4.3.21 \ No newline at end of file +isort>=5.0.4 \ No newline at end of file diff --git a/runtests.py b/runtests.py index 84b8a52b..2e2cd512 100755 --- a/runtests.py +++ b/runtests.py @@ -16,7 +16,7 @@ MYPY_ARGS = ['--config-file=tox.ini', 'drf_spectacular'] -ISORT_ARGS = ['--check', '-df'] +ISORT_ARGS = ['--check', '--diff', '.'] sys.path.append(os.path.dirname(__file__)) @@ -43,7 +43,7 @@ def mypy_main(args): def isort_main(args): print('Running isort code linting') ret = subprocess.call(['isort'] + args) - print('isort failed, run: isort -rc .' if ret else 'isort passed') + print('isort failed, run: isort --interactive .' if ret else 'isort passed') return ret diff --git a/tests/__init__.py b/tests/__init__.py index aa45988a..571a6350 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -2,7 +2,7 @@ def assert_schema(schema, reference_file): - from drf_spectacular.renderers import OpenApiYamlRenderer, OpenApiJsonRenderer + from drf_spectacular.renderers import OpenApiJsonRenderer, OpenApiYamlRenderer schema_yml = OpenApiYamlRenderer().render(schema, renderer_context={}) # render also a json and provoke serialization issues @@ -22,6 +22,7 @@ def generate_schema(route, viewset=None, view=None, view_function=None): from django.urls import path from rest_framework import routers from rest_framework.viewsets import ViewSetMixin + from drf_spectacular.generators import SchemaGenerator patterns = [] diff --git a/tests/contrib/test_oauth_toolkit.py b/tests/contrib/test_oauth_toolkit.py index a757f45d..bc2bc75c 100644 --- a/tests/contrib/test_oauth_toolkit.py +++ b/tests/contrib/test_oauth_toolkit.py @@ -10,8 +10,8 @@ try: from oauth2_provider.contrib.rest_framework import ( - IsAuthenticatedOrTokenHasScope, OAuth2Authentication, - TokenHasReadWriteScope, TokenHasResourceScope, + IsAuthenticatedOrTokenHasScope, OAuth2Authentication, TokenHasReadWriteScope, + TokenHasResourceScope, ) except ImportError: IsAuthenticatedOrTokenHasScope = None diff --git a/tests/test_warnings.py b/tests/test_warnings.py index 519e6c2e..f71d7fe2 100644 --- a/tests/test_warnings.py +++ b/tests/test_warnings.py @@ -10,6 +10,7 @@ def test_serializer_name_reuse(warnings): from rest_framework import routers + from drf_spectacular.generators import SchemaGenerator router = routers.SimpleRouter()