mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 00:04:16 +03:00
OpenAPI schemas: Ensure lazy field descriptions are converted to str(). (#6832)
This commit is contained in:
parent
659375ffe6
commit
ca727872c8
|
@ -377,7 +377,7 @@ class AutoSchema(ViewInspector):
|
|||
if field.default and field.default != empty: # why don't they use None?!
|
||||
schema['default'] = field.default
|
||||
if field.help_text:
|
||||
schema['description'] = field.help_text
|
||||
schema['description'] = str(field.help_text)
|
||||
self._map_field_validators(field.validators, schema)
|
||||
|
||||
properties[field.field_name] = schema
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import pytest
|
||||
from django.conf.urls import url
|
||||
from django.test import RequestFactory, TestCase, override_settings
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from rest_framework import filters, generics, pagination, routers, serializers
|
||||
from rest_framework.compat import uritemplate
|
||||
|
@ -52,6 +53,15 @@ class TestFieldMapping(TestCase):
|
|||
with self.subTest(field=field):
|
||||
assert inspector._map_field(field) == mapping
|
||||
|
||||
def test_lazy_string_field(self):
|
||||
class Serializer(serializers.Serializer):
|
||||
text = serializers.CharField(help_text=_('lazy string'))
|
||||
|
||||
inspector = AutoSchema()
|
||||
|
||||
data = inspector._map_serializer(Serializer())
|
||||
assert isinstance(data['properties']['text']['description'], str), "description must be str"
|
||||
|
||||
|
||||
@pytest.mark.skipif(uritemplate is None, reason='uritemplate not installed.')
|
||||
class TestOperationIntrospection(TestCase):
|
||||
|
|
Loading…
Reference in New Issue
Block a user