我有一个需要使用最少 API 的实现。但不知何故,无法将其从 swagger API 资源管理器中排除。在 MVC Controller 方法中,我们可以使用 [ApiExplorerSettings(IgnoreApi=true)]
隐藏端点,但最小 API 并非如此。
代码:
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", () => { ... });
将属性放在端点中是有效的,但它不起作用。
代码:
app.MapGet("api/v1/endpoint_b", [ApiExplorerSettings(IgnoreApi=true)]() => { ... });
知道我在这里遗漏了什么吗?
最佳答案
试试这个:
在你的端点后添加 ExcludeFromDescription()
方法,它对我有用。
app.MapPost("api/newUser", [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Roles = "Administrator")]
(string email, string password, int idUserGroup) =>
{
//Some code here
}).ExcludeFromDescription();
https://stackoverflow.com/questions/71616644/