Incorrect OpenApi documentation in Minimal API when using WithOpenApi extension method
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Describe the bug
I’m using .NET 7.0. I have created a Minimal API with the following endpoint:
app.MapDelete("api/people/{id:int}", Results<NoContent, NotFound> (int id) =>
{
return id > 0 ? TypedResults.NoContent() : TypedResults.NotFound();
});
This produces the following page in Swagger:

In particular, the description of the 404 response is correctly “Not Found”.
However, if I add the WithOpenApi extension method to the endpoint, like this:
app.MapDelete("api/people/{id:int}", Results<NoContent, NotFound> (int id) =>
{
return id > 0 ? TypedResults.NoContent() : TypedResults.NotFound();
})
.WithOpenApi(operation =>
{
operation.Summary = "Deletes a person given the ID";
operation.Description = "If the person does not exist, a 404 response is returned";
return operation;
});
I obtain this:

So, the 404 response now has the description “Client error”, which is incorrect.
Expected Behavior
The description of 404 response should be “Not Found” even when I use the WithOpenApi extension method.
Steps To Reproduce
Minimal repro here: https://github.com/marcominerva/OpenApiIssue.
Exceptions (if any)
No response
.NET Version
7.0.100
Anything else?
Visual Studio 2022 17.4.1
.NET SDK: Version: 7.0.100 Commit: e12b7af219
Ambiente di runtime: OS Name: Windows OS Version: 10.0.22621 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\7.0.100\
Host: Version: 7.0.0 Architecture: x64 Commit: d099f075e4
.NET SDKs installed: 7.0.100 [C:\Program Files\dotnet\sdk]
.NET runtimes installed: Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables: Not set
global.json file: Not found
Issue Analytics
- State:
- Created 10 months ago
- Reactions:14
- Comments:5 (5 by maintainers)

Top Related StackOverflow Question
@marcominerva Thank you for reporting the issue and submitting a PR! I’ve opened a backport to .NET 7 so we can fix it there too. 🙇🏽
Thank you for the workaround, I’ll try to make a PR with the fix as soon as possible!