'ASP.NET Core 6 - hide minimal api endpoint from swagger explorer
I have an implementation that requires the use of minimal APIs. But somehow, there is no way to exclude this from the swagger API explorer. In an MVC controller approach, we can hide endpoints using the [ApiExplorerSettings(IgnoreApi=true)], but this is not the case for minimal APIs.
Code:
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("api/v1/endpoint_a", () => { ... });
// Hide this from Swagger API explorer
app.MapGet("api/v1/endpoint_b", () => { ... });
Putting the attribute in the endpoint is valid, but it does not work.
Code:
app.MapGet("api/v1/endpoint_b", [ApiExplorerSettings(IgnoreApi=true)]() => { ... });
Any idea what I am missing in here?
Solution 1:[1]
Try this:
add ExcludeFromDescription() method after your endpoint, it worked for me.
app.MapPost("api/newUser", [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Roles = "Administrator")]
(string email, string password, int idUserGroup) =>
{
//Some code here
}).ExcludeFromDescription();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sajed |
