.NET Core WebAPI Swagger使用
2017-04-05 10:58
585 查看
相对于普通的webapi而言,.net core webapi本身并不具备文档的功能,所以可以借助第三方插件:swagger,使用的话很简单。
步骤一、
Nuget Packages安装,使用程序包管理器控制台,安装命令:
步骤二、
在Startup 文件中添加配置:
然后直接访问地址 http://localhost:44632/swagger/
效果图:
参考地址:
https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-help-pages-using-swagger
步骤一、
Nuget Packages安装,使用程序包管理器控制台,安装命令:
Install-Package Swashbuckle.AspNetCore -Pre
步骤二、
在Startup 文件中添加配置:
public void ConfigureServices(IServiceCollection services) {// Add framework services. services.AddMvc() .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver());//JSON首字母小写解决 services.AddSwaggerGen(options => { options.SwaggerDoc("v1", new Info { Version = "v1", Title = "MsSystem API" }); //Determine base path for the application. var basePath = PlatformServices.Default.Application.ApplicationBasePath; //Set the comments path for the swagger json and ui. var xmlPath = Path.Combine(basePath, "MsSystem.API.xml"); options.IncludeXmlComments(xmlPath); }); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } //app.UseStaticFiles(); app.UseMvc(); //app.UseMvc(routes => //{ // routes.MapRoute( // name: "default", // template: "api/{controller}/{action}", // defaults: new { controller = "Home", action = "Index" }); //}); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "MsSystem API V1"); }); }
然后直接访问地址 http://localhost:44632/swagger/
效果图:
参考地址:
https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-help-pages-using-swagger
相关文章推荐
- Asp.net Core WebApi 使用Swagger做帮助文档,并且自定义Swagger的UI
- Asp .Net Core Web API的swagger 使用
- asp.net core webapi 使用swagger
- 使用Swagger来生成asp.net core Web API 文档
- 使用 Swagger 自动生成 ASP.NET Core Web API 的文档、在线帮助测试文档(ASP.NET Core Web API 自动生成文档)
- 在ASP.NET Core Web API上使用Swagger提供API文档
- 在ASP.NET Core Web API上使用Swagger提供API文档
- 在ASP.NET Core Web API上使用Swagger提供API文档
- ASP.NET Core WebApi使用Swagger生成api说明文档看这篇就够了
- 在ASP.NET Core Web API上使用Swagger提供API文档
- Asp.net core WebApi 使用Swagger生成帮助页实例
- asp.net core webapi swagger 使用二
- 使用 Swagger 自动生成 ASP.NET Core Web API 的文档、在线帮助测试文档(ASP.NET Core Web API 自动生成文档)
- Asp.net core WebApi 使用Swagger生成帮助页实例
- .net core webapi 使用Authorize身份认证
- 【swagger学习】.net WebApi中使用swagger
- .net WebApi中使用swagger
- 【译】使用Jwt身份认证保护 Asp.Net Core Web Api
- net WebApi中使用swagger
- [译]ASP.NET Core Web API 中使用Oracle数据库和Dapper看这篇就够了