|
17 | 17 | AutoSchema, ManualSchema, SchemaGenerator, get_schema_view
|
18 | 18 | )
|
19 | 19 | from rest_framework.schemas.generators import EndpointEnumerator
|
| 20 | +from rest_framework.schemas.inspectors import field_to_schema |
20 | 21 | from rest_framework.schemas.utils import is_list_view
|
21 | 22 | from rest_framework.test import APIClient, APIRequestFactory
|
22 | 23 | from rest_framework.utils import formatting
|
@@ -763,6 +764,46 @@ class CustomView(APIView):
|
763 | 764 | link = view.schema.get_link(path, method, base_url)
|
764 | 765 | assert link == expected
|
765 | 766 |
|
| 767 | + def test_field_to_schema(self): |
| 768 | + label = 'Test label' |
| 769 | + help_text = 'This is a helpful test text' |
| 770 | + |
| 771 | + cases = [ |
| 772 | + # tuples are ([field], [expected schema]) |
| 773 | + # TODO: Add remaining cases |
| 774 | + ( |
| 775 | + serializers.BooleanField(label=label, help_text=help_text), |
| 776 | + coreschema.Boolean(title=label, description=help_text) |
| 777 | + ), |
| 778 | + ( |
| 779 | + serializers.DecimalField(1000, 1000, label=label, help_text=help_text), |
| 780 | + coreschema.Number(title=label, description=help_text) |
| 781 | + ), |
| 782 | + ( |
| 783 | + serializers.FloatField(label=label, help_text=help_text), |
| 784 | + coreschema.Number(title=label, description=help_text) |
| 785 | + ), |
| 786 | + ( |
| 787 | + serializers.IntegerField(label=label, help_text=help_text), |
| 788 | + coreschema.Integer(title=label, description=help_text) |
| 789 | + ), |
| 790 | + ( |
| 791 | + serializers.DateField(label=label, help_text=help_text), |
| 792 | + coreschema.String(title=label, description=help_text, format='date') |
| 793 | + ), |
| 794 | + ( |
| 795 | + serializers.DateTimeField(label=label, help_text=help_text), |
| 796 | + coreschema.String(title=label, description=help_text, format='date-time') |
| 797 | + ), |
| 798 | + ( |
| 799 | + serializers.JSONField(label=label, help_text=help_text), |
| 800 | + coreschema.Object(title=label, description=help_text) |
| 801 | + ), |
| 802 | + ] |
| 803 | + |
| 804 | + for case in cases: |
| 805 | + self.assertEqual(field_to_schema(case[0]), case[1]) |
| 806 | + |
766 | 807 |
|
767 | 808 | def test_docstring_is_not_stripped_by_get_description():
|
768 | 809 | class ExampleDocstringAPIView(APIView):
|
|
0 commit comments