Use SafeString.represent_str to represent SafeString as str

This commit is contained in:
hashlash 2022-03-17 21:06:48 +07:00
parent df92e57ad6
commit 1aad0371e0

View File

@ -18,6 +18,7 @@ from django.http.multipartparser import parse_header
from django.template import engines, loader from django.template import engines, loader
from django.urls import NoReverseMatch from django.urls import NoReverseMatch
from django.utils.html import mark_safe from django.utils.html import mark_safe
from django.utils.safestring import SafeString
from rest_framework import VERSION, exceptions, serializers, status from rest_framework import VERSION, exceptions, serializers, status
from rest_framework.compat import ( from rest_framework.compat import (
@ -1060,6 +1061,7 @@ class OpenAPIRenderer(BaseRenderer):
class Dumper(yaml.Dumper): class Dumper(yaml.Dumper):
def ignore_aliases(self, data): def ignore_aliases(self, data):
return True 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') return yaml.dump(data, default_flow_style=False, sort_keys=False, Dumper=Dumper).encode('utf-8')