C# 将模型信息添加到swagger输出
是否有方法将模型信息(如有效值、默认值、摘要和其他注释)添加到swagger输出中 例如,在c#中,我如何将以下注释和属性添加到swagger中C# 将模型信息添加到swagger输出,c#,swagger,swashbuckle,C#,Swagger,Swashbuckle,是否有方法将模型信息(如有效值、默认值、摘要和其他注释)添加到swagger输出中 例如,在c#中,我如何将以下注释和属性添加到swagger中 /// <summary> /// A clear summary /// </summary> /// <remarks> /// Some remarks /// </remarks> public class A { public A() { _Field_A = 0
/// <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; }
}
}
}
//
///明确的总结
///
///
///一些评论
///
公共A类
{
公共A()
{
_字段_A=0;
_字段_B=string.Empty;
}
私有整型字段{get;set;}
[范围(0,150)]
公共int字段
{
得到
{
返回_字段_A;
}
设置
{
如果(value!=null){u字段\ u A=value;}
}
}
私有字符串_字段_B{get;set;}
///
///字段B摘要
///
公共字符串字段
{
得到
{
返回_字段_B;
}
设置
{
如果(value!=null){u字段\ u B=value;}
}
}
}
您需要在项目属性中启用XML文档文件创建:
项目属性>生成>选中XML文档文件框
然后,可以取消注释或将以下行添加到SwaggerConfig.cs文件中:
c.includexmlcoments(getxmlcomentspath())代码>根据Swashback,您可以启用XML注释,这将允许您相应地添加元数据
httpConfiguration
.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "A title for your API");
c.IncludeXmlComments(GetXmlCommentsPathForControllers());
c.IncludeXmlComments(GetXmlCommentsPathForModels());
});
生成的XML文档始终是最新的,这一点也非常重要!