mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 09:36:49 +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):
|
def get_paths(self, request=None):
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
paths, view_endpoints = self._get_paths_and_endpoints(request)
|
_, view_endpoints = self._get_paths_and_endpoints(request)
|
||||||
|
|
||||||
# Only generate the path prefix for paths that will be included
|
|
||||||
if not paths:
|
|
||||||
return None
|
|
||||||
|
|
||||||
for path, method, view in view_endpoints:
|
for path, method, view in view_endpoints:
|
||||||
if not self.has_view_permissions(path, method, view):
|
if not self.has_view_permissions(path, method, view):
|
||||||
continue
|
continue
|
||||||
|
@ -62,9 +57,6 @@ class SchemaGenerator(BaseSchemaGenerator):
|
||||||
self._initialise_endpoints()
|
self._initialise_endpoints()
|
||||||
|
|
||||||
paths = self.get_paths(None if public else request)
|
paths = self.get_paths(None if public else request)
|
||||||
if not paths:
|
|
||||||
return None
|
|
||||||
|
|
||||||
schema = {
|
schema = {
|
||||||
'openapi': '3.0.2',
|
'openapi': '3.0.2',
|
||||||
'info': self.get_info(),
|
'info': self.get_info(),
|
||||||
|
|
|
@ -707,6 +707,15 @@ class TestGenerator(TestCase):
|
||||||
assert 'openapi' in schema
|
assert 'openapi' in schema
|
||||||
assert 'paths' 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):
|
def test_schema_information(self):
|
||||||
"""Construction of the top level dictionary."""
|
"""Construction of the top level dictionary."""
|
||||||
patterns = [
|
patterns = [
|
||||||
|
|
Loading…
Reference in New Issue
Block a user