mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-27 16:40:03 +03:00
Allow customization in determining if a serializer produces a component schema
This commit is contained in:
parent
19655edbf7
commit
e97047954b
|
@ -375,6 +375,16 @@ operationIds.
|
|||
In order to work around this, you can override `get_operation_id_base()` to
|
||||
provide a different base for name part of the ID.
|
||||
|
||||
#### `is_valid_serializer()`
|
||||
|
||||
Returns true if a serializer instance will produce a valid component schema
|
||||
for describing request and response bodies. The default behavior is to return
|
||||
'True' for any Serializer instance.
|
||||
|
||||
If you have a custom subclass of BaseSerializer which is capable of producing
|
||||
a component schema, you can use that component schema by overrideing this method
|
||||
(along with `map_serializer()`).
|
||||
|
||||
### `AutoSchema.__init__()` kwargs
|
||||
|
||||
`AutoSchema` provides a number of `__init__()` kwargs that can be used for
|
||||
|
|
|
@ -194,7 +194,7 @@ class AutoSchema(ViewInspector):
|
|||
|
||||
serializer = self.get_serializer(path, method)
|
||||
|
||||
if not isinstance(serializer, serializers.Serializer):
|
||||
if not self.is_valid_serializer(serializer):
|
||||
return {}
|
||||
|
||||
component_name = self.get_component_name(serializer)
|
||||
|
@ -626,7 +626,7 @@ class AutoSchema(ViewInspector):
|
|||
|
||||
serializer = self.get_serializer(path, method)
|
||||
|
||||
if not isinstance(serializer, serializers.Serializer):
|
||||
if not self.is_valid_serializer(serializer):
|
||||
item_schema = {}
|
||||
else:
|
||||
item_schema = self._get_reference(serializer)
|
||||
|
@ -650,7 +650,7 @@ class AutoSchema(ViewInspector):
|
|||
|
||||
serializer = self.get_serializer(path, method)
|
||||
|
||||
if not isinstance(serializer, serializers.Serializer):
|
||||
if not self.is_valid_serializer(serializer):
|
||||
item_schema = {}
|
||||
else:
|
||||
item_schema = self._get_reference(serializer)
|
||||
|
@ -692,6 +692,10 @@ class AutoSchema(ViewInspector):
|
|||
|
||||
return [path.split('/')[0].replace('_', '-')]
|
||||
|
||||
def is_valid_serializer(self, serializer):
|
||||
# return True if the serializer produces a valid component schema
|
||||
return isinstance(serializer, serializers.Serializer)
|
||||
|
||||
def _get_path_parameters(self, path, method):
|
||||
warnings.warn(
|
||||
"Method `_get_path_parameters()` has been renamed to `get_path_parameters()`. "
|
||||
|
|
Loading…
Reference in New Issue
Block a user