Skip to content

Commit b053848

Browse files
committed
fix: yaml blocks and line returns
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
1 parent 314dd38 commit b053848

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Microsoft.OpenApi.YamlReader/YamlConverter.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,19 @@ private static YamlScalarNode ToYamlScalar(this JsonValue val)
151151
// Strings that look like numbers, booleans, or null need to be quoted
152152
// to preserve their string type when round-tripping
153153
var needsQuoting = NeedsQuoting(stringValue);
154+
155+
var containsNewLine = stringValue.Contains('\n');
156+
157+
var style = (needsQuoting, containsNewLine) switch
158+
{
159+
(true, _) => ScalarStyle.DoubleQuoted,
160+
(false, true) => ScalarStyle.Literal,
161+
(false, false) => ScalarStyle.Plain
162+
};
154163

155164
return new YamlScalarNode(stringValue)
156165
{
157-
Style = needsQuoting ? ScalarStyle.DoubleQuoted : ScalarStyle.Plain
166+
Style = style
158167
};
159168
}
160169

0 commit comments

Comments
 (0)