.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.......
  }
相关推荐
颜淡慕潇20 小时前
动态代理赋能:高效爬取沃尔玛海量商品信息与AI分析实战
人工智能·后端
FL162386312921 小时前
C# winform部署yolo26-obb旋转框检测的onnx模型演示源码+模型+说明
开发语言·c#
半夏知半秋21 小时前
kcp学习-通用的kcp lua绑定
服务器·开发语言·笔记·后端·学习
hero.fei21 小时前
kaptcha 验证码生成工具在springboot中集成
java·spring boot·后端
w***76551 天前
存储技术全景:从基础原理到未来趋势
spring boot·后端·mybatis
J_liaty1 天前
基于ip2region.xdb数据库从IP获取到属地解析全攻略
java·网络·后端
且去填词1 天前
深入理解 GMP 模型:Go 高并发的基石
开发语言·后端·学习·算法·面试·golang·go
FAFU_kyp1 天前
Rust 模式匹配:match 与 if let 详解
开发语言·后端·rust
爬山算法1 天前
Hibernate(46) Hibernate的配置文件如何加载?
java·后端·hibernate
青w韵1 天前
SpringBoot3.x 升级到 SpringBoot 4.x,JDK17升级到JDK21
java·后端·spring