-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2b69550
commit 1a2888a
Showing
7 changed files
with
41 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
# The API we expose | ||
# from .views import get_schema_view | ||
from .generators import SchemaGenerator | ||
from .inspectors import AutoSchema, ManualSchema # noqa | ||
|
||
|
||
# Shared function. TODO: move to utils. | ||
def is_list_view(path, method, view): | ||
def get_schema_view( | ||
title=None, url=None, description=None, urlconf=None, renderer_classes=None, | ||
public=False, patterns=None, generator_class=SchemaGenerator): | ||
""" | ||
Return True if the given path/method appears to represent a list view. | ||
Return a schema view. | ||
""" | ||
if hasattr(view, 'action'): | ||
# Viewsets have an explicitly defined action, which we can inspect. | ||
return view.action == 'list' | ||
|
||
if method.lower() != 'get': | ||
return False | ||
path_components = path.strip('/').split('/') | ||
if path_components and '{' in path_components[-1]: | ||
return False | ||
return True | ||
# Avoid import cycle on APIView | ||
from .views import SchemaView | ||
generator = generator_class( | ||
title=title, url=url, description=description, | ||
urlconf=urlconf, patterns=patterns, | ||
) | ||
return SchemaView.as_view( | ||
renderer_classes=renderer_classes, | ||
schema_generator=generator, | ||
public=public, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
|
||
def is_list_view(path, method, view): | ||
""" | ||
Return True if the given path/method appears to represent a list view. | ||
""" | ||
if hasattr(view, 'action'): | ||
# Viewsets have an explicitly defined action, which we can inspect. | ||
return view.action == 'list' | ||
|
||
if method.lower() != 'get': | ||
return False | ||
path_components = path.strip('/').split('/') | ||
if path_components and '{' in path_components[-1]: | ||
return False | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters