mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 09:36:49 +03:00
Represent SafeString as plain string on schema rendering. (#8429)
* Use SafeString.represent_str to represent SafeString as str * Add SafeString yaml rendering test
This commit is contained in:
parent
c0d95cb967
commit
ebde56b932
|
@ -19,6 +19,7 @@ from django.core.paginator import Page
|
|||
from django.template import engines, loader
|
||||
from django.urls import NoReverseMatch
|
||||
from django.utils.html import mark_safe
|
||||
from django.utils.safestring import SafeString
|
||||
|
||||
from rest_framework import VERSION, exceptions, serializers, status
|
||||
from rest_framework.compat import (
|
||||
|
@ -1055,6 +1056,7 @@ class OpenAPIRenderer(BaseRenderer):
|
|||
class Dumper(yaml.Dumper):
|
||||
def ignore_aliases(self, data):
|
||||
return True
|
||||
Dumper.add_representer(SafeString, Dumper.represent_str)
|
||||
return yaml.dump(data, default_flow_style=False, sort_keys=False, Dumper=Dumper).encode('utf-8')
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import pytest
|
|||
from django.db import models
|
||||
from django.test import RequestFactory, TestCase, override_settings
|
||||
from django.urls import path
|
||||
from django.utils.safestring import SafeString
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from rest_framework import filters, generics, pagination, routers, serializers
|
||||
|
@ -583,6 +584,11 @@ class TestOperationIntrospection(TestCase):
|
|||
renderer.render(data) == b'o2:\n test: test\no1:\n test: test\n' # py <= 3.5
|
||||
)
|
||||
|
||||
def test_openapi_yaml_safestring_render(self):
|
||||
renderer = OpenAPIRenderer()
|
||||
data = {'o1': SafeString('test')}
|
||||
assert renderer.render(data) == b'o1: test\n'
|
||||
|
||||
def test_serializer_filefield(self):
|
||||
path = '/{id}/'
|
||||
method = 'POST'
|
||||
|
|
Loading…
Reference in New Issue
Block a user