mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-29 01:20:02 +03:00
fix #6831
This commit is contained in:
parent
659375ffe6
commit
8d8ba719e4
|
@ -377,7 +377,7 @@ class AutoSchema(ViewInspector):
|
||||||
if field.default and field.default != empty: # why don't they use None?!
|
if field.default and field.default != empty: # why don't they use None?!
|
||||||
schema['default'] = field.default
|
schema['default'] = field.default
|
||||||
if field.help_text:
|
if field.help_text:
|
||||||
schema['description'] = field.help_text
|
schema['description'] = force_text(field.help_text)
|
||||||
self._map_field_validators(field.validators, schema)
|
self._map_field_validators(field.validators, schema)
|
||||||
|
|
||||||
properties[field.field_name] = schema
|
properties[field.field_name] = schema
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import pytest
|
import pytest
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
from django.test import RequestFactory, TestCase, override_settings
|
from django.test import RequestFactory, TestCase, override_settings
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from rest_framework import filters, generics, pagination, routers, serializers
|
from rest_framework import filters, generics, pagination, routers, serializers
|
||||||
from rest_framework.compat import uritemplate
|
from rest_framework.compat import uritemplate
|
||||||
|
@ -273,6 +274,15 @@ class TestOperationIntrospection(TestCase):
|
||||||
assert response_schema['ip']['type'] == 'string'
|
assert response_schema['ip']['type'] == 'string'
|
||||||
assert 'format' not in response_schema['ip']
|
assert 'format' not in response_schema['ip']
|
||||||
|
|
||||||
|
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.')
|
@pytest.mark.skipif(uritemplate is None, reason='uritemplate not installed.')
|
||||||
@override_settings(REST_FRAMEWORK={'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.openapi.AutoSchema'})
|
@override_settings(REST_FRAMEWORK={'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.openapi.AutoSchema'})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user