Made api_setting.UNICODE_JSON/ensure_ascii affecting json schema (#7991)

This commit is contained in:
Alexander Klimenko 2021-12-08 17:37:32 +03:00 committed by GitHub
parent 3a762d9aac
commit b0d407fd63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1035,13 +1035,16 @@ class CoreAPIJSONOpenAPIRenderer(_BaseOpenAPIRenderer):
media_type = 'application/vnd.oai.openapi+json' media_type = 'application/vnd.oai.openapi+json'
charset = None charset = None
format = 'openapi-json' format = 'openapi-json'
ensure_ascii = not api_settings.UNICODE_JSON
def __init__(self): def __init__(self):
assert coreapi, 'Using CoreAPIJSONOpenAPIRenderer, but `coreapi` is not installed.' assert coreapi, 'Using CoreAPIJSONOpenAPIRenderer, but `coreapi` is not installed.'
def render(self, data, media_type=None, renderer_context=None): def render(self, data, media_type=None, renderer_context=None):
structure = self.get_structure(data) structure = self.get_structure(data)
return json.dumps(structure, indent=4).encode('utf-8') return json.dumps(
structure, indent=4,
ensure_ascii=self.ensure_ascii).encode('utf-8')
class OpenAPIRenderer(BaseRenderer): class OpenAPIRenderer(BaseRenderer):
@ -1065,6 +1068,9 @@ class JSONOpenAPIRenderer(BaseRenderer):
charset = None charset = None
encoder_class = encoders.JSONEncoder encoder_class = encoders.JSONEncoder
format = 'openapi-json' format = 'openapi-json'
ensure_ascii = not api_settings.UNICODE_JSON
def render(self, data, media_type=None, renderer_context=None): def render(self, data, media_type=None, renderer_context=None):
return json.dumps(data, cls=self.encoder_class, indent=2).encode('utf-8') return json.dumps(
data, cls=self.encoder_class, indent=2,
ensure_ascii=self.ensure_ascii).encode('utf-8')