mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 08:14:16 +03:00
Fix OpenAPI path generation with common prefixes.
Closes #6675. Closes #6823.
This commit is contained in:
parent
30a21a98dc
commit
e309a4f0b8
|
@ -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
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user