mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-26 16:09:49 +03:00
Add docs and test
This commit is contained in:
parent
58f55b466a
commit
65ab47ce55
|
@ -583,6 +583,10 @@ class AutoSchema(ViewInspector):
|
|||
schema['minimum'] = -schema['maximum']
|
||||
|
||||
def get_field_name(self, field):
|
||||
"""
|
||||
Override this method if you want to change schema field name.
|
||||
For example, convert snake_case field name to camelCase.
|
||||
"""
|
||||
return field.field_name
|
||||
|
||||
def get_paginator(self):
|
||||
|
|
|
@ -107,6 +107,20 @@ class TestFieldMapping(TestCase):
|
|||
assert data['properties']['default_false']['default'] is False, "default must be false"
|
||||
assert 'default' not in data['properties']['without_default'], "default must not be defined"
|
||||
|
||||
def test_custom_field_name(self):
|
||||
class CustomSchema(AutoSchema):
|
||||
def get_field_name(self, field):
|
||||
return 'custom_' + field.field_name
|
||||
|
||||
class Serializer(serializers.Serializer):
|
||||
text_field = serializers.CharField()
|
||||
|
||||
inspector = CustomSchema()
|
||||
|
||||
data = inspector.map_serializer(Serializer())
|
||||
assert 'custom_text_field' in data['properties']
|
||||
assert 'text_field' not in data['properties']
|
||||
|
||||
|
||||
@pytest.mark.skipif(uritemplate is None, reason='uritemplate not installed.')
|
||||
class TestOperationIntrospection(TestCase):
|
||||
|
|
Loading…
Reference in New Issue
Block a user