.net:swagger 显示所有注释

一、安装下图的两个nuget包

二、请求和返回的class都需要加上summary包裹的注释头

三、program.cs添加配置

c# 复制代码
builder.Services.AddSwaggerGen(c =>
{
    c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
    c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "swagger文档标题", Version = "v1" });
    var sss = Assembly.GetExecutingAssembly();
    var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
    var xmlModelFile = "model层名称.xml";
    // 获取xml文件路径
   // var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); 
    c.CustomSchemaIds(x => x.FullName);
    c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFile), true);
    c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlModelFile), true);
    //c.IncludeXmlComments(xmlPath, true); 
});

四、接口请求头配置

c# 复制代码
  /// <summary>
  /// 接口名称
  /// </summary>
  /// <param name="参数名">注释</param>
   /// <returns></returns>
  [HttpPost]
  [AllowAnonymous] 
  [SwaggerResponse(200, "成功", typeof(返回的class名))]
  public ActionResult<返回的class名> getList([FromForm] 请求的class名 request)
  {
      return.......
  }
相关推荐
陈随易5 小时前
Postman 被曝自动往 Claude Code 和 Codex 装插件
前端·后端·程序员
云-缩影6 小时前
拆解 AI 图像生成应用的后端架构:ECS、OSS 和大模型 API 怎么配合
java·spring boot·后端
考虑考虑8 小时前
Posrgresql恢复.backup文件
数据库·后端·postgresql
无奈何杨8 小时前
风控决策系统决策流,策略模式,权重、顺序、投票、最坏
后端
Patrick_Wilson9 小时前
Go 为什么需要 defer?从函数怎么收尾说起
后端·go·编程语言
苏三说技术9 小时前
DeepSeek Harness入驻B站,评论区被干成了大型插件集市!
后端
橙序员小站10 小时前
我一句话让 AI 把公众号工作台搭完了:部署实测记录
后端
Patrick_Wilson10 小时前
从文本输出理解 Go 方法与接口
后端·go·编程语言
QCoding11 小时前
企业级Agent Evaluation实战:Agent能跑就能上线?AI Agent到底怎么测?
后端·spring
苍何11 小时前
让 WorkBuddy 操控浏览器,干活有点猛啊1
后端