惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
The Blog of Author Tim Ferriss
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
有赞技术团队
有赞技术团队
量子位
S
SegmentFault 最新的问题
博客园 - 聂微东
博客园 - 【当耐特】
J
Java Code Geeks
美团技术团队
Hugging Face - Blog
Hugging Face - Blog
H
Help Net Security
V
V2EX
人人都是产品经理
人人都是产品经理
博客园 - Franky
罗磊的独立博客
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
云风的 BLOG
云风的 BLOG
Y
Y Combinator Blog
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - 余昭(Ray)

AI 编程实战营毕业总结 解决github访问速度慢的问题 使用交互界面配置centos网络(NMTUI) 银河麒麟安装达梦数据库失败Unable to load native library: libnsl.so.1: cannot open shared object file: No such file or directory 编译Windows 版本的Redis 6.x TypeScript入门 NetCore使用Nlog记录日志 QuickStart系列:Docker部署PostgreSQL 搭建docker本地仓库 NT Kernel & System (ntoskrnl)占用80端口 简单的验证码识别 使用SSH配置git服务器免密提交 QuickStart系列:docker部署之Gitlab本地代码仓库 https环境搭建(本地搭建) docker搭建elk 使用本机IP调试web项目 本地调试微信(内网穿透) ElasticsearchCRUD翻译系列之(一): ElasticsearchCRUD 介绍 阿里云Oss对象存储 asp.netmvc部署到linux(centos)
Net5中使用Swagger
余昭(Ray) · 2021-03-02 · via 博客园 - 余昭(Ray)

1. 新建netcore项目

2. 使用nuget包安装 Swashbuckle.AspNetCore

使用RestorePackagesPath属性配置nuget包的路径(可选)

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
      <RestorePackagesPath>..\packages</RestorePackagesPath>
  </PropertyGroup>

3. 勾选生成项目xml文件

 4.在Startup中添加代码

在ConfigureServices 中添加配置。

services.AddSwaggerGen(c =>
 {
    c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
   
   var basePath = HostEnvironment.ContentRootPath;
   var xmlPath = Path.Combine(basePath, $"{typeof(Startup).Namespace}.xml");
   c.IncludeXmlComments(xmlPath, true);
});

在Configure中添加代码

 app.UseSwagger(); 
app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); });

5.访问

/swagger (访问swagger页面。)

/swagger/v1/swagger.json  (查看异常页)