我有一个看起来像这样的 Controller 方法:
[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 没有为成员提取///三重斜杠注释。我的其他 Controller 使用 FromBody 和///三重斜杠注释与它们配合得很好。看起来底部的模型部分会提取评论,但当我查看 Controller 时,我说的是浅绿色部分中的模型描述。
我查看了模式注册表,描述确实存在。
编辑:使用 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);
});
关于c# - Asp.Net Core Swagger/FromForm///(三斜线)注释没有被拾取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54083757/