Reputation: 2077
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; }
}
}
}
Upvotes: 2
Views: 2602
Reputation: 59
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());
});
Upvotes: 2
Reputation: 1587
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());
Upvotes: 4