2018-10-24 17:12:16 +08:00
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class HttpHeaderOperation : IOperationFilter
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="operation"></param>
|
|
|
|
|
/// <param name="context"></param>
|
|
|
|
|
public void Apply(Operation operation, OperationFilterContext context)
|
|
|
|
|
{
|
|
|
|
|
if (operation.Parameters == null) operation.Parameters = new List<IParameter>();
|
|
|
|
|
|
2019-01-12 15:54:05 +08:00
|
|
|
|
if (context.MethodInfo.GetCustomAttributes(typeof(AllowAnonymousAttribute), true).Length == 0)
|
2018-10-24 17:12:16 +08:00
|
|
|
|
{
|
|
|
|
|
operation.Parameters.Add(new NonBodyParameter()
|
|
|
|
|
{
|
|
|
|
|
Name = "Authorization", //添加Authorization头部参数
|
|
|
|
|
In = "header",
|
|
|
|
|
Type = "string",
|
|
|
|
|
Required = false
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|