引用
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
实现
public class ActionDesc : IOperationFilter
{
string documentName;
public ActionDesc(string documentName)
{
this.documentName = documentName;
}
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
//过滤处理
//context.ApiDescription.ActionDescriptor.FilterDescriptors;
var attrs = context.MethodInfo.GetCustomAttributes(true);
//context.ApiDescription.ActionDescriptor.DisplayName += "helloworld";
if (attrs != null && attrs.Length > 0)
{
if (attrs.Any(f => f.GetType() == typeof(HttpGetAttribute)))
{
//添加需要的注释
operation.Description += " This is a GET method action";
}
}
}
}
效果