mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-10 19:56:59 +03:00
Corrected openapi.SchemaGenerator path prefixes. (#6724)
This commit is contained in:
parent
60bcc93202
commit
a63860fc8b
|
@ -249,7 +249,7 @@ class BaseSchemaGenerator(object):
|
|||
/api/v1/users/
|
||||
/api/v1/users/{pk}/
|
||||
|
||||
The path prefix is '/api/v1/'
|
||||
The path prefix is '/api/v1'
|
||||
"""
|
||||
prefixes = []
|
||||
for path in paths:
|
||||
|
|
|
@ -35,12 +35,14 @@ class SchemaGenerator(BaseSchemaGenerator):
|
|||
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):]
|
||||
subpath = path[len(prefix):]
|
||||
result.setdefault(subpath, {})
|
||||
result[subpath][method.lower()] = operation
|
||||
|
||||
|
|
|
@ -214,6 +214,20 @@ class TestGenerator(TestCase):
|
|||
assert 'get' in example_operations
|
||||
assert 'post' in example_operations
|
||||
|
||||
def test_prefixed_paths_construction(self):
|
||||
"""Construction of the `paths` key with a common prefix."""
|
||||
patterns = [
|
||||
url(r'^api/v1/example/?$', views.ExampleListView.as_view()),
|
||||
url(r'^api/v1/example/{pk}/?$', views.ExampleDetailView.as_view()),
|
||||
]
|
||||
generator = SchemaGenerator(patterns=patterns)
|
||||
generator._initialise_endpoints()
|
||||
|
||||
paths = generator.get_paths()
|
||||
|
||||
assert '/example/' in paths
|
||||
assert '/example/{id}/' in paths
|
||||
|
||||
def test_schema_construction(self):
|
||||
"""Construction of the top level dictionary."""
|
||||
patterns = [
|
||||
|
|
Loading…
Reference in New Issue
Block a user