diff --git a/rest_framework/schemas/openapi.py b/rest_framework/schemas/openapi.py index 7b5ae709b..93fc7a739 100644 --- a/rest_framework/schemas/openapi.py +++ b/rest_framework/schemas/openapi.py @@ -1,4 +1,5 @@ import warnings +from urllib.parse import urljoin from django.core.validators import ( DecimalValidator, EmailValidator, MaxLengthValidator, MaxValueValidator, @@ -39,17 +40,18 @@ class SchemaGenerator(BaseSchemaGenerator): # Only generate the path prefix for paths that will be included if not paths: return None - prefix = self.determine_path_prefix(paths) - if prefix == '/': # no prefix - prefix = '' for path, method, view in view_endpoints: if not self.has_view_permissions(path, method, view): continue operation = view.schema.get_operation(path, method) - subpath = path[len(prefix):] - result.setdefault(subpath, {}) - result[subpath][method.lower()] = operation + # Normalise path for any provided mount url. + if path.startswith('/'): + path = path[1:] + path = urljoin(self.url or '/', path) + + result.setdefault(path, {}) + result[path][method.lower()] = operation return result diff --git a/tests/schemas/test_openapi.py b/tests/schemas/test_openapi.py index b667c4020..7dc37c547 100644 --- a/tests/schemas/test_openapi.py +++ b/tests/schemas/test_openapi.py @@ -247,7 +247,7 @@ class TestGenerator(TestCase): url(r'^example/?$', views.ExampleListView.as_view()), url(r'^example/{pk}/?$', views.ExampleDetailView.as_view()), ] - generator = SchemaGenerator(patterns=patterns, url='/api/') + generator = SchemaGenerator(patterns=patterns, url='/api') generator._initialise_endpoints() paths = generator.get_paths()