c# - Asp.Net Core Swagger / FromForm ///(三斜杠)评论没有被拾起?
问题描述
我有一个如下所示的控制器方法:
[HttpPost]
[Consumes("application/x-www-form-urlencoded")]
[Produces("application/json")]
public async Task<IActionResult> GenerateTokenAsync([FromForm]TokenParameters tokenParameters)
TokenParameters 看起来像这样:
public class TokenParameters
{
/// <summary>
/// Specifies the grant type. Must be "password".
/// </summary>
[Required]
public GrantType? grant_type
{
get;
set;
}
/// <summary>
/// Specifies the username.
/// </summary>
[Required]
public string username
{
get;
set;
}
/// <summary>
/// Specifies the password.
/// </summary>
[Required]
public string password
{
get;
set;
}
}
一切正常,但 Swagger UI 没有为成员接收 /// 三斜杠评论。我的其他控制器使用 FromBody 和 /// 三斜杠注释可以很好地处理这些。看起来底部的模型部分接受了评论,但是当我查看控制器时,我正在谈论浅绿色部分中的模型描述。
我查看了模式注册表,描述确实在那里。
编辑:使用 Swashbuckle 5.0 Beta。
编辑#2:它似乎也没有从模式注册表中获取表单参数的示例值。
有任何想法吗?
解决方案
确保您的项目已Generate xml documentation
选中该选项。
此外,当您配置 Swagger 时,请确保它包含 xml 注释。
// Register the Swagger generator, defining one or more Swagger documents
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v2", new Info { Title = "my API", Version = "v2" });
// Set the comments path for the Swagger JSON and UI.
var basePath = PlatformServices.Default.Application.ApplicationBasePath;
var xmlPath = Path.Combine(basePath, "myapp.xml");
c.IncludeXmlComments(xmlPath);
});
推荐阅读
- r - 功能主成分分数的双图
- reactjs - 有没有在 React 中使用锚标签的特定方法?
- php - 合并长度不等的数组
- python-2.7 - 从 blob 下载文件
- c++ - 如何使用非平凡(POD)类的缓冲区协议实现 pybind11
- typescript - 定义具有可选第一个和最后一个元素的元组列表
- r - R data.table 按条件分组的最后一行的二进制值
- macos - 当可可中不存在 NSNavigationController 时,macOS 中的系统偏好设置应用程序使用什么来在项目及其详细信息之间导航?
- r - 如何通过两个变量总结关键统计数据?
- php - 是否可以使用 PHP 生成 WAV 文件?