From 0379265f130e693ad90dec5bd408f2409fa54b59 Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Tue, 26 Mar 2019 15:03:40 +0100 Subject: [PATCH] Note uritemplate dependency. --- rest_framework/schemas/inspectors.py | 2 ++ tests/schemas/test_openapi.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/rest_framework/schemas/inspectors.py b/rest_framework/schemas/inspectors.py index 265172b01..fec5f75bc 100644 --- a/rest_framework/schemas/inspectors.py +++ b/rest_framework/schemas/inspectors.py @@ -532,6 +532,8 @@ class OpenAPIAutoSchema(ViewInspector): """ Return a list of parameters from templated path variables. """ + assert uritemplate, '`uritemplate` must be installed for OpenAPI schema support.' + model = getattr(getattr(self.view, 'queryset', None), 'model', None) parameters = [] diff --git a/tests/schemas/test_openapi.py b/tests/schemas/test_openapi.py index 23937a7d1..2585def44 100644 --- a/tests/schemas/test_openapi.py +++ b/tests/schemas/test_openapi.py @@ -1,7 +1,9 @@ +import pytest from django.conf.urls import url from django.test import RequestFactory, TestCase, override_settings from rest_framework import filters, pagination +from rest_framework.compat import uritemplate from rest_framework.request import Request from rest_framework.schemas.generators import OpenAPISchemaGenerator from rest_framework.schemas.inspectors import OpenAPIAutoSchema @@ -38,6 +40,7 @@ class TestBasics(TestCase): assert f.get_schema_operation_parameters(self.dummy_view) +@pytest.mark.skipif(uritemplate is None, reason='uritemplate not installed.') class TestOperationIntrospection(TestCase): def test_path_without_parameters(self): @@ -82,6 +85,7 @@ class TestOperationIntrospection(TestCase): }] +@pytest.mark.skipif(uritemplate is None, reason='uritemplate not installed.') @override_settings(REST_FRAMEWORK={'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.inspectors.OpenAPIAutoSchema'}) class TestGenerator(TestCase):