Skip to content

Commit b74bff1

Browse files
committed
Improve comments
1 parent 12633da commit b74bff1

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/OpenApi/src/Extensions/OpenApiEndpointRouteBuilderExtensions.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ public static IEndpointConventionBuilder MapOpenApi(this IEndpointRouteBuilder e
3030
var options = endpoints.ServiceProvider.GetRequiredService<IOptionsMonitor<OpenApiOptions>>();
3131
return endpoints.MapGet(pattern, async (HttpContext context, string documentName = OpenApiConstants.DefaultDocumentName) =>
3232
{
33-
// We need to retrieve the document name in a case-insensitive manner
34-
// to support case-insensitive document name resolution.
35-
// Keyed Services are case-sensitive by default, which doesn't work well for document names in ASP.NET Core
36-
// as routing in ASP.NET Core is case-insensitive by default.
33+
// We need to retrieve the document name in a case-insensitive manner to support case-insensitive document name resolution.
34+
// The document service is registered with a key equal to the document name, but in lowercase.
35+
// The GetRequiredKeyedService() method is case-sensitive, which doesn't work well for OpenAPI document names here,
36+
// 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.
37+
// The same goes for the document options below, which is also case-sensitive, and thus we need to pass in a case-insensitive document name.
38+
// See OpenApiServiceCollectionExtensions.cs for more info.
3739
var lowercasedDocumentName = documentName.ToLowerInvariant();
3840

3941
// It would be ideal to use the `HttpResponseStreamWriter` to

src/OpenApi/src/Extensions/OpenApiServiceCollectionExtensions.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,9 @@ public static IServiceCollection AddOpenApi(this IServiceCollection services, st
5757
ArgumentNullException.ThrowIfNull(services);
5858
ArgumentNullException.ThrowIfNull(configureOptions);
5959

60-
// We need to store the document name in a case-insensitive manner
61-
// to support case-insensitive document name resolution.
62-
// Keyed Services are case-sensitive by default, which doesn't work well for document names in ASP.NET Core
63-
// as routing in ASP.NET Core is case-insensitive by default.
60+
// We need to register the document name in a case-insensitive manner to support case-insensitive document name resolution.
61+
// The document name is used to store and retrieve keyed services and configuration options, which are all case-sensitive.
62+
// To achieve parity with ASP.NET Core routing, which is case-insensitive, we need to ensure the document name is lowercased.
6463
var lowercasedDocumentName = documentName.ToLowerInvariant();
6564

6665
services.AddOpenApiCore(lowercasedDocumentName);

0 commit comments

Comments
 (0)