ASP.NET Core 6 - 从 swagger explorer 中隐藏最小的 api 端点

我有一个需要使用最少 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/

相关文章:

javascript - 如果其中没有图像, block 就会消失

rust - 为什么不可变结构在移入向量时会变为可变结构?

node.js - 连接 redis 时在 docker-compose 中出现错误 : conne

flutter - 如何在 Flutter App 上设置自定义图片图标?使用应用图标

r - 使用逗号分隔的长度不等的数字字符串对多列进行数学运算

javascript - 现代 Javascript 中的闭包 VS 类

typescript - 修改后的模板字面量类型

r - 根据字符串匹配过滤列表

rust - 为什么在堆栈中分配的值不会导致双自由指针?

r - 将一列拆分为两列 : dataframes within a list