mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-27 00:19:53 +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']
|
schema['minimum'] = -schema['maximum']
|
||||||
|
|
||||||
def get_field_name(self, field):
|
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
|
return field.field_name
|
||||||
|
|
||||||
def get_paginator(self):
|
def get_paginator(self):
|
||||||
|
|
|
@ -107,6 +107,20 @@ class TestFieldMapping(TestCase):
|
||||||
assert data['properties']['default_false']['default'] is False, "default must be false"
|
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"
|
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.')
|
@pytest.mark.skipif(uritemplate is None, reason='uritemplate not installed.')
|
||||||
class TestOperationIntrospection(TestCase):
|
class TestOperationIntrospection(TestCase):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user