Skip to content

Made api_setting.UNICODE_JSON/ensure_ascii affecting json schema #7991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions rest_framework/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,13 +1035,16 @@ class CoreAPIJSONOpenAPIRenderer(_BaseOpenAPIRenderer):
media_type = 'application/vnd.oai.openapi+json'
charset = None
format = 'openapi-json'
ensure_ascii = not api_settings.UNICODE_JSON

def __init__(self):
assert coreapi, 'Using CoreAPIJSONOpenAPIRenderer, but `coreapi` is not installed.'

def render(self, data, media_type=None, renderer_context=None):
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):
Expand All @@ -1065,6 +1068,9 @@ class JSONOpenAPIRenderer(BaseRenderer):
charset = None
encoder_class = encoders.JSONEncoder
format = 'openapi-json'
ensure_ascii = not api_settings.UNICODE_JSON

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')