Skip to content

Commit

Permalink
Merge pull request #692 from ProstoMaxim/utf8-support
Browse files Browse the repository at this point in the history
Add utf-8 support for generated formats
  • Loading branch information
JoelLefkowitz authored Jul 14, 2022
2 parents 3f01252 + 55d2805 commit 113be08
Showing 1 changed file with 9 additions and 3 deletions.
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

0 comments on commit 113be08

Please sign in to comment.