.Net 6, Minimal API - Endpoint does not appear in swagger-output if Microsoft.AspNetCore.Http parameter exists in "MapXXX"
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Describe the bug
I want to use minimal API with swagger, but if i use the “HttpContext” in the parameter-list, the endpoint is not showing in the swagger-result (json and output).
The error only happens if the “HttpContext” parameter stands alone.
Is this a bug or a misunderstanding ?
You can see the example above, the endpoint “WithContext” is not showing in swagger-output/json, all ohter are showing.
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
app.UseSwagger();
app.MapGet("/", () => "Hello World!"); // => is showing
// is showing
app.MapGet("/WithHttpResonse", async (HttpResponse response) =>
await response.WriteAsJsonAsync("Test")).WithName("GetWithHttpResonse");
// is showing
app.MapGet("/WithHttpResonseV2", async (HttpResponse response,HttpContext httpContext) =>
await httpContext.Response.WriteAsJsonAsync("Test")).WithName("GetWithHttpResonseV2");
// DOES NOT APPEAR
app.MapGet("/WithContext", async (HttpContext context) =>
await context.Response.WriteAsJsonAsync("Test")).WithName("GetWithContext");
app.MapSwagger();
app.UseSwaggerUI();
app.Run();
Expected Behavior
The endpoint “WithContext” is showing in the swagger-output.
Steps To Reproduce
See code-example in description
Exceptions (if any)
No response
.NET Version
Visual Studio Community 2022 (17.0.5)
.NET SDK (reflecting any global.json):
Version: 6.0.101
Commit: ef49f6213a
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19043
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\6.0.101\
Host (useful for support):
Version: 6.0.1
Commit: 3a25a7f1cc
.NET SDKs installed:
6.0.101 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Anything else?
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Minimal API endpoints with only Microsoft.AspNetCore.Http ...
I use Version 6.2.3.0 I want to use minimal API with swagger, but if i use the ... Http parameter does not appear...
Read more >Parameter binding in Minimal API applications
Binding from form values is not natively supported in .NET 6 and 7. The following GET route handler uses some of these parameter...
Read more >Minimal APIs quick reference
Provides an overview of minimal APIs in ASP. ... WebApplication; WebApplicationBuilder; ASP.NET Core Middleware; Routing ... Show 6 more.
Read more >Tutorial: Create a minimal API with ASP.NET Core
Another approach to creating APIs in ASP.NET Core is to use controllers. For help in choosing between minimal APIs and controller-based APIs, ...
Read more >Create responses in Minimal API applications
Learn how to create responses for minimal APIs in ASP.NET Core. ... defines a contract that represents the result of an HTTP endpoint....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
A valid situation to define an endpoint that is affected by this issue is for health checking (something that I define in all APIs).
Since this practice is common I think many applications are affected.
I’ve tried this again on .NET 7 RC 2 and have confirmed that I’m seeing endpoints with HttpContext. Closing for now.