-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Closed
Copy link
Labels
area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-actionsController-like actions for endpoint routingController-like actions for endpoint routingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Milestone
Description
Calling .WithName("ApiName") on a minimal endpoint API does not add a RouteNameMetadata with specified name to the endpoint's metadata, just an EndpointNameMetadata. This means URLs can't be generated for the endpoint by IUrlHelper using route values, which includes the Results.CreatedAtRoute method.
We should update .WithName(string name) to also add the RouteNameMetadata.
Repro code:
app.MapGet("/todos/{id}", async (int id, TodoDb db) =>
{
return await db.Todos.FindAsync(id)
is Todo todo
? Results.Ok(todo)
: Results.NotFound();
})
.WithName("GetTodoById")
.Produces<Todo>()
.Produces(StatusCodes.Status404NotFound);
app.MapPost("/todos", async (Todo todo, TodoDb db) =>
{
db.Todos.Add(todo);
await db.SaveChangesAsync();
return Results.CreatedAtRoute("GetTodoById", new { todo.Id } , todo);
})
.WithName("AddTodo")
.ProducesValidationProblem()
.Produces<Todo>(StatusCodes.Status201Created);Metadata
Metadata
Assignees
Labels
area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-actionsController-like actions for endpoint routingController-like actions for endpoint routingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels