是否可以在Swashbuckle.AspNetCore中隐藏一个Enum成员? [英] Is it possible to hide an Enum member in Swashbuckle.AspNetCore?
本文介绍了是否可以在Swashbuckle.AspNetCore中隐藏一个Enum成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个枚举
public enum SampleFormats
{
unknown = 0,
audio = 1,
video = 2,
}
是否可以用生成的swagger json排除的方式装饰unknown
成员?
Is it possible to decorate the unknown
member in a way that it is excluded by the generated swagger json?
我可能可以编写一个模式/文档过滤器,但是想知道是否有一些现成的东西.
I could possibly write a schema/document filter, but was wondering if there was something out of the box.
推荐答案
您可以尝试以下操作:
public enum SampleFormats
{
unknown = 0,
audio = 1,
video = 2,
}
public class ResultModel
{
public SampleFormats Format { get; set; }
[JsonIgnore]
public bool FormatSpecified
{
get { return Format != SampleFormats.unknown; }
}
public string Name { get; set; }
}
[HttpGet()]
[AllowAnonymous]
public async Task<ResultModel> Get()
{
return new ResultModel { Format = SampleFormats.unknown, Name = "Test" };
}
一个魔术技巧是后缀Specified
,该后缀表示属性将由Newtonsoft.Json呈现.
A magic trick is suffix Specified
that indicate a property would be rendered by Newtonsoft.Json
这篇关于是否可以在Swashbuckle.AspNetCore中隐藏一个Enum成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文