Skip to content

Commit 9d9671d

Browse files
[OpenAPI] Fix Culture formatting for [Range]
Update OpenAPI range formatting to format using the target culture and update tests to write in the invariant culture. Co-Authored-By: Sjoerd van der Meer <[email protected]>
1 parent 1ad7bdf commit 9d9671d

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/OpenApi/src/Extensions/JsonNodeSchemaExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ internal static void ApplyValidationAttributes(this JsonNode schema, IEnumerable
9797
? CultureInfo.InvariantCulture
9898
: CultureInfo.CurrentCulture;
9999

100-
var minString = rangeAttribute.Minimum.ToString();
101-
var maxString = rangeAttribute.Maximum.ToString();
100+
var minString = string.Format(targetCulture, "{0}", rangeAttribute.Minimum);
101+
var maxString = string.Format(targetCulture, "{0}", rangeAttribute.Maximum);
102102

103103
if (decimal.TryParse(minString, NumberStyles.Any, targetCulture, out var minDecimal))
104104
{

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/SnapshotTestHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Diagnostics;
5+
using System.Globalization;
56
using System.Reflection;
67
using System.Runtime.Loader;
78
using System.Text;
@@ -16,6 +17,7 @@
1617
using Microsoft.Extensions.DependencyInjection;
1718
using Microsoft.Extensions.Hosting;
1819
using Microsoft.OpenApi.Models;
20+
using Microsoft.OpenApi.Writers;
1921

2022
namespace Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests;
2123

@@ -197,8 +199,7 @@ void OnEntryPointExit(Exception exception)
197199

198200
var service = services.GetService(serviceType) ?? throw new InvalidOperationException("Could not resolve IDocumentProvider service.");
199201
using var stream = new MemoryStream();
200-
var encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);
201-
using var writer = new StreamWriter(stream, encoding, bufferSize: 1024, leaveOpen: true);
202+
using var writer = new FormattingStreamWriter(stream, CultureInfo.InvariantCulture) { AutoFlush = true };
202203
var targetMethod = serviceType.GetMethod("GenerateAsync", [typeof(string), typeof(TextWriter)]) ?? throw new InvalidOperationException("Could not resolve GenerateAsync method.");
203204
targetMethod.Invoke(service, ["v1", writer]);
204205
stream.Position = 0;

0 commit comments

Comments
 (0)