-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Description
When using WebApplication.MapMethods() with multiple HTTP methods (e.g., both GET and POST), the OpenAPI generation fails with an exception
Like this:
app.MapMethods("/weatherforecast", [HttpMethods.Get, HttpMethods.Post], TestHandler)
.WithName("GetWeatherForecast")
.WithOpenApi();
Expected Behavior
The OpenAPI generator should properly handle endpoints with multiple HTTP methods ,
Properly handle collections of HTTP methods instead of expecting a single method
Steps To Reproduce
1.Create a Minimal API project
2.Create an endpoint with multiple HTTP methods:
In Programs.cs
public static void Main(string[] args){
.........
app.MapMethods("/weatherforecast", [HttpMethods.Get, HttpMethods.Post], TestHandler)
.WithName("GetWeatherForecast")
.WithOpenApi();
app.Run();
}
public static IEnumerable<WeatherForecast> TestHandler()
{
.........
}
3.Run the application
The following exception occurs:
Exceptions (if any)
Message:"Sequence contains more than one element":
At System.Linq.ThrowHelper.ThrowMoreThanOneElementException()
At System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable1 source, Boolean& found) At System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable
1 source)
At Microsoft.AspNetCore.OpenApi.OpenApiGenerator.GetOpenApiOperation(MethodInfo methodInfo, EndpointMetadataCollection metadata, RoutePattern pattern)
At Microsoft.AspNetCore.Builder.OpenApiEndpointConventionBuilderExtensions.AddAndConfigureOperationForEndpoint(EndpointBuilder endpointBuilder, Func`2 configure)
.NET Version
8.0.14
Anything else?
No response