minimal api 测试
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-10-15 14:19:39 +08:00
parent 8e1ae18de0
commit 5d51ac562a
6 changed files with 78 additions and 125 deletions
@@ -43,70 +43,6 @@ public enum SwaggerVersion
public static class SwaggerSetup
{
public static void AddSwaggerSetupOld(this IServiceCollection services)
{
services.AddEndpointsApiExplorer();
services.AddSwaggerGen(options =>
{
typeof(SwaggerVersion).GetFields(BindingFlags.Public | BindingFlags.Static).ToList()
.ForEach(field =>
{
var description = field.GetCustomAttribute<DescriptionAttribute>()?.Description ?? field.Name;
options.SwaggerDoc(field.Name, new Microsoft.OpenApi.Models.OpenApiInfo
{
Version = field.Name,
Description = $"{field.Name} API",
Title = description // 使用Description作为Title
});
});
// 接口排序
options.OrderActionsBy(o => o.GroupName);
options.DocInclusionPredicate((docName, apiDes) =>
{
if (!apiDes.TryGetMethodInfo(out MethodInfo methodInfo)) return false;
var versions = methodInfo.DeclaringType.GetCustomAttributes(true)
.OfType<ApiExplorerSettingsAttribute>()
.Select(attr => attr.GroupName);
return versions.Any(v => v.ToString() == docName);
});
//添加注释
var basePath = AppContext.BaseDirectory;
var xmlPath1 = Path.Combine(basePath, "IRaCIS.Core.Application.xml");
var xmlPath2 = Path.Combine(basePath, "IRaCIS.Core.API.xml");
options.IncludeXmlComments(xmlPath1, true);
options.IncludeXmlComments(xmlPath2, true);
// 在header中添加token,传递到后台
options.OperationFilter<SecurityRequirementsOperationFilter>();
// 添加登录按钮
options.AddSecurityDefinition("bearerAuth", new OpenApiSecurityScheme()
{
Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
Name = "Authorization",
//In = "header",
//Type = "apiKey"
});
//// 添加登录按钮
//options.AddSecurityDefinition("bearerAuth", new OpenApiSecurityScheme()
//{
// Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
// Name = "Authorization",
// //In = "header",
// //Type = "apiKey"
//});
});
}
public static void AddSwaggerSetup(this IServiceCollection services)
{
services.AddEndpointsApiExplorer();