" V1 Docs " );});} 4.删除Properties/launchSettings.json中的"lau

时间:2022-04-25 03:58:05

1.项目右键-打点NuGet措施包添加Swashbuckle.AspNetCore

" V1 Docs " );});} 4.删除Properties/launchSettings.json中的"lau

2.改削Startup.cs中的ConfigureServices要领

public void ConfigureServices(IServiceCollection services) { services.AddMvc().AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new DefaultContractResolver(); }); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info { Title = "My API", Version = "v1" }); }); }

3.改削Startup.cs中的Configure要领

public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc(); app.UseSwagger(c => { c.PreSerializeFilters.Add((swagger, httpReq) => swagger.Host = httpReq.Host.Value); }); app.UseSwaggerUI(c => { c.RoutePrefix = ""; // serve the UI at root c.SwaggerEndpoint("/swagger/v1/swagger.json", "V1 Docs"); }); }

4.删除Properties/launchSettings.json中的 "launchUrl": "api/values",

" V1 Docs " );});} 4.删除Properties/launchSettings.json中的"lau

5.此时可以使用Swagger

" V1 Docs " );});} 4.删除Properties/launchSettings.json中的"lau