Skip to content

Commit 4522e67

Browse files
committed
Implemented PR comments
1 parent 3d318ca commit 4522e67

File tree

3 files changed

+3
-8
lines changed

3 files changed

+3
-8
lines changed

src/OpenApi/src/Extensions/OpenApiServiceCollectionExtensions.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@ public static IServiceCollection AddOpenApi(this IServiceCollection services, Ac
105105
public static IServiceCollection AddOpenApi(this IServiceCollection services)
106106
=> services.AddOpenApi(OpenApiConstants.DefaultDocumentName);
107107

108-
/// <param name="services">The <see cref="IServiceCollection"/> to register services onto.</param>
109-
/// <param name="documentName">Please ensure this is lowercased to prevent case-sensitive routing issues</param>
110-
/// <remarks>See https://github.com/dotnet/aspnetcore/issues/59175 for more information around the routing issue mentioned above</remarks>
111108
private static IServiceCollection AddOpenApiCore(this IServiceCollection services, string documentName)
112109
{
113110
services.AddEndpointsApiExplorer();

src/OpenApi/src/Services/OpenApiDocumentProvider.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ internal sealed class OpenApiDocumentProvider(IServiceProvider serviceProvider)
2525
/// <param name="writer">A text writer associated with the document to write to.</param>
2626
public async Task GenerateAsync(string documentName, TextWriter writer)
2727
{
28-
// We need to retrieve the document name in a case-insensitive manner to support case-insensitive document name resolution.
29-
// The options are registered with a key equal to the document name, but in lowercase.
30-
// The options monitor's Get() method is case-sensitive, which doesn't work well for OpenAPI document names here,
31-
// as the document name is also used as the route to retrieve the document, so we need to ensure this is lowercased to achieve consistency with ASP.NET Core routing.
32-
// See OpenApiServiceCollectionExtensions.cs for more info.
28+
// See OpenApiServiceCollectionExtensions.cs to learn why we lowercase the document name
3329
var lowercasedDocumentName = documentName.ToLowerInvariant();
3430

3531
var options = serviceProvider.GetRequiredService<IOptionsMonitor<OpenApiOptions>>();

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Services/OpenApiDocumentProviderTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public async Task GenerateAsync_ShouldRetrieveOpenApiDocumentServiceWithACaseIns
7070
await documentProvider.GenerateAsync(documentName, stringWriter, OpenApiSpecVersion.OpenApi3_0);
7171

7272
// Assert
73+
var document = stringWriter.ToString();
7374

7475
// If the Document Service is retrieved with a non-existent (case-sensitive) key, it would throw:
7576
// https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.serviceproviderkeyedserviceextensions.getrequiredkeyedservice?view=net-9.0-pp
@@ -79,6 +80,7 @@ public async Task GenerateAsync_ShouldRetrieveOpenApiDocumentServiceWithACaseIns
7980
// Therefore, if the test doesn't throw, we know it has passed correctly.
8081
// We still do a small check to validate the document, just in case. But the main test is that it doesn't throw.
8182
ValidateOpenApiDocument(stringWriter, _ => { });
83+
Assert.StartsWith("{\n \"openapi\": \"3.0.1\"", document);
8284
}
8385

8486
[Fact]

0 commit comments

Comments
 (0)