.net core 安装Swagger
Install-Package Swashbuckle -Pre
1.Startup
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
//******************* swagger start ***********************
services.AddSwaggerGen(c =>
{
c.SingleApiVersion(new Info
{
Version = "v1", // 这个属性必须要填,否则会引发一个异常
Title = "Feature List",
Description = "特征"
});
});
services.ConfigureSwaggerGen(c =>
{
// 配置生成的 xml 注释文档路径
c.IncludeXmlComments(GetXmlCommentsPath());
});
//******************* swagger end ***********************
}
private string GetXmlCommentsPath()
{
var app = PlatformServices.Default.Application;
return Path.Combine(app.ApplicationBasePath, Path.ChangeExtension(app.ApplicationName, "xml"));
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseMvc();
//******************* swagger start ***********************
app.UseSwagger();
app.UseSwaggerUi("swagger/ui/index");
//******************* swagger end ***********************
}
如上:
//******************* swagger start ***********************
//******************* swagger end ***********************
2.launchSettings.json
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:40675/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger/ui/index",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"SigmalHex.WebApi": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger/ui/index",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:40676"
}
}
}
如:
"launchUrl": "swagger/ui/index",
分类:
dotnet core
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 新年开篇:在本地部署DeepSeek大模型实现联网增强的AI应用
· DeepSeek火爆全网,官网宕机?本地部署一个随便玩「LLM探索」
· Janus Pro:DeepSeek 开源革新,多模态 AI 的未来
· 上周热点回顾(1.20-1.26)
· 【译】.NET 升级助手现在支持升级到集中式包管理
2015-05-26 Linux基础命令(1)
2015-05-26 Ubuntu 安装Redis体验
2015-05-26 ubuntu 重置密码
2015-05-26 log4net按照不同的级别输出到不同文件
2015-05-26 ConversionPattern 解析