安裝配置
1.NuGet安裝Swashbuckle.AspNetCore
2.在Startup中的Configure方法中添加
#region Swagger app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "ApiHelp V1"); c.RoutePrefix = "";//路徑配置,設置爲空,表示直接訪問該文件, }); #endregion
在ConfigureServices中添加
#region Swagger services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Version = "v0.1.0", Title = "test API", Description = "框架說明文檔", TermsOfService = "None", Contact = new Swashbuckle.AspNetCore.Swagger.Contact { Name = "Testapi", Email = "Testapi.com", Url = "http://test:3334" } }); }); #endregion
根據VS提示新建info,contact2個類。
3.Properties中的launchSettings.json,將2個launchUrl置空。
即可用