忽略属性我使用Swashbuckle产生了webapi2项目招摇的文档\ UI。我们的模型与一些传统界面共享,因此我想在模型上忽略一些属性。我无法使用JsonIgnore属性,因为旧接口也需要序列化为JSON,因此我不想忽略全局属性,只需在Swashbuckle配置中。如何Swashbuckle配置对模型
我发现这样做在此处介绍的方法:
https://github.com/domaindrivendev/Swashbuckle/issues/73
但是这似乎是过时的当前Swashbuckle释放。
public class OmitIgnoredProperties : IModelFilter
{
public void Apply(DataType model, DataTypeRegistry dataTypeRegistry, Type type)
{
var ignoredProperties = // use reflection to find any properties on type decorated with the ignore attributes
foreach (var prop in ignoredProperties)
{
model.Properties.Remove(prop.Name);
}
}
}
SwaggerSpecConfig.Customize(c => c.ModelFilter<OmitIgnoredProperties>());
但我不能确定如何配置Swashbuckle使用IModelFilter在当前版本:
的方法推荐用于旧版本Swashbuckle的如下使用IModelFilter实现?我正在使用Swashbuckle 5.5.3。
可以实际上使用JsonIgno欢迎使用属性重新将不招摇 –
显示属性正如我不希望使用JsonIgnore因为我有遗留代码也需要使用模型中的问题中提到的,如果我申请JsonIgnore会影响招摇和遗留代码... – mutex