mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 09:36:49 +03:00
Avoid outputting callable defaults to schema. (#7105)
This commit is contained in:
parent
07376f128c
commit
ced37a56cb
|
@ -393,7 +393,7 @@ class AutoSchema(ViewInspector):
|
|||
schema['writeOnly'] = True
|
||||
if field.allow_null:
|
||||
schema['nullable'] = True
|
||||
if field.default and field.default != empty: # why don't they use None?!
|
||||
if field.default and field.default != empty and not callable(field.default): # why don't they use None?!
|
||||
schema['default'] = field.default
|
||||
if field.help_text:
|
||||
schema['description'] = str(field.help_text)
|
||||
|
|
|
@ -571,6 +571,22 @@ class TestOperationIntrospection(TestCase):
|
|||
properties = response_schema['items']['properties']
|
||||
assert properties['hstore']['type'] == 'object'
|
||||
|
||||
def test_serializer_callable_default(self):
|
||||
path = '/'
|
||||
method = 'GET'
|
||||
view = create_view(
|
||||
views.ExampleGenericAPIView,
|
||||
method,
|
||||
create_request(path),
|
||||
)
|
||||
inspector = AutoSchema()
|
||||
inspector.view = view
|
||||
|
||||
responses = inspector._get_responses(path, method)
|
||||
response_schema = responses['200']['content']['application/json']['schema']
|
||||
properties = response_schema['items']['properties']
|
||||
assert 'default' not in properties['uuid_field']
|
||||
|
||||
def test_serializer_validators(self):
|
||||
path = '/'
|
||||
method = 'GET'
|
||||
|
|
|
@ -58,6 +58,7 @@ class ExampleSerializer(serializers.Serializer):
|
|||
date = serializers.DateField()
|
||||
datetime = serializers.DateTimeField()
|
||||
hstore = serializers.HStoreField()
|
||||
uuid_field = serializers.UUIDField(default=uuid.uuid4)
|
||||
|
||||
|
||||
class ExampleGenericAPIView(generics.GenericAPIView):
|
||||
|
|
Loading…
Reference in New Issue
Block a user