Write multi-line strings in block style (#466)

Closes  #439
This commit is contained in:
Ned Batchelder authored and Cristi Vîjdea committed 2019-10-03 02:06:05 +03:00
1 parent 13311582ea
commit a72e5b2899
4 files changed
+31 -7

No files matched your search

+9 -2
View File
@@ -1,5 +1,3 @@
from six import raise_from
import copy
import json
import logging
@@ -8,6 +6,8 @@ from collections import OrderedDict
from coreapi.compat import force_bytes
from ruamel import yaml
from six import binary_type, raise_from, text_type
from . import openapi
from .errors import SwaggerValidationError
@@ -176,7 +176,14 @@ class SaneYamlDumper(yaml.SafeDumper):
node.flow_style = best_style
return node
def represent_text(self, text):
if "\n" in text:
return self.represent_scalar('tag:yaml.org,2002:str', text, style='|')
return self.represent_scalar('tag:yaml.org,2002:str', text)
SaneYamlDumper.add_representer(binary_type, SaneYamlDumper.represent_text)
SaneYamlDumper.add_representer(text_type, SaneYamlDumper.represent_text)
SaneYamlDumper.add_representer(OrderedDict, SaneYamlDumper.represent_odict)
SaneYamlDumper.add_multi_representer(OrderedDict, SaneYamlDumper.represent_odict)