.Net Core Swagger配置
第一步,安装swagger
使用程序包管理器控制台,输入如下命令:
PM> Install-Package Swashbuckle.AspNetCore -Version 5.0.0-rc4
第二部,StartUp.cs配置
ConfigureServices方法中添加如下代码:
public void ConfigureServices(IServiceCollection services) { services.AddSwaggerGen(m=> { m.SwaggerDoc("SWG1",new OpenApiInfo {Title = "swaggerTest",Version= "SWG1" }); }); services.AddControllers(); }
注意 SWG1 这是随便取的名字
Configure中添加如下代码,使用中间件:
app.UseSwagger(); app.UseSwaggerUI(m=> { m.SwaggerEndpoint("/Swagger/SWG1/swagger.json","swaggerTest"); });
注意这里的,SWG1要和上面的SWG1名称保存一直。
在配置一下 launchSettings.json
"profiles": { "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "launchUrl": "swagger/index.html", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "WebSwagger": { "commandName": "Project", "launchBrowser": true, "launchUrl": "weatherforecast", "applicationUrl": "http://localhost:5000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } }
运行项目之后
相关推荐
XuDanT 2020-09-16
Qizonghui 2020-05-28
pontuss 2020-05-08
SAMXIE 2020-11-04
permanent00 2020-09-15
哈嘿Blog 2020-09-08
Qizonghui 2020-08-02
莫问前程 2020-08-02
SAMXIE 2020-07-26
XuDanT 2020-07-24
莫问前程 2020-07-18
Qizonghui 2020-07-18
coolhty 2020-07-05
Qizonghui 2020-06-28
Qizonghui 2020-06-25
莫问前程 2020-06-22
SAMXIE 2020-06-14
莫问前程 2020-06-14
XuDanT 2020-06-07