Sle*_*mer 6 c# swagger swagger-ui asp.net-core
我有一个如下所示的控制器方法:
[HttpPost]
[Consumes("application/x-www-form-urlencoded")]
[Produces("application/json")]
public async Task<IActionResult> GenerateTokenAsync([FromForm]TokenParameters tokenParameters)
Run Code Online (Sandbox Code Playgroud)
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;
}
}
Run Code Online (Sandbox Code Playgroud)
一切正常,但 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);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2957 次 |
| 最近记录: |