1.在ConfigureSwaggerServices中配置SwaggerDoc,并options.DocInclusionPredicate((doc, desc) => { return doc == desc.GroupName; });这句话可以删除也可以改成这样去写
private static void ConfigureSwaggerServices(ServiceConfigurationContext context, IConfiguration configuration) { context.Services.AddSwaggerGen(options => { options.SwaggerDoc("v1", new OpenApiInfo { Title = "MH业务.WebApi", Version = "v1" }); options.SwaggerDoc("v2", new OpenApiInfo { Title = "WGG业务.WebApi", Version = "v2" }); options.SwaggerDoc("v3", new OpenApiInfo { Title = "WJB业务.WebApi", Version = "v3" }); options.SwaggerDoc("v4", new OpenApiInfo { Title = "ZRN业务.WebApi", Version = "v4" }); options.SwaggerDoc("v5", new OpenApiInfo { Title = "LHY业务.WebApi", Version = "v5" }); options.SwaggerDoc("v6", new OpenApiInfo { Title = "公共业务.WebApi", Version = "v6" }); options.DocInclusionPredicate((doc, desc) => { return doc == desc.GroupName; }); //开启权限小锁 options.OperationFilter<AddResponseHeadersFilter>(); options.OperationFilter<AppendAuthorizeToSummaryOperationFilter>(); options.OperationFilter<SecurityRequirementsOperationFilter>(); //在header中添加token,传递到后台 options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme { Description = "JWT授权(数据将在请求头中进行传递)直接在下面框中输入Bearer {token}(注意两者之间是一个空格) \"", Name = "Authorization",//jwt默认的参数名称 In = ParameterLocation.Header,//jwt默认存放Authorization信息的位置(请求头中) Type = SecuritySchemeType.ApiKey });
//注意 Abp要在Application的属性中开启XML文件
var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);//获取应用程序所在目录(绝对,不受工作目录影响,建议采用此方法获取路径)
var xmlPath = Path.Combine(basePath, "TMSLogistics.Application.xml"); // 添加 swagger xml 注释 这个xml文件开始是不存在的写上项目名.xml即可
options.IncludeXmlComments(xmlPath, true); }); }
2.在管道中添加 SwaggerEndpoint
app.UseSwagger(); app.UseAbpSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "MH业务.WebApi"); c.SwaggerEndpoint("/swagger/v2/swagger.json", "WGG业务.WebApi API"); c.SwaggerEndpoint("/swagger/v3/swagger.json", "WJB业务.WebApi API"); c.SwaggerEndpoint("/swagger/v4/swagger.json", "ZRN业务.WebApi API"); c.SwaggerEndpoint("/swagger/v5/swagger.json", "LHY业务.WebApi API"); c.SwaggerEndpoint("/swagger/v6/swagger.json", " 公共业务.WebApi"); });
3.引入using Microsoft.AspNetCore.Mvc;命名空间,在服务层添加 [ApiExplorerSettings(GroupName = "v1")]
4.服务层打开XML注释
标签:WebApi,Swgger,SwaggerEndpoint,Abp,分组,new,SwaggerDoc,swagger,options From: https://www.cnblogs.com/LaoMa0109/p/16913162.html