有没有办法将模型信息(如有效值、默认值、摘要和其他备注)添加到 swagger 输出中?
例如在 c# 中,我如何将以下注释和属性添加到 swagger 中?
/// <summary>
/// A clear summary
/// </summary>
/// <remarks>
/// Some remarks
/// </remarks>
public class A
{
public A()
{
_Field_A = 0;
_Field_B = string.Empty;
}
private int _Field_A { get; set; }
[Range(0, 150)]
public int Field_A
{
get
{
return _Field_A;
}
set
{
if (value != null) { _Field_A = value; }
}
}
private string _Field_B { get; set; }
/// <summary>
/// Field_B summary
/// </summary>
public string Field_B
{
get
{
return _Field_B;
}
set
{
if (value != null) { _Field_B = value; }
}
}
}
最佳答案
您需要在项目属性中启用 XML 文档文件创建: 项目属性 > 构建 > 检查 XML 文档文件框
然后您可以取消注释或将以下行添加到您的 SwaggerConfig.cs 文件中:
c.IncludeXmlComments(GetXmlCommentsPath());
关于c# - 将模型信息添加到 swagger 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37195375/