新增 版本設定,使api介面更加簡潔

This commit is contained in:
leo890808 2024-04-24 16:28:19 +08:00
parent c2698a66c2
commit dfb05c45d5

View File

@ -112,7 +112,20 @@ builder.Services.AddDbContext<SqlContext>(opt =>
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(); builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("校園外網", new OpenApiInfo
{
Version = "校園外網",
Title = "校園外網",
});
c.SwaggerDoc("校園大內網", new OpenApiInfo
{
Version = "校園大內網",
Title = "校園大內網",
});
});
//註解 //註解
builder.Services.AddSwaggerGen(options => builder.Services.AddSwaggerGen(options =>
@ -129,7 +142,11 @@ var app = builder.Build();
// app.UseSwaggerUI(); // app.UseSwaggerUI();
//} //}
app.UseSwagger(); app.UseSwagger();
app.UseSwaggerUI(); app.UseSwaggerUI(c=>
{
c.SwaggerEndpoint("/swagger/校園外網/swagger.json", "校園外網");
c.SwaggerEndpoint("/swagger/校園大內網/swagger.json", "校園大內網");
});
//在 ASP.NET Core 中啟用 CORS (跨原始來源要求) //在 ASP.NET Core 中啟用 CORS (跨原始來源要求)
// Shows UseCors with CorsPolicyBuilder. // Shows UseCors with CorsPolicyBuilder.
app.UseCors(builder => app.UseCors(builder =>