-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into pr125
- Loading branch information
Showing
32 changed files
with
1,275 additions
and
162 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
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
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 +1 @@ | ||
__version__ = '0.9.11' | ||
__version__ = '0.9.14' |
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,39 @@ | ||
from drf_spectacular.plumbing import build_parameter_type, follow_field_source, get_view_model | ||
from drf_spectacular.utils import OpenApiParameter | ||
|
||
try: | ||
from django_filters.rest_framework import DjangoFilterBackend as OriginalDjangoFilterBackend | ||
except ImportError: | ||
class OriginalDjangoFilterBackend: # type: ignore | ||
pass | ||
|
||
|
||
class SpectacularDjangoFilterBackendMixin: | ||
def get_schema_operation_parameters(self, view): | ||
model = get_view_model(view) | ||
if not model: | ||
return [] | ||
|
||
filterset_class = self.get_filterset_class(view, model.objects.none()) | ||
if not filterset_class: | ||
return [] | ||
|
||
parameters = [] | ||
for field_name, field in filterset_class.base_filters.items(): | ||
path = field.field_name.split('__') | ||
model_field = follow_field_source(model, path) | ||
|
||
parameters.append(build_parameter_type( | ||
name=field_name, | ||
required=field.extra['required'], | ||
location=OpenApiParameter.QUERY, | ||
description=field.label if field.label is not None else field_name, | ||
schema=view.schema._map_model_field(model_field, direction=None), | ||
enum=[c for c, _ in field.extra.get('choices', [])], | ||
)) | ||
|
||
return parameters | ||
|
||
|
||
class DjangoFilterBackend(SpectacularDjangoFilterBackendMixin, OriginalDjangoFilterBackend): | ||
pass |
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
Oops, something went wrong.