Skip to content

Commit 14dd22b

Browse files
committed
Update OpenAPI range formatting to format using the target culture and Update tests to write in the InvariantCulture
1 parent 944f0f5 commit 14dd22b

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
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/SchemaTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Net.Http;

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)