Skip to content

Commit 1ad7bdf

Browse files
Repro issue
Change the integration test to use HTTP client so that the middleware to write the OpenAPI document is invoked, which is where the bug is. Going through `OpenApiDocument.SerializeAsJsonAsync()` uses a different code path that already uses a culture-invariant `TextWriter` so wasn't susceptible to the bug.
1 parent 7904a02 commit 1ad7bdf

File tree

16 files changed

+80
-16
lines changed

16 files changed

+80
-16
lines changed

src/OpenApi/src/Extensions/OpenApiEndpointRouteBuilderExtensions.cs

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

44
using System.Diagnostics.CodeAnalysis;
5-
using System.Globalization;
65
using Microsoft.AspNetCore.Http;
76
using Microsoft.AspNetCore.Internal;
87
using Microsoft.AspNetCore.OpenApi;
@@ -55,7 +54,7 @@ public static IEndpointConventionBuilder MapOpenApi(this IEndpointRouteBuilder e
5554
var document = await documentService.GetOpenApiDocumentAsync(context.RequestServices, context.Request, context.RequestAborted);
5655
var documentOptions = options.Get(lowercasedDocumentName);
5756

58-
using var textWriter = new Utf8BufferTextWriter(CultureInfo.InvariantCulture);
57+
using var textWriter = new Utf8BufferTextWriter(System.Globalization.CultureInfo.InvariantCulture);
5958
textWriter.SetWriter(context.Response.BodyWriter);
6059

6160
string contentType;

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/OpenApiDocumentIntegrationTests.cs

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

44
using Microsoft.AspNetCore.InternalTesting;
5-
using Microsoft.AspNetCore.OpenApi;
6-
using Microsoft.Extensions.DependencyInjection;
75
using Microsoft.OpenApi;
8-
using Microsoft.OpenApi.Extensions;
96

107
[UsesVerify]
118
public sealed class OpenApiDocumentIntegrationTests(SampleAppFixture fixture) : IClassFixture<SampleAppFixture>
@@ -38,10 +35,8 @@ public static TheoryData<string, OpenApiSpecVersion> OpenApiDocuments()
3835
[MemberData(nameof(OpenApiDocuments))]
3936
public async Task VerifyOpenApiDocument(string documentName, OpenApiSpecVersion version)
4037
{
41-
var documentService = fixture.Services.GetRequiredKeyedService<OpenApiDocumentService>(documentName);
42-
var scopedServiceProvider = fixture.Services.CreateScope();
43-
var document = await documentService.GetOpenApiDocumentAsync(scopedServiceProvider.ServiceProvider);
44-
var json = await document.SerializeAsJsonAsync(version);
38+
using var client = fixture.CreateClient();
39+
var json = await client.GetStringAsync($"/openapi/{documentName}.json");
4540
var baseSnapshotsDirectory = SkipOnHelixAttribute.OnHelix()
4641
? Path.Combine(Environment.GetEnvironmentVariable("HELIX_WORKITEM_ROOT"), "Integration", "snapshots")
4742
: "snapshots";

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_0/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=controllers.verified.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
{
2-
"openapi": "3.0.4",
2+
"openapi": "3.1.1",
33
"info": {
44
"title": "Sample | controllers",
55
"version": "1.0.0"
66
},
7+
"servers": [
8+
{
9+
"url": "http://localhost/"
10+
}
11+
],
712
"paths": {
813
"/getbyidandname/{id}/{name}": {
914
"get": {

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_0/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=forms.verified.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
{
2-
"openapi": "3.0.4",
2+
"openapi": "3.1.1",
33
"info": {
44
"title": "Sample | forms",
55
"version": "1.0.0"
66
},
7+
"servers": [
8+
{
9+
"url": "http://localhost/"
10+
}
11+
],
712
"paths": {
813
"/forms/form-file": {
914
"post": {

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_0/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=responses.verified.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
{
2-
"openapi": "3.0.4",
2+
"openapi": "3.1.1",
33
"info": {
44
"title": "Sample | responses",
55
"version": "1.0.0"
66
},
7+
"servers": [
8+
{
9+
"url": "http://localhost/"
10+
}
11+
],
712
"paths": {
813
"/responses/200-add-xml": {
914
"get": {

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_0/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=schemas-by-ref.verified.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
{
2-
"openapi": "3.0.4",
2+
"openapi": "3.1.1",
33
"info": {
44
"title": "Sample | schemas-by-ref",
55
"version": "1.0.0"
66
},
7+
"servers": [
8+
{
9+
"url": "http://localhost/"
10+
}
11+
],
712
"paths": {
813
"/schemas-by-ref/typed-results": {
914
"get": {

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_0/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=v1.verified.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
{
2-
"openapi": "3.0.4",
2+
"openapi": "3.1.1",
33
"info": {
44
"title": "Sample | v1",
55
"version": "1.0.0"
66
},
7+
"servers": [
8+
{
9+
"url": "http://localhost/"
10+
}
11+
],
712
"paths": {
813
"/v1/array-of-guids": {
914
"get": {

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_0/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=v2.verified.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"openapi": "3.0.4",
2+
"openapi": "3.1.1",
33
"info": {
44
"title": "Sample | v2",
55
"contact": {
@@ -11,6 +11,11 @@
1111
},
1212
"version": "1.0.0"
1313
},
14+
"servers": [
15+
{
16+
"url": "http://localhost/"
17+
}
18+
],
1419
"paths": {
1520
"/v2/users": {
1621
"get": {

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_0/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=xml.verified.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
{
2-
"openapi": "3.0.4",
2+
"openapi": "3.1.1",
33
"info": {
44
"title": "Sample | xml",
55
"version": "1.0.0"
66
},
7+
"servers": [
8+
{
9+
"url": "http://localhost/"
10+
}
11+
],
712
"paths": {
813
"/xml/type-with-examples": {
914
"get": {

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_1/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=controllers.verified.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"title": "Sample | controllers",
55
"version": "1.0.0"
66
},
7+
"servers": [
8+
{
9+
"url": "http://localhost/"
10+
}
11+
],
712
"paths": {
813
"/getbyidandname/{id}/{name}": {
914
"get": {

0 commit comments

Comments
 (0)