using IGeekFan.AspNetCore.Knife4jUI; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.OpenApi.Models; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "API V1", Version = "v1" }); var filePath = Path.Combine(System.AppContext.BaseDirectory, "AspNetCore7Api.xml"); c.IncludeXmlComments(filePath, true); }); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseKnife4UI(c => { c.RoutePrefix = "swagger"; // serve the UI at root c.SwaggerEndpoint("/v1/swagger.json", "V1 Docs"); }); } app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapSwagger("/k4/{documentName}/swagger.json"); }); app.Run();