swagger的配置
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "API接口文档", Version = "v1", Description = "开发接口调试.", Contact = new Contact { Name = "ListXiong", Email = "", }, TermsOfService = "None" } ); //注释 c.IncludeXmlComments(GetXmlCommentsPath()); }); services.AddSupportServices(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc(); app.UseSwagger(c => { c.RouteTemplate = "doc/{documentName}/swagger.json"; }); app.UseSwaggerUI(c => { c.RoutePrefix = "doc"; c.SwaggerEndpoint("/doc/v1/swagger.json", "API v1"); }); app.UseStaticFiles(); } /// <summary> /// 获取XML文档地址 /// </summary> /// <returns></returns> private string GetXmlCommentsPath() { var app = PlatformServices.Default.Application; return Path.Combine(app.ApplicationBasePath, Path.ChangeExtension(app.ApplicationName, "xml")); }