c# - Asp.Net Core Swagger/FromForm///(三斜线)注释没有被拾取?

标签 c# asp.net-core swagger swagger-ui

我有一个看起来像这样的 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/

相关文章:

c# - GUI 不在同一线程中更新 c# winforms

c# - 使用包括目录的 FQDN 发送电子邮件

c# - 检查 Active Directory 角色花费的时间太长

asp.net-core - .NET Core 2 和 Font Awesome。如何在构建时将 webfonts 从 node_modules 复制到 wwwroot?

c# - xUnit - 显示理论成员数据的测试名称 (TestCase)

c# - 查询表达式中的语法错误(缺少运算符)

c# - .net 核心注入(inject)和解析服务

node.js - 如何为包含许多 Swagger 定义 .json/.yml 文件的目录组织/构建 Swagger UI 界面

java - 如何使用 Swagger 生成的客户端 (Feign)

api - 在正常路线旁边使用 Swagger for Express