asp.net-core - ASP.NET Core 6.0 最小 API/Swagger 标签

标签 asp.net-core swagger swashbuckle.aspnetcore

有什么方法可以更改用最少的 api 编写的给定 http 方法的标记?

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

...

app.MapGet("/todo", () => "Hello world");

这样我就可以在文档中对方法进行逻辑分组,类似于它们在 Controller 中时的方法。

已编辑

我尝试了(来自@Modar Na 的提示)SwaggerOperation,不幸的是它没有帮助。

app.MapGet("/todo", [SwaggerOperation(Tags = new[] { "ToDo" })]() => "Hello world");
app.MapPost("/todo", [SwaggerOperation(Tags = new[] { "ToDo" })]() => "Hello world");

app.MapGet("/projects", [SwaggerOperation(Tags = new[] { "Projects" })]() => "Hello world");
app.MapPost("/projects", [SwaggerOperation(Tags = new[] { "Projects" })]() => "Hello world");

enter image description here

已更新

作为解决方法,我在配置 swagger 生成器时使用了 TagActionsBy 方法。

builder.Services.AddSwaggerGen(c =>
{
    c.TagActionsBy(d =>
    {
        return new List<string>() { d.ActionDescriptor.DisplayName! };
    });
});

查看我的 blog post .

最佳答案

怎么样:

app.MapGet("/todo", () => "Hello world").WithTags("ToDo");

关于asp.net-core - ASP.NET Core 6.0 最小 API/Swagger 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69356127/

相关文章:

java - SpringFox Swagger 与 Springboot 应用程序集成

swagger - Swagger 的多个 Api 版本

asp.net-core - Swagger Swashbuckle Asp.NET Core : show details about every enum is used

C# MVC/API - 从 Amazon S3 为我的 API 调用返回图像

c# - 使用 ReactJS SPA 在 .net Core 中进行身份验证

c# - 选择 webApi 模板时如何将 ASP.Net 身份添加到 Asp.Net Core?

c# - 如何允许 powershell 从 .net 核心 MVC web 应用程序下载 EXE?

django - 为什么我收到 django Rest Framework swagger 的 "no module named urls"错误?

ABP/Swashbuckle - 使用 Swashbuckle CLI 生成 swagger 文档

.net - 解决混合内容错误的Swagger设置