2

Is there a way to add model information, like valid values, default values, summary, and other remarks into the swagger output?

For instance in c# how would I add the following comments and attributes into 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; }
        }
    }
}
chhenning
  • 2,017
  • 3
  • 26
  • 44

2 Answers2

4

You will need to enable XML documentation file creation in your project properties: Project Properties > Build > Check the XML Documentation File box

Then you can uncomment or add the following line to your SwaggerConfig.cs file: c.IncludeXmlComments(GetXmlCommentsPath());

Brian P
  • 1,569
  • 13
  • 23
  • 2
    It also is very important that the generated XML documents are always up to date! http://stackoverflow.com/questions/21895257/how-can-xml-documentation-for-web-api-include-documentation-from-beyond-the-main – chhenning May 12 '16 at 21:42
2

According to the Swashbuckle github, you can enable XML comments which will allow you to add the metadata accordingly.

httpConfiguration
    .EnableSwagger(c =>
        {
            c.SingleApiVersion("v1", "A title for your API");
            c.IncludeXmlComments(GetXmlCommentsPathForControllers());
            c.IncludeXmlComments(GetXmlCommentsPathForModels());
        });
venerik
  • 5,766
  • 2
  • 33
  • 43