Skip to content

Commit 78ef1b0

Browse files
committed
Register document names in a case-insensitive manner
1 parent e16335d commit 78ef1b0

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/OpenApi/src/Extensions/OpenApiEndpointRouteBuilderExtensions.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,22 @@ 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.
37+
var lowercasedDocumentName = documentName.ToLowerInvariant();
38+
3339
// It would be ideal to use the `HttpResponseStreamWriter` to
3440
// asynchronously write to the response stream here but Microsoft.OpenApi
3541
// does not yet support async APIs on their writers.
3642
// See https://github.com/microsoft/OpenAPI.NET/issues/421 for more info.
37-
var documentService = context.RequestServices.GetKeyedService<OpenApiDocumentService>(documentName);
43+
var documentService = context.RequestServices.GetKeyedService<OpenApiDocumentService>(lowercasedDocumentName);
3844
if (documentService is null)
3945
{
4046
context.Response.StatusCode = StatusCodes.Status404NotFound;
4147
context.Response.ContentType = "text/plain;charset=utf-8";
42-
await context.Response.WriteAsync($"No OpenAPI document with the name '{documentName}' was found.");
48+
await context.Response.WriteAsync($"No OpenAPI document with the name '{lowercasedDocumentName}' was found.");
4349
}
4450
else
4551
{

0 commit comments

Comments
 (0)