Skip to content
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

Add utf-8 support for generated formats #692

Merged
merged 3 commits into from
Jul 14, 2022
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
12 changes: 9 additions & 3 deletions src/drf_yasg/codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ def _dump_dict(self, spec):

:rtype: str"""
if self.pretty:
out = json.dumps(spec, indent=4, separators=(',', ': '))
out = json.dumps(spec, indent=4, separators=(',', ': '), ensure_ascii=False)
if out[-1] != '\n':
out += '\n'
return out
else:
return json.dumps(spec)
return json.dumps(spec, ensure_ascii=False)


YAML_MAP_TAG = u'tag:yaml.org,2002:map'
Expand Down Expand Up @@ -199,7 +199,13 @@ def yaml_sane_dump(data, binary):
:return: the serialized YAML
:rtype: str or bytes
"""
return yaml.dump(data, Dumper=SaneYamlDumper, default_flow_style=False, encoding='utf-8' if binary else None)
return yaml.dump(
data,
Dumper=SaneYamlDumper,
default_flow_style=False,
encoding='utf-8' if binary else None,
allow_unicode=binary
)


class SaneYamlLoader(yaml.SafeLoader):
Expand Down