.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.......
  }
相关推荐
Victor35619 小时前
https://editor.csdn.net/md/?articleId=139321571&spm=1011.2415.3001.9698
后端
Victor35619 小时前
Hibernate(89)如何在压力测试中使用Hibernate?
后端
灰子学技术21 小时前
go response.Body.close()导致连接异常处理
开发语言·后端·golang
Gogo8161 天前
BigInt 与 Number 的爱恨情仇,为何大佬都劝你“能用 Number 就别用 BigInt”?
后端
fuquxiaoguang1 天前
深入浅出:使用MDC构建SpringBoot全链路请求追踪系统
java·spring boot·后端·调用链分析
bugcome_com1 天前
零基础入门C#:一篇搞懂核心知识点
c#
毕设源码_廖学姐1 天前
计算机毕业设计springboot招聘系统网站 基于SpringBoot的在线人才对接平台 SpringBoot驱动的智能求职与招聘服务网
spring boot·后端·课程设计
野犬寒鸦1 天前
从零起步学习并发编程 || 第六章:ReentrantLock与synchronized 的辨析及运用
java·服务器·数据库·后端·学习·算法
逍遥德1 天前
如何学编程之01.理论篇.如何通过阅读代码来提高自己的编程能力?
前端·后端·程序人生·重构·软件构建·代码规范
程序员敲代码吗1 天前
如何通过命令行启动COMSOL的参数化、批处理和集群扫描
java·c#·bash