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

Closes  #439
This commit is contained in:
Ned Batchelder
2019-10-02 19:06:05 -04:00
committed by Cristi Vîjdea
parent 13311582ea
commit a72e5b2899
4 changed files with 31 additions and 7 deletions
+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)