向Swagger UI中的Example Value添加注释



我正试图将代码中的摘要注释添加到Swagger UI中的示例值字段中。但是,注释仅在Schema字段中可见。有没有办法将注释也包括在示例值中(例如作为额外的参数或额外的行(?我使用的只是一个基本的天气预报模板代码与Swashbuckle。

这是我的GET端点:

[HttpGet("weather")]
[Produces("application/vnd.ms-excel")]
public IEnumerable<WeatherForecast> Get()
{
...
}

这是我的型号:

/// <summary>
///     Object containing the weather forecast data.
/// </summary>
public class WeatherForecast
{
/// <summary>
///     Date of the forecast.
/// </summary>
/// <example>01/01/2022 12:00:00</example>
public DateTime Date { get; set; }
/// <summary>
///     Temperature in Celsius.
/// </summary>
/// <example>20</example>>
public int TemperatureC { get; set; }
/// <summary>
///     Temperature in Fahrenheit.
/// </summary>
/// <example>68</example>
public int TemperatureF => 32 + (int) (TemperatureC / 0.5556);
/// <summary>
///     Summary of the forecast.
/// </summary>
/// <example>Chilly</example>
public string? Summary { get; set; }
}

这是我的Swagger配置:

builder.Services.AddSwaggerGen(c =>
{
c.IncludeXmlComments(string.Format(@"{0}MyAPIProject.xml",AppDomain.CurrentDomain.BaseDirectory));
c.ExampleFilters();
});

尝试根据文档添加https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-6.0&tabs=visual studio

<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>

最新更新