【发布时间】:2018-07-05 22:01:18
【问题描述】:
我正在使用 Swashbuckle.AspNetCore.Swagger (1.0.0) 和 Swashbuckle.AspNetCore.SwaggerGen (1.0.0)。我正在尝试在Default model example in Swashbuckle (Swagger) 之后向我的 API 添加默认示例。我创建了一个新的类文件并添加了,
public class SwaggerDefaultValue : Attribute
{
public string ParameterName { get; set; }
public string Value { get; set; }
public SwaggerDefaultValue(string parameterName, string value)
{
this.ParameterName = parameterName;
this.Value = value;
}
}
public class AddDefaultValues : IOperationFilter
{
public void Apply(Operation operation, DataTypeRegistry dataTypeRegistry, ApiDescription apiDescription)
{
foreach (var param in operation.Parameters)
{
var actionParam = apiDescription.ActionDescriptor.GetParameters().First(p => p.ParameterName == param.Name);
if (actionParam != null)
{
var customAttribute = actionParam.ActionDescriptor.GetCustomAttributes<SwaggerDefaultValue>().FirstOrDefault();
if (customAttribute != null)
{
param.DefaultValue = customAttribute.Value;
}
}
}
}
}
但我收到此错误 - AddDefaultValues does not implement interface member IOperationFilter.Apply(Operation, OperationFilterContext)
【问题讨论】:
标签: asp.net-core swagger swashbuckle