Swagger插件netcore配置

步驟1、html

Nuget Packages安裝,使用程序包管理器控制檯,安裝命令:Install-Package Swashbuckle.AspNetCore -Prejson

步驟2、bash

在Startup 文件中添加配置:app

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");//右鍵項目屬性,生成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.UseMvc();   app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "MsSystem API V1"); }); }
直接訪問地址 http://localhost:*/swagger/index.html
相關文章
相關標籤/搜索