【问题标题】:Adding Model information to swagger output将模型信息添加到大摇大摆的输出中
【发布时间】:2016-05-12 19:00:26
【问题描述】:

有没有办法在 swagger 输出中添加模型信息,例如有效值、默认值、摘要和其他备注?

例如在 c# 中,我如何将以下 cmets 和属性添加到 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; }
        }
    }
}

【问题讨论】:

    标签: c# swagger swashbuckle


    【解决方案1】:

    您需要在项目属性中启用 XML 文档文件创建: 项目属性 > 构建 > 检查 XML 文档文件框

    然后您可以取消注释或将以下行添加到您的 SwaggerConfig.cs 文件中: c.IncludeXmlComments(GetXmlCommentsPath());

    【讨论】:

    【解决方案2】:

    根据 Swashbuckle github,您可以启用 XML cmets,这将允许您相应地添加元数据。

    httpConfiguration
        .EnableSwagger(c =>
            {
                c.SingleApiVersion("v1", "A title for your API");
                c.IncludeXmlComments(GetXmlCommentsPathForControllers());
                c.IncludeXmlComments(GetXmlCommentsPathForModels());
            });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-29
      • 2014-07-19
      • 2015-12-14
      • 1970-01-01
      • 2018-12-21
      • 1970-01-01
      相关资源
      最近更新 更多