swagger 分组

This commit is contained in:
youngq 2024-06-28 10:59:25 +08:00
parent fb83651055
commit f1bf00f4b5
8 changed files with 49 additions and 2 deletions

View File

@ -12,6 +12,7 @@ using WGShare.Domain.FriendlyException;
namespace WGShare.API.Controllers
{
[ApiExplorerSettings(GroupName = "public")]
[Route("auth")]
public class AuthController : BasicController
{

View File

@ -11,6 +11,7 @@ using Yitter.IdGenerator;
namespace WGShare.API.Controllers.Backend
{
[ApiExplorerSettings(GroupName = "backend")]
[Route("be/perm")]
public class PremController : BasicController
{

View File

@ -8,6 +8,7 @@ using Yitter.IdGenerator;
namespace WGShare.API.Controllers.Backend
{
[ApiExplorerSettings(GroupName = "backend")]
[Route("be/role")]
public class RoleController : BasicController
{

View File

@ -11,6 +11,7 @@ using Yitter.IdGenerator;
namespace WGShare.API.Controllers.Backend
{
[ApiExplorerSettings(GroupName = "backend")]
[Route("be/tenant")]
public class TenantController : BasicController
{

View File

@ -11,6 +11,7 @@ using Yitter.IdGenerator;
namespace WGShare.API.Controllers.Backend
{
[ApiExplorerSettings(GroupName = "backend")]
[Route("be/user")]
public class UserController : BasicController
{

View File

@ -13,6 +13,7 @@ namespace WGShare.API.Controllers.Frontend
/// <summary>
/// 首页接口
/// </summary>
[ApiExplorerSettings(GroupName = "frontend")]
[Route("home")]
public class HomeController : BasicController
{

View File

@ -19,6 +19,7 @@ namespace WGShare.API.Controllers.Frontend
/// <summary>
/// 会议室接口
/// </summary>
[ApiExplorerSettings(GroupName = "frontend")]
[Route("room")]
public class RoomController : BasicController
{

View File

@ -1,3 +1,4 @@
using Microsoft.OpenApi.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
@ -36,7 +37,40 @@ namespace WGShare.API
});
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddSwaggerGen(w =>
{
w.SwaggerDoc("frontend", new OpenApiInfo { Title = "前端", Version = "frontend" });
w.SwaggerDoc("backend", new OpenApiInfo { Title = "后端", Version = "backend" });
w.SwaggerDoc("public", new OpenApiInfo { Title = "公共接口", Version = "public" });
w.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
Name = "Authorization",
In = ParameterLocation.Header,
Type = SecuritySchemeType.ApiKey,
Scheme = "Bearer"
});
w.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "Bearer"
}
},
new string[] {}
}
});
//string xmlPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SwaggerGroup.xml");
//w.IncludeXmlComments(xmlPath, true);
}
);
builder.Services.AddSingleton(new JwtHelper(configuration));
builder.Services.AddAuth(configuration["Jwt:Issuer"],
configuration["Jwt:Audience"],
@ -64,7 +98,13 @@ namespace WGShare.API
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint($"/swagger/frontend/swagger.json", "前端");
options.SwaggerEndpoint($"/swagger/backend/swagger.json", "后端");
options.SwaggerEndpoint($"/swagger/public/swagger.json", "公共接口");
});
app.UseCustomCors();
}