mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 01:26:53 +03:00
Return valid OpenAPI schema even when empty.
This commit is contained in:
parent
7bd730124c
commit
d0b9577605
|
@ -35,12 +35,7 @@ class SchemaGenerator(BaseSchemaGenerator):
|
|||
def get_paths(self, request=None):
|
||||
result = {}
|
||||
|
||||
paths, view_endpoints = self._get_paths_and_endpoints(request)
|
||||
|
||||
# Only generate the path prefix for paths that will be included
|
||||
if not paths:
|
||||
return None
|
||||
|
||||
_, view_endpoints = self._get_paths_and_endpoints(request)
|
||||
for path, method, view in view_endpoints:
|
||||
if not self.has_view_permissions(path, method, view):
|
||||
continue
|
||||
|
@ -62,9 +57,6 @@ class SchemaGenerator(BaseSchemaGenerator):
|
|||
self._initialise_endpoints()
|
||||
|
||||
paths = self.get_paths(None if public else request)
|
||||
if not paths:
|
||||
return None
|
||||
|
||||
schema = {
|
||||
'openapi': '3.0.2',
|
||||
'info': self.get_info(),
|
||||
|
|
|
@ -707,6 +707,15 @@ class TestGenerator(TestCase):
|
|||
assert 'openapi' in schema
|
||||
assert 'paths' in schema
|
||||
|
||||
def test_schema_with_no_paths(self):
|
||||
patterns = []
|
||||
generator = SchemaGenerator(patterns=patterns)
|
||||
|
||||
request = create_request('/')
|
||||
schema = generator.get_schema(request=request)
|
||||
|
||||
assert schema['paths'] == {}
|
||||
|
||||
def test_schema_information(self):
|
||||
"""Construction of the top level dictionary."""
|
||||
patterns = [
|
||||
|
|
Loading…
Reference in New Issue
Block a user