using Microsoft.AspNetCore.Authorization; using Swashbuckle.AspNetCore.Swagger; using Swashbuckle.AspNetCore.SwaggerGen; using System.Collections.Generic; using System.Linq; using Operation = Swashbuckle.AspNetCore.Swagger.Operation; namespace Bootstrap.Admin { /// /// /// public class HttpHeaderOperation : IOperationFilter { /// /// /// /// /// public void Apply(Operation operation, OperationFilterContext context) { if (operation.Parameters == null) operation.Parameters = new List(); if (context.MethodInfo.GetCustomAttributes(typeof(AllowAnonymousAttribute), true).Length == 0) { operation.Parameters.Add(new NonBodyParameter() { Name = "Authorization", //添加Authorization头部参数 In = "header", Type = "string", Required = false }); } } } }