Skip to content

Commit af3abd5

Browse files
committed
Add culture invariant writer.
1 parent 8315dc9 commit af3abd5

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
using System.Globalization;
45
using System.IO;
56
using Microsoft.OpenApi.Exceptions;
67
using Microsoft.OpenApi.Interfaces;
@@ -62,13 +63,14 @@ public static void Serialize<T>(
6263
}
6364

6465
IOpenApiWriter writer;
66+
var streamWriter = new FormattingStreamWriter(stream, CultureInfo.InvariantCulture);
6567
switch (format)
6668
{
6769
case OpenApiFormat.Json:
68-
writer = new OpenApiJsonWriter(new StreamWriter(stream));
70+
writer = new OpenApiJsonWriter(streamWriter);
6971
break;
7072
case OpenApiFormat.Yaml:
71-
writer = new OpenApiYamlWriter(new StreamWriter(stream));
73+
writer = new OpenApiYamlWriter(streamWriter);
7274
break;
7375
default:
7476
throw new OpenApiException(string.Format(SRResource.OpenApiFormatNotSupported, format));
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Microsoft.OpenApi.Writers
9+
{
10+
public class FormattingStreamWriter : StreamWriter
11+
{
12+
public FormattingStreamWriter(Stream stream, IFormatProvider formatProvider)
13+
: base(stream)
14+
{
15+
this.FormatProvider = formatProvider;
16+
}
17+
18+
public override IFormatProvider FormatProvider { get; }
19+
}
20+
}

0 commit comments

Comments
 (0)