Include="Swashbuckle.AspNetCore" Version="6.4.0"
Include="Swashbuckle.AspNetCore.Filters" Version="7.0.5"
Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.4.0"
2.
Program添加swagger服务
using Microsoft.OpenApi.Models;
using System.Reflection;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
builder.Services.AddSwaggerGen(options =>
options.SwaggerDoc("v1", new OpenApiInfo
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Wechat Doc", Version = "v1" });
c.CustomSchemaIds((type) => type.FullName);
var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);
var apiXmlPath = Path.Combine(basePath, "xxx.xxx.Client.xml");
var entityXmlPath = Path.Combine(basePath, "xxx.xxxx.Application.xml");
c.IncludeXmlComments(apiXmlPath);
c.IncludeXmlComments(entityXmlPath);
c.OperationFilter<HttpAuthHeaderFilter>();
services.AddSwaggerGenNewtonsoftSupport();
var app = builder.Build();
if (!app.Environment.IsDevelopment())
app.UseSwagger();
app.UseSwaggerUI(c =>
c.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
c.RoutePrefix = string.Empty;
c.DocExpansion(Swashbuckle.AspNetCore.SwaggerUI.DocExpansion.None);
c.DefaultModelsExpandDepth(-1);
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
复制代码