Skip to content

Return valid OpenAPI schema even when empty. #7125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions rest_framework/schemas/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ def get_info(self):
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
Expand All @@ -62,9 +57,6 @@ def get_schema(self, request=None, public=False):
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(),
Expand Down
9 changes: 9 additions & 0 deletions tests/schemas/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,15 @@ def test_schema_construction(self):
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 = [
Expand Down